diff --git a/gitlab-ci/functional-test-python.sh b/gitlab-ci/functional-test-python.sh new file mode 100755 index 00000000..e524214a --- /dev/null +++ b/gitlab-ci/functional-test-python.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +echo "$0 preparation script" +pwd + +source ./gitlab-ci/shared.sh + +echo "Starting services..." +cp ./gitlab-ci/bbfdm_services.conf /etc/supervisor/conf.d/ + +supervisorctl reread +supervisorctl update +sleep 10 + +supervisorctl status all +exec_cmd ubus wait_for bbfdm + +# Test ubus bbfdm 'notify_event' method +./test/python-test-cases/python/validate_ubus_notify_event_method.py test/python-test-cases/json/ubus_notify_event_method.json + +# Test 'bbfdm.event' event callback +./test/python-test-cases/python/validate_event_callback.py test/python-test-cases/json/event_callback.json + +# Test 'bbfdm.AddObj' & 'bbfdm.DelObj' event +./test/python-test-cases/python/validate_add_del_event.py test/python-test-cases/json/add_del_event.json + +# Test ubus bbfdm 'get' method +./test/python-test-cases/python/validate_ubus_get_method.py test/python-test-cases/json/ubus_get_method.json + +# Test ubus bbfdm 'instances' method +./test/python-test-cases/python/validate_ubus_schema_method.py test/python-test-cases/json/ubus_schema_method.json + +# Test ubus bbfdm 'add' method +./test/python-test-cases/python/validate_ubus_add_method.py test/python-test-cases/json/ubus_add_method.json + +# Test ubus bbfdm 'del' method +./test/python-test-cases/python/validate_ubus_del_method.py test/python-test-cases/json/ubus_del_method.json + +# Test ubus bbfdm 'schema' method +./test/python-test-cases/python/validate_ubus_schema_method.py test/python-test-cases/json/ubus_schema_method.json + +supervisorctl stop all +supervisorctl status + +echo "Functional Test :: PASS" diff --git a/test/files/tmp/bbfdm/input.json b/test/files/tmp/bbfdm/input.json index 035f213e..1e7c26d8 100755 --- a/test/files/tmp/bbfdm/input.json +++ b/test/files/tmp/bbfdm/input.json @@ -1,6 +1,7 @@ { "daemon": { "config": { + "loglevel": 2 }, "input": { "type": "DotSo", diff --git a/test/python-test-cases/json/add_del_event.json b/test/python-test-cases/json/add_del_event.json new file mode 100644 index 00000000..edf74f3d --- /dev/null +++ b/test/python-test-cases/json/add_del_event.json @@ -0,0 +1,30 @@ +{ + "events": [ + { + "description": "Validate & event using internal object defined in the core Data Model: Device.DeviceInfo.FirmwareImage.", + "config_path": "/tmp/fwbank.data", + "objects_to_look": [ + "Device.DeviceInfo.FirmwareImage.1", + "Device.DeviceInfo.FirmwareImage.2" + ] + }, + { + "description": "Validate & event using external object JSON Plugin: Device.X_IOPSYS_EU_Dropbear.", + "config_path": "/etc/config/dropbear", + "objects_to_look": [ + "Device.X_IOPSYS_EU_Dropbear.1", + "Device.SSH.Server.1" + ] + }, + { + "description": "Validate & event using external object JSON Plugin: Device.X_IOPSYS_EU_IGMP.", + "config_path": "/etc/config/mcast", + "objects_to_look": [ + "Device.X_IOPSYS_EU_IGMP.Proxy.1", + "Device.X_IOPSYS_EU_IGMP.Proxy.1.Interface.1", + "Device.X_IOPSYS_EU_IGMP.Proxy.1.Interface.2", + "Device.X_IOPSYS_EU_IGMP.Proxy.1.Filter.1" + ] + } + ] +} \ No newline at end of file diff --git a/test/python-test-cases/json/event_callback.json b/test/python-test-cases/json/event_callback.json new file mode 100644 index 00000000..d5c3ca6a --- /dev/null +++ b/test/python-test-cases/json/event_callback.json @@ -0,0 +1,70 @@ +{ + "events": [ + { + "description": "Validate event using internal event defined in the core Data Model: Device.WiFi.DataElements.AssociationEvent.Associated!", + "event_name": "wifi.dataelements.Associated", + "inputs": { + "eventTime": "2020-10-24T01:09:34+01:00", + "wfa-dataelements:AssociationEvent": { + "AssocData": { + "BSSID": "00:22:07:6b:17:52", + "MACAddress": "54:b8:02:80:25:e8", + "StatusCode": 12, + "HTCapabilities": "AA==\n", + "VHTCapabilities": "AAAAAAAA\n", + "HECapabilities": "AA==\n" + } + } + }, + "output": { + "name": "Device.WiFi.DataElements.AssociationEvent.Associated!", + "input": { + "TimeStamp": "2020-10-24T01:09:34+01:00", + "BSSID": "00:22:07:6b:17:52", + "MACAddress": "54:b8:02:80:25:e8", + "StatusCode": "12", + "HTCapabilities": "AA==\n", + "VHTCapabilities": "AAAAAAAA\n", + "HECapabilities": "AA==\n" + } + } + }, + { + "description": "Validate event using internal event defined in the core Data Model: Device.WiFi.DataElements.DisassociationEvent.Disassociated!", + "event_name": "wifi.dataelements.Disassociated", + "inputs": { + "eventTime": "2020-10-24T01:10:20+01:00", + "wfa-dataelements:DisassociationEvent": { + "DisassocData": { + "BSSID": "00:22:07:6b:17:51", + "MACAddress": "d2:a2:d1:17:27:f7", + "ReasonCode": 12, + "BytesSent": 181625, + "BytesReceived": 11497, + "PacketsSent": 1951, + "PacketsReceived": 105, + "ErrorsSent": 107, + "ErrorsReceived": 78, + "RetransCount": 9999 + } + } + }, + "output": { + "name": "Device.WiFi.DataElements.DisassociationEvent.Disassociated!", + "input": { + "TimeStamp": "2020-10-24T01:10:20+01:00", + "BSSID": "00:22:07:6b:17:51", + "MACAddress": "d2:a2:d1:17:27:f7", + "ReasonCode": "12", + "BytesSent": "181625", + "BytesReceived": "11497", + "PacketsSent": "1951", + "PacketsReceived": "105", + "ErrorsSent": "107", + "ErrorsReceived": "78", + "RetransCount": "9999" + } + } + } + ] +} \ No newline at end of file diff --git a/test/python-test-cases/json/ubus_add_method.json b/test/python-test-cases/json/ubus_add_method.json new file mode 100644 index 00000000..ff6d850e --- /dev/null +++ b/test/python-test-cases/json/ubus_add_method.json @@ -0,0 +1,107 @@ +{ + "object": "bbfdm", + "add": [ + { + "description": "Add Object for '' path (proto usp)", + "input": { + "path": "", + "optional": {"format": "raw", "proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [ + { + "path": "", + "fault": 7026, + "fault_msg": "Path is not present in the data model schema" + } + ] + } + }, + { + "description": "Add Object for '' path (proto cwmp)", + "input": { + "path": "", + "optional": {"format": "raw", "proto": "cwmp"} + }, + "expected_error": 9005, + "output": { + "results": [ + { + "path": "", + "fault": 9005, + "fault_msg": "Invalid parameter name" + } + ] + } + }, + { + "description": "Add Object for 'Device.ATM.' path (proto usp)", + "input": { + "path": "Device.ATM.", + "optional": {"format": "raw", "proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [ + { + "path": "Device.ATM.", + "fault": 7026, + "fault_msg": "Path is not present in the data model schema" + } + ] + } + }, + { + "description": "Add Object for 'Device.ATM.' path (proto cwmp)", + "input": { + "path": "Device.ATM.", + "optional": {"format": "raw", "proto": "cwmp"} + }, + "expected_error": 9005, + "output": { + "results": [ + { + "path": "Device.ATM.", + "fault": 9005, + "fault_msg": "Invalid parameter name" + } + ] + } + }, + { + "description": "Add Object for 'Device.ATM.Link.' path (proto usp)", + "input": { + "path": "Device.ATM.Link.", + "optional": {"format": "raw", "proto": "usp"} + }, + "expected_error": 0, + "output": { + "results": [ + { + "path": "Device.ATM.Link.", + "data": "2" + } + ] + } + }, + { + "description": "Add Object for 'Device.ATM.Link.' path (proto cwmp)", + "input": { + "path": "Device.ATM.Link.", + "optional": {"format": "raw", "proto": "cwmp"} + }, + "expected_error": 0, + "output": { + "results": [ + { + "path": "Device.ATM.Link.", + "data": "3" + } + ] + } + } + ] +} + + diff --git a/test/python-test-cases/json/ubus_del_method.json b/test/python-test-cases/json/ubus_del_method.json new file mode 100644 index 00000000..0ccaa280 --- /dev/null +++ b/test/python-test-cases/json/ubus_del_method.json @@ -0,0 +1,141 @@ +{ + "object": "bbfdm", + "del": [ + { + "description": "Del Object for '' path (proto usp)", + "input": { + "path": "", + "optional": {"format": "raw", "proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [ + { + "path": "", + "fault": 7026, + "fault_msg": "Path is not present in the data model schema" + } + ] + } + }, + { + "description": "Del Object for '' path (proto cwmp)", + "input": { + "path": "", + "optional": {"format": "raw", "proto": "cwmp"} + }, + "expected_error": 9005, + "output": { + "results": [ + { + "path": "", + "fault": 9005, + "fault_msg": "Invalid parameter name" + } + ] + } + }, + { + "description": "Del Object for 'Device.ATM.' path (proto usp)", + "input": { + "path": "Device.ATM.", + "optional": {"format": "raw", "proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [ + { + "path": "Device.ATM.", + "fault": 7026, + "fault_msg": "Path is not present in the data model schema" + } + ] + } + }, + { + "description": "Del Object for 'Device.ATM.' path (proto cwmp)", + "input": { + "path": "Device.ATM.", + "optional": {"format": "raw", "proto": "cwmp"} + }, + "expected_error": 9005, + "output": { + "results": [ + { + "path": "Device.ATM.", + "fault": 9005, + "fault_msg": "Invalid parameter name" + } + ] + } + }, + { + "description": "Del Object for 'Device.ATM.2' path (proto usp)", + "input": { + "path": "Device.ATM.2", + "optional": {"format": "raw", "proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [ + { + "path": "Device.ATM.2", + "fault": 7026, + "fault_msg": "Path is not present in the data model schema" + } + ] + } + }, + { + "description": "Del Object for 'Device.ATM.2' path (proto cwmp)", + "input": { + "path": "Device.ATM.2", + "optional": {"format": "raw", "proto": "cwmp"} + }, + "expected_error": 9005, + "output": { + "results": [ + { + "path": "Device.ATM.2", + "fault": 9005, + "fault_msg": "Invalid parameter name" + } + ] + } + }, + { + "description": "Del Object for 'Device.ATM.Link.2.' path (proto usp)", + "input": { + "path": "Device.ATM.Link.2.", + "optional": {"format": "raw", "proto": "usp"} + }, + "expected_error": 0, + "output": { + "results": [ + { + "path": "Device.ATM.Link.2.", + "data": "1" + } + ] + } + }, + { + "description": "Del Object for 'Device.ATM.Link.3.' path (proto cwmp)", + "input": { + "path": "Device.ATM.Link.3.", + "optional": {"format": "raw", "proto": "cwmp"} + }, + "expected_error": 0, + "output": { + "results": [ + { + "path": "Device.ATM.Link.3.", + "data": "1" + } + ] + } + } + ] +} + + diff --git a/test/python-test-cases/json/ubus_get_method.json b/test/python-test-cases/json/ubus_get_method.json new file mode 100644 index 00000000..52e25b19 --- /dev/null +++ b/test/python-test-cases/json/ubus_get_method.json @@ -0,0 +1,93 @@ +{ + "object": "bbfdm", + "get": [ + { + "description": "Get Value for '' path (proto usp)", + "input": { + "path": "", + "optional": {"format": "raw", "proto": "usp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Get Value for '' path (proto cwmp)", + "input": { + "path": "", + "optional": {"format": "raw", "proto": "cwmp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Get Value for 'Device.DeviceInfo.Manufacturer' path (proto usp)", + "input": { + "path": "Device.DeviceInfo.Manufacturer", + "optional": {"format": "raw", "proto": "usp"} + }, + "expected_error": 0, + "output": { + "results": [ + { + "path": "Device.DeviceInfo.Manufacturer", + "data": "iopsys", + "type": "xsd:string" + } + ] + } + }, + { + "description": "Get Value for 'Device.DeviceInfo.Manufacturer' path (proto cwmp)", + "input": { + "path": "Device.DeviceInfo.Manufacturer", + "optional": {"format": "raw", "proto": "cwmp"} + }, + "expected_error": 0, + "output": { + "results": [ + { + "path": "Device.DeviceInfo.Manufacturer", + "data": "iopsys", + "type": "xsd:string" + } + ] + } + }, + { + "description": "Get Value for 'Device.DeviceInfo.Manufacture' path (proto usp)", + "input": { + "path": "Device.DeviceInfo.Manufacture", + "optional": {"format": "raw", "proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [ + { + "path": "Device.DeviceInfo.Manufacture", + "fault": 7026, + "fault_msg": "Path is not present in the data model schema" + } + ] + } + }, + { + "description": "Get Value for 'Device.DeviceInfo.Manufacture' path (proto cwmp)", + "input": { + "path": "Device.DeviceInfo.Manufacture", + "optional": {"format": "raw", "proto": "cwmp"} + }, + "expected_error": 9005, + "output": { + "results": [ + { + "path": "Device.DeviceInfo.Manufacture", + "fault": 9005, + "fault_msg": "Invalid parameter name" + } + ] + } + } + ] +} + + diff --git a/test/python-test-cases/json/ubus_instances_method.json b/test/python-test-cases/json/ubus_instances_method.json new file mode 100644 index 00000000..c21fecca --- /dev/null +++ b/test/python-test-cases/json/ubus_instances_method.json @@ -0,0 +1,141 @@ +{ + "object": "bbfdm", + "instances": [ + { + "description": "Del Object for '' path (proto usp)", + "input": { + "path": "", + "optional": {"format": "raw", "proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [ + { + "path": "", + "fault": 7026, + "fault_msg": "Path is not present in the data model schema" + } + ] + } + }, + { + "description": "Del Object for '' path (proto cwmp)", + "input": { + "path": "", + "optional": {"format": "raw", "proto": "cwmp"} + }, + "expected_error": 9005, + "output": { + "results": [ + { + "path": "", + "fault": 9005, + "fault_msg": "Invalid parameter name" + } + ] + } + }, + { + "description": "Del Object for 'Device.ATM.' path (proto usp)", + "input": { + "path": "Device.ATM.", + "optional": {"format": "raw", "proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [ + { + "path": "Device.ATM.", + "fault": 7026, + "fault_msg": "Path is not present in the data model schema" + } + ] + } + }, + { + "description": "Del Object for 'Device.ATM.' path (proto cwmp)", + "input": { + "path": "Device.ATM.", + "optional": {"format": "raw", "proto": "cwmp"} + }, + "expected_error": 9005, + "output": { + "results": [ + { + "path": "Device.ATM.", + "fault": 9005, + "fault_msg": "Invalid parameter name" + } + ] + } + }, + { + "description": "Del Object for 'Device.ATM.2' path (proto usp)", + "input": { + "path": "Device.ATM.2", + "optional": {"format": "raw", "proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [ + { + "path": "Device.ATM.2", + "fault": 7026, + "fault_msg": "Path is not present in the data model schema" + } + ] + } + }, + { + "description": "Del Object for 'Device.ATM.2' path (proto cwmp)", + "input": { + "path": "Device.ATM.2", + "optional": {"format": "raw", "proto": "cwmp"} + }, + "expected_error": 9005, + "output": { + "results": [ + { + "path": "Device.ATM.2", + "fault": 9005, + "fault_msg": "Invalid parameter name" + } + ] + } + }, + { + "description": "Del Object for 'Device.ATM.Link.2.' path (proto usp)", + "input": { + "path": "Device.ATM.Link.2.", + "optional": {"format": "raw", "proto": "usp"} + }, + "expected_error": 0, + "output": { + "results": [ + { + "path": "Device.ATM.Link.2.", + "data": "1" + } + ] + } + }, + { + "description": "Del Object for 'Device.ATM.Link.3.' path (proto cwmp)", + "input": { + "path": "Device.ATM.Link.3.", + "optional": {"format": "raw", "proto": "cwmp"} + }, + "expected_error": 0, + "output": { + "results": [ + { + "path": "Device.ATM.Link.3.", + "data": "1" + } + ] + } + } + ] +} + + diff --git a/test/python-test-cases/json/ubus_notify_event_method.json b/test/python-test-cases/json/ubus_notify_event_method.json new file mode 100644 index 00000000..5c4733ff --- /dev/null +++ b/test/python-test-cases/json/ubus_notify_event_method.json @@ -0,0 +1,23 @@ +{ + "events": [ + { + "description": "Validate ubus bbfdm method", + "service": "bbfdm", + "method": "notify_event", + "input": { + "name": "Device.LocalAgent.TransferComplete!", + "input": { + "param1": "val1", + "param2": "val2" + } + }, + "output": { + "name": "Device.LocalAgent.TransferComplete!", + "input": { + "param1": "val1", + "param2": "val2" + } + } + } + ] +} diff --git a/test/python-test-cases/json/ubus_schema_method.json b/test/python-test-cases/json/ubus_schema_method.json new file mode 100644 index 00000000..7c407c89 --- /dev/null +++ b/test/python-test-cases/json/ubus_schema_method.json @@ -0,0 +1,302 @@ +{ + "object": "bbfdm", + "schema": [ + { + "description": "Schema for empty path with first_level=true (proto usp)", + "input": { + "path": "", + "first_level": true, + "optional": {"proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [] + } + }, + { + "description": "Schema for empty path with first_level=false (proto usp)", + "input": { + "path": "", + "first_level": false, + "optional": {"proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [] + } + }, + { + "description": "Schema for 'Device.' path with first_level=true (proto usp)", + "input": { + "path": "Device.", + "first_level": true, + "optional": {"proto": "usp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Schema for 'Device.' path with first_level=false (proto usp)", + "input": { + "path": "Device.", + "first_level": false, + "optional": {"proto": "usp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Schema for 'Device.DeviceInfo.' path with first_level=true (proto usp)", + "input": { + "path": "Device.DeviceInfo.", + "first_level": true, + "optional": {"proto": "usp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Schema for 'Device.DeviceInfo.' path with first_level=false (proto usp)", + "input": { + "path": "Device.DeviceInfo.", + "first_level": false, + "optional": {"proto": "usp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Schema for 'Device.DeviceInfo.Manufacturer' path with first_level=true (proto usp)", + "input": { + "path": "Device.DeviceInfo.Manufacturer", + "first_level": true, + "optional": {"proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [] + } + }, + { + "description": "Schema for 'Device.DeviceInfo.Manufacturer' path with first_level=false (proto usp)", + "input": { + "path": "Device.DeviceInfo.Manufacturer", + "first_level": false, + "optional": {"proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [] + } + }, + { + "description": "Schema for 'Device.DeviceInfo.' & 'Device.Time.' & 'Device.WiFi.Radio.' path with first_level=true (proto usp)", + "input": { + "path": "Device.DeviceInfo.", + "paths": ["Device.Time.", "Device.WiFi.Radio."], + "first_level": true, + "optional": {"proto": "usp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Schema for 'Device.DeviceInfo.' & 'Device.Time.' & 'Device.WiFi.Radio.' path with first_level=false (proto usp)", + "input": { + "path": "Device.DeviceInfo.", + "paths": ["Device.Time.", "Device.WiFi.Radio."], + "first_level": false, + "optional": {"proto": "usp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Schema for 'Device.Time.' & 'Device.WiFi.Radio.' path with first_level=true (proto usp)", + "input": { + "paths": ["Device.Time.", "Device.WiFi.Radio."], + "first_level": true, + "optional": {"proto": "usp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Schema for 'Device.Time.' & 'Device.WiFi.Radio.' path with first_level=false (proto usp)", + "input": { + "paths": ["Device.Time.", "Device.WiFi.Radio."], + "first_level": false, + "optional": {"proto": "usp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Schema for 'Device.DeviceIn' path with first_level=true (proto usp)", + "input": { + "path": "Device.DeviceIn", + "first_level": true, + "optional": {"proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [] + } + }, + { + "description": "Schema for 'Device.DeviceInfo.' path with first_level=false (proto usp)", + "input": { + "path": "Device.DeviceIn", + "first_level": false, + "optional": {"proto": "usp"} + }, + "expected_error": 7026, + "output": { + "results": [] + } + }, + { + "description": "Get Name for empty path with first_level=true (proto cwmp)", + "input": { + "path": "", + "first_level": true, + "optional": {"proto": "cwmp"} + }, + "expected_error": 0, + "output": { + "results": [ + { + "path": "Device.", + "data": "0", + "type": "xsd:object" + + } + ] + } + }, + { + "description": "Get Name for empty path with first_level=false (proto cwmp)", + "input": { + "path": "", + "first_level": false, + "optional": {"proto": "cwmp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Get Name for 'Device.' with first_level=true (proto cwmp)", + "input": { + "path": "Device.", + "first_level": true, + "optional": {"proto": "cwmp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Get Name for 'Device.' path with first_level=false (proto cwmp)", + "input": { + "path": "Device.", + "first_level": false, + "optional": {"proto": "cwmp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Get Name for 'Device.DeviceInfo.' with first_level=true (proto cwmp)", + "input": { + "path": "Device.DeviceInfo.", + "first_level": true, + "optional": {"proto": "cwmp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Get Name for 'Device.DeviceInfo.' path with first_level=false (proto cwmp)", + "input": { + "path": "Device.DeviceInfo.", + "first_level": false, + "optional": {"proto": "cwmp"} + }, + "expected_error": 0, + "output": {} + }, + { + "description": "Get Name for 'Device.DeviceInfo.Manufacturer' with first_level=true (proto cwmp)", + "input": { + "path": "Device.DeviceInfo.Manufacturer", + "first_level": true, + "optional": {"proto": "cwmp"} + }, + "expected_error": 9003, + "output": { + "results": [ + { + "path": "Device.DeviceInfo.Manufacturer", + "fault": 9003, + "fault_msg": "Invalid arguments" + + } + ] + } + }, + { + "description": "Get Name for 'Device.DeviceInfo.Manufacturer' path with first_level=false (proto cwmp)", + "input": { + "path": "Device.DeviceInfo.Manufacturer", + "first_level": false, + "optional": {"proto": "cwmp"} + }, + "expected_error": 0, + "output": { + "results": [ + { + "path": "Device.DeviceInfo.Manufacturer", + "data": "0", + "type": "xsd:string" + + } + ] + } + }, + { + "description": "Get Name for 'Device.DeviceInfo.Manuf' with first_level=true (proto cwmp)", + "input": { + "path": "Device.DeviceInfo.Manuf", + "first_level": true, + "optional": {"proto": "cwmp"} + }, + "expected_error": 9005, + "output": { + "results": [ + { + "path": "Device.DeviceInfo.Manuf", + "fault": 9005, + "fault_msg": "Invalid parameter name" + } + ] + } + }, + { + "description": "Get Name for 'Device.DeviceInfo.Manufac' path with first_level=false (proto cwmp)", + "input": { + "path": "Device.DeviceInfo.Manufac", + "first_level": false, + "optional": {"proto": "cwmp"} + }, + "expected_error": 9005, + "output": { + "results": [ + { + "path": "Device.DeviceInfo.Manufac", + "fault": 9005, + "fault_msg": "Invalid parameter name" + } + ] + } + } + ] +} diff --git a/test/python-test-cases/python/validate_add_del_event.py b/test/python-test-cases/python/validate_add_del_event.py new file mode 100755 index 00000000..be98753f --- /dev/null +++ b/test/python-test-cases/python/validate_add_del_event.py @@ -0,0 +1,100 @@ +#!/usr/bin/python3 + +import os +import sys +import ubus +import json + +# Global variable to track UBUS disconnection +UBUS_DISCONNECT = 0 + +class TestArguments: + """ + Class to hold test arguments. + """ + def __init__(self, description, config_path, objects_to_look): + self.description = description + self.config_path = config_path + self.objects_to_look = objects_to_look + +def callback(event, data): + """ + Callback function to handle UBUS events. + """ + global UBUS_DISCONNECT + # Check if the objects to look for are in the instances list + if set(args.objects_to_look).issubset(set(data['instances'])): + # Mark UBUS as disconnected + UBUS_DISCONNECT = 1 + # Disconnect from UBUS + ubus.disconnect() + +def run_global_test(args, event_name, path_1, path_2): + """ + Run a global test. + """ + global UBUS_DISCONNECT + + # Connect to UBUS + ubus.connect() + UBUS_DISCONNECT = 0 + + # Listen for UBUS events + ubus.listen((event_name, callback)) + + # Force change in schema by moving dependency file + os.rename(path_1, path_2) + + # Run UBUS loop with a timeout + ubus.loop(timeout=35000) + + # If UBUS is still connected, disconnect and mark test as failed + if UBUS_DISCONNECT == 0: + ubus.disconnect() + return -1 + + return 0 + +def run_test(args): + """ + Run a single test. + """ + print("Running: " + args.description) + + # Test deletion of object + res = run_global_test(args, "bbfdm.DelObj", args.config_path, "/tmp/bbfdm_test_1") + if res != 0: + print("FAIL: " + args.description) + return + + # Test addition of object + res = run_global_test(args, "bbfdm.AddObj", "/tmp/bbfdm_test_1", args.config_path) + if res != 0: + print("FAIL: " + args.description) + return + + print("PASS: " + args.description) + +if __name__ == "__main__": + # Check for correct command line arguments + if len(sys.argv) != 2: + print("Usage: {} ".format(sys.argv[0])) + sys.exit(1) + + test_arguments_file = sys.argv[1] + + try: + # Load test arguments from JSON file + with open(test_arguments_file, 'r') as f: + test_arguments_data = json.load(f) + args_list = [TestArguments(**event) for event in test_arguments_data["events"]] + except FileNotFoundError: + print("File not found:", test_arguments_file) + sys.exit(1) + except json.JSONDecodeError as e: + print("Error parsing JSON:", e) + sys.exit(1) + + # Run tests for each set of arguments + for args in args_list: + run_test(args) diff --git a/test/python-test-cases/python/validate_event_callback.py b/test/python-test-cases/python/validate_event_callback.py new file mode 100755 index 00000000..2a260903 --- /dev/null +++ b/test/python-test-cases/python/validate_event_callback.py @@ -0,0 +1,80 @@ +#!/usr/bin/python3 + +import sys +import ubus +import json + +# Global variable to track UBUS disconnection +UBUS_DISCONNECT = 0 + +class TestArguments: + """ + Class to hold test arguments. + """ + def __init__(self, description, event_name, inputs, output): + self.description = description + self.event_name = event_name + self.inputs = inputs + self.output = output + +def callback(event, data): + """ + Callback function to handle UBUS events. + """ + global UBUS_DISCONNECT + if data == args.output: + print("PASS: " + args.description) + else: + print("FAIL: " + args.description) + ubus.disconnect() + UBUS_DISCONNECT = 1 + +def run_test(args): + """ + Run a single test. + """ + global UBUS_DISCONNECT + + print("Running: " + args.description) + + # Connect to UBUS + ubus.connect() + UBUS_DISCONNECT = 0 + + # Listen for UBUS events + ubus.listen(("bbfdm.event", callback)) + + # Send UBUS event with inputs + ubus.send(args.event_name, args.inputs) + + # Run UBUS loop with a timeout + ubus.loop(timeout=5000) + + # If UBUS is still connected, disconnect and mark test as failed + if UBUS_DISCONNECT == 0: + ubus.disconnect() + print("FAIL: " + args.description) + +if __name__ == "__main__": + # Check for correct command line arguments + if len(sys.argv) != 2: + print("Usage: {} ".format(sys.argv[0])) + sys.exit(1) + + test_arguments_file = sys.argv[1] + + try: + # Load test arguments from JSON file + with open(test_arguments_file, 'r') as f: + test_arguments_data = json.load(f) + args_list = [TestArguments(**event) for event in test_arguments_data["events"]] + except FileNotFoundError: + print("File not found:", test_arguments_file) + sys.exit(1) + except json.JSONDecodeError as e: + print("Error parsing JSON:", e) + sys.exit(1) + + # Run tests for each set of arguments + for args in args_list: + run_test(args) diff --git a/test/python-test-cases/python/validate_ubus_add_method.py b/test/python-test-cases/python/validate_ubus_add_method.py new file mode 100755 index 00000000..e9776556 --- /dev/null +++ b/test/python-test-cases/python/validate_ubus_add_method.py @@ -0,0 +1,79 @@ +#!/usr/bin/python3 + +import sys +import ubus +import json + +class TestArguments: + """ + Class to hold test arguments. + """ + def __init__(self, description, service, input, expected_error, output): + self.description = description + self.service = service + self.input = input + self.expected_error = expected_error + self.output = output + +def run_test(args): + """ + Run a single test. + """ + + print("Running: " + args.description) + + out = ubus.call(args.service, "add", args.input) + + if isinstance(out, list) and out: + out = out[0] + else: + print("FAIL: " + args.description) + return + + res_len = len(out["results"]) + fault = out["results"][0]["fault"] if res_len and "fault" in out["results"][0] else 0 + + if fault != args.expected_error: + print("FAIL: " + args.description) + return + + if args.expected_error == 0 and res_len == 0: + print("FAIL: " + args.description) + return + + # Check if output matches expected output + if args.output != {}: + if out == args.output: + print("PASS: " + args.description) + else: + print("FAIL: " + args.description) + else: + print("PASS: " + args.description) + +if __name__ == "__main__": + # Check for correct command line arguments + if len(sys.argv) != 2: + print("Usage: {} ".format(sys.argv[0])) + sys.exit(1) + + test_arguments_file = sys.argv[1] + + try: + with open(test_arguments_file, 'r') as f: + test_arguments_data = json.load(f) + service_name = test_arguments_data.get("object", "bbfdm") + args_list = [TestArguments(**test_case, service=service_name) for test_case in test_arguments_data["add"]] + except FileNotFoundError: + print("File not found:", test_arguments_file) + sys.exit(1) + except json.JSONDecodeError as e: + print("Error parsing JSON:", e) + sys.exit(1) + + ubus.connect() + + # Run tests for each set of arguments + for args in args_list: + run_test(args) + + ubus.disconnect() diff --git a/test/python-test-cases/python/validate_ubus_del_method.py b/test/python-test-cases/python/validate_ubus_del_method.py new file mode 100755 index 00000000..07bb0fc2 --- /dev/null +++ b/test/python-test-cases/python/validate_ubus_del_method.py @@ -0,0 +1,79 @@ +#!/usr/bin/python3 + +import sys +import ubus +import json + +class TestArguments: + """ + Class to hold test arguments. + """ + def __init__(self, description, service, input, expected_error, output): + self.description = description + self.service = service + self.input = input + self.expected_error = expected_error + self.output = output + +def run_test(args): + """ + Run a single test. + """ + + print("Running: " + args.description) + + out = ubus.call(args.service, "del", args.input) + + if isinstance(out, list) and out: + out = out[0] + else: + print("FAIL: " + args.description) + return + + res_len = len(out["results"]) + fault = out["results"][0]["fault"] if res_len and "fault" in out["results"][0] else 0 + + if fault != args.expected_error: + print("FAIL: " + args.description) + return + + if args.expected_error == 0 and res_len == 0: + print("FAIL: " + args.description) + return + + # Check if output matches expected output + if args.output != {}: + if out == args.output: + print("PASS: " + args.description) + else: + print("FAIL: " + args.description) + else: + print("PASS: " + args.description) + +if __name__ == "__main__": + # Check for correct command line arguments + if len(sys.argv) != 2: + print("Usage: {} ".format(sys.argv[0])) + sys.exit(1) + + test_arguments_file = sys.argv[1] + + try: + with open(test_arguments_file, 'r') as f: + test_arguments_data = json.load(f) + service_name = test_arguments_data.get("object", "bbfdm") + args_list = [TestArguments(**test_case, service=service_name) for test_case in test_arguments_data["del"]] + except FileNotFoundError: + print("File not found:", test_arguments_file) + sys.exit(1) + except json.JSONDecodeError as e: + print("Error parsing JSON:", e) + sys.exit(1) + + ubus.connect() + + # Run tests for each set of arguments + for args in args_list: + run_test(args) + + ubus.disconnect() diff --git a/test/python-test-cases/python/validate_ubus_get_method.py b/test/python-test-cases/python/validate_ubus_get_method.py new file mode 100755 index 00000000..38bb52ac --- /dev/null +++ b/test/python-test-cases/python/validate_ubus_get_method.py @@ -0,0 +1,79 @@ +#!/usr/bin/python3 + +import sys +import ubus +import json + +class TestArguments: + """ + Class to hold test arguments. + """ + def __init__(self, description, service, input, expected_error, output): + self.description = description + self.service = service + self.input = input + self.expected_error = expected_error + self.output = output + +def run_test(args): + """ + Run a single test. + """ + + print("Running: " + args.description) + + out = ubus.call(args.service, "get", args.input) + + if isinstance(out, list) and out: + out = out[0] + else: + print("FAIL: " + args.description) + return + + res_len = len(out["results"]) + fault = out["results"][0]["fault"] if res_len and "fault" in out["results"][0] else 0 + + if fault != args.expected_error: + print("FAIL: " + args.description) + return + + if args.expected_error == 0 and res_len == 0: + print("FAIL: " + args.description) + return + + # Check if output matches expected output + if args.output != {}: + if out == args.output: + print("PASS: " + args.description) + else: + print("FAIL: " + args.description) + else: + print("PASS: " + args.description) + +if __name__ == "__main__": + # Check for correct command line arguments + if len(sys.argv) != 2: + print("Usage: {} ".format(sys.argv[0])) + sys.exit(1) + + test_arguments_file = sys.argv[1] + + try: + with open(test_arguments_file, 'r') as f: + test_arguments_data = json.load(f) + service_name = test_arguments_data.get("object", "bbfdm") + args_list = [TestArguments(**test_case, service=service_name) for test_case in test_arguments_data["get"]] + except FileNotFoundError: + print("File not found:", test_arguments_file) + sys.exit(1) + except json.JSONDecodeError as e: + print("Error parsing JSON:", e) + sys.exit(1) + + ubus.connect() + + # Run tests for each set of arguments + for args in args_list: + run_test(args) + + ubus.disconnect() diff --git a/test/python-test-cases/python/validate_ubus_instances_method.py b/test/python-test-cases/python/validate_ubus_instances_method.py new file mode 100755 index 00000000..5c60f6e7 --- /dev/null +++ b/test/python-test-cases/python/validate_ubus_instances_method.py @@ -0,0 +1,79 @@ +#!/usr/bin/python3 + +import sys +import ubus +import json + +class TestArguments: + """ + Class to hold test arguments. + """ + def __init__(self, description, service, input, expected_error, output): + self.description = description + self.service = service + self.input = input + self.expected_error = expected_error + self.output = output + +def run_test(args): + """ + Run a single test. + """ + + print("Running: " + args.description) + + out = ubus.call(args.service, "instances", args.input) + + if isinstance(out, list) and out: + out = out[0] + else: + print("FAIL: " + args.description) + return + + res_len = len(out["results"]) + fault = out["results"][0]["fault"] if res_len and "fault" in out["results"][0] else 0 + + if fault != args.expected_error: + print("FAIL: " + args.description) + return + + if args.expected_error == 0 and res_len == 0: + print("FAIL: " + args.description) + return + + # Check if output matches expected output + if args.output != {}: + if out == args.output: + print("PASS: " + args.description) + else: + print("FAIL: " + args.description) + else: + print("PASS: " + args.description) + +if __name__ == "__main__": + # Check for correct command line arguments + if len(sys.argv) != 2: + print("Usage: {} ".format(sys.argv[0])) + sys.exit(1) + + test_arguments_file = sys.argv[1] + + try: + with open(test_arguments_file, 'r') as f: + test_arguments_data = json.load(f) + service_name = test_arguments_data.get("object", "bbfdm") + args_list = [TestArguments(**test_case, service=service_name) for test_case in test_arguments_data["instances"]] + except FileNotFoundError: + print("File not found:", test_arguments_file) + sys.exit(1) + except json.JSONDecodeError as e: + print("Error parsing JSON:", e) + sys.exit(1) + + ubus.connect() + + # Run tests for each set of arguments + for args in args_list: + run_test(args) + + ubus.disconnect() diff --git a/test/python-test-cases/python/validate_ubus_notify_event_method.py b/test/python-test-cases/python/validate_ubus_notify_event_method.py new file mode 100755 index 00000000..9b63fe3f --- /dev/null +++ b/test/python-test-cases/python/validate_ubus_notify_event_method.py @@ -0,0 +1,69 @@ +#!/usr/bin/python3 + +import sys +import ubus +import json + +class TestArguments: + """ + Class to hold test arguments. + """ + def __init__(self, description, service, method, input, output): + self.description = description + self.service = service + self.method = method + self.input = input + self.output = output + +def callback(event, data): + """ + Callback function to handle UBUS events. + """ + if data == args.output: + print("PASS: " + args.description) + else: + print("FAIL: " + args.description) + ubus.disconnect() + exit(0) + +def run_test(args): + """ + Run a single test. + """ + + print("Running: " + args.description) + + ubus.connect() + + ubus.listen(("bbfdm.event", callback)) + + ubus.call(args.service, args.method, args.input) + + # Run UBUS loop with a timeout + ubus.loop(timeout=5000) + + ubus.disconnect() + print("FAIL: " + args.description) + +if __name__ == "__main__": + # Check for correct command line arguments + if len(sys.argv) != 2: + print("Usage: {} ".format(sys.argv[0])) + sys.exit(1) + + test_arguments_file = sys.argv[1] + + try: + with open(test_arguments_file, 'r') as f: + test_arguments_data = json.load(f) + args_list = [TestArguments(**event) for event in test_arguments_data["events"]] + except FileNotFoundError: + print("File not found:", test_arguments_file) + sys.exit(1) + except json.JSONDecodeError as e: + print("Error parsing JSON:", e) + sys.exit(1) + + # Run tests for each set of arguments + for args in args_list: + run_test(args) diff --git a/test/python-test-cases/python/validate_ubus_schema_method.py b/test/python-test-cases/python/validate_ubus_schema_method.py new file mode 100755 index 00000000..c5180ba3 --- /dev/null +++ b/test/python-test-cases/python/validate_ubus_schema_method.py @@ -0,0 +1,80 @@ +#!/usr/bin/python3 + +import sys +import ubus +import json + +class TestArguments: + """ + Class to hold test arguments. + """ + def __init__(self, description, service, input, expected_error, output): + self.description = description + self.service = service + self.input = input + self.expected_error = expected_error + self.output = output + +def run_test(args): + """ + Run a single test. + """ + + print("Running: " + args.description) + + out = ubus.call(args.service, "schema", args.input) + + if isinstance(out, list) and out: + out = out[0] + else: + print("FAIL: " + args.description) + return + + res_len = len(out["results"]) + fault = out["results"][0]["fault"] if res_len and "fault" in out["results"][0] else 0 + + if fault != args.expected_error: + print("FAIL: " + args.description) + return + + if args.expected_error == 0 and res_len == 0: + print("FAIL: " + args.description) + return + + # Check if output matches expected output + if args.output != {}: + print(out) + if out == args.output: + print("PASS: " + args.description) + else: + print("FAIL: " + args.description) + else: + print("PASS: " + args.description) + +if __name__ == "__main__": + # Check for correct command line arguments + if len(sys.argv) != 2: + print("Usage: {} ".format(sys.argv[0])) + sys.exit(1) + + test_arguments_file = sys.argv[1] + + try: + with open(test_arguments_file, 'r') as f: + test_arguments_data = json.load(f) + service_name = test_arguments_data.get("object", "bbfdm") + args_list = [TestArguments(**test_case, service=service_name) for test_case in test_arguments_data["schema"]] + except FileNotFoundError: + print("File not found:", test_arguments_file) + sys.exit(1) + except json.JSONDecodeError as e: + print("Error parsing JSON:", e) + sys.exit(1) + + ubus.connect() + + # Run tests for each set of arguments + for args in args_list: + run_test(args) + + ubus.disconnect()