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 <seppo.takalo@nordicsemi.no>
This commit is contained in:
Seppo Takalo 2024-07-18 12:48:43 +03:00 committed by Anas Nashif
commit 9fc2048bcc
3 changed files with 94 additions and 14 deletions

View file

@ -190,6 +190,8 @@ Tests are written from test spec;
|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-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.

View file

@ -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')

View file

@ -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' : {}}