summaryrefslogtreecommitdiff
path: root/tests/test-csum.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2010-11-16 12:52:10 -0800
committerBen Pfaff <blp@nicira.com>2010-11-16 12:52:10 -0800
commit80642190644ae6fbcf485924b1c59e67d0be8a87 (patch)
tree7efb50ebfa588b7296e721918ce5d9c65dc6ad24 /tests/test-csum.c
parentd932cf70b1fe1cdf7d97e598847d9b82e4be3e0b (diff)
downloadopenvswitch-80642190644ae6fbcf485924b1c59e67d0be8a87.tar.gz
csum: Avoid misaligned data access.
This should fix a checksum test failure observed on Alpha in Debian's buildds.
Diffstat (limited to 'tests/test-csum.c')
-rw-r--r--tests/test-csum.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/tests/test-csum.c b/tests/test-csum.c
index fd16dd3f1..af6655e7b 100644
--- a/tests/test-csum.c
+++ b/tests/test-csum.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include "random.h"
+#include "unaligned.h"
#include "util.h"
#undef NDEBUG
@@ -149,7 +150,7 @@ main(void)
/* Test csum_add16(). */
partial = 0;
for (i = 0; i < tc->size / 2; i++) {
- partial = csum_add16(partial, data16[i]);
+ partial = csum_add16(partial, get_unaligned_u16(&data16[i]));
}
assert(ntohs(csum_finish(partial)) == tc->csum);
mark('.');
@@ -157,7 +158,7 @@ main(void)
/* Test csum_add32(). */
partial = 0;
for (i = 0; i < tc->size / 4; i++) {
- partial = csum_add32(partial, data32[i]);
+ partial = csum_add32(partial, get_unaligned_u32(&data32[i]));
}
assert(ntohs(csum_finish(partial)) == tc->csum);
mark('.');
@@ -166,10 +167,12 @@ main(void)
partial = 0;
for (i = 0; i < tc->size / 4; i++) {
if (i % 2) {
- partial = csum_add32(partial, data32[i]);
+ partial = csum_add32(partial, get_unaligned_u32(&data32[i]));
} else {
- partial = csum_add16(partial, data16[i * 2]);
- partial = csum_add16(partial, data16[i * 2 + 1]);
+ uint16_t u0 = get_unaligned_u16(&data16[i * 2]);
+ uint16_t u1 = get_unaligned_u16(&data16[i * 2 + 1]);
+ partial = csum_add16(partial, u0);
+ partial = csum_add16(partial, u1);
}
}
assert(ntohs(csum_finish(partial)) == tc->csum);