From 9ca9f7d8e58061cec28417e3b26d7a1652441740 Mon Sep 17 00:00:00 2001 From: Dinesh Kumar Sellappan <40899231+selldinesh@users.noreply.github.com> Date: Tue, 14 Nov 2023 00:02:14 -0800 Subject: [PATCH] Adding API test cases for a bunch of SAI objects (#187) Signed-off-by: selldinesh --- tests/api/test_ars.py | 26 +++ tests/api/test_ars_profile.py | 26 +++ tests/api/test_counter.py | 26 +++ tests/api/test_dtel.py | 218 +++++++++++++++++++++++++ tests/api/test_dtel_event.py | 29 ++++ tests/api/test_dtel_int_session.py | 26 +++ tests/api/test_dtel_report_session.py | 26 +++ tests/api/test_generic_programmable.py | 26 +++ tests/api/test_hash.py | 26 +++ tests/api/test_l2mc_group.py | 26 +++ tests/api/test_macsec.py | 29 ++++ tests/api/test_macsec_flow.py | 29 ++++ tests/api/test_nat_zone_counter.py | 26 +++ tests/api/test_next_hop_group_map.py | 29 ++++ tests/api/test_tam.py | 26 +++ tests/api/test_tam_collector.py | 47 ++++++ tests/api/test_udf.py | 93 +++++++++++ tests/api/test_udf_match.py | 26 +++ 18 files changed, 760 insertions(+) create mode 100644 tests/api/test_ars.py create mode 100644 tests/api/test_ars_profile.py create mode 100644 tests/api/test_counter.py create mode 100644 tests/api/test_dtel.py create mode 100644 tests/api/test_dtel_event.py create mode 100644 tests/api/test_dtel_int_session.py create mode 100644 tests/api/test_dtel_report_session.py create mode 100644 tests/api/test_generic_programmable.py create mode 100644 tests/api/test_hash.py create mode 100644 tests/api/test_l2mc_group.py create mode 100644 tests/api/test_macsec.py create mode 100644 tests/api/test_macsec_flow.py create mode 100644 tests/api/test_nat_zone_counter.py create mode 100644 tests/api/test_next_hop_group_map.py create mode 100644 tests/api/test_tam.py create mode 100644 tests/api/test_tam_collector.py create mode 100644 tests/api/test_udf.py create mode 100644 tests/api/test_udf_match.py diff --git a/tests/api/test_ars.py b/tests/api/test_ars.py new file mode 100644 index 00000000..1a0d22da --- /dev/null +++ b/tests/api/test_ars.py @@ -0,0 +1,26 @@ +from pprint import pprint + + +class TestSaiArs: + # object with no attributes + + def test_ars_create(self, npu): + commands = [ + { + 'name': 'ars_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_ARS', + 'attributes': [], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_ars_remove(self, npu): + commands = [{'name': 'ars_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_ars_profile.py b/tests/api/test_ars_profile.py new file mode 100644 index 00000000..0d45f96e --- /dev/null +++ b/tests/api/test_ars_profile.py @@ -0,0 +1,26 @@ +from pprint import pprint + + +class TestSaiArsProfile: + # object with no attributes + + def test_ars_profile_create(self, npu): + commands = [ + { + 'name': 'ars_profile_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_ARS_PROFILE', + 'attributes': [], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_ars_profile_remove(self, npu): + commands = [{'name': 'ars_profile_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_counter.py b/tests/api/test_counter.py new file mode 100644 index 00000000..2e3ac1c5 --- /dev/null +++ b/tests/api/test_counter.py @@ -0,0 +1,26 @@ +from pprint import pprint + + +class TestSaiCounter: + # object with no attributes + + def test_counter_create(self, npu): + commands = [ + { + 'name': 'counter_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_COUNTER', + 'attributes': [], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_counter_remove(self, npu): + commands = [{'name': 'counter_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_dtel.py b/tests/api/test_dtel.py new file mode 100644 index 00000000..309d5563 --- /dev/null +++ b/tests/api/test_dtel.py @@ -0,0 +1,218 @@ +from pprint import pprint + +import pytest + + +@pytest.fixture(scope='module', autouse=True) +def skip_all(testbed_instance): + testbed = testbed_instance + if testbed is not None and len(testbed.npu) != 1: + pytest.skip('invalid for {} testbed'.format(testbed.name)) + + +@pytest.mark.npu +class TestSaiDtel: + # object with no attributes + + def test_dtel_create(self, npu): + commands = [ + { + 'name': 'dtel_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_DTEL', + 'attributes': [], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + @pytest.mark.dependency(name='test_sai_dtel_attr_postcard_enable_set') + def test_sai_dtel_attr_postcard_enable_set(self, npu): + commands = [ + { + 'name': 'dtel_1', + 'op': 'set', + 'attributes': ['SAI_DTEL_ATTR_POSTCARD_ENABLE', 'false'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + @pytest.mark.dependency(depends=['test_sai_dtel_attr_postcard_enable_set']) + def test_sai_dtel_attr_postcard_enable_get(self, npu): + commands = [ + { + 'name': 'dtel_1', + 'op': 'get', + 'attributes': ['SAI_DTEL_ATTR_POSTCARD_ENABLE'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values get =======') + for command in results: + for attribute in command: + pprint(attribute.raw()) + r_value = results[0][0].value() + print(r_value) + assert r_value == 'false', 'Get error, expected false but got %s' % r_value + + @pytest.mark.dependency(name='test_sai_dtel_attr_drop_report_enable_set') + def test_sai_dtel_attr_drop_report_enable_set(self, npu): + commands = [ + { + 'name': 'dtel_1', + 'op': 'set', + 'attributes': ['SAI_DTEL_ATTR_DROP_REPORT_ENABLE', 'false'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + @pytest.mark.dependency(depends=['test_sai_dtel_attr_drop_report_enable_set']) + def test_sai_dtel_attr_drop_report_enable_get(self, npu): + commands = [ + { + 'name': 'dtel_1', + 'op': 'get', + 'attributes': ['SAI_DTEL_ATTR_DROP_REPORT_ENABLE'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values get =======') + for command in results: + for attribute in command: + pprint(attribute.raw()) + r_value = results[0][0].value() + print(r_value) + assert r_value == 'false', 'Get error, expected false but got %s' % r_value + + @pytest.mark.dependency(name='test_sai_dtel_attr_queue_report_enable_set') + def test_sai_dtel_attr_queue_report_enable_set(self, npu): + commands = [ + { + 'name': 'dtel_1', + 'op': 'set', + 'attributes': ['SAI_DTEL_ATTR_QUEUE_REPORT_ENABLE', 'false'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + @pytest.mark.dependency(depends=['test_sai_dtel_attr_queue_report_enable_set']) + def test_sai_dtel_attr_queue_report_enable_get(self, npu): + commands = [ + { + 'name': 'dtel_1', + 'op': 'get', + 'attributes': ['SAI_DTEL_ATTR_QUEUE_REPORT_ENABLE'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values get =======') + for command in results: + for attribute in command: + pprint(attribute.raw()) + r_value = results[0][0].value() + print(r_value) + assert r_value == 'false', 'Get error, expected false but got %s' % r_value + + @pytest.mark.dependency(name='test_sai_dtel_attr_switch_id_set') + def test_sai_dtel_attr_switch_id_set(self, npu): + commands = [ + { + 'name': 'dtel_1', + 'op': 'set', + 'attributes': ['SAI_DTEL_ATTR_SWITCH_ID', '0'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + @pytest.mark.dependency(depends=['test_sai_dtel_attr_switch_id_set']) + def test_sai_dtel_attr_switch_id_get(self, npu): + commands = [ + {'name': 'dtel_1', 'op': 'get', 'attributes': ['SAI_DTEL_ATTR_SWITCH_ID']} + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values get =======') + for command in results: + for attribute in command: + pprint(attribute.raw()) + r_value = results[0][0].value() + print(r_value) + assert r_value == '0', 'Get error, expected 0 but got %s' % r_value + + @pytest.mark.dependency(name='test_sai_dtel_attr_flow_state_clear_cycle_set') + def test_sai_dtel_attr_flow_state_clear_cycle_set(self, npu): + commands = [ + { + 'name': 'dtel_1', + 'op': 'set', + 'attributes': ['SAI_DTEL_ATTR_FLOW_STATE_CLEAR_CYCLE', '0'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + @pytest.mark.dependency(depends=['test_sai_dtel_attr_flow_state_clear_cycle_set']) + def test_sai_dtel_attr_flow_state_clear_cycle_get(self, npu): + commands = [ + { + 'name': 'dtel_1', + 'op': 'get', + 'attributes': ['SAI_DTEL_ATTR_FLOW_STATE_CLEAR_CYCLE'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values get =======') + for command in results: + for attribute in command: + pprint(attribute.raw()) + r_value = results[0][0].value() + print(r_value) + assert r_value == '0', 'Get error, expected 0 but got %s' % r_value + + @pytest.mark.dependency(name='test_sai_dtel_attr_latency_sensitivity_set') + def test_sai_dtel_attr_latency_sensitivity_set(self, npu): + commands = [ + { + 'name': 'dtel_1', + 'op': 'set', + 'attributes': ['SAI_DTEL_ATTR_LATENCY_SENSITIVITY', '0'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values set =======') + pprint(results) + + @pytest.mark.dependency(depends=['test_sai_dtel_attr_latency_sensitivity_set']) + def test_sai_dtel_attr_latency_sensitivity_get(self, npu): + commands = [ + { + 'name': 'dtel_1', + 'op': 'get', + 'attributes': ['SAI_DTEL_ATTR_LATENCY_SENSITIVITY'], + } + ] + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values get =======') + for command in results: + for attribute in command: + pprint(attribute.raw()) + r_value = results[0][0].value() + print(r_value) + assert r_value == '0', 'Get error, expected 0 but got %s' % r_value + + def test_dtel_remove(self, npu): + commands = [{'name': 'dtel_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_dtel_event.py b/tests/api/test_dtel_event.py new file mode 100644 index 00000000..2b6b2778 --- /dev/null +++ b/tests/api/test_dtel_event.py @@ -0,0 +1,29 @@ +from pprint import pprint + + +class TestSaiDtelEvent: + # object with no parents + + def test_dtel_event_create(self, npu): + commands = [ + { + 'name': 'dtel_event_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_DTEL_EVENT', + 'attributes': [ + 'SAI_DTEL_EVENT_ATTR_TYPE', + 'SAI_DTEL_EVENT_TYPE_FLOW_STATE', + ], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_dtel_event_remove(self, npu): + commands = [{'name': 'dtel_event_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_dtel_int_session.py b/tests/api/test_dtel_int_session.py new file mode 100644 index 00000000..0a2b9651 --- /dev/null +++ b/tests/api/test_dtel_int_session.py @@ -0,0 +1,26 @@ +from pprint import pprint + + +class TestSaiDtelIntSession: + # object with no attributes + + def test_dtel_int_session_create(self, npu): + commands = [ + { + 'name': 'dtel_int_session_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_DTEL_INT_SESSION', + 'attributes': [], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_dtel_int_session_remove(self, npu): + commands = [{'name': 'dtel_int_session_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_dtel_report_session.py b/tests/api/test_dtel_report_session.py new file mode 100644 index 00000000..6369606c --- /dev/null +++ b/tests/api/test_dtel_report_session.py @@ -0,0 +1,26 @@ +from pprint import pprint + + +class TestSaiDtelReportSession: + # object with no attributes + + def test_dtel_report_session_create(self, npu): + commands = [ + { + 'name': 'dtel_report_session_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_DTEL_REPORT_SESSION', + 'attributes': [], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_dtel_report_session_remove(self, npu): + commands = [{'name': 'dtel_report_session_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_generic_programmable.py b/tests/api/test_generic_programmable.py new file mode 100644 index 00000000..8dbccde9 --- /dev/null +++ b/tests/api/test_generic_programmable.py @@ -0,0 +1,26 @@ +from pprint import pprint + + +class TestSaiGenericProgrammable: + # object with no parents + + def test_generic_programmable_create(self, npu): + commands = [ + { + 'name': 'generic_programmable_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_GENERIC_PROGRAMMABLE', + 'attributes': ['SAI_GENERIC_PROGRAMMABLE_ATTR_OBJECT_NAME', '2:10,11'], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_generic_programmable_remove(self, npu): + commands = [{'name': 'generic_programmable_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_hash.py b/tests/api/test_hash.py new file mode 100644 index 00000000..38b9e658 --- /dev/null +++ b/tests/api/test_hash.py @@ -0,0 +1,26 @@ +from pprint import pprint + + +class TestSaiHash: + # object with no attributes + + def test_hash_create(self, npu): + commands = [ + { + 'name': 'hash_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_HASH', + 'attributes': [], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_hash_remove(self, npu): + commands = [{'name': 'hash_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_l2mc_group.py b/tests/api/test_l2mc_group.py new file mode 100644 index 00000000..1f05f0f4 --- /dev/null +++ b/tests/api/test_l2mc_group.py @@ -0,0 +1,26 @@ +from pprint import pprint + + +class TestSaiL2McGroup: + # object with no attributes + + def test_l2mc_group_create(self, npu): + commands = [ + { + 'name': 'l2mc_group_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_L2MC_GROUP', + 'attributes': [], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_l2mc_group_remove(self, npu): + commands = [{'name': 'l2mc_group_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_macsec.py b/tests/api/test_macsec.py new file mode 100644 index 00000000..b1b66dd7 --- /dev/null +++ b/tests/api/test_macsec.py @@ -0,0 +1,29 @@ +from pprint import pprint + + +class TestSaiMacsec: + # object with no parents + + def test_macsec_create(self, npu): + commands = [ + { + 'name': 'macsec_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_MACSEC', + 'attributes': [ + 'SAI_MACSEC_ATTR_DIRECTION', + 'SAI_MACSEC_DIRECTION_EGRESS', + ], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_macsec_remove(self, npu): + commands = [{'name': 'macsec_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_macsec_flow.py b/tests/api/test_macsec_flow.py new file mode 100644 index 00000000..acb9b49c --- /dev/null +++ b/tests/api/test_macsec_flow.py @@ -0,0 +1,29 @@ +from pprint import pprint + + +class TestSaiMacsecFlow: + # object with no parents + + def test_macsec_flow_create(self, npu): + commands = [ + { + 'name': 'macsec_flow_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_MACSEC_FLOW', + 'attributes': [ + 'SAI_MACSEC_FLOW_ATTR_MACSEC_DIRECTION', + 'SAI_MACSEC_DIRECTION_EGRESS', + ], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_macsec_flow_remove(self, npu): + commands = [{'name': 'macsec_flow_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_nat_zone_counter.py b/tests/api/test_nat_zone_counter.py new file mode 100644 index 00000000..7c17626e --- /dev/null +++ b/tests/api/test_nat_zone_counter.py @@ -0,0 +1,26 @@ +from pprint import pprint + + +class TestSaiNatZoneCounter: + # object with no attributes + + def test_nat_zone_counter_create(self, npu): + commands = [ + { + 'name': 'nat_zone_counter_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_NAT_ZONE_COUNTER', + 'attributes': [], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_nat_zone_counter_remove(self, npu): + commands = [{'name': 'nat_zone_counter_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_next_hop_group_map.py b/tests/api/test_next_hop_group_map.py new file mode 100644 index 00000000..0d65717e --- /dev/null +++ b/tests/api/test_next_hop_group_map.py @@ -0,0 +1,29 @@ +from pprint import pprint + + +class TestSaiNextHopGroupMap: + # object with no parents + + def test_next_hop_group_map_create(self, npu): + commands = [ + { + 'name': 'next_hop_group_map_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MAP', + 'attributes': [ + 'SAI_NEXT_HOP_GROUP_MAP_ATTR_TYPE', + 'SAI_NEXT_HOP_GROUP_MAP_TYPE_FORWARDING_CLASS_TO_INDEX', + ], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_next_hop_group_map_remove(self, npu): + commands = [{'name': 'next_hop_group_map_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_tam.py b/tests/api/test_tam.py new file mode 100644 index 00000000..94aa30fe --- /dev/null +++ b/tests/api/test_tam.py @@ -0,0 +1,26 @@ +from pprint import pprint + + +class TestSaiTam: + # object with no attributes + + def test_tam_create(self, npu): + commands = [ + { + 'name': 'tam_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_TAM', + 'attributes': [], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_tam_remove(self, npu): + commands = [{'name': 'tam_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_tam_collector.py b/tests/api/test_tam_collector.py new file mode 100644 index 00000000..6e5eb428 --- /dev/null +++ b/tests/api/test_tam_collector.py @@ -0,0 +1,47 @@ +from pprint import pprint + + +class TestSaiTamCollector: + # object with parent SAI_OBJECT_TYPE_TAM_TRANSPORT + + def test_tam_collector_create(self, npu): + commands = [ + { + 'name': 'tam_transport_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_TAM_TRANSPORT', + 'attributes': [ + 'SAI_TAM_TRANSPORT_ATTR_TRANSPORT_TYPE', + 'SAI_TAM_TRANSPORT_TYPE_TCP', + ], + }, + { + 'name': 'tam_collector_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_TAM_COLLECTOR', + 'attributes': [ + 'SAI_TAM_COLLECTOR_ATTR_SRC_IP', + '180.0.0.1', + 'SAI_TAM_COLLECTOR_ATTR_DST_IP', + '180.0.0.1', + 'SAI_TAM_COLLECTOR_ATTR_TRANSPORT', + '$tam_transport_1', + 'SAI_TAM_COLLECTOR_ATTR_DSCP_VALUE', + '1', + ], + }, + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_tam_collector_remove(self, npu): + commands = [ + {'name': 'tam_collector_1', 'op': 'remove'}, + {'name': 'tam_transport_1', 'op': 'remove'}, + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_udf.py b/tests/api/test_udf.py new file mode 100644 index 00000000..566ec48d --- /dev/null +++ b/tests/api/test_udf.py @@ -0,0 +1,93 @@ +from pprint import pprint +import pytest + + +@pytest.fixture(scope='module', autouse=True) +def skip_all(testbed_instance): + testbed = testbed_instance + if testbed is not None and len(testbed.npu) != 1: + pytest.skip('invalid for {} testbed'.format(testbed.name)) + +@pytest.mark.npu +class TestSaiUdf: + # object with parent SAI_OBJECT_TYPE_UDF_MATCH SAI_OBJECT_TYPE_UDF_GROUP + + def test_udf_create(self, npu): + commands = [ + { + 'name': 'udf_match_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_UDF_MATCH', + 'attributes': [], + }, + { + 'name': 'udf_group_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_UDF_GROUP', + 'attributes': ['SAI_UDF_GROUP_ATTR_LENGTH', '10'], + }, + { + 'name': 'udf_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_UDF', + 'attributes': [ + 'SAI_UDF_ATTR_MATCH_ID', + '$udf_match_1', + 'SAI_UDF_ATTR_GROUP_ID', + '$udf_group_1', + 'SAI_UDF_ATTR_OFFSET', + '10', + ], + }, + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + @pytest.mark.dependency(name="test_sai_udf_attr_base_set") + def test_sai_udf_attr_base_set(self, npu): + + commands = [ + { + "name": "udf_1", + "op": "set", + "attributes": ["SAI_UDF_ATTR_BASE", 'SAI_UDF_BASE_L2'] + } + ] + results = [*npu.process_commands(commands)] + print("======= SAI commands RETURN values set =======") + pprint(results) + + + + @pytest.mark.dependency(depends=["test_sai_udf_attr_base_set"]) + def test_sai_udf_attr_base_get(self, npu): + + commands = [ + { + "name": "udf_1", + "op": "get", + "attributes": ["SAI_UDF_ATTR_BASE"] + } + ] + results = [*npu.process_commands(commands)] + print("======= SAI commands RETURN values get =======") + for command in results: + for attribute in command: + pprint(attribute.raw()) + r_value = results[0][0].value() + print(r_value) + assert r_value == 'SAI_UDF_BASE_L2', 'Get error, expected SAI_UDF_BASE_L2 but got %s' % r_value + + + def test_udf_remove(self, npu): + commands = [ + {'name': 'udf_1', 'op': 'remove'}, + {'name': 'udf_group_1', 'op': 'remove'}, + {'name': 'udf_match_1', 'op': 'remove'}, + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results) diff --git a/tests/api/test_udf_match.py b/tests/api/test_udf_match.py new file mode 100644 index 00000000..53fa01fc --- /dev/null +++ b/tests/api/test_udf_match.py @@ -0,0 +1,26 @@ +from pprint import pprint + + +class TestSaiUdfMatch: + # object with no attributes + + def test_udf_match_create(self, npu): + commands = [ + { + 'name': 'udf_match_1', + 'op': 'create', + 'type': 'SAI_OBJECT_TYPE_UDF_MATCH', + 'attributes': [], + } + ] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values create =======') + pprint(results) + + def test_udf_match_remove(self, npu): + commands = [{'name': 'udf_match_1', 'op': 'remove'}] + + results = [*npu.process_commands(commands)] + print('======= SAI commands RETURN values remove =======') + pprint(results)