X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Ftest-csum.c;h=ef126de742bd1f19add68eacbe4d301da6636fa1;hb=69fc54f47bbc35e81bfe2e38e57f5dcfd9858df4;hp=5f736d6cc929f7ee70b9234939899be4e93ea576;hpb=8706009e555bb9fa04a5679e4be2c7c67506802b;p=sliver-openvswitch.git diff --git a/tests/test-csum.c b/tests/test-csum.c index 5f736d6cc..ef126de74 100644 --- a/tests/test-csum.c +++ b/tests/test-csum.c @@ -16,6 +16,7 @@ #include #include "csum.h" +#include "crc32c.h" #include #include #include @@ -94,9 +95,12 @@ static void test_rfc1624(void) { /* "...an IP packet header in which a 16-bit field m = 0x5555..." */ - uint8_t data[32] = - "\xfe\x8f\xc1\x14\x4b\x6f\x70\x2a\x80\x29\x78\xc0\x58\x81\x77\xaa" - "\x66\x64\xfc\x96\x63\x97\x64\xee\x12\x53\x1d\xa9\x2d\xa9\x55\x55"; + uint8_t data[32] = { + 0xfe, 0x8f, 0xc1, 0x14, 0x4b, 0x6f, 0x70, 0x2a, + 0x80, 0x29, 0x78, 0xc0, 0x58, 0x81, 0x77, 0xaa, + 0x66, 0x64, 0xfc, 0x96, 0x63, 0x97, 0x64, 0xee, + 0x12, 0x53, 0x1d, 0xa9, 0x2d, 0xa9, 0x55, 0x55 + }; /* "...the one's complement sum of all other header octets is 0xCD7A." */ assert(ntohs(csum(data, sizeof data - 2)) == 0xffff - 0xcd7a); @@ -133,6 +137,44 @@ test_rfc1624(void) mark('#'); } +/* 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('#'); +} + int main(void) { @@ -195,6 +237,7 @@ main(void) } test_rfc1624(); + test_crc32c(); /* Test recalc_csum16(). */ for (i = 0; i < 32; i++) {