diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2020-05-06 18:35:26 +0200 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2020-05-06 18:49:31 +0200 |
commit | ab1904a307b531dbd1c738ef04eeeeb68f9920b3 (patch) | |
tree | 665d524265171d0e977633f4c29536b9174d8364 /selftest/config_test | |
parent | 636f560dc2f26d303a0bdb7115744cb402159131 (diff) |
selftest: Move tests into own subdirectories
Change-Id: Id21cda19df131e24402e1a593036e1e33a914920
Diffstat (limited to 'selftest/config_test')
l--------- | selftest/config_test/_prep.py | 1 | ||||
-rw-r--r-- | selftest/config_test/config_test.err | 0 | ||||
-rw-r--r-- | selftest/config_test/config_test.ok | 112 | ||||
-rwxr-xr-x | selftest/config_test/config_test.py | 216 |
4 files changed, 329 insertions, 0 deletions
diff --git a/selftest/config_test/_prep.py b/selftest/config_test/_prep.py new file mode 120000 index 0000000..9cea3fe --- /dev/null +++ b/selftest/config_test/_prep.py @@ -0,0 +1 @@ +../_prep.py
\ No newline at end of file diff --git a/selftest/config_test/config_test.err b/selftest/config_test/config_test.err new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/selftest/config_test/config_test.err diff --git a/selftest/config_test/config_test.ok b/selftest/config_test/config_test.ok new file mode 100644 index 0000000..e1fb87d --- /dev/null +++ b/selftest/config_test/config_test.ok @@ -0,0 +1,112 @@ +{'addr': ['0.0.0.0', + '255.255.255.255', + '10.11.12.13', + '10.0.99.1', + '192.168.0.14'], + 'bts': [{'addr': '10.42.42.114', + 'name': 'sysmoBTS 1002', + 'trx': [{'band': 'GSM-1800', + 'timeslots': ['CCCH+SDCCH4', + 'SDCCH8', + 'TCH/F_TCH/H_PDCH', + 'TCH/F_TCH/H_PDCH', + 'TCH/F_TCH/H_PDCH', + 'TCH/F_TCH/H_PDCH', + 'TCH/F_TCH/H_PDCH', + 'TCH/F_TCH/H_PDCH']}, + {'band': 'GSM-1900', + 'timeslots': ['SDCCH8', + 'PDCH', + 'PDCH', + 'PDCH', + 'PDCH', + 'PDCH', + 'PDCH', + 'PDCH']}], + 'type': 'sysmobts'}], + 'hwaddr': ['ca:ff:ee:ba:aa:be', + '00:00:00:00:00:00', + 'CA:FF:EE:BA:AA:BE', + 'cA:Ff:eE:Ba:aA:Be', + 'ff:ff:ff:ff:ff:ff'], + 'imsi': ['012345', '012345678', '012345678912345'], + 'ki': ['000102030405060708090a0b0c0d0e0f', '000102030405060708090a0b0c0d0e0f'], + 'modems': [{'dbus_path': '/sierra_0', + 'imsi': '901700000009001', + 'ki': 'D620F48487B1B782DA55DF6717F08FF9', + 'msisdn': '7801'}, + {'dbus_path': '/sierra_1', + 'imsi': '901700000009002', + 'ki': 'D620F48487B1B782DA55DF6717F08FF9', + 'msisdn': '7802'}]} +- expect validation success: +Validation: OK +- unknown item: +--- -: ERR: ValueError: config item not known: 'bts[].unknown_item' +Validation: Error +- wrong type modems[].imsi: +--- -: ERR: ValueError: config item is dict but should be a leaf node of type 'imsi': 'modems[].imsi' +Validation: Error +- invalid key with space: +--- -: ERR: ValueError: invalid config key: 'imsi ' +Validation: Error +- list instead of dict: +--- -: ERR: ValueError: config item not known: 'a_dict[]' +Validation: Error +- unknown band: +--- bts[].trx[].band: ERR: ValueError: Unknown GSM band: 'what' +Validation: Error +- invalid v4 addrs: +--- addr[]: ERR: ValueError: Invalid IPv4 address: '1.2.3' +Validation: Error +--- addr[]: ERR: ValueError: Invalid IPv4 address: '1.2.3 .4' +Validation: Error +--- addr[]: ERR: ValueError: Invalid IPv4 address: '91.2.3' +Validation: Error +--- addr[]: ERR: ValueError: Invalid IPv4 address: 'go away' +Validation: Error +--- addr[]: ERR: ValueError: Invalid IPv4 address: '' +Validation: Error +--- addr[]: ERR: ValueError: Invalid IPv4 address: None +Validation: Error +- invalid hw addrs: +--- hwaddr[]: ERR: ValueError: Invalid hardware address: '1.2.3' +Validation: Error +--- hwaddr[]: ERR: ValueError: Invalid hardware address: '0b:0c:0d:0e:0f:0g' +Validation: Error +--- hwaddr[]: ERR: ValueError: Invalid hardware address: '0b:0c:0d:0e : 0f:0f' +Validation: Error +--- hwaddr[]: ERR: ValueError: Invalid hardware address: 'go away' +Validation: Error +--- hwaddr[]: ERR: ValueError: Invalid hardware address: '' +Validation: Error +--- hwaddr[]: ERR: ValueError: Invalid hardware address: None +Validation: Error +- invalid imsis: +--- imsi[]: ERR: ValueError: Invalid IMSI: '99999999x9' +Validation: Error +--- imsi[]: ERR: ValueError: Invalid IMSI: '123 456 789 123' +Validation: Error +--- imsi[]: ERR: ValueError: Invalid IMSI: 'go away' +Validation: Error +--- imsi[]: ERR: ValueError: Invalid IMSI: '' +Validation: Error +--- imsi[]: ERR: ValueError: Invalid IMSI: None +Validation: Error +- Combine dicts: +- Combine dicts 2: +- Combine lists: +- Combine lists 2: +- Combine lists 3: +ValueError expected +- Combine lists 4: +ValueError expected +- Combine lists 5: +ValueError expected +- Combine lists 6: +- Combine lists 7: +- Combine lists 8: +- Combine lists 9: +- Combine lists 10: +- Combine lists 13: +- Combine lists 14: diff --git a/selftest/config_test/config_test.py b/selftest/config_test/config_test.py new file mode 100755 index 0000000..797553d --- /dev/null +++ b/selftest/config_test/config_test.py @@ -0,0 +1,216 @@ +#!/usr/bin/env python3 + +import _prep + +import sys +import os +import io +import pprint +import copy + +from osmo_gsm_tester.core import config, log, schema + +example_config_file = 'test.cfg' +example_config = os.path.join(_prep.script_dir, example_config_file) +cfg = config.read(example_config) + +pprint.pprint(cfg, width=81) + +test_schema = { + 'modems[].dbus_path': schema.STR, + 'modems[].msisdn': schema.STR, + 'modems[].imsi': schema.IMSI, + 'modems[].ki': schema.STR, + 'bts[].name' : schema.STR, + 'bts[].type' : schema.STR, + 'bts[].addr' : schema.STR, + 'bts[].trx[].timeslots[]' : schema.STR, + 'bts[].trx[].band' : schema.BAND, + 'a_dict.foo' : schema.INT, + 'addr[]' : schema.IPV4, + 'hwaddr[]' : schema.HWADDR, + 'imsi[]' : schema.IMSI, + 'ki[]' : schema.KI, + } + +def val(which): + try: + schema.validate(which, test_schema) + print('Validation: OK') + except ValueError: + log.log_exn() + print('Validation: Error') + +print('- expect validation success:') +val(cfg) + +print('- unknown item:') +c = copy.deepcopy(cfg) +c['bts'][0]['unknown_item'] = 'no' +val(c) + +print('- wrong type modems[].imsi:') +c = copy.deepcopy(cfg) +c['modems'][0]['imsi'] = {'no':'no'} +val(c) + +print('- invalid key with space:') +c = copy.deepcopy(cfg) +c['modems'][0]['imsi '] = '12345' +val(c) + +print('- list instead of dict:') +c = copy.deepcopy(cfg) +c['a_dict'] = [ 1, 2, 3 ] +val(c) + +print('- unknown band:') +c = copy.deepcopy(cfg) +c['bts'][0]['trx'][0]['band'] = 'what' +val(c) + +print('- invalid v4 addrs:') +c = copy.deepcopy(cfg) +c['addr'][3] = '1.2.3' +val(c) +c['addr'][3] = '1.2.3 .4' +val(c) +c['addr'][3] = '91.2.3' +val(c) +c['addr'][3] = 'go away' +val(c) +c['addr'][3] = '' +val(c) +c['addr'][3] = None +val(c) + +print('- invalid hw addrs:') +c = copy.deepcopy(cfg) +c['hwaddr'][3] = '1.2.3' +val(c) +c['hwaddr'][3] = '0b:0c:0d:0e:0f:0g' +val(c) +c['hwaddr'][3] = '0b:0c:0d:0e : 0f:0f' +val(c) +c['hwaddr'][3] = 'go away' +val(c) +c['hwaddr'][3] = '' +val(c) +c['hwaddr'][3] = None +val(c) + +print('- invalid imsis:') +c = copy.deepcopy(cfg) +c['imsi'][2] = '99999999x9' +val(c) +c['imsi'][2] = '123 456 789 123' +val(c) +c['imsi'][2] = 'go away' +val(c) +c['imsi'][2] = '' +val(c) +c['imsi'][2] = None +val(c) + +print('- Combine dicts:') +a = {'times': '2'} +b = {'type': 'osmo-bts-trx'} +res = {'times': '2', 'type': 'osmo-bts-trx'} +schema.combine(a, b) +assert a == res + +print('- Combine dicts 2:') +a = {'times': '1', 'label': 'foo', 'type': 'osmo-bts-trx'} +b = {'type': 'osmo-bts-trx'} +res = {'times': '1', 'label': 'foo', 'type': 'osmo-bts-trx'} +schema.combine(a, b) +assert a == res + +print('- Combine lists:') +a = { 'a_list': ['x', 'y', 'z'] } +b = { 'a_list': ['y'] } +res = {'a_list': ['x', 'y', 'z']} +schema.combine(a, b) +assert a == res + +print('- Combine lists 2:') +a = { 'a_list': ['x'] } +b = { 'a_list': ['w', 'u', 'x', 'y', 'z'] } +res = {'a_list': ['x', 'w', 'u', 'y', 'z']} +schema.combine(a, b) +assert a == res + +print('- Combine lists 3:') +a = { 'a_list': ['x', 3] } +b = { 'a_list': ['y', 'z'] } +try: + schema.combine(a, b) +except ValueError: + print("ValueError expected") + +print('- Combine lists 4:') +a = { 'a_list': [2, 3] } +b = { 'a_list': ['y', 'z'] } +try: + schema.combine(a, b) +except ValueError: + print("ValueError expected") + +print('- Combine lists 5:') +a = { 'a_list': [{}, {}] } +b = { 'a_list': ['y', 'z'] } +try: + schema.combine(a, b) +except ValueError: + print("ValueError expected") + +print('- Combine lists 6:') +a = { 'a_list': [{}, {}] } +b = { 'a_list': [{}] } +res = {'a_list': [{}, {}]} +schema.combine(a, b) +assert a == res + +print('- Combine lists 7:') +a = { 'times': '1', 'label': 'foo', 'trx': [{'nominal power': '10'}, {'nominal power': '12'}] } +b = { 'type': 'osmo-bts-trx', 'trx': [{'nominal power': '10'}, {'nominal power': '12'}] } +res = {'times': '1', 'label': 'foo', 'trx': [{'nominal power': '10'}, {'nominal power': '12'}], 'type': 'osmo-bts-trx'} +schema.combine(a, b) +assert a == res + +print('- Combine lists 8:') +a = { 'times': '1', 'label': 'foo', 'trx': [{'nominal power': '10'}] } +b = { 'type': 'osmo-bts-trx', 'trx': [{'nominal power': '10'}, {'nominal power': '12'}] } +res = {'times': '1', 'label': 'foo', 'trx': [{'nominal power': '10'}, {'nominal power': '12'}], 'type': 'osmo-bts-trx'} +schema.combine(a, b) +assert a == res + +print('- Combine lists 9:') +a = { 'times': '1', 'label': 'foo', 'trx': [{'nominal power': '10'}, {'nominal power': '12'}] } +b = { 'type': 'osmo-bts-trx', 'trx': [{'nominal power': '10'}] } +res = {'times': '1', 'label': 'foo', 'trx': [{'nominal power': '10'}, {'nominal power': '12'}], 'type': 'osmo-bts-trx'} +schema.combine(a, b) +assert a == res + +print('- Combine lists 10:') +a = { 'times': '1', 'label': 'foo', 'trx': [{'nominal power': '10'}, {'nominal power': '12'}] } +b = { 'type': 'osmo-bts-trx', 'trx': [{}, {'nominal power': '12'}] } +res = {'times': '1', 'label': 'foo', 'trx': [{'nominal power': '10'}, {'nominal power': '12'}], 'type': 'osmo-bts-trx'} +schema.combine(a, b) +assert a == res + +print('- Combine lists 13:') +a = { 'times': '1', 'label': 'foo', 'trx': [{}, {'nominal power': '12'}] } +b = { 'type': 'osmo-bts-trx', 'trx': [{'nominal power': '10'}, {'nominal power': '12'}] } +res = {'times': '1', 'label': 'foo', 'trx': [{'nominal power': '10'}, {'nominal power': '12'}], 'type': 'osmo-bts-trx'} +schema.combine(a, b) +assert a == res + +print('- Combine lists 14:') +a = { 'times': '1', 'label': 'foo', 'trx': [] } +b = { 'type': 'osmo-bts-trx', 'trx': [] } +res = {'times': '1', 'label': 'foo', 'trx': [], 'type': 'osmo-bts-trx'} +schema.combine(a, b) +assert a == res + +# vim: expandtab tabstop=4 shiftwidth=4 |