Skip to content

Commit

Permalink
tests cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bktsim-arista authored and arista-nwolfe committed Mar 25, 2024
1 parent 17fe792 commit acfd7f4
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 130 deletions.
221 changes: 109 additions & 112 deletions tests/ecn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,129 +18,26 @@
sys.path.insert(0, modules_path)



class TestEcnConfig(object):
class TestEcnConfigBase(object):
@classmethod
def setup_class(cls):
print("SETUP")
os.environ["PATH"] += os.pathsep + scripts_path
os.environ['UTILITIES_UNIT_TESTING'] = "2"
print("SETUP")

def test_ecn_show_config(self):
TestEcnConfig.executor(testData['ecn_show_config'])

def test_ecn_show_config_verbose(self):
TestEcnConfig.executor(testData['ecn_show_config_verbose'])

def test_ecn_config_gmin(self):
TestEcnConfig.executor(testData['ecn_cfg_gmin'])

def test_ecn_config_gmin_verbose(self):
TestEcnConfig.executor(testData['ecn_cfg_gmin_verbose'])

def test_ecn_config_gmax(self):
TestEcnConfig.executor(testData['ecn_cfg_gmax'])

def test_ecn_config_ymin(self):
TestEcnConfig.executor(testData['ecn_cfg_ymin'])

def test_ecn_config_ymax(self):
TestEcnConfig.executor(testData['ecn_cfg_ymax'])

def test_ecn_config_rmin(self):
TestEcnConfig.executor(testData['ecn_cfg_gmin'])

def test_ecn_config_rmax(self):
TestEcnConfig.executor(testData['ecn_cfg_gmax'])

def test_ecn_config_gdrop(self):
TestEcnConfig.executor(testData['ecn_cfg_gdrop'])

def test_ecn_config_gdrop_verbose(self):
TestEcnConfig.executor(testData['ecn_cfg_gdrop_verbose'])

def test_ecn_config_ydrop(self):
TestEcnConfig.executor(testData['ecn_cfg_ydrop'])

def test_ecn_config_rdrop(self):
TestEcnConfig.executor(testData['ecn_cfg_rdrop'])

def test_ecn_config_multi_set(self):
TestEcnConfig.executor(testData['ecn_cfg_multi_set'])

def test_ecn_config_gmin_gmax_invalid(self):
TestEcnConfig.executor(testData['ecn_cfg_gmin_gmax_invalid'])

def test_ecn_config_ymin_ymax_invalid(self):
TestEcnConfig.executor(testData['ecn_cfg_ymin_ymax_invalid'])

def test_ecn_config_rmin_rmax_invalid(self):
TestEcnConfig.executor(testData['ecn_cfg_rmin_rmax_invalid'])

def test_ecn_config_rmax_invalid(self):
TestEcnConfig.executor(testData['ecn_cfg_rmax_invalid'])

def test_ecn_config_rdrop_invalid(self):
TestEcnConfig.executor(testData['ecn_cfg_rdrop_invalid'])

def test_ecn_queue_get(self):
TestEcnConfig.executor(testData['ecn_q_get'])

def test_ecn_queue_get_verbose(self):
TestEcnConfig.executor(testData['ecn_q_get_verbose'])

def test_ecn_queue_get_lossy(self):
TestEcnConfig.executor(testData['ecn_lossy_q_get'])

def test_ecn_all_queue_get(self):
TestEcnConfig.executor(testData['ecn_q_all_get'])

def test_ecn_queue_all_get_verbose(self):
TestEcnConfig.executor(testData['ecn_q_all_get_verbose'])

def test_ecn_queue_set_q_off(self):
TestEcnConfig.executor(testData['ecn_cfg_q_off'])

def test_ecn_queue_set_q_off_verbose(self):
TestEcnConfig.executor(testData['ecn_cfg_q_off_verbose'])

def test_ecn_queue_set_all_off(self):
TestEcnConfig.executor(testData['ecn_cfg_q_all_off'])

def test_ecn_queue_set_all_off_verbose(self):
TestEcnConfig.executor(testData['ecn_cfg_q_all_off_verbose'])

def test_ecn_queue_set_q_on(self):
TestEcnConfig.executor(testData['ecn_cfg_q_on'])

def test_ecn_queue_set_q_on_verbose(self):
TestEcnConfig.executor(testData['ecn_cfg_q_on_verbose'])

def test_ecn_queue_set_all_on(self):
TestEcnConfig.executor(testData['ecn_cfg_q_all_on'])

def test_ecn_queue_set_all_on_verbose(self):
TestEcnConfig.executor(testData['ecn_cfg_q_all_on_verbose'])

def test_ecn_queue_set_lossy_q_on(self):
TestEcnConfig.executor(testData['ecn_cfg_lossy_q_on'])

@staticmethod
def process_cmp_args(cmp_args):
def process_cmp_args(self, cmp_args):
if cmp_args is None:
return (None, None)
return cmp_args.split(',')

@staticmethod
def verify_profile(queue_db_entry, profile, value):
def verify_profile(self, queue_db_entry, profile, value):
if profile != None:
assert queue_db_entry[profile] == value
else:
assert profile not in queue_db_entry,\
"Profile needs to be fully removed from table to propagate NULL OID to SAI"

@staticmethod
def executor(input):
def executor(self, input):
runner = CliRunner()

if 'db_table' in input:
Expand Down Expand Up @@ -173,15 +70,15 @@ def executor(input):
fd = open('/tmp/ecnconfig', 'r')
cmp_data = json.load(fd)
if 'cmp_q_args' in input:
profile, value = TestEcnConfig.process_cmp_args(input['cmp_args'][0])
profile, value = self.process_cmp_args(input['cmp_args'][0])
if 'other_q' in input:
profile1, value1 = TestEcnConfig.process_cmp_args(input['cmp_args'][-1])
profile1, value1 = self.process_cmp_args(input['cmp_args'][-1])
for key in cmp_data:
queue_idx = ast.literal_eval(key)[-1]
if queue_idx in input['cmp_q_args']:
TestEcnConfig.verify_profile(cmp_data[key], profile, value)
self.verify_profile(cmp_data[key], profile, value)
if 'other_q' in input and queue_idx in input['other_q']:
TestEcnConfig.verify_profile(cmp_data[key], profile1, value1)
self.verify_profile(cmp_data[key], profile1, value1)
else:
for args in input['cmp_args']:
profile, name, value = args.split(',')
Expand All @@ -201,3 +98,103 @@ def teardown_class(cls):
if os.path.isfile('/tmp/ecnconfig'):
os.remove('/tmp/ecnconfig')
print("TEARDOWN")

class TestEcnConfig(TestEcnConfigBase):
def test_ecn_show_config(self):
self.executor(testData['ecn_show_config'])

def test_ecn_show_config_verbose(self):
self.executor(testData['ecn_show_config_verbose'])

def test_ecn_config_gmin(self):
self.executor(testData['ecn_cfg_gmin'])

def test_ecn_config_gmin_verbose(self):
self.executor(testData['ecn_cfg_gmin_verbose'])

def test_ecn_config_gmax(self):
self.executor(testData['ecn_cfg_gmax'])

def test_ecn_config_ymin(self):
self.executor(testData['ecn_cfg_ymin'])

def test_ecn_config_ymax(self):
self.executor(testData['ecn_cfg_ymax'])

def test_ecn_config_rmin(self):
self.executor(testData['ecn_cfg_gmin'])

def test_ecn_config_rmax(self):
self.executor(testData['ecn_cfg_gmax'])

def test_ecn_config_gdrop(self):
self.executor(testData['ecn_cfg_gdrop'])

def test_ecn_config_gdrop_verbose(self):
self.executor(testData['ecn_cfg_gdrop_verbose'])

def test_ecn_config_ydrop(self):
self.executor(testData['ecn_cfg_ydrop'])

def test_ecn_config_rdrop(self):
self.executor(testData['ecn_cfg_rdrop'])

def test_ecn_config_multi_set(self):
self.executor(testData['ecn_cfg_multi_set'])

def test_ecn_config_gmin_gmax_invalid(self):
self.executor(testData['ecn_cfg_gmin_gmax_invalid'])

def test_ecn_config_ymin_ymax_invalid(self):
self.executor(testData['ecn_cfg_ymin_ymax_invalid'])

def test_ecn_config_rmin_rmax_invalid(self):
self.executor(testData['ecn_cfg_rmin_rmax_invalid'])

def test_ecn_config_rmax_invalid(self):
self.executor(testData['ecn_cfg_rmax_invalid'])

def test_ecn_config_rdrop_invalid(self):
self.executor(testData['ecn_cfg_rdrop_invalid'])

def test_ecn_queue_get(self):
self.executor(testData['ecn_q_get'])

def test_ecn_queue_get_verbose(self):
self.executor(testData['ecn_q_get_verbose'])

def test_ecn_queue_get_lossy(self):
self.executor(testData['ecn_lossy_q_get'])

def test_ecn_all_queue_get(self):
self.executor(testData['ecn_q_all_get'])

def test_ecn_queue_all_get_verbose(self):
self.executor(testData['ecn_q_all_get_verbose'])

def test_ecn_queue_set_q_off(self):
self.executor(testData['ecn_cfg_q_off'])

def test_ecn_queue_set_q_off_verbose(self):
self.executor(testData['ecn_cfg_q_off_verbose'])

def test_ecn_queue_set_all_off(self):
self.executor(testData['ecn_cfg_q_all_off'])

def test_ecn_queue_set_all_off_verbose(self):
self.executor(testData['ecn_cfg_q_all_off_verbose'])

def test_ecn_queue_set_q_on(self):
self.executor(testData['ecn_cfg_q_on'])

def test_ecn_queue_set_q_on_verbose(self):
self.executor(testData['ecn_cfg_q_on_verbose'])

def test_ecn_queue_set_all_on(self):
self.executor(testData['ecn_cfg_q_all_on'])

def test_ecn_queue_set_all_on_verbose(self):
self.executor(testData['ecn_cfg_q_all_on_verbose'])

def test_ecn_queue_set_lossy_q_on(self):
self.executor(testData['ecn_cfg_lossy_q_on'])
30 changes: 12 additions & 18 deletions tests/multi_asic_ecnconfig_test.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
import os

from ecn_test import *
import sys
from ecn_test import TestEcnConfigBase
from ecn_input.ecn_test_vectors import *

root_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(root_path)
scripts_path = os.path.join(modules_path, "scripts")
sys.path.insert(0, root_path)
sys.path.insert(0, modules_path)


class TestEcnConfigMultiAsic(object):
class TestEcnConfigMultiAsic(TestEcnConfigBase):
@classmethod
def setup_class(cls):
os.environ["PATH"] += os.pathsep + scripts_path
super().setup_class()
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "multi_asic"
os.environ['UTILITIES_UNIT_TESTING'] = "2"
print("SETUP")

def test_ecn_show_config_all_masic(self):
TestEcnConfig.executor(testData['ecn_show_config_masic'])
self.executor(testData['ecn_show_config_masic'])

def test_ecn_show_config_all_verbose_masic(self):
TestEcnConfig.executor(testData['test_ecn_show_config_verbose_masic'])
self.executor(testData['test_ecn_show_config_verbose_masic'])

def test_ecn_show_config_one_masic(self):
TestEcnConfig.executor(testData['test_ecn_show_config_namespace'])
self.executor(testData['test_ecn_show_config_namespace'])

def test_ecn_show_config_one_verbose_masic(self):
TestEcnConfig.executor(testData['test_ecn_show_config_namespace_verbose'])
self.executor(testData['test_ecn_show_config_namespace_verbose'])

def test_ecn_config_change_other_threshold_masic(self):
TestEcnConfig.executor(testData['ecn_cfg_threshold_masic'])
self.executor(testData['ecn_cfg_threshold_masic'])

def test_ecn_config_change_other_prob_masic(self):
TestEcnConfig.executor(testData['ecn_cfg_probability_masic'])
self.executor(testData['ecn_cfg_probability_masic'])

@classmethod
def teardown_class(cls):
os.environ['PATH'] = os.pathsep.join(os.environ['PATH'].split(os.pathsep)[:-1])
os.environ['UTILITIES_UNIT_TESTING'] = "0"
super().teardown_class()
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = ""
if os.path.isfile('/tmp/ecnconfig'):
os.remove('/tmp/ecnconfig')
print("TEARDOWN")

0 comments on commit acfd7f4

Please sign in to comment.