X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Ftest-csum.c;h=c74133a7f320fad2cc02e48427c8fa357888dea9;hb=e379e4d167e31d1cd5f7b86fff091a2e09ff6e45;hp=b08f236f4120a30135136f84887c048cee641dab;hpb=8d32c1d34b235d08007c8cf5ab1d0eee139d9e47;p=sliver-openvswitch.git diff --git a/tests/test-csum.c b/tests/test-csum.c index b08f236f4..c74133a7f 100644 --- a/tests/test-csum.c +++ b/tests/test-csum.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, 2011 Nicira, Inc. + * Copyright (c) 2009, 2010, 2011, 2014 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ #include #include "csum.h" +#include "crc32c.h" #include #include #include @@ -24,6 +25,7 @@ #include "random.h" #include "unaligned.h" #include "util.h" +#include "ovstest.h" #undef NDEBUG #include @@ -136,8 +138,47 @@ test_rfc1624(void) mark('#'); } -int -main(void) +/* CRC32C checksum tests, based on Intel IPPs, Chapter 13, + * ippsCRC32C_8u() example, found at the following location: + * http://software.intel.com/sites/products/documentation/hpc/ipp/ipps/ */ +static void +test_crc32c(void) +{ + int i; + uint8_t data[48] = { + 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, + 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + /* iSCSI Read PDU */ + assert(ntohl(crc32c(data, 48)) == 0x563a96d9L); + + /* 32 bytes of all zeroes */ + for (i = 0; i < 32; i++) data[i] = 0x00; + assert(ntohl(crc32c(data, 32)) == 0xaa36918aL); + + /* 32 bytes of all ones */ + for (i = 0; i < 32; i++) data[i] = 0xff; + assert(ntohl(crc32c(data, 32)) == 0x43aba862L); + + /* 32 bytes of incrementing 00..1f */ + for (i = 0; i < 32; i++) data[i] = i; + assert(ntohl(crc32c(data, 32)) == 0x4e79dd46L); + + /* 32 bytes of decrementing 1f..00 */ + for (i = 0; i < 32; i++) data[i] = 31 - i; + assert(ntohl(crc32c(data, 32)) == 0x5cdb3f11L); + + mark('#'); +} + + +static void +test_csum_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { const struct test_case *tc; int i; @@ -198,6 +239,7 @@ main(void) } test_rfc1624(); + test_crc32c(); /* Test recalc_csum16(). */ for (i = 0; i < 32; i++) { @@ -240,6 +282,6 @@ main(void) mark('#'); putchar('\n'); - - return 0; } + +OVSTEST_REGISTER("test-csum", test_csum_main);