-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ca9676
commit 0f4e623
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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] | ||
|
||
os.remove(GENERATE_DUMP_FILE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |