Pārlūkot izejas kodu

Adds Epath tests, adds non-idling OPENER_ASSERT

CapXilinx 9 gadi atpakaļ
vecāks
revīzija
054a6110a1

+ 1 - 0
source/src/cip/cipepath.c

@@ -203,6 +203,7 @@ void SetPathPortSegmentExtendedPortIdentifier(
 
 
 LogicalSegmentLogicalType GetPathLogicalSegmentLogicalType(
 LogicalSegmentLogicalType GetPathLogicalSegmentLogicalType(
     const char *const cip_path) {
     const char *const cip_path) {
+  OPENER_ASSERT(kSegmentTypeLogicalSegment == GetPathSegmentType(cip_path));
   const unsigned int kLogicalTypeMask = 0x1C;
   const unsigned int kLogicalTypeMask = 0x1C;
   const unsigned int logical_type = (*cip_path) & kLogicalTypeMask;
   const unsigned int logical_type = (*cip_path) & kLogicalTypeMask;
   LogicalSegmentLogicalType result = kLogicalSegmentLogicalTypeExtendedLogical;
   LogicalSegmentLogicalType result = kLogicalSegmentLogicalTypeExtendedLogical;

+ 1 - 0
source/src/cip/cipepath.h

@@ -78,5 +78,6 @@ unsigned int GetPathPortSegmentExtendedPortNumber(const char *const cip_path);
 void SetPathPortSegmentExtendedPortIdentifier(
 void SetPathPortSegmentExtendedPortIdentifier(
     const unsigned int extended_port_identifier, char *const cip_path);
     const unsigned int extended_port_identifier, char *const cip_path);
 
 
+LogicalSegmentLogicalType GetPathLogicalSegmentLogicalType(const char *const cip_path);
 
 
 #endif /* SRC_CIP_CIPEPATH_H_ */
 #endif /* SRC_CIP_CIPEPATH_H_ */

+ 1 - 1
source/src/cip/ciptypes.h

@@ -39,7 +39,7 @@ typedef enum {
   kLogicalSegmentLogicalTypeAttributeId, /**< Attribute ID */
   kLogicalSegmentLogicalTypeAttributeId, /**< Attribute ID */
   kLogicalSegmentLogicalTypeSpecial, /**< Special */
   kLogicalSegmentLogicalTypeSpecial, /**< Special */
   kLogicalSegmentLogicalTypeServiceId, /**< Service ID */
   kLogicalSegmentLogicalTypeServiceId, /**< Service ID */
-  kLogicalSegmentLogicalTypeExtendedLogical/**< Extended Logical */
+  kLogicalSegmentLogicalTypeExtendedLogical /**< Extended Logical */
 } LogicalSegmentLogicalType;
 } LogicalSegmentLogicalType;
 
 
 typedef enum {
 typedef enum {

+ 5 - 0
source/src/ports/POSIX/sample_application/opener_user_conf.h

@@ -25,6 +25,7 @@
 #include <sys/socket.h>
 #include <sys/socket.h>
 #include <arpa/inet.h>
 #include <arpa/inet.h>
 #include <sys/select.h>
 #include <sys/select.h>
+#include <assert.h>
 
 
 #include "typedefs.h"
 #include "typedefs.h"
 
 
@@ -116,6 +117,7 @@ static const int kOpenerProducedDataHasRunIdleHeader = 0;
 /** @brief A specialized assertion command that will log the assertion and block
 /** @brief A specialized assertion command that will log the assertion and block
  *  further execution in an while(1) loop.
  *  further execution in an while(1) loop.
  */
  */
+#ifdef IDLING_ASSERT
 #define OPENER_ASSERT(assertion) \
 #define OPENER_ASSERT(assertion) \
     do { \
     do { \
       if(!(assertion)) { \
       if(!(assertion)) { \
@@ -129,6 +131,9 @@ static const int kOpenerProducedDataHasRunIdleHeader = 0;
 //#include <stdio.h>
 //#include <stdio.h>
 //#define OPENER_ASSERT(assertion) assert(assertion)
 //#define OPENER_ASSERT(assertion) assert(assertion)
 #else
 #else
+#define OPENER_ASSERT(assertion) assert(assertion)
+#endif
+#else
 
 
 /* for release builds execute the assertion, but don't test it */
 /* for release builds execute the assertion, but don't test it */
 #define OPENER_ASSERT(assertion) (assertion)
 #define OPENER_ASSERT(assertion) (assertion)

+ 55 - 0
source/tests/cip/cipepathtest.cpp

@@ -117,3 +117,58 @@ TEST(CipEpath, SetPortSegmentExtendedPortNoExtendedAddress) {
   SetPathPortSegmentExtendedPortIdentifier((unsigned int)25634, message);
   SetPathPortSegmentExtendedPortIdentifier((unsigned int)25634, message);
   MEMCMP_EQUAL(expected_message, message, 3);
   MEMCMP_EQUAL(expected_message, message, 3);
 }
 }
+
+TEST(CipEpath, SetPortSegmentExtendedPortWithExtendedAddress) {
+  char message[] = {0x10, 0x00, 0x00, 0x00};
+  const char expected_message[] = {0x1F, 0x00, 0x22, 0x64};
+  SetPathPortSegmentExtendedPortIdentifier((unsigned int)25634, message);
+  MEMCMP_EQUAL(expected_message, message, 4);
+}
+
+TEST(CipEpath, GetLogicalSegmentLogicalTypeClassId) {
+  const char message[] = {0x20};
+  const LogicalSegmentLogicalType type = GetPathLogicalSegmentLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentLogicalTypeClassId, type);
+}
+
+TEST(CipEpath, GetLogicalSegmentLogicalTypeInstanceId) {
+  const char message[] = {0x24};
+  const LogicalSegmentLogicalType type = GetPathLogicalSegmentLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentLogicalTypeInstanceId, type);
+}
+
+TEST(CipEpath, GetLogicalSegmentLogicalTypeMemberId) {
+  const char message[] = {0x28};
+  const LogicalSegmentLogicalType type = GetPathLogicalSegmentLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentLogicalTypeMemberId, type);
+}
+
+TEST(CipEpath, GetLogicalSegmentLogicalTypeConnectionPoint) {
+  const char message[] = {0x2C};
+  const LogicalSegmentLogicalType type = GetPathLogicalSegmentLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentLogicalTypeConnectionPoint, type);
+}
+
+TEST(CipEpath, GetLogicalSegmentLogicalTypeAttributeId) {
+  const char message[] = {0x30};
+  const LogicalSegmentLogicalType type = GetPathLogicalSegmentLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentLogicalTypeAttributeId, type);
+}
+
+TEST(CipEpath, GetLogicalSegmentLogicalTypeSpecial) {
+  const char message[] = {0x34};
+  const LogicalSegmentLogicalType type = GetPathLogicalSegmentLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentLogicalTypeSpecial, type);
+}
+
+TEST(CipEpath, GetLogicalSegmentLogicalTypeServiceId) {
+  const char message[] = {0x38};
+  const LogicalSegmentLogicalType type = GetPathLogicalSegmentLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentLogicalTypeServiceId, type);
+}
+
+TEST(CipEpath, GetLogicalSegmentLogicalTypeExtendedLogical) {
+  const char message[] = {0x3C};
+  const LogicalSegmentLogicalType type = GetPathLogicalSegmentLogicalType(message);
+  CHECK_EQUAL(kLogicalSegmentLogicalTypeExtendedLogical, type);
+}