Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
- regression testing found a bug ftw
Browse files Browse the repository at this point in the history
 - update test cases to do the U/L bit right
 - add "check" target so you can test lib6lowpan with just "make check"


git-svn-id: http://tinyos-main.googlecode.com/svn/branches/blip-rpl-devel@5425 285f258d-8064-b571-fbc6-9656dc998e90
  • Loading branch information
sdhags committed Feb 6, 2011
1 parent de001b7 commit 41eaf7e
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 22 deletions.
2 changes: 1 addition & 1 deletion support/sdk/c/blip/lib6lowpan/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

SUBDIRS = . trace
SUBDIRS = . trace tests

AM_CFLAGS = -DPC -I../../../../../tos/types -DHAVE_LOWPAN_EXTERN_MATCH_CONTEXT
noinst_LIBRARIES = lib6lowpan.a
Expand Down
14 changes: 7 additions & 7 deletions support/sdk/c/blip/lib6lowpan/lib6lowpan.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ uint8_t *unpack_address(struct in6_addr *addr, uint8_t dispatch,
// unspecified address ::
return buf;
} else {
lowpan_extern_read_context(addr, context);
int ctxlen = lowpan_extern_read_context(addr, context);
switch (dispatch & LOWPAN_IPHC_AM_MASK) {
case LOWPAN_IPHC_AM_64:
memcpy(&addr->s6_addr[8], buf, 8);
Expand All @@ -521,12 +521,12 @@ uint8_t *unpack_address(struct in6_addr *addr, uint8_t dispatch,
case LOWPAN_IPHC_AM_0:
// not clear how to use this:
// "and 'possibly' link-layer addresses"
if (frame->ieee_mode == IEEE154_ADDR_EXT) {
int i;
for (i = 0; i < 8; i++)
addr->s6_addr[i+8] = frame->i_laddr.data[7-i];
addr->s6_addr[8] ^= 0x2;
} else {
if (ctxlen <= 64 && frame->ieee_mode == IEEE154_ADDR_EXT) {
int i;
for (i = 0; i < 8; i++)
addr->s6_addr[i+8] = frame->i_laddr.data[7-i];
addr->s6_addr[8] ^= 0x2;
} else if (ctxlen <= 112) {
memset(&addr->s6_addr[8], 0, 8);
addr->s6_addr16[7] = leton16(frame->i_saddr);
}
Expand Down
3 changes: 3 additions & 0 deletions support/sdk/c/blip/lib6lowpan/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ TARGETS=test_bit_range_zero_p test_pack_tcfl test_pack_multicast test_pack_addre

all: $(TARGETS)

check:
./run.sh

clean:
rm $(TARGETS)

Expand Down
2 changes: 1 addition & 1 deletion support/sdk/c/blip/lib6lowpan/tests/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "ip.h"

int lowpan_extern_read_context(struct in6_addr *addr, int context) {
return -1;
return 0;
}

int lowpan_extern_match_context(struct in6_addr *addr, uint8_t *ctx_id) {
Expand Down
6 changes: 4 additions & 2 deletions support/sdk/c/blip/lib6lowpan/tests/run.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/bin/sh

TESTS="test_bit_range_zero_p test_pack_tcfl test_pack_multicast test_pack_address \
test_lowpan_pack_headers test_unpack_tcfl test_unpack_address \
test_unpack_tcfl test_unpack_address \
test_unpack_multicast test_unpack_ipnh test_unpack_udp test_pack_nhc_chain \
"
# test_lowpan_frag_get"
# test_lowpan_frag_get" test_lowpan_pack_headers

for T in $(echo $TESTS); do
./$T | grep -a tests
done

exit 0
20 changes: 16 additions & 4 deletions support/sdk/c/blip/lib6lowpan/tests/test_pack_address.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct {
{"fe80::1:00ff:fe00:2", 0, "1", 8, 8, {0, 1, 0, 0xff, 0xfe, 0x0, 0, 02}, LOWPAN_IPHC_AM_64},

// matching with the L2 addr
{"fe80::aabb:ccdd:eeff:0011", 0, "aa:bb:cc:dd:ee:ff:00:11",
{"fe80::aabb:ccdd:eeff:0011", 0, "a8:bb:cc:dd:ee:ff:00:11",
8, 0, {}, LOWPAN_IPHC_AM_0},

// matching 64-bit L2 addr, but prefix isn't all zero
Expand All @@ -47,7 +47,7 @@ struct {
{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11}
, LOWPAN_IPHC_AM_128},

{"fe80::226:bbff:fe11:478b", 0, "2:26:bb:ff:fe:11:47:8c", 0,
{"fe80::226:bbff:fe11:478b", 0, "00:26:bb:ff:fe:11:47:8c", 0,
8, {0x2, 0x26, 0xbb, 0xff, 0xfe, 0x11, 0x47, 0x8b}, LOWPAN_IPHC_AM_64},
// unspecified address
{"::", 0, "12", 0, 0, {}, LOWPAN_IPHC_AM_128 | LOWPAN_IPHC_AC_CONTEXT},
Expand All @@ -66,6 +66,13 @@ struct {
LOWPAN_IPHC_AM_128},

{"2002::1:1", 128, "12", 1, 0, {0}, LOWPAN_IPHC_AM_0 | LOWPAN_IPHC_AC_CONTEXT},

// global addresses, derived from L2.
// contiki packs this to zero bytes using the L2 info; however hc-06
// is a little vague on this point so I don't do this. We will win fact
// decompress that right now.
{"2002::226:bbff:fe11:478b", 64, "00:26:bb:ff:fe:11:47:8b", 1,
8, {0x2, 0x26, 0xbb, 0xff, 0xfe, 0x11, 0x47, 0x8b}, LOWPAN_IPHC_AM_64 | LOWPAN_IPHC_AC_CONTEXT},
};

int run_tests() {
Expand All @@ -89,14 +96,19 @@ struct {
printf("flags: 0x%x(0x%x) len: %li\n", flags, test_cases[i].result_rv, rv - buf );
print_buffer(buf, rv - buf);
if (test_cases[i].result_len != (rv - buf)) {
printf("result len failed\n");
printf("case %u: result len failed expected: %i got: %li\n",
i, test_cases[i].result_len, (rv - buf));
continue;
}
if (test_cases[i].result_rv != flags) {

printf("case %u: desired rv: 0x%x flags: %x\n",
i, test_cases[i].result_rv, flags);
continue;
}
if (memcmp(test_cases[i].result, buf, test_cases[i].result_len) != 0) {
printf("case %u: buffers did not match\n", i);
print_buffer(test_cases[i].result, test_cases[i].result_len);
print_buffer(buf, test_cases[i].result_len);
continue;
}

Expand Down
17 changes: 14 additions & 3 deletions support/sdk/c/blip/lib6lowpan/tests/test_unpack_address.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ struct {

int lowpan_extern_read_context(struct in6_addr *addr, int context) {
struct in6_addr ctx;
printf("read context: %i (%i)\n", context,
prefix_options[context].pfx_len);
inet_pton6(prefix_options[context].prefix, &ctx);
print_buffer(ctx.s6_addr, 16);
memcpy(addr->s6_addr, ctx.s6_addr, prefix_options[context].pfx_len / 8);
return prefix_options[context].pfx_len;
}
int lowpan_extern_match_context(struct in6_addr *addr, UNUSED uint8_t *ctx_id) {
}
Expand All @@ -47,7 +51,7 @@ struct {
{0xfe, 0x80, 0x12, 0x34, 0x87, 0x65, 0xab, 0xde, 0x12, 0x34, 0x87, 0x65, 0xab, 0xde, 0xf0, 0x12}, "1", 1},

// derived from the MAC address
{"fe80::1234:8765:abde:f012", LOWPAN_IPHC_AM_0, 0, 0, {}, "12:34:87:65:ab:de:f0:12", 1},
{"fe80::1234:8765:abde:f012", LOWPAN_IPHC_AM_0, 0, 0, {}, "10:34:87:65:ab:de:f0:12", 1},

// RFC4944-style addresses
{"fe80::1:00ff:fe00:25", LOWPAN_IPHC_AM_0, 0, 0, {}, "25", 1},
Expand Down Expand Up @@ -86,11 +90,18 @@ struct {
inet_ntop6(&addr, buf, 512);
printf("result: %s length: %li\n", buf, rv - test_cases[i].buf);

if (test_cases[i].len != rv - test_cases[i].buf)
if (test_cases[i].len != rv - test_cases[i].buf) {
printf("case %u: result len: %li expected: %i\n",
i, rv - test_cases[i].buf, test_cases[i].len);
continue;
}

if (memcmp(&addr, &correct, 16) != 0)
if (memcmp(&addr, &correct, 16) != 0) {
printf("case %u: unexpected result\n", i);
print_buffer(correct.s6_addr, 16);
print_buffer(addr.s6_addr, 16);
continue;
}

success++;
}
Expand Down
2 changes: 1 addition & 1 deletion support/sdk/c/blip/lib6lowpan/tests/test_unpack_tcfl.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int run_tests() {
rb = unpack_tcfl(&hdr, test_cases[i].test_dispatch, test_cases[i].test);
printf("result: 0x%x correct: 0x%x\n", ntohl(hdr.ip6_flow), test_cases[i].result);

printf("length: %i\n", rb - test_cases[i].test);
printf("length: %li\n", rb - test_cases[i].test);

if (test_cases[i].test_len != rb - test_cases[i].test)
continue;
Expand Down
2 changes: 1 addition & 1 deletion support/sdk/c/blip/lib6lowpan/trace/compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "../lib6lowpan.h"

uint8_t frame[1500], *cur;
uint8_t fragment[128];
uint8_t fragment[100];

int lowpan_extern_read_context(struct in6_addr *addr, int context) {
memset(addr->s6_addr, 0, 0);
Expand Down
4 changes: 2 additions & 2 deletions support/sdk/c/blip/lib6lowpan/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ int ieee154_parse(char *in, ieee154_addr_t *out) {
long val;
char *endp = in;
long saddr = strtol(in, &endp, 16);
fprintf(stderr, "ieee154_parse: %s, %c\n", in, *endp);
// fprintf(stderr, "ieee154_parse: %s, %c\n", in, *endp);

if (*endp == ':') {
endp = in;
// must be a long address
for (i = 0; i < 8; i++) {
val = strtol(endp, &endp, 16);
out->i_laddr.data[i] = val;
out->i_laddr.data[7-i] = val;
endp++;
}
out->ieee_mode = IEEE154_ADDR_EXT;
Expand Down

0 comments on commit 41eaf7e

Please sign in to comment.