From 9fc2048bccd322e94fb3945166a2755f02b9a86b Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 18 Jul 2024 12:48:43 +0300 Subject: [PATCH] tests: lwm2m: Add Portfolio testcases Add testcases: * LightweightM2M-1.1-int-1630 - Create Portfolio Object Instance * LightweightM2M-1.1-int-1635 - Delete Portfolio Object Instance Signed-off-by: Seppo Takalo --- tests/net/lib/lwm2m/interop/README.md | 30 ++++----- .../net/lib/lwm2m/interop/pytest/conftest.py | 15 +++++ .../lwm2m/interop/pytest/test_portfolio.py | 63 +++++++++++++++++++ 3 files changed, 94 insertions(+), 14 deletions(-) create mode 100644 tests/net/lib/lwm2m/interop/pytest/test_portfolio.py diff --git a/tests/net/lib/lwm2m/interop/README.md b/tests/net/lib/lwm2m/interop/README.md index 7df931203aa..cac3f9a31d0 100644 --- a/tests/net/lib/lwm2m/interop/README.md +++ b/tests/net/lib/lwm2m/interop/README.md @@ -162,34 +162,36 @@ Tests are written from test spec; |LightweightM2M-1.1-int-226 - Write (Partial Update) on Object Instance |:white_check_mark:| | |LightweightM2M-1.1-int-227 - Write (replace) on Resource |:white_check_mark:| | |LightweightM2M-1.1-int-228 - Write on Resource Instance |:white_check_mark:|[~~#64011~~](https://github.com/zephyrproject-rtos/zephyr/issues/64011) | -|LightweightM2M-1.1-int-229 - Read-Composite Operation|:white_check_mark:|[~~#64012~~](https://github.com/zephyrproject-rtos/zephyr/issues/64012) [~~#64189~~](https://github.com/zephyrproject-rtos/zephyr/issues/64189) | -|LightweightM2M-1.1-int-230 - Write-Composite Operation|:white_check_mark:| | +|LightweightM2M-1.1-int-229 - Read-Composite Operation |:white_check_mark:|[~~#64012~~](https://github.com/zephyrproject-rtos/zephyr/issues/64012) [~~#64189~~](https://github.com/zephyrproject-rtos/zephyr/issues/64189) | +|LightweightM2M-1.1-int-230 - Write-Composite Operation |:white_check_mark:| | |LightweightM2M-1.1-int-231 - Querying basic information in SenML JSON format|:white_check_mark:| | |LightweightM2M-1.1-int-232 - Querying basic information in SenML CBOR format|:white_check_mark:| | |LightweightM2M-1.1-int-233 - Setting basic information in SenML CBOR format|:white_check_mark:| | |LightweightM2M-1.1-int-234 - Setting basic information in SenML JSON format|:white_check_mark:| | -|LightweightM2M-1.1-int-235 - Read-Composite Operation on root path|:white_check_mark:| | +|LightweightM2M-1.1-int-235 - Read-Composite Operation on root path |:white_check_mark:| | |LightweightM2M-1.1-int-236 - Read-Composite - Partial Presence|:white_check_mark:| | |LightweightM2M-1.1-int-237 - Read on Object without specifying Content-Type|:white_check_mark:| | -|LightweightM2M-1.1-int-241 - Executable Resource: Rebooting the device|:white_check_mark:| | -|LightweightM2M-1.1-int-256 - Write Operation Failure|:white_check_mark:| | -|LightweightM2M-1.1-int-257 - Write-Composite Operation|:white_check_mark:| | -|LightweightM2M-1.1-int-260 - Discover Command|:white_check_mark:| | +|LightweightM2M-1.1-int-241 - Executable Resource: Rebooting the device |:white_check_mark:| | +|LightweightM2M-1.1-int-256 - Write Operation Failure |:white_check_mark:| | +|LightweightM2M-1.1-int-257 - Write-Composite Operation |:white_check_mark:| | +|LightweightM2M-1.1-int-260 - Discover Command |:white_check_mark:| | |LightweightM2M-1.1-int-261 - Write-Attribute Operation on a multiple resource|:white_check_mark:| | -|LightweightM2M-1.1-int-280 - Successful Read-Composite Operation|:white_check_mark:| | +|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-301 - Observation and Notification of parameter values|:white_check_mark:| | -|LightweightM2M-1.1-int-302 - Cancel Observations using Reset Operation|:white_check_mark:| | +|LightweightM2M-1.1-int-302 - Cancel Observations using Reset Operation |:white_check_mark:| | |LightweightM2M-1.1-int-303 - Cancel observations using Observe with Cancel parameter|:white_check_mark:|| -|LightweightM2M-1.1-int-304 - Observe-Composite Operation|:white_check_mark:| | -|LightweightM2M-1.1-int-305 - Cancel Observation-Composite Operation|:white_check_mark:| | -|LightweightM2M-1.1-int-306 – Send Operation|:white_check_mark:|[~~#64290~~](https://github.com/zephyrproject-rtos/zephyr/issues/64290)| -|LightweightM2M-1.1-int-307 – Muting Send|:white_check_mark:| | +|LightweightM2M-1.1-int-304 - Observe-Composite Operation |:white_check_mark:| | +|LightweightM2M-1.1-int-305 - Cancel Observation-Composite Operation |:white_check_mark:| | +|LightweightM2M-1.1-int-306 – Send Operation |:white_check_mark:|[~~#64290~~](https://github.com/zephyrproject-rtos/zephyr/issues/64290)| +|LightweightM2M-1.1-int-307 – Muting Send |:white_check_mark:| | |LightweightM2M-1.1-int-308 - Observe-Composite and Creating Object Instance|:white_check_mark:|[~~#64634~~](https://github.com/zephyrproject-rtos/zephyr/issues/64634)| |LightweightM2M-1.1-int-309 - Observe-Composite and Deleting Object Instance|:white_check_mark:|[~~#64634~~](https://github.com/zephyrproject-rtos/zephyr/issues/64634)| |LightweightM2M-1.1-int-310 - Observe-Composite and modification of parameter values|:white_check_mark:| | -|LightweightM2M-1.1-int-311 - Send command|:white_check_mark:| | +|LightweightM2M-1.1-int-311 - Send command |:white_check_mark:| | |LightweightM2M-1.1-int-401 - UDP Channel Security - PSK Mode |:white_check_mark:| | +|LightweightM2M-1.1-int-1630 - Create Portfolio Object Instance |:white_check_mark:| | +|LightweightM2M-1.1-int-1635 - Delete Portfolio Object Instance |:white_check_mark:| | * :white_check_mark: Working OK. * :large_orange_diamond: Feature or operation not implemented. diff --git a/tests/net/lib/lwm2m/interop/pytest/conftest.py b/tests/net/lib/lwm2m/interop/pytest/conftest.py index f5e901fcc7b..2c3512f0b6d 100644 --- a/tests/net/lib/lwm2m/interop/pytest/conftest.py +++ b/tests/net/lib/lwm2m/interop/pytest/conftest.py @@ -182,3 +182,18 @@ def endpoint(endpoint_registered) -> str: """Fixture that returns an endpoint that is registered.""" endpoint_registered.check_update() return endpoint_registered + +@pytest.fixture(scope='module') +def configuration_C13(endpoint_registered, shell: Shell) -> str: + """Fixture that returns an endpoint that has C13 configuration.""" + shell.exec_command('lwm2m create /16/0') + shell.exec_command('lwm2m create /16/0/0/0') + shell.exec_command('lwm2m create /16/0/0/1') + shell.exec_command('lwm2m create /16/0/0/2') + shell.exec_command('lwm2m create /16/0/0/3') + shell.exec_command('lwm2m write /16/0/0/0 "Host Device ID #1"') + shell.exec_command('lwm2m write /16/0/0/1 "Host Device Manufacturer #1"') + shell.exec_command('lwm2m write /16/0/0/2 "Host Device Model #1"') + shell.exec_command('lwm2m write /16/0/0/3 "Host Device Software Version #1"') + yield endpoint_registered + shell.exec_command('lwm2m delete /16/0') diff --git a/tests/net/lib/lwm2m/interop/pytest/test_portfolio.py b/tests/net/lib/lwm2m/interop/pytest/test_portfolio.py new file mode 100644 index 00000000000..9a6448be659 --- /dev/null +++ b/tests/net/lib/lwm2m/interop/pytest/test_portfolio.py @@ -0,0 +1,63 @@ +""" +Various LwM2M interoperability tests +#################################### + +Copyright (c) 2024 Nordic Semiconductor ASA + +SPDX-License-Identifier: Apache-2.0 + +Test specification: +=================== +https://www.openmobilealliance.org/release/LightweightM2M/ETS/OMA-ETS-LightweightM2M-V1_1-20190912-D.pdf + + +This module contains testcases for + * Portfolio Object (ID 16) [1600-1699] + +""" + +import logging +import pytest +from leshan import Leshan + +from twister_harness import Shell + +logger = logging.getLogger(__name__) + +def test_LightweightM2M_1_1_int_1630(shell: Shell, leshan: Leshan, endpoint: str, configuration_C13: str): + """LightweightM2M-1.1-int-1630 - Create Portfolio Object Instance""" + resp = leshan.discover(endpoint, '16/0') + expected_keys = ['/16/0', '/16/0/0'] + missing_keys = [key for key in expected_keys if key not in resp.keys()] + assert len(missing_keys) == 0 + assert int(resp['/16/0/0']['dim']) == 4 + resources = { + 0: {0: 'Host Device ID #2', + 1: 'Host Device Model #2'} + } + assert leshan.create_obj_instance(endpoint, '16/1', resources)['status'] == 'CREATED(201)' + resp = leshan.discover(endpoint, '16/1') + assert int(resp['/16/1/0']['dim']) == 2 + resp = leshan.read(endpoint, '16') + expected = { + 16: {0: {0: {0: 'Host Device ID #1', + 1: 'Host Device Manufacturer #1', + 2: 'Host Device Model #1', + 3: 'Host Device Software Version #1'}}, + 1: {0: {0: 'Host Device ID #2', + 1: 'Host Device Model #2'}}} + } + assert resp == expected + shell.exec_command('lwm2m delete /16/1') + +# Testcase invalidates the C13 configuration, so mark it as indirect +@pytest.mark.parametrize(("configuration_C13"),[None], scope='function', indirect=['configuration_C13']) +def test_LightweightM2M_1_1_int_1635(shell: Shell, leshan: Leshan, endpoint: str, configuration_C13: str): + """LightweightM2M-1.1-int-1635 - Delete Portfolio Object Instance""" + resp = leshan.discover(endpoint, '16') + expected_keys = ['/16/0', '/16/0/0'] + missing_keys = [key for key in expected_keys if key not in resp.keys()] + assert len(missing_keys) == 0 + assert leshan.delete(endpoint, '16/0')['status'] == 'DELETED(202)' + resp = leshan.discover(endpoint, '16') + assert resp == {'/16' : {}}