Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VOQ][saidump] Add saidump unit test scripts #3079

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions tests/saidump_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
import subprocess

GENERATE_DUMP_FILE = "/tmp/generate_dump_tmp"

test_path = os.path.dirname(os.path.abspath(__file__))
modules_path = os.path.dirname(test_path)
scripts_path = os.path.join(modules_path, "scripts")


def run_saidump(asic_num, route_num):
result = subprocess.run([". " + test_path + "/saidump_test.sh && test_saidump " + str(asic_num) +
" " + str(route_num)], capture_output=True, text=True, shell=True, executable='/bin/bash')
return result.stdout.strip()


# saidump test list format: [ACIS number, ipv4 and ipv6 route table size, expected function save_cmd arguments]
saidump_test_list = [
[1, 10000, "docker exec syncd saidump saidump"],
[1, 12000, "docker exec syncd saidump saidump"],
[1, 12001, "docker exec syncd saidump.sh saidump"],
[1, 20000, "docker exec syncd saidump.sh saidump"],
[2, 10000, "docker exec syncd0 saidump saidump0\ndocker exec syncd1 saidump saidump1"],
[2, 12000, "docker exec syncd0 saidump saidump0\ndocker exec syncd1 saidump saidump1"],
[2, 12001, "docker exec syncd0 saidump.sh saidump0\ndocker exec syncd1 saidump.sh saidump1"],
[2, 20000, "docker exec syncd0 saidump.sh saidump0\ndocker exec syncd1 saidump.sh saidump1"]
]


def shell_pre_process(in_file, out_file):
buf = []

with open(in_file, 'r') as file:
lines = file.readlines()

for line in lines:
if line.strip().startswith("while getopts"):
break
else:
buf.append(line)

# Write the modified content back to the file
with open(out_file, 'w') as file:
file.writelines(buf)


def test_saidump():
# preprocess the generate_dump to a new script without non-functional codes
shell_pre_process(scripts_path + '/generate_dump', GENERATE_DUMP_FILE)

for item in saidump_test_list:
output = run_saidump(item[0], item[1])
assert output == item[2]

if os.path.exists(GENERATE_DUMP_FILE):
os.remove(GENERATE_DUMP_FILE)
41 changes: 41 additions & 0 deletions tests/saidump_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

GENERATE_DUMP_FILE="/tmp/generate_dump_tmp"
ROUTE_FILE="/tmp/route_summary.txt"
shopt -s expand_aliases
alias eval="mock_eval"
alias save_cmd="mock_save_cmd"

source $GENERATE_DUMP_FILE

mock_route_summary(){
local routenum=$1
echo "\
{
\"routesTotal\":$routenum
}" > $ROUTE_FILE
}

route_num=0
save_cmd_arguments=""

# Mock eval command in function get_route_table_size_by_asic_id_and_ipver
mock_eval(){
mock_route_summary $route_num
}

# Mock function save_cmd called in function save_saidump_by_route_size
mock_save_cmd(){
save_cmd_arguments="$save_cmd_arguments$*\n"
}

test_saidump(){
NUM_ASICS=$1
route_num=$2
save_saidump_by_route_size > /dev/null
echo -e $save_cmd_arguments
local ret=$save_cmd_arguments
save_cmd_arguments=""
rm $ROUTE_FILE
return $ret
}
Loading