Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/net/ieee802154/l2 uses semaphore before initialization #3753

Closed
zephyrbot opened this issue Jun 27, 2017 · 2 comments
Closed

tests/net/ieee802154/l2 uses semaphore before initialization #3753

zephyrbot opened this issue Jun 27, 2017 · 2 comments
Assignees
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Milestone

Comments

@zephyrbot
Copy link
Collaborator

zephyrbot commented Jun 27, 2017

Reported by Andrew Boie:

I found this when testing some experimental code to show that kernel objects have been properly initialized.

In this particular test, the "driver_lock" semaphore gets initialized in the initialize_test_environment() function.

However, a network stack thread is attempting to give this semaphore before initialization can take place:

<span>#</span>0  _k_object_validate (obj=0x1119c8 <driver_lock>, otype=K_OBJ_SEM)
    at /projects/zephyr/kernel/object_validate.c:145
<span>#</span>1  0x0010e33a in k_sem_give (sem=0x1119c8 <driver_lock>) at /projects/zephyr/kernel/sem.c:135
<span>#</span>2  0x001008f2 in fake_tx (dev=0x11104c <__device_fake>, pkt=0x113480 <_k_mem_slab_buf_tx_pkts+256>, 
    frag=0x1128d0 <_net_buf_tx_bufs+144>)
    at /projects/zephyr/tests/net/ieee802154/l2/src/ieee802154_fake_driver.c:93
<span>#</span>3  0x00105582 in csma_ca_tx_fragment (iface=0x111140 <__net_if_fake_0>, 
    pkt=0x113480 <_k_mem_slab_buf_tx_pkts+256>, frag=0x1128d0 <_net_buf_tx_bufs+144>)
    at /projects/zephyr/subsys/net/ip/l2/ieee802154/ieee802154_radio_csma_ca.c:64
<span>#</span>4  0x00105612 in tx_packet_fragments (tx_func=0x10546d <csma_ca_tx_fragment>, 
    pkt=0x113480 <_k_mem_slab_buf_tx_pkts+256>, iface=0x111140 <__net_if_fake_0>)
    at /projects/zephyr/subsys/net/ip/l2/ieee802154/ieee802154_radio_utils.h:67
<span>#</span>5  csma_ca_radio_send (iface=0x111140 <__net_if_fake_0>, pkt=0x113480 <_k_mem_slab_buf_tx_pkts+256>)
    at /projects/zephyr/subsys/net/ip/l2/ieee802154/ieee802154_radio_csma_ca.c:82
<span>#</span>6  0x00103022 in net_if_tx (iface=0x111140 <__net_if_fake_0>)
    at /projects/zephyr/subsys/net/ip/net_if.c:111
<span>#</span>7  0x0010306a in net_if_process_events (event=0x111340 <__net_if_event_fake_0>, 
    ev_count=ev_count@entry=1) at /projects/zephyr/subsys/net/ip/net_if.c:171
<span>#</span>8  0x001030a8 in net_if_tx_thread (startup_sync=0x1110d8 <startup_sync>)
    at /projects/zephyr/subsys/net/ip/net_if.c:214
<span>#</span>9  0x0010e87c in _thread_entry (entry=0x103072 <net_if_tx_thread>, p1=0x1110d8 <startup_sync>, 
    p2=0x0, p3=0x0) at /projects/zephyr/kernel/thread.c:186
<span>#</span>10 0x00000202 in ?? ()

(Imported from Jira ZEP-2319)

@zephyrbot
Copy link
Collaborator Author

by Andrew Boie:

I tried to simply initialize the semaphore at toplevel with:

diff --git a/tests/net/ieee802154/l2/src/ieee802154_test.c b/tests/net/ieee802154/l2/src/ieee802154_test.c
index 057e452..f9a3c39 100644
--- a/tests/net/ieee802154/l2/src/ieee802154_test.c
+++ b/tests/net/ieee802154/l2/src/ieee802154_test.c
@@ -101,7 +101,7 @@ struct ieee802154_pkt_test test_sec_data_pkt = {
 };
 
 struct net_pkt *current_pkt;
-struct k_sem driver_lock;
+K_SEM_DEFINE(driver_lock, 0, UINT_MAX);
 struct net_if *iface;
 
 static void pkt_hexdump(u8_t *pkt, u8_t length)
@@ -259,8 +259,6 @@ static bool initialize_test_environment(void)
 {
        struct device *dev;
 
-       k_sem_init(&driver_lock, 0, UINT_MAX);
-
        current_pkt = net_pkt_get_reserve_rx(0, K_FOREVER);
        if (!current_pkt) {
                NET_ERR("*** No buffer to allocate\n");

However this causes some tests to fail:

***** BOOTING ZEPHYR OS v1.8.99 - BUILD: Jun 27 2017 22:10:13 *****
Running test suite ieee802154_l2
tc_start() - init_test
 -> IEEE 802.15.4 Address: 00:12:4b:00:00:9e:a3:c2
===================================================================
PASS - init_test.
tc_start() - parsing_ns_pkt
===================================================================
PASS - parsing_ns_pkt.
tc_start() - sending_ns_pkt

    Assertion failed at /projects/zephyr/tests/net/ieee802154/l2/src/ieee802154_test.c:312: sending_ns_pkt: NS sent (ret is false)
===================================================================
FAIL - sending_ns_pkt.
tc_start() - parsing_ack_pkt
===================================================================
PASS - parsing_ack_pkt.
tc_start() - replying_ack_pkt
 -> Packet content:
	41 d8 40 cd ab ff ff 00 00 00 
	00 00 00 00 00 7b 09 3a 20 01 
	db 08 00 00 00 00 00 00 00 00 
	00 00 00 01 02 01 ff 00 00 01 
	87 00 91 11 00 00 00 00 ff 02 
	00 00 00 00 00 00 00 00 00 01 
	ff 00 00 01 01 

    Assertion failed at /projects/zephyr/tests/net/ieee802154/l2/src/ieee802154_test.c:330: replying_ack_pkt: ACK replied (ret is false)
===================================================================
FAIL - replying_ack_pkt.
tc_start() - parsing_beacon_pkt
===================================================================
PASS - parsing_beacon_pkt.
tc_start() - parsing_sec_data_pkt
===================================================================
PASS - parsing_sec_data_pkt.
===================================================================
PROJECT EXECUTION FAILED

@zephyrbot
Copy link
Collaborator Author

by Tomasz Bursztyka:

#650

@zephyrbot zephyrbot added priority: low Low impact/importance bug area: Networking bug The issue is a bug, or the PR is fixing a bug labels Sep 23, 2017
@zephyrbot zephyrbot added this to the v1.9.0 milestone Sep 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

2 participants