From 4109bb9f474f733b5d029bfabd5c9e168a957369 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Tue, 24 Oct 2023 17:01:55 +0300 Subject: [PATCH] test: lwm2m: Add test cases 306 and 307 Add testcases for LwM2M SEND. Signed-off-by: Seppo Takalo --- subsys/net/lib/lwm2m/lwm2m_shell.c | 7 +++- tests/net/lib/lwm2m/interop/README.md | 2 ++ tests/net/lib/lwm2m/interop/prj.conf | 2 +- .../lib/lwm2m/interop/pytest/test_lwm2m.py | 34 +++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_shell.c b/subsys/net/lib/lwm2m/lwm2m_shell.c index 335004ec5d5daf7..61d82552affea0a 100644 --- a/subsys/net/lib/lwm2m/lwm2m_shell.c +++ b/subsys/net/lib/lwm2m/lwm2m_shell.c @@ -54,6 +54,11 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); "PATH is LwM2M path\n" \ "NUM how many elements to cache\n" \ +static void send_cb(enum lwm2m_send_status status) +{ + LOG_INF("SEND status: %d\n", status); +} + static int cmd_send(const struct shell *sh, size_t argc, char **argv) { int ret = 0; @@ -85,7 +90,7 @@ static int cmd_send(const struct shell *sh, size_t argc, char **argv) } } - ret = lwm2m_send_cb(ctx, lwm2m_path_list, path_cnt, NULL); + ret = lwm2m_send_cb(ctx, lwm2m_path_list, path_cnt, send_cb); if (ret < 0) { shell_error(sh, "can't do send operation, request failed (%d)\n", ret); diff --git a/tests/net/lib/lwm2m/interop/README.md b/tests/net/lib/lwm2m/interop/README.md index 72eb430f8e4d6dd..50e45ebf5c0f4ce 100644 --- a/tests/net/lib/lwm2m/interop/README.md +++ b/tests/net/lib/lwm2m/interop/README.md @@ -170,6 +170,8 @@ Tests are written from test spec; |LightweightM2M-1.1-int-261 - Write-Attribute Operation on a multiple resource|:large_orange_diamond:|Leshan don't allow writing attributes to resource instance| |LightweightM2M-1.1-int-280 - Successful Read-Composite Operation|:white_check_mark:| | |LightweightM2M-1.1-int-281 - Partially Successful Read-Composite Operation|:white_check_mark:| | +|LightweightM2M-1.1-int-306 – Send Operation|:red_circle:|[#64290](https://github.com/zephyrproject-rtos/zephyr/issues/64290)| +|LightweightM2M-1.1-int-307 – Muting Send|:white_check_mark:| | |LightweightM2M-1.1-int-401 - UDP Channel Security - PSK Mode |:white_check_mark:| | * :white_check_mark: Working OK. diff --git a/tests/net/lib/lwm2m/interop/prj.conf b/tests/net/lib/lwm2m/interop/prj.conf index e4551bd6fad8db1..5be0143b72d2228 100644 --- a/tests/net/lib/lwm2m/interop/prj.conf +++ b/tests/net/lib/lwm2m/interop/prj.conf @@ -99,5 +99,5 @@ CONFIG_LWM2M_NUM_ATTR=10 # Configure stack sizes CONFIG_MAIN_STACK_SIZE=1024 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 -CONFIG_SHELL_STACK_SIZE=1024 +CONFIG_SHELL_STACK_SIZE=1536 CONFIG_LWM2M_ENGINE_STACK_SIZE=2048 diff --git a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py index 384e3cadda5c712..0a8dda75e48c3ea 100644 --- a/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py +++ b/tests/net/lib/lwm2m/interop/pytest/test_lwm2m.py @@ -47,6 +47,8 @@ def leshan_bootstrap() -> Leshan: # Test specification: # https://www.openmobilealliance.org/release/LightweightM2M/ETS/OMA-ETS-LightweightM2M-V1_1-20190912-D.pdf # +# Bootstrap Interface: [0-99} +# def verify_LightweightM2M_1_1_int_0(shell: Shell): logger.info("LightweightM2M-1.1-int-0 - Client Initiated Bootstrap") @@ -60,6 +62,10 @@ def verify_LightweightM2M_1_1_int_1(shell: Shell, leshan: Leshan, endpoint: str) verify_LightweightM2M_1_1_int_101(shell, leshan, endpoint) verify_LightweightM2M_1_1_int_401(shell, leshan, endpoint) +# +# Registration Interface [100-199] +# + def verify_LightweightM2M_1_1_int_101(shell: Shell, leshan: Leshan, endpoint: str): logger.info("LightweightM2M-1.1-int-101 - Initial Registration") shell._device.readlines_until(regex='.*Registration Done', timeout=5.0) @@ -129,6 +135,10 @@ def verify_LightweightM2M_1_1_int_109(shell: Shell, leshan: Leshan, endpoint: st shell.exec_command('lwm2m write 1/0/1 -u32 86400') shell._device.readlines_until(regex='.*Registration update complete', timeout=10) +# +# Device management & Service Enablement Interface [200-299] +# + def verify_LightweightM2M_1_1_int_201(shell: Shell, leshan: Leshan, endpoint: str): logger.info("LightweightM2M-1.1-int-201 - Querying basic information in Plain Text format") fmt = leshan.format @@ -550,6 +560,24 @@ def verify_LightweightM2M_1_1_int_281(shell: Shell, leshan: Leshan, endpoint: st assert resp[1][0][1] == 86400 assert resp[1][0][7] == 'U' +# +# Information Reporting Interface [300-399] +# + +def verify_LightweightM2M_1_1_int_306(shell: Shell, leshan: Leshan, endpoint: str): + logger.info("LightweightM2M-1.1-int-306 - Send Operation") + shell.exec_command('lwm2m send /1 /3 /16') + shell._device.readlines_until(regex=r'.*send_cb: 0', timeout=5.0) + +def verify_LightweightM2M_1_1_int_307(shell: Shell, leshan: Leshan, endpoint: str): + logger.info("LightweightM2M-1.1-int-307 – Muting Send") + leshan.write(endpoint, '1/0/23', True) + lines = shell.get_filtered_output(shell.exec_command('lwm2m send /3/0')) + assert any("can't do send operation" in line for line in lines) + leshan.write(endpoint, '1/0/23', False) + shell.exec_command('lwm2m send /3/0') + shell._device.readlines_until(regex=r'.*send_cb: 0', timeout=5.0) + def verify_LightweightM2M_1_1_int_401(shell: Shell, leshan: Leshan, endpoint: str): logger.info("LightweightM2M-1.1-int-401 - UDP Channel Security - Pre-shared Key Mode") lines = shell.get_filtered_output(shell.exec_command('lwm2m read 0/0/0 -s')) @@ -643,6 +671,12 @@ def test_lwm2m_bootstrap_psk(shell: Shell, leshan, leshan_bootstrap): verify_LightweightM2M_1_1_int_280(shell, leshan, endpoint) verify_LightweightM2M_1_1_int_281(shell, leshan, endpoint) + # + # Device management & Service Enablement Interface test cases + # + verify_LightweightM2M_1_1_int_306(shell, leshan, endpoint) + verify_LightweightM2M_1_1_int_307(shell, leshan, endpoint) + shell.exec_command('lwm2m stop') shell._device.readlines_until(regex=r'.*Deregistration success', timeout=10.0)