[ovs-dev] [PATCH] test-csum: endianess fix

Flavio Leitner fbl at redhat.com
Fri Apr 10 14:07:50 UTC 2015


The math is done in network byte order so the 32 bits won't
match between big and little endian, so the assert fails.

Reduce to 16 bits and then compare to the converted constant.

Signed-off-by: Flavio Leitner <fbl at redhat.com>
---
 tests/test-csum.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tests/test-csum.c b/tests/test-csum.c
index 2685f67..cecdeb9 100644
--- a/tests/test-csum.c
+++ b/tests/test-csum.c
@@ -181,6 +181,7 @@ test_crc32c(void)
 static void
 test_pseudo(void)
 {
+    uint32_t csum;
     /* Try an IP header similar to one that the tunnel code
      * might generate. */
     struct ip_header ip = {
@@ -196,12 +197,14 @@ test_pseudo(void)
         .ip_dst = { .hi = htons(0x1400), .lo = htons(0x0001) }
     };
 
-    assert(packet_csum_pseudoheader(&ip) == 0x8628);
+    csum = csum_finish(packet_csum_pseudoheader(&ip));
+    assert(csum == htons(0xd779));
 
     /* And also test something totally different to check for
      * corner cases. */
     memset(&ip, 0xff, sizeof ip);
-    assert(packet_csum_pseudoheader(&ip) == 0x5c2fb);
+    csum = csum_finish(packet_csum_pseudoheader(&ip));
+    assert(csum == htons(0xff3c));
 
     mark('#');
 }
-- 
2.1.0




More information about the dev mailing list