Bläddra i källkod

[test] Update IPv6 tests to use okx()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 år sedan
förälder
incheckning
a454baaf11
1 ändrade filer med 39 tillägg och 25 borttagningar
  1. 39
    25
      src/tests/ipv6_test.c

+ 39
- 25
src/tests/ipv6_test.c Visa fil

@@ -70,22 +70,27 @@ static const struct in6_addr sample_multicast = {
70 70
  *
71 71
  * @v addr		IPv6 address
72 72
  * @v text		Expected textual representation
73
+ * @v file		Test code file
74
+ * @v line		Test code line
73 75
  */
76
+static void inet6_ntoa_okx ( const struct in6_addr *addr, const char *text,
77
+			     const char *file, unsigned int line ) {
78
+	char *actual;
79
+
80
+	actual = inet6_ntoa ( addr );
81
+	DBG ( "inet6_ntoa ( %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ) "
82
+	      "= %s\n", ntohs ( addr->s6_addr16[0] ),
83
+	      ntohs ( addr->s6_addr16[1] ), ntohs ( addr->s6_addr16[2] ),
84
+	      ntohs ( addr->s6_addr16[3] ), ntohs ( addr->s6_addr16[4] ),
85
+	      ntohs ( addr->s6_addr16[5] ), ntohs ( addr->s6_addr16[6] ),
86
+	      ntohs ( addr->s6_addr16[7] ), actual );
87
+	okx ( strcmp ( actual, text ) == 0, file, line );
88
+}
74 89
 #define inet6_ntoa_ok( addr, text ) do {				\
75 90
 	static const struct in6_addr in = {				\
76 91
 		.s6_addr = addr,					\
77 92
 	};								\
78
-	static const char expected[] = text;				\
79
-	char *actual;							\
80
-									\
81
-	actual = inet6_ntoa ( &in );					\
82
-	DBG ( "inet6_ntoa ( %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ) "	\
83
-	      "= %s\n", ntohs ( in.s6_addr16[0] ),			\
84
-	      ntohs ( in.s6_addr16[1] ), ntohs ( in.s6_addr16[2] ),	\
85
-	      ntohs ( in.s6_addr16[3] ), ntohs ( in.s6_addr16[4] ),	\
86
-	      ntohs ( in.s6_addr16[5] ), ntohs ( in.s6_addr16[6] ),	\
87
-	      ntohs ( in.s6_addr16[7] ), actual );			\
88
-	ok ( strcmp ( actual, expected ) == 0 );			\
93
+	inet6_ntoa_okx ( &in, text, __FILE__, __LINE__ );		\
89 94
 	} while ( 0 )
90 95
 
91 96
 /**
@@ -93,31 +98,40 @@ static const struct in6_addr sample_multicast = {
93 98
  *
94 99
  * @v text		Textual representation
95 100
  * @v addr		Expected IPv6 address
101
+ * @v file		Test code file
102
+ * @v line		Test code line
96 103
  */
104
+static void inet6_aton_okx ( const char *text, const struct in6_addr *addr,
105
+			     const char *file, unsigned int line ) {
106
+	struct in6_addr actual;
107
+
108
+	okx ( inet6_aton ( text, &actual ) == 0, file, line );
109
+	DBG ( "inet6_aton ( \"%s\" ) = %s\n", text, inet6_ntoa ( &actual ) );
110
+	okx ( memcmp ( &actual, addr, sizeof ( actual ) ) == 0,
111
+	      file, line );
112
+}
97 113
 #define inet6_aton_ok( text, addr ) do {				\
98
-	static const char string[] = text;				\
99
-	static const struct in6_addr expected = {			\
114
+	static const struct in6_addr in = {				\
100 115
 		.s6_addr = addr,					\
101 116
 	};								\
102
-	struct in6_addr actual;						\
103
-									\
104
-	ok ( inet6_aton ( string, &actual ) == 0 );			\
105
-	DBG ( "inet6_aton ( \"%s\" ) = %s\n", string,			\
106
-	      inet6_ntoa ( &actual ) );					\
107
-	ok ( memcmp ( &actual, &expected, sizeof ( actual ) ) == 0 );	\
117
+	inet6_aton_okx ( text, &in, __FILE__, __LINE__ );		\
108 118
 	} while ( 0 )
109 119
 
110 120
 /**
111 121
  * Report an inet6_aton() failure test result
112 122
  *
113 123
  * @v text		Textual representation
124
+ * @v file		Test code file
125
+ * @v line		Test code line
114 126
  */
115
-#define inet6_aton_fail_ok( text ) do {					\
116
-	static const char string[] = text;				\
117
-	struct in6_addr dummy;						\
118
-									\
119
-	ok ( inet6_aton ( string, &dummy ) != 0 );			\
120
-	} while ( 0 )
127
+static void inet6_aton_fail_okx ( const char *text, const char *file,
128
+				  unsigned int line ) {
129
+	struct in6_addr dummy;
130
+
131
+	okx ( inet6_aton ( text, &dummy ) != 0, file, line );
132
+}
133
+#define inet6_aton_fail_ok( text )					\
134
+	inet6_aton_fail_okx ( text, __FILE__, __LINE__ )
121 135
 
122 136
 /**
123 137
  * Perform IPv6 self-tests

Laddar…
Avbryt
Spara