From 06362ff5c6d897fb96bef941ef189fc2683e80de Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Wed, 9 Nov 2016 21:56:36 +0100 Subject: [PATCH] tests: net: Using unified kernel API Dropping legacy API. Change-Id: Ife835e38fb03e909e89c3060771f42d1cfa12164 Signed-off-by: Tomasz Bursztyka --- tests/net/6lo/src/main.c | 15 ++-- tests/net/arp/src/main.c | 23 +++--- tests/net/context/src/main.c | 79 ++++++++----------- tests/net/dhcpv4/src/main.c | 11 +-- tests/net/icmpv6/src/main.c | 19 ++--- tests/net/ieee802154/fragment/src/main.c | 15 ++-- .../l2/src/ieee802154_fake_driver.c | 4 +- tests/net/ieee802154/l2/src/ieee802154_test.c | 8 +- tests/net/ip-addr/src/main.c | 15 ++-- tests/net/ipv6/src/main.c | 14 ++-- tests/net/mgmt/src/mgmt.c | 19 ++--- tests/net/neighbor/src/main.c | 15 ++-- tests/net/route/src/main.c | 21 ++--- tests/net/rpl/src/main.c | 27 +++---- tests/net/tcp/src/main.c | 32 ++++---- tests/net/udp/src/main.c | 27 +++---- tests/net/utils/src/main.c | 15 ++-- tests/net/zoap/src/main.c | 8 +- 18 files changed, 155 insertions(+), 212 deletions(-) diff --git a/tests/net/6lo/src/main.c b/tests/net/6lo/src/main.c index ee58204eff0..d7eef8b0477 100644 --- a/tests/net/6lo/src/main.c +++ b/tests/net/6lo/src/main.c @@ -888,7 +888,7 @@ static const struct { #endif }; -static void main_fiber(void) +static void main_thread(void) { int count, pass; @@ -913,17 +913,12 @@ static void main_fiber(void) TC_END_REPORT(((pass != ARRAY_SIZE(tests)) ? TC_FAIL : TC_PASS)); } -#if defined(CONFIG_NANOKERNEL) #define STACKSIZE 2000 -char __noinit __stack fiberStack[STACKSIZE]; -#endif +char __noinit __stack thread_stack[STACKSIZE]; void main(void) { -#if defined(CONFIG_MICROKERNEL) - main_fiber(); -#else - task_fiber_start(&fiberStack[0], STACKSIZE, - (nano_fiber_entry_t)main_fiber, 0, 0, 7, 0); -#endif + k_thread_spawn(&thread_stack[0], STACKSIZE, + (k_thread_entry_t)main_thread, + NULL, NULL, NULL, K_PRIO_COOP(7), 0, 0); } diff --git a/tests/net/arp/src/main.c b/tests/net/arp/src/main.c index 6759635b8a5..04636e54ab3 100644 --- a/tests/net/arp/src/main.c +++ b/tests/net/arp/src/main.c @@ -626,8 +626,8 @@ static bool run_tests(void) break; } - /* Yielding so that network interface TX fiber can proceed. */ - fiber_yield(); + /* Yielding so that network interface TX thread can proceed. */ + k_yield(); if (send_status < 0) { printk("ARP reply was not sent\n"); @@ -685,8 +685,8 @@ static bool run_tests(void) net_nbuf_unref(buf2); - /* Yielding so that network interface TX fiber can proceed. */ - fiber_yield(); + /* Yielding so that network interface TX thread can proceed. */ + k_yield(); if (send_status < 0) { printk("ARP req was not sent\n"); @@ -700,7 +700,7 @@ static bool run_tests(void) return true; } -void main_fiber(void) +void main_thread(void) { if (run_tests()) { TC_END_REPORT(TC_PASS); @@ -709,17 +709,12 @@ void main_fiber(void) } } -#if defined(CONFIG_NANOKERNEL) #define STACKSIZE 2000 -char __noinit __stack fiberStack[STACKSIZE]; -#endif +char __noinit __stack thread_stack[STACKSIZE]; void main(void) { -#if defined(CONFIG_MICROKERNEL) - main_fiber(); -#else - task_fiber_start(&fiberStack[0], STACKSIZE, - (nano_fiber_entry_t)main_fiber, 0, 0, 7, 0); -#endif + k_thread_spawn(&thread_stack[0], STACKSIZE, + (k_thread_entry_t)main_thread, + NULL, NULL, NULL, K_PRIO_COOP(7), 0, 0); } diff --git a/tests/net/context/src/main.c b/tests/net/context/src/main.c index 8943f6a8807..bea1c17e289 100644 --- a/tests/net/context/src/main.c +++ b/tests/net/context/src/main.c @@ -66,10 +66,10 @@ static bool recv_cb_reconfig_called; static bool recv_cb_timeout_called; static int test_token, timeout_token; -static struct nano_sem wait_data; +static struct k_sem wait_data; -#define WAIT_TIME (sys_clock_ticks_per_sec / 4) -#define WAIT_TIME_LONG (sys_clock_ticks_per_sec) +#define WAIT_TIME 250 +#define WAIT_TIME_LONG MSEC_PER_SEC #define SENDING 93244 #define MY_PORT 1969 #define PEER_PORT 16233 @@ -640,7 +640,7 @@ static void recv_cb(struct net_context *context, DBG("Data received.\n"); recv_cb_called = true; - nano_sem_give(&wait_data); + k_sem_give(&wait_data); } static bool net_ctx_recv_v6(void) @@ -656,7 +656,7 @@ static bool net_ctx_recv_v6(void) net_ctx_sendto_v6(); - nano_sem_take(&wait_data, WAIT_TIME); + k_sem_take(&wait_data, WAIT_TIME); if (!recv_cb_called) { TC_ERROR("No data received on time, IPv6 recv test failed\n"); @@ -681,7 +681,7 @@ static bool net_ctx_recv_v4(void) net_ctx_sendto_v4(); - nano_sem_take(&wait_data, WAIT_TIME); + k_sem_take(&wait_data, WAIT_TIME); if (!recv_cb_called) { TC_ERROR("No data received on time, IPv4 recv test failed\n"); @@ -735,7 +735,7 @@ static bool net_ctx_recv_v6_fail(void) { net_ctx_sendto_v6_wrong_src(); - if (nano_sem_take(&wait_data, WAIT_TIME)) { + if (!k_sem_take(&wait_data, WAIT_TIME)) { TC_ERROR("Semaphore triggered but should not\n"); return false; } @@ -791,7 +791,7 @@ static bool net_ctx_recv_v4_fail(void) { net_ctx_sendto_v4_wrong_src(); - if (nano_sem_take(&wait_data, WAIT_TIME)) { + if (!k_sem_take(&wait_data, WAIT_TIME)) { TC_ERROR("Semaphore triggered but should not\n"); return false; } @@ -811,7 +811,7 @@ static bool net_ctx_recv_v6_again(void) { net_ctx_sendto_v6(); - nano_sem_take(&wait_data, WAIT_TIME); + k_sem_take(&wait_data, WAIT_TIME); if (!recv_cb_called) { TC_ERROR("No data received on time 2nd time, " @@ -828,7 +828,7 @@ static bool net_ctx_recv_v4_again(void) { net_ctx_sendto_v4(); - nano_sem_take(&wait_data, WAIT_TIME); + k_sem_take(&wait_data, WAIT_TIME); if (!recv_cb_called) { TC_ERROR("No data received on time 2nd time, " @@ -849,7 +849,7 @@ static void recv_cb_another(struct net_context *context, DBG("Data received in another callback.\n"); recv_cb_reconfig_called = true; - nano_sem_give(&wait_data); + k_sem_give(&wait_data); } static bool net_ctx_recv_v6_reconfig(void) @@ -866,7 +866,7 @@ static bool net_ctx_recv_v6_reconfig(void) net_ctx_sendto_v6(); - nano_sem_take(&wait_data, WAIT_TIME); + k_sem_take(&wait_data, WAIT_TIME); if (!recv_cb_reconfig_called) { TC_ERROR("No data received on time, " @@ -893,7 +893,7 @@ static bool net_ctx_recv_v4_reconfig(void) net_ctx_sendto_v4(); - nano_sem_take(&wait_data, WAIT_TIME); + k_sem_take(&wait_data, WAIT_TIME); if (!recv_cb_reconfig_called) { TC_ERROR("No data received on time, " @@ -906,10 +906,8 @@ static bool net_ctx_recv_v4_reconfig(void) return true; } -#if defined(CONFIG_NANOKERNEL) #define STACKSIZE 1024 -char __noinit __stack fiberStack[STACKSIZE]; -#endif +char __noinit __stack thread_stack[STACKSIZE]; static void recv_cb_timeout(struct net_context *context, struct net_buf *buf, @@ -919,15 +917,14 @@ static void recv_cb_timeout(struct net_context *context, DBG("Data received after a timeout.\n"); recv_cb_timeout_called = true; - nano_sem_give(&wait_data); + k_sem_give(&wait_data); } -void timeout_fiber(struct net_context *ctx, sa_family_t family) +void timeout_thread(struct net_context *ctx, sa_family_t *family) { int ret; - ret = net_context_recv(ctx, recv_cb_timeout, WAIT_TIME_LONG, - INT_TO_POINTER((int)family)); + ret = net_context_recv(ctx, recv_cb_timeout, WAIT_TIME_LONG, family); if (ret || cb_failure) { TC_ERROR("Context recv UDP timeout test failed (%d)\n", ret); @@ -941,44 +938,38 @@ void timeout_fiber(struct net_context *ctx, sa_family_t family) return; } - fiber_abort(); + k_thread_abort(k_current_get()); } -static void start_timeout_v6_fiber(void) +static void start_timeout_v6_thread(void) { -#if defined(CONFIG_MICROKERNEL) - timeout_fiber(udp_v6_ctx, AF_INET6); -#else - task_fiber_start(&fiberStack[0], STACKSIZE, - (nano_fiber_entry_t)timeout_fiber, - (int)udp_v6_ctx, AF_INET6, 7, 0); -#endif + k_thread_spawn(&thread_stack[0], STACKSIZE, + (k_thread_entry_t)timeout_thread, + udp_v6_ctx, INT_TO_POINTER(AF_INET6), NULL, + K_PRIO_COOP(7), 0, 0); } -static void start_timeout_v4_fiber(void) +static void start_timeout_v4_thread(void) { -#if defined(CONFIG_MICROKERNEL) - timeout_fiber(udp_v4_ctx, AF_INET); -#else - task_fiber_start(&fiberStack[0], STACKSIZE, - (nano_fiber_entry_t)timeout_fiber, - (int)udp_v4_ctx, AF_INET, 7, 0); -#endif + k_thread_spawn(&thread_stack[0], STACKSIZE, + (k_thread_entry_t)timeout_thread, + udp_v4_ctx, INT_TO_POINTER(AF_INET), NULL, + K_PRIO_COOP(7), 0, 0); } static bool net_ctx_recv_v6_timeout(void) { cb_failure = false; - /* Start a fiber that will send data to receiver. */ - start_timeout_v6_fiber(); + /* Start a thread that will send data to receiver. */ + start_timeout_v6_thread(); net_ctx_send_v6(); timeout_token = SENDING; DBG("Sent data\n"); - nano_sem_take(&wait_data, TICKS_UNLIMITED); + k_sem_take(&wait_data, K_FOREVER); return !cb_failure; } @@ -987,13 +978,13 @@ static bool net_ctx_recv_v4_timeout(void) { cb_failure = false; - /* Start a fiber that will send data to receiver. */ - start_timeout_v4_fiber(); + /* Start a thread that will send data to receiver. */ + start_timeout_v4_thread(); net_ctx_send_v4(); timeout_token = SENDING; - nano_sem_take(&wait_data, TICKS_UNLIMITED); + k_sem_take(&wait_data, K_FOREVER); return !cb_failure; } @@ -1186,7 +1177,7 @@ static bool test_init(void) } /* The semaphore is there to wait the data to be received. */ - nano_sem_init(&wait_data); + k_sem_init(&wait_data, 0, UINT_MAX); return true; } diff --git a/tests/net/dhcpv4/src/main.c b/tests/net/dhcpv4/src/main.c index 3f8b8633b2c..a66fd27d312 100644 --- a/tests/net/dhcpv4/src/main.c +++ b/tests/net/dhcpv4/src/main.c @@ -534,7 +534,7 @@ static void receiver_cb(struct net_mgmt_event_callback *cb, test_result(true); } -void main_fiber(void) +void main_thread(void) { struct net_if *iface; @@ -551,14 +551,15 @@ void main_fiber(void) net_dhcpv4_start(iface); - fiber_yield(); + k_yield(); } #define STACKSIZE 3000 -char __noinit __stack fiberStack[STACKSIZE]; +char __noinit __stack thread_stack[STACKSIZE]; void main(void) { - task_fiber_start(&fiberStack[0], STACKSIZE, - (nano_fiber_entry_t)main_fiber, 0, 0, 7, 0); + k_thread_spawn(&thread_stack[0], STACKSIZE, + (k_thread_entry_t)main_thread, NULL, NULL, NULL, + K_PRIO_COOP(7), 0, 0); } diff --git a/tests/net/icmpv6/src/main.c b/tests/net/icmpv6/src/main.c index 4c1f76d4260..e3c2a71bd6c 100644 --- a/tests/net/icmpv6/src/main.c +++ b/tests/net/icmpv6/src/main.c @@ -39,8 +39,8 @@ struct header { #define TEST_MSG "foobar devnull" -static struct nano_fifo bufs_fifo; -static struct nano_fifo data_fifo; +static struct k_fifo bufs_fifo; +static struct k_fifo data_fifo; static NET_BUF_POOL(bufs_pool, 2, 0, &bufs_fifo, NULL, sizeof(struct header)); static NET_BUF_POOL(data_pool, 2, 128, &data_fifo, NULL, 0); @@ -127,7 +127,7 @@ static bool run_tests(void) return true; } -void main_fiber(void) +void main_thread(void) { if (run_tests()) { TC_END_REPORT(TC_PASS); @@ -136,17 +136,12 @@ void main_fiber(void) } } -#if defined(CONFIG_NANOKERNEL) #define STACKSIZE 2000 -char __noinit __stack fiberStack[STACKSIZE]; -#endif +char __noinit __stack thread_stack[STACKSIZE]; void main(void) { -#if defined(CONFIG_MICROKERNEL) - main_fiber(); -#else - task_fiber_start(&fiberStack[0], STACKSIZE, - (nano_fiber_entry_t)main_fiber, 0, 0, 7, 0); -#endif + k_thread_spawn(&thread_stack[0], STACKSIZE, + (k_thread_entry_t)main_thread, NULL, NULL, NULL, + K_PRIO_COOP(7), 0, 0); } diff --git a/tests/net/ieee802154/fragment/src/main.c b/tests/net/ieee802154/fragment/src/main.c index 1a58973cac9..689f35e58c9 100644 --- a/tests/net/ieee802154/fragment/src/main.c +++ b/tests/net/ieee802154/fragment/src/main.c @@ -518,7 +518,7 @@ static const struct { { "test_fragment_ipv6_dispatch_big", &test_data_8}, }; -static void main_fiber(void) +static void main_thread(void) { int count, pass; @@ -536,17 +536,12 @@ static void main_fiber(void) TC_END_REPORT(((pass != ARRAY_SIZE(tests)) ? TC_FAIL : TC_PASS)); } -#if defined(CONFIG_NANOKERNEL) #define STACKSIZE 8000 -char __noinit __stack fiberStack[STACKSIZE]; -#endif +char __noinit __stack thread_stack[STACKSIZE]; void main(void) { -#if defined(CONFIG_MICROKERNEL) - main_fiber(); -#else - task_fiber_start(&fiberStack[0], STACKSIZE, - (nano_fiber_entry_t)main_fiber, 0, 0, 7, 0); -#endif + k_thread_spawn(&thread_stack[0], STACKSIZE, + (k_thread_entry_t)main_thread, NULL, NULL, NULL, + K_PRIO_COOP(7), 0, 0); } diff --git a/tests/net/ieee802154/l2/src/ieee802154_fake_driver.c b/tests/net/ieee802154/l2/src/ieee802154_fake_driver.c index e3d3d370650..6bf3a762366 100644 --- a/tests/net/ieee802154/l2/src/ieee802154_fake_driver.c +++ b/tests/net/ieee802154/l2/src/ieee802154_fake_driver.c @@ -23,7 +23,7 @@ #include extern struct net_buf *current_buf; -extern struct nano_sem driver_lock; +extern struct k_sem driver_lock; static int fake_cca(struct device *dev) { @@ -94,7 +94,7 @@ static int fake_tx(struct device *dev, struct net_buf *buf) insert_frag_dummy_way(buf); - nano_sem_give(&driver_lock); + k_sem_give(&driver_lock); return 0; } diff --git a/tests/net/ieee802154/l2/src/ieee802154_test.c b/tests/net/ieee802154/l2/src/ieee802154_test.c index 35f650105e4..d7393016bc7 100644 --- a/tests/net/ieee802154/l2/src/ieee802154_test.c +++ b/tests/net/ieee802154/l2/src/ieee802154_test.c @@ -87,7 +87,7 @@ struct ieee802154_pkt_test test_beacon_pkt = { }; struct net_buf *current_buf; -struct nano_sem driver_lock; +struct k_sem driver_lock; struct net_if *iface; static void pkt_hexdump(uint8_t *pkt, uint8_t length) @@ -161,7 +161,7 @@ static inline int test_ns_sending(struct ieee802154_pkt_test *t) return TC_FAIL; } - nano_sem_take(&driver_lock, MSEC(10)); + k_sem_take(&driver_lock, 10); if (!current_buf->frags) { TC_ERROR("*** Could not send IPv6 NS packet\n"); @@ -212,7 +212,7 @@ static inline int test_ack_reply(struct ieee802154_pkt_test *t) net_recv_data(iface, buf); - nano_sem_take(&driver_lock, MSEC(20)); + k_sem_take(&driver_lock, 20); /* an ACK packet should be in current_buf */ if (!current_buf->frags) { @@ -244,7 +244,7 @@ static inline int initialize_test_environment(void) { struct device *dev; - nano_sem_init(&driver_lock); + k_sem_init(&driver_lock, 0, UINT_MAX); current_buf = net_nbuf_get_reserve_rx(0); if (!current_buf) { diff --git a/tests/net/ip-addr/src/main.c b/tests/net/ip-addr/src/main.c index 3b3d2235230..b7f8c41fb2f 100644 --- a/tests/net/ip-addr/src/main.c +++ b/tests/net/ip-addr/src/main.c @@ -444,7 +444,7 @@ static bool run_tests(void) return true; } -void main_fiber(void) +void main_thread(void) { if (run_tests()) { TC_END_REPORT(TC_PASS); @@ -453,17 +453,12 @@ void main_fiber(void) } } -#if defined(CONFIG_NANOKERNEL) #define STACKSIZE 2000 -char __noinit __stack fiberStack[STACKSIZE]; -#endif +char __noinit __stack thread_stack[STACKSIZE]; void main(void) { -#if defined(CONFIG_MICROKERNEL) - main_fiber(); -#else - task_fiber_start(&fiberStack[0], STACKSIZE, - (nano_fiber_entry_t)main_fiber, 0, 0, 7, 0); -#endif + k_thread_spawn(&thread_stack[0], STACKSIZE, + (k_thread_entry_t)main_thread, NULL, NULL, NULL, + K_PRIO_COOP(7), 0, 0); } diff --git a/tests/net/ipv6/src/main.c b/tests/net/ipv6/src/main.c index 0774a67d9f0..c0338e7edf1 100644 --- a/tests/net/ipv6/src/main.c +++ b/tests/net/ipv6/src/main.c @@ -130,10 +130,10 @@ static const unsigned char ipv6_hbho[] = { }; static bool test_failed; -static struct nano_sem wait_data; +static struct k_sem wait_data; -#define WAIT_TIME (sys_clock_ticks_per_sec / 4) -#define WAIT_TIME_LONG (sys_clock_ticks_per_sec) +#define WAIT_TIME 250 +#define WAIT_TIME_LONG MSEC_PER_SEC #define SENDING 93244 #define MY_PORT 1969 #define PEER_PORT 16233 @@ -278,7 +278,7 @@ static bool test_init(void) } /* The semaphore is there to wait the data to be received. */ - nano_sem_init(&wait_data); + k_sem_init(&wait_data, 0, UINT_MAX); return true; } @@ -437,7 +437,7 @@ static bool net_test_prefix_timeout(void) net_if_ipv6_prefix_set_lf(prefix, false); net_if_ipv6_prefix_set_timer(prefix, lifetime); - nano_sem_take(&wait_data, SECONDS(lifetime * 3/2)); + k_sem_take(&wait_data, (lifetime * 3/2) * MSEC_PER_SEC); prefix = net_if_ipv6_prefix_lookup(net_if_get_default(), &addr, len); @@ -463,7 +463,7 @@ static bool net_test_prefix_timeout_overflow(void) net_if_ipv6_prefix_set_lf(prefix, false); net_if_ipv6_prefix_set_timer(prefix, lifetime); - if (nano_sem_take(&wait_data, SECONDS(lifetime * 3/2))) { + if (!k_sem_take(&wait_data, (lifetime * 3/2) * MSEC_PER_SEC)) { TC_ERROR("Prefix %s/%d lock should still be there", net_sprint_ipv6_addr(&addr), len); return false; @@ -567,7 +567,7 @@ void main(void) pass++; } - fiber_yield(); + k_yield(); } TC_END_REPORT(((pass != ARRAY_SIZE(tests)) ? TC_FAIL : TC_PASS)); diff --git a/tests/net/mgmt/src/mgmt.c b/tests/net/mgmt/src/mgmt.c index 87daf5e4c8b..9fb02027fe0 100644 --- a/tests/net/mgmt/src/mgmt.c +++ b/tests/net/mgmt/src/mgmt.c @@ -31,7 +31,7 @@ static uint32_t event2throw; static uint32_t throw_times; static char __noinit __stack thrower_stack[512]; -static struct nano_sem thrower_lock; +static struct k_sem thrower_lock; /* Receiver infra */ static uint32_t rx_event; @@ -102,10 +102,10 @@ static inline int test_requesting_nm(void) return TC_PASS; } -static void thrower_fiber(void) +static void thrower_thread(void) { while (1) { - nano_fiber_sem_take(&thrower_lock, TICKS_UNLIMITED); + k_sem_take(&thrower_lock, K_FOREVER); TC_PRINT("\tThrowing event 0x%08X %u times\n", event2throw, throw_times); @@ -139,9 +139,9 @@ static inline int test_sending_event(uint32_t times, bool receiver) net_mgmt_add_event_callback(&rx_cb); } - nano_sem_give(&thrower_lock); + k_sem_give(&thrower_lock); - fiber_yield(); + k_yield(); if (receiver) { TC_PRINT("\tReceived 0x%08X %u times\n", @@ -170,12 +170,13 @@ static void initialize_event_tests(void) rx_event = 0; rx_calls = 0; - nano_sem_init(&thrower_lock); + k_sem_init(&thrower_lock, 0, UINT_MAX); net_mgmt_init_event_callback(&rx_cb, receiver_cb, TEST_MGMT_EVENT); - fiber_start(thrower_stack, sizeof(thrower_stack), - (nano_fiber_entry_t)thrower_fiber, 0, 0, 7, 0); + k_thread_spawn(thrower_stack, sizeof(thrower_stack), + (k_thread_entry_t)thrower_thread, + NULL, NULL, NULL, K_PRIO_COOP(7), 0, 0); } static int test_core_event(uint32_t event, bool (*func)(void)) @@ -193,7 +194,7 @@ static int test_core_event(uint32_t event, bool (*func)(void)) goto out; } - fiber_yield(); + k_yield(); if (!rx_calls) { ret = TC_FAIL; diff --git a/tests/net/neighbor/src/main.c b/tests/net/neighbor/src/main.c index 711cc057276..c636dc39585 100644 --- a/tests/net/neighbor/src/main.c +++ b/tests/net/neighbor/src/main.c @@ -370,7 +370,7 @@ static bool run_tests(void) } -void main_fiber(void) +void main_thread(void) { if (run_tests()) { TC_END_REPORT(TC_PASS); @@ -379,17 +379,12 @@ void main_fiber(void) } } -#if defined(CONFIG_NANOKERNEL) #define STACKSIZE 2000 -char __noinit __stack fiberStack[STACKSIZE]; -#endif +char __noinit __stack thread_stack[STACKSIZE]; void main(void) { -#if defined(CONFIG_MICROKERNEL) - main_fiber(); -#else - task_fiber_start(&fiberStack[0], STACKSIZE, - (nano_fiber_entry_t)main_fiber, 0, 0, 7, 0); -#endif + k_thread_spawn(&thread_stack[0], STACKSIZE, + (k_thread_entry_t)main_thread, NULL, NULL, NULL, + K_PRIO_COOP(7), 0, 0); } diff --git a/tests/net/route/src/main.c b/tests/net/route/src/main.c index 857da003afb..4a2f82d4b3c 100644 --- a/tests/net/route/src/main.c +++ b/tests/net/route/src/main.c @@ -88,14 +88,9 @@ static bool feed_data; /* feed data back to IP stack */ static int msg_sending; -static struct nano_sem wait_data; +static struct k_sem wait_data; -#define WAIT_TIME (sys_clock_ticks_per_sec / 4) - -#if defined(CONFIG_NANOKERNEL) -#define STACKSIZE 1024 -char __noinit __stack fiberStack[STACKSIZE]; -#endif +#define WAIT_TIME 250 struct net_route_test { uint8_t mac_addr[sizeof(struct net_eth_addr)]; @@ -154,7 +149,7 @@ static int tester_send(struct net_if *iface, struct net_buf *buf) test_failed = true; } - nano_sem_give(&wait_data); + k_sem_give(&wait_data); return 0; } @@ -169,7 +164,7 @@ static int tester_send(struct net_if *iface, struct net_buf *buf) msg_sending = 0; - nano_sem_give(&wait_data); + k_sem_give(&wait_data); return 0; } @@ -194,7 +189,7 @@ static int tester_send_peer(struct net_if *iface, struct net_buf *buf) test_failed = true; } - nano_sem_give(&wait_data); + k_sem_give(&wait_data); return 0; } @@ -209,7 +204,7 @@ static int tester_send_peer(struct net_if *iface, struct net_buf *buf) msg_sending = 0; - nano_sem_give(&wait_data); + k_sem_give(&wait_data); return 0; } @@ -307,7 +302,7 @@ static bool test_init(void) } /* The semaphore is there to wait the data to be received. */ - nano_sem_init(&wait_data); + k_sem_init(&wait_data, 0, UINT_MAX); return true; } @@ -485,7 +480,7 @@ static bool populate_nbr_cache(void) return false; } - nano_sem_take(&wait_data, WAIT_TIME); + k_sem_take(&wait_data, WAIT_TIME); feed_data = false; diff --git a/tests/net/rpl/src/main.c b/tests/net/rpl/src/main.c index dabf29fab10..4b9f5f14acc 100644 --- a/tests/net/rpl/src/main.c +++ b/tests/net/rpl/src/main.c @@ -84,17 +84,12 @@ static bool feed_data; /* feed data back to IP stack */ static int msg_sending; static int expected_icmpv6 = NET_ICMPV6_RPL; -static struct nano_sem wait_data; +static struct k_sem wait_data; static struct net_if_link_cb link_cb; static bool link_cb_called; -#define WAIT_TIME (sys_clock_ticks_per_sec / 4) - -#if defined(CONFIG_NANOKERNEL) -#define STACKSIZE 1024 -char __noinit __stack fiberStack[STACKSIZE]; -#endif +#define WAIT_TIME 250 struct net_rpl_test { uint8_t mac_addr[sizeof(struct net_eth_addr)]; @@ -165,7 +160,7 @@ static int tester_send(struct net_if *iface, struct net_buf *buf) test_failed = true; } - nano_sem_give(&wait_data); + k_sem_give(&wait_data); return 0; } @@ -216,7 +211,7 @@ out: msg_sending = 0; - nano_sem_give(&wait_data); + k_sem_give(&wait_data); return 0; } @@ -286,7 +281,7 @@ static bool test_init(void) } /* The semaphore is there to wait the data to be received. */ - nano_sem_init(&wait_data); + k_sem_init(&wait_data, 0, UINT_MAX); net_if_register_link_cb(&link_cb, send_link_cb); @@ -360,7 +355,7 @@ static bool test_dio_dummy_input(void) } data_failure = false; - nano_sem_take(&wait_data, WAIT_TIME); + k_sem_take(&wait_data, WAIT_TIME); if (data_failure) { TC_ERROR("%d: Unexpected ICMPv6 code received\n", __LINE__); @@ -387,7 +382,7 @@ static bool test_dis_sending(void) return false; } - nano_sem_take(&wait_data, WAIT_TIME); + k_sem_take(&wait_data, WAIT_TIME); if (data_failure) { data_failure = false; @@ -509,7 +504,7 @@ static bool populate_nbr_cache(void) return false; } - nano_sem_take(&wait_data, WAIT_TIME); + k_sem_take(&wait_data, WAIT_TIME); feed_data = false; @@ -574,7 +569,7 @@ static bool test_dao_sending_ok(void) return false; } - nano_sem_take(&wait_data, WAIT_TIME); + k_sem_take(&wait_data, WAIT_TIME); if (data_failure) { data_failure = false; @@ -596,7 +591,7 @@ static bool test_link_cb(void) net_test_send_ns(); - nano_sem_take(&wait_data, WAIT_TIME); + k_sem_take(&wait_data, WAIT_TIME); /* Restore earlier expected value, by default we only accept * RPL ICMPv6 messages. @@ -666,7 +661,7 @@ static bool test_dio_receive_dest(void) return false; } - nano_sem_take(&wait_data, WAIT_TIME); + k_sem_take(&wait_data, WAIT_TIME); if (data_failure) { data_failure = false; diff --git a/tests/net/tcp/src/main.c b/tests/net/tcp/src/main.c index 4853af01d8e..7ed4fafd4d5 100644 --- a/tests/net/tcp/src/main.c +++ b/tests/net/tcp/src/main.c @@ -47,7 +47,7 @@ static bool test_failed; static bool fail = true; -static struct nano_sem recv_lock; +static struct k_sem recv_lock; static struct net_context *v6_ctx; static struct net_context *reply_v6_ctx; static struct net_context *v4_ctx; @@ -74,12 +74,12 @@ static struct sockaddr_in peer_v4_addr; #define MY_TCP_PORT 5545 #define PEER_TCP_PORT 9876 -#define WAIT_TIME (sys_clock_ticks_per_sec / 4) -#define WAIT_TIME_LONG (sys_clock_ticks_per_sec) +#define WAIT_TIME 250 +#define WAIT_TIME_LONG MSEC_PER_SEC -static struct nano_sem wait_connect; +static struct k_sem wait_connect; #if 0 -static struct nano_sem wait_in_accept; +static struct k_sem wait_in_accept; static bool connect_cb_called; static int accept_cb_called; #endif @@ -161,7 +161,7 @@ static void v6_send_syn_ack(struct net_if *iface, struct net_buf *req) net_nbuf_unref(rsp); } - nano_sem_give(&wait_connect); + k_sem_give(&wait_connect); } static int send_status = -EINVAL; @@ -233,7 +233,7 @@ static enum net_verdict test_ok(struct net_conn *conn, { struct ud *ud = (struct ud *)user_data; - nano_sem_give(&recv_lock); + k_sem_give(&recv_lock); if (!ud) { fail = true; @@ -321,7 +321,7 @@ static void setup_ipv4_tcp(struct net_buf *buf, sizeof(struct net_tcp_hdr)); } -#define TIMEOUT (sys_clock_ticks_per_sec / 6) +#define TIMEOUT 200 static bool send_ipv6_tcp_msg(struct net_if *iface, struct in6_addr *src, @@ -350,7 +350,7 @@ static bool send_ipv6_tcp_msg(struct net_if *iface, return false; } - if (!nano_sem_take(&recv_lock, TIMEOUT)) { + if (k_sem_take(&recv_lock, TIMEOUT)) { printk("Timeout, packet not received\n"); if (expect_failure) { return false; @@ -398,7 +398,7 @@ static bool send_ipv4_tcp_msg(struct net_if *iface, return false; } - if (!nano_sem_take(&recv_lock, TIMEOUT)) { + if (k_sem_take(&recv_lock, TIMEOUT)) { printk("Timeout, packet not received\n"); if (expect_failure) { return false; @@ -479,7 +479,7 @@ static bool test_register(void) net_ipaddr_copy(&peer_addr4.sin_addr, &in4addr_peer); peer_addr4.sin_family = AF_INET; - nano_sem_init(&recv_lock); + k_sem_init(&recv_lock, 0, UINT_MAX); ifaddr = net_if_ipv6_addr_add(iface, &in6addr_my, NET_ADDR_MANUAL, 0); if (!ifaddr) { @@ -1098,7 +1098,7 @@ static void connect_v4_cb(struct net_context *context, void *user_data) fail = false; connect_cb_called = true; - nano_sem_give(&wait_connect); + k_sem_give(&wait_connect); DBG("IPv4 connect cb called\n"); } @@ -1352,7 +1352,7 @@ static bool test_init_tcp_connect(void) return false; } - if (!nano_sem_take(&wait_in_accept, WAIT_TIME_LONG)) { + if (k_sem_take(&wait_in_accept, WAIT_TIME_LONG)) { TC_ERROR("Timeout while waiting data back\n"); return false; } @@ -1374,7 +1374,7 @@ static bool test_init_tcp_connect(void) DBG("Waiting v6 connection\n"); - if (!nano_sem_take(&wait_connect, WAIT_TIME_LONG)) { + if (k_sem_take(&wait_connect, WAIT_TIME_LONG)) { TC_ERROR("Timeout while waiting data back\n"); return false; } @@ -1394,7 +1394,7 @@ static bool test_init_tcp_connect(void) return false; } - nano_sem_take(&wait_connect, WAIT_TIME); + k_sem_take(&wait_connect, WAIT_TIME); if (!connect_cb_called) { TC_ERROR("No IPv4 connect cb called on time, " "TCP connect test failed\n"); @@ -1414,7 +1414,7 @@ static bool test_init(void) net_ipaddr_copy(&any_addr4.sin_addr, &in4addr_any); any_addr4.sin_family = AF_INET; - nano_sem_init(&wait_connect); + k_sem_init(&wait_connect, 0, UINT_MAX); return true; } diff --git a/tests/net/udp/src/main.c b/tests/net/udp/src/main.c index b5f58b8a8e6..177cd92467e 100644 --- a/tests/net/udp/src/main.c +++ b/tests/net/udp/src/main.c @@ -45,7 +45,7 @@ #include "net_private.h" static bool fail = true; -static struct nano_sem recv_lock; +static struct k_sem recv_lock; struct net_udp_context { uint8_t mac_addr[sizeof(struct net_eth_addr)]; @@ -150,7 +150,7 @@ static enum net_verdict test_ok(struct net_conn *conn, { struct ud *ud = (struct ud *)user_data; - nano_sem_give(&recv_lock); + k_sem_give(&recv_lock); if (!ud) { fail = true; @@ -238,7 +238,7 @@ static void setup_ipv4_udp(struct net_buf *buf, sizeof(struct net_udp_hdr)); } -#define TIMEOUT (sys_clock_ticks_per_sec / 6) +#define TIMEOUT 200 static bool send_ipv6_udp_msg(struct net_if *iface, struct in6_addr *src, @@ -267,7 +267,7 @@ static bool send_ipv6_udp_msg(struct net_if *iface, return false; } - if (!nano_sem_take(&recv_lock, TIMEOUT)) { + if (k_sem_take(&recv_lock, TIMEOUT)) { printk("Timeout, packet not received\n"); if (expect_failure) { return false; @@ -315,7 +315,7 @@ static bool send_ipv4_udp_msg(struct net_if *iface, return false; } - if (!nano_sem_take(&recv_lock, TIMEOUT)) { + if (k_sem_take(&recv_lock, TIMEOUT)) { printk("Timeout, packet not received\n"); if (expect_failure) { return false; @@ -408,7 +408,7 @@ static bool run_tests(void) net_ipaddr_copy(&peer_addr4.sin_addr, &in4addr_peer); peer_addr4.sin_family = AF_INET; - nano_sem_init(&recv_lock); + k_sem_init(&recv_lock, 0, UINT_MAX); ifaddr = net_if_ipv6_addr_add(iface, &in6addr_my, NET_ADDR_MANUAL, 0); if (!ifaddr) { @@ -591,7 +591,7 @@ static bool run_tests(void) return true; } -void main_fiber(void) +void main_thread(void) { if (run_tests()) { TC_END_REPORT(TC_PASS); @@ -600,17 +600,12 @@ void main_fiber(void) } } -#if defined(CONFIG_NANOKERNEL) #define STACKSIZE 2000 -char __noinit __stack fiberStack[STACKSIZE]; -#endif +char __noinit __stack thread_stack[STACKSIZE]; void main(void) { -#if defined(CONFIG_MICROKERNEL) - main_fiber(); -#else - task_fiber_start(&fiberStack[0], STACKSIZE, - (nano_fiber_entry_t)main_fiber, 0, 0, 7, 0); -#endif + k_thread_spawn(&thread_stack[0], STACKSIZE, + (k_thread_entry_t)main_thread, + NULL, NULL, NULL, K_PRIO_COOP(7), 0, 0); } diff --git a/tests/net/utils/src/main.c b/tests/net/utils/src/main.c index 0621c72cd19..7de76de5605 100644 --- a/tests/net/utils/src/main.c +++ b/tests/net/utils/src/main.c @@ -376,7 +376,7 @@ static bool run_tests(void) return true; } -void main_fiber(void) +void main_thread(void) { if (run_tests()) { TC_END_REPORT(TC_PASS); @@ -385,17 +385,12 @@ void main_fiber(void) } } -#if defined(CONFIG_NANOKERNEL) #define STACKSIZE 2000 -char __noinit __stack fiberStack[STACKSIZE]; -#endif +char __noinit __stack thread_stack[STACKSIZE]; void main(void) { -#if defined(CONFIG_MICROKERNEL) - main_fiber(); -#else - task_fiber_start(&fiberStack[0], STACKSIZE, - (nano_fiber_entry_t)main_fiber, 0, 0, 7, 0); -#endif + k_thread_spawn(&thread_stack[0], STACKSIZE, + (k_thread_entry_t)main_thread, + NULL, NULL, NULL, K_PRIO_COOP(7), 0, 0); } diff --git a/tests/net/zoap/src/main.c b/tests/net/zoap/src/main.c index 0471f0b917a..59bdbdfe45d 100644 --- a/tests/net/zoap/src/main.c +++ b/tests/net/zoap/src/main.c @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include @@ -39,15 +39,15 @@ #define NUM_OBSERVERS 3 #define NUM_REPLIES 3 -static struct nano_fifo zoap_nbuf_fifo; +static struct k_fifo zoap_nbuf_fifo; static NET_BUF_POOL(zoap_nbuf_pool, 4, 0, &zoap_nbuf_fifo, NULL, sizeof(struct net_nbuf)); -static struct nano_fifo zoap_data_fifo; +static struct k_fifo zoap_data_fifo; static NET_BUF_POOL(zoap_data_pool, 4, ZOAP_BUF_SIZE, &zoap_data_fifo, NULL, 0); -static struct nano_fifo zoap_limited_data_fifo; +static struct k_fifo zoap_limited_data_fifo; static NET_BUF_POOL(zoap_limited_data_pool, 4, ZOAP_LIMITED_BUF_SIZE, &zoap_limited_data_fifo, NULL, 0);