Skip to content

Commit

Permalink
Attempt to fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scribam committed Jun 15, 2024
1 parent 123cfe3 commit fa1434b
Show file tree
Hide file tree
Showing 27 changed files with 516 additions and 359 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: make
- name: Unit tests
run: |
sudo apt-get update
sudo apt-get install check
make clean
make units UNITS=1 && ./test/units.sh
if: runner.os == 'Linux'
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ RANLIB:=$(CROSS_COMPILE)ranlib
SIZE:=$(CROSS_COMPILE)size
STRIP_BIN:=$(CROSS_COMPILE)strip
TEST_LDFLAGS=-pthread $(PREFIX)/modules/*.o $(PREFIX)/lib/*.o -lvdeplug
UNIT_LDFLAGS=-lcheck -lm -pthread -lrt
ifneq ("$(wildcard /etc/debian-release)","")
UNIT_LDFLAGS+=-lsubunit
endif
UNIT_LDFLAGS=-lcheck -lsubunit -lm -pthread -lrt
UNIT_CFLAGS= $(CFLAGS) -Wno-missing-braces

LIBNAME:="libpicotcp.a"
Expand Down
7 changes: 7 additions & 0 deletions include/pico_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@

#include "pico_config.h"

/* This is used in unit tests to declare a new tree, leaf root by default */
#define PICO_TREE_DECLARE(name, compareFunction) \
struct pico_tree name = \
{ \
&LEAF, \
compareFunction \
}

#define USE_PICO_PAGE0_ZALLOC (1)
#define USE_PICO_ZALLOC (2)
Expand Down
5 changes: 3 additions & 2 deletions test/dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ volatile uint32_t pico_ms_tick;

int main(void)
{
pico_stack_init();
pico_stack_tick();
struct pico_stack *stack = NULL;
pico_stack_init(&stack);
pico_stack_tick(stack);
return 0;
}
13 changes: 7 additions & 6 deletions test/ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,21 @@ static void cb_sock(uint16_t ev, struct pico_socket *s)

}

static void ping(void)
static void ping(struct pico_stack *stack)
{
struct pico_socket *s;
struct pico_ip4 dst;

pico_string_to_ipv4("80.68.95.85", &dst.addr);
s = pico_socket_open(PICO_PROTO_IPV4, PICO_PROTO_TCP, cb_sock);
s = pico_socket_open(stack, PICO_PROTO_IPV4, PICO_PROTO_TCP, cb_sock);
pico_socket_connect(s, &dst, short_be(80));
pico_icmp4_ping("80.68.95.85", 10, 1000, 4000, 8, cb_ping);
pico_icmp4_ping(stack, "80.68.95.85", 10, 1000, 4000, 8, cb_ping);
}


int main(int argc, const char *argv[])
{
struct pico_stack *stack = NULL;
const char *path = MODEM;
const char *apn = APN;
const char *passwd = PASSWD;
Expand All @@ -162,7 +163,7 @@ int main(int argc, const char *argv[])
signal(SIGUSR2, sigusr2_hdl);
signal(SIGINT, sigusr2_hdl);

pico_stack_init();
pico_stack_init(&stack);

#if defined PICO_SUPPORT_POLARSSL || defined PICO_SUPPORT_CYASSL
pico_register_md5sum(md5sum);
Expand All @@ -183,11 +184,11 @@ int main(int argc, const char *argv[])
pico_ppp_connect(ppp);

while(1 < 2) {
pico_stack_tick();
pico_stack_tick(stack);
usleep(1000);
if (ppp->link_state(ppp) && !ping_on) {
ping_on++;
ping();
ping(stack);
}
}
}
15 changes: 8 additions & 7 deletions test/test_tftp_app_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int32_t get_filesize(const char *filename)
return buf.st_size;
}

void start_rx(struct pico_tftp_session *session, int *synchro, const char *filename, int options)
void start_rx(struct pico_stack *stack, struct pico_tftp_session *session, int *synchro, const char *filename, int options)
{
int ret;
int fd;
Expand Down Expand Up @@ -60,7 +60,7 @@ void start_rx(struct pico_tftp_session *session, int *synchro, const char *filen

for(; left; left -= countdown) {
usleep(2000); /* PICO_IDLE(); */
pico_stack_tick();
pico_stack_tick(stack);
if (countdown)
continue;

Expand Down Expand Up @@ -93,7 +93,7 @@ void start_rx(struct pico_tftp_session *session, int *synchro, const char *filen
}
}

void start_tx(struct pico_tftp_session *session, int *synchro, const char *filename, int options)
void start_tx(struct pico_stack *stack, struct pico_tftp_session *session, int *synchro, const char *filename, int options)
{
int ret;
int fd;
Expand Down Expand Up @@ -133,7 +133,7 @@ void start_tx(struct pico_tftp_session *session, int *synchro, const char *filen

for(; left; left -= countdown) {
usleep(2000); /* PICO_IDLE(); */
pico_stack_tick();
pico_stack_tick(stack);
if (countdown)
continue;

Expand Down Expand Up @@ -184,9 +184,10 @@ int main(int argc, char**argv)
union pico_address server_address;
struct pico_ip4 netmask;
struct pico_tftp_session *session;
struct pico_stack *stack;
int synchro;
int options = 0;
void (*operation)(struct pico_tftp_session *session, int *synchro, const char *filename, int options);
void (*operation)(struct pico_stack *stack, struct pico_tftp_session *session, int *synchro, const char *filename, int options);

unsigned char macaddr[6] = {
0, 0, 0, 0xa, 0xb, 0x0
Expand Down Expand Up @@ -221,15 +222,15 @@ int main(int argc, char**argv)
}

printf("%s start!\n", argv[0]);
pico_stack_init();
pico_stack_init(&stack);
pico_dev = (struct pico_device *) pico_vde_create("/tmp/vde_switch", "tap0", macaddr);

if(!pico_dev) {
fprintf(stderr, "Error creating pico device, got enough privileges? Exiting...\n");
exit(1);
}

pico_ipv4_link_add(pico_dev, my_ip, netmask);
pico_ipv4_link_add(stack, pico_dev, my_ip, netmask);
printf("Starting picoTCP loop\n");

session = pico_tftp_app_setup(&server_address, short_be(PICO_TFTP_PORT), PICO_PROTO_IPV4, &synchro);
Expand Down
15 changes: 8 additions & 7 deletions test/tickless.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static void iperf_cb(uint16_t ev, struct pico_socket *s)
}


static void socket_setup(void)
static void socket_setup(struct pico_stack *stack)
{
int yes = 1;
uint16_t send_port = 0;
Expand All @@ -78,7 +78,7 @@ static void socket_setup(void)

pico_string_to_ipv4("192.168.2.1", &dst.ip4.addr);
send_port = short_be(5001);
s = pico_socket_open(PICO_PROTO_IPV4, PICO_PROTO_TCP, &iperf_cb);
s = pico_socket_open(stack, PICO_PROTO_IPV4, PICO_PROTO_TCP, &iperf_cb);
pico_socket_connect(s, &dst.ip4, send_port);
return;
}
Expand All @@ -92,16 +92,17 @@ int main(void)

uint8_t mac[6] = {0x00,0x00,0x00,0x12,0x34,0x56};
struct pico_socket *s;
struct pico_stack *stack;

pico_stack_init();
pico_stack_init(&stack);

tap = (struct pico_device *) pico_tap_create("tap0");
tap = (struct pico_device *) pico_tap_create(stack, "tap0");
if (!tap)
while (1);

pico_string_to_ipv4(ipaddr, &my_eth_addr.addr);
pico_string_to_ipv4("255.255.255.0", &netmask.addr);
pico_ipv4_link_add(tap, my_eth_addr, netmask);
pico_ipv4_link_add(stack, tap, my_eth_addr, netmask);
#ifdef PICO_SUPPORT_IPV6
{
struct pico_ip6 my_addr6, netmask6;
Expand All @@ -111,10 +112,10 @@ int main(void)
}
#endif

socket_setup();
socket_setup(stack);

while(1) {
interval = pico_stack_go();
interval = pico_stack_go(stack);
if (interval != 0) {
// printf("Interval: %lld\n", interval);
pico_tap_WFI(tap, interval);
Expand Down
23 changes: 3 additions & 20 deletions test/unit/modunit_pico_6lowpan.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ START_TEST(tc_ctx_lookup)
pico_string_to_ipv6("2aaa:1234:5678:9145:0102:0304:0506:0708", b.addr);

STARTING();
pico_stack_init();

TRYING("To find a prefix in the context tree\n");
ret = ctx_insert(a, 13, 54, 0, PICO_IPHC_CTX_COMPRESS, NULL);
Expand Down Expand Up @@ -524,8 +523,6 @@ START_TEST(tc_addr_comp_mode)

STARTING();

pico_stack_init();

TRYING("With MAC derived address\n");
ret = addr_comp_mode(iphc, &local2, addr, &dev, SRC_SHIFT);
OUTPUT();
Expand Down Expand Up @@ -571,8 +568,6 @@ START_TEST(tc_addr_comp_prefix)

STARTING();

pico_stack_init();

TRYING("With MCAST address\n");
ret = addr_comp_prefix(iphc, &ip, 1);
RESULTS();
Expand Down Expand Up @@ -623,7 +618,6 @@ START_TEST(tc_compressor_src)

dev.mode = LL_MODE_IEEE802154;
STARTING();
pico_stack_init();

TRYING("With unspecified source address, should: set SAC, clear SAM\n");
ret = compressor_src(unspec.addr, buf, iphc, &mac, NULL, &dev);
Expand Down Expand Up @@ -675,7 +669,6 @@ START_TEST(tc_compressor_src)
FAIL_UNLESS(0 == memcmp(buf, ll_nmac_64.addr + 8, 8), test, "Should've copied IID of source address inline");

TRYING("With context derived address\n");
pico_stack_init();
ctx_insert(ip_ctx, 13, 64, 0, PICO_IPHC_CTX_COMPRESS, NULL);
ret = compressor_src(ip_ctx.addr, buf, iphc, &mac, NULL, &dev);
OUTPUT();
Expand Down Expand Up @@ -743,7 +736,6 @@ START_TEST(tc_decompressor_src)
uint8_t buf[PICO_SIZE_IP6] = { 0 };
dev.mode = LL_MODE_IEEE802154;

pico_stack_init();
STARTING();

TRYING("With statelessly compressed address\n");
Expand All @@ -756,7 +748,6 @@ START_TEST(tc_decompressor_src)
memset(buf, 0, PICO_SIZE_IP6);

TRYING("With context\n");
pico_stack_init();
ctx_insert(ip2, 13, 64, 0, PICO_IPHC_CTX_COMPRESS, NULL);
ret = decompressor_src(buf, buf2, iphc2, &mac, NULL, &dev);
OUTPUT();
Expand Down Expand Up @@ -831,7 +822,6 @@ START_TEST(tc_compressor_dst)

dev.mode = LL_MODE_IEEE802154;
STARTING();
pico_stack_init();

TRYING("48-bit derivable mcast address\n");
ret = compressor_dst(mcast1.addr, buf, iphc, NULL, &mac, &dev);
Expand Down Expand Up @@ -900,7 +890,6 @@ START_TEST(tc_decompressor_dst)

dev.mode = LL_MODE_IEEE802154;
STARTING();
pico_stack_init();

TRYING("48-bit compressed address\n");
ret = decompressor_dst(buf,buf1,iphc1,NULL, &mac,&dev);
Expand Down Expand Up @@ -972,7 +961,6 @@ START_TEST(tc_compressor_iphc)
f->dst = dst;

STARTING();
pico_stack_init();

TRYING("To compress a IPv6 frame from a sample capture\n");
buf = compressor_iphc(f, &compressed_len, &nh);
Expand Down Expand Up @@ -1011,7 +999,6 @@ START_TEST(tc_decompressor_iphc)
f->dst = dst;

STARTING();
pico_stack_init();

TRYING("To decompress a 6LoWPAN frame from a sampel capture\n");
buf = decompressor_iphc(f, &compressed_len);
Expand Down Expand Up @@ -1248,7 +1235,6 @@ START_TEST(tc_pico_iphc_compress)
f->dst = dst;

STARTING();
pico_stack_init();

TRYING("Trying to compress an IPv6 frame from an example capture\n");
new = pico_iphc_compress(f);
Expand Down Expand Up @@ -1282,7 +1268,6 @@ START_TEST(tc_pico_iphc_decompress)
f->dst = dst;

STARTING();
pico_stack_init();

TRYING("Trying to decompress a 6LoWPAN frame from an example capture\n");
new = pico_iphc_decompress(f);
Expand Down Expand Up @@ -1396,6 +1381,7 @@ static char *cpy_arg(char **dst, char *str)

static void app_ping(char *arg)
{
struct pico_stack *S = NULL;
char *dest = NULL;
char *next = NULL;
char *abort = NULL;
Expand Down Expand Up @@ -1439,7 +1425,7 @@ static void app_ping(char *arg)
printf("Initial delay: %u seconds\n", initial_delay);
initial_delay = PICO_TIME_MS() + (initial_delay * 1000);
while (PICO_TIME_MS() < initial_delay) {
pico_stack_tick();
pico_stack_tick(S);
usleep(10000);
}
}
Expand Down Expand Up @@ -1486,9 +1472,6 @@ START_TEST(tc_tx_rx)
n_area0 = (uint8_t) atoi(area0);
n_area1 = (uint8_t) atoi(area1);

/* Initialize picoTCP */
pico_stack_init();

pico_string_to_ipv6(pan_addr, myaddr.addr);
pico_string_to_ipv6(pan_addr, pan.addr);
pico_string_to_ipv6(pan_netmask, netmask.addr);
Expand All @@ -1513,7 +1496,7 @@ START_TEST(tc_tx_rx)

printf("%s: launching PicoTCP loop\n", __FUNCTION__);
while(!rx) {
pico_stack_tick();
pico_stack_tick(S);
usleep(2000);
}
OUTPUT();
Expand Down
6 changes: 4 additions & 2 deletions test/unit/modunit_pico_802154.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ START_TEST(tc_802154_process_out)
dev.hostvars.lowpan_flags = PICO_6LP_FLAG_LOWPAN;

STARTING();
pico_stack_init();
struct pico_stack *S = NULL;
pico_stack_init(&S);

// TEST 1
TRYING("Trying with bare frame\n");
Expand Down Expand Up @@ -484,7 +485,8 @@ START_TEST(tc_802154_process_in)
f->dst.pan = dst;

STARTING();
pico_stack_init();
struct pico_stack *S = NULL;
pico_stack_init(&S);

TRYING("Apply processing function on predefined buffer\n");
ret = pico_802154_process_in(f);
Expand Down
Loading

0 comments on commit fa1434b

Please sign in to comment.