forked from dentproject/testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andriy Lozovyy <andriy.lozovyy@plvision.eu>
- Loading branch information
1 parent
3441f4d
commit eec6fae
Showing
6 changed files
with
525 additions
and
5 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
Empty file.
102 changes: 102 additions & 0 deletions
102
...ramework/DentOsTestbed/src/dent_os_testbed/test/test_suite/functional/devlink/conftest.py
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,102 @@ | ||
import pytest | ||
import pytest_asyncio | ||
|
||
|
||
from dent_os_testbed.utils.test_utils.tgen_utils import ( | ||
tgen_utils_get_dent_devices_with_tgen, | ||
) | ||
|
||
|
||
CODE = ''' | ||
tcpdump_cpu_traps_rate() | ||
{ | ||
local IFACE="any" | ||
if [ $# -ge 1 ]; then IFACE=$1; fi | ||
timeout 1.06 tcpdump -i $IFACE &> xx; cat xx | grep -Eo "[0-9]+ packets received by filter" | cut -d " " -f 1; rm xx | ||
} | ||
tcpdump_cpu_traps_rate_avg() | ||
{ | ||
local start_index=0 | ||
local end=25 | ||
local counter=0 | ||
for((num=start_index; num<=end; num++)); do | ||
local temp=$(tcpdump_cpu_traps_rate $1) | ||
sleep 1 | ||
counter=$((counter+temp)) | ||
done | ||
echo $((counter/6)) | ||
} | ||
get_cpu_traps_rate_code() | ||
{ | ||
R1=`cat /sys/kernel/debug/prestera/$2_counters/traps/cpu_code_$1_stats | tr -d "\\0"` | ||
sleep 1 | ||
R2=`cat /sys/kernel/debug/prestera/$2_counters/traps/cpu_code_$1_stats | tr -d "\\0"` | ||
RXPPS=`expr $R2 - $R1` | ||
echo $RXPPS | ||
} | ||
get_cpu_traps_rate_code_avg() | ||
{ | ||
local start_index=0 | ||
local end=9 | ||
local counter=0 | ||
for((num=start_index; num<=end; num++)); do | ||
local temp=$(get_cpu_traps_rate_code $1 $2) | ||
sleep 1 | ||
counter=$((counter+temp)) | ||
done | ||
echo $((counter/10)) | ||
} | ||
get_devlink_cpu_traps_rate() | ||
{ | ||
R1=`devlink -vs trap show pci/0000:01:00.0 trap $1 | grep -o "packets.*" | cut -d " " -f 2` | ||
sleep 1 | ||
R2=`devlink -vs trap show pci/0000:01:00.0 trap $1 | grep -o "packets.*" | cut -d " " -f 2` | ||
RXPPS=`expr $R2 - $R1` | ||
echo $RXPPS | ||
} | ||
get_devlink_cpu_traps_rate_avg() | ||
{ | ||
local start_index=0 | ||
local end=9 | ||
local counter=0 | ||
for((num=start_index; num<=end; num++)); do | ||
local temp=$(get_devlink_cpu_traps_rate $1) | ||
sleep 1 | ||
counter=$((counter+temp)) | ||
done | ||
echo $((counter/10)) | ||
} | ||
''' | ||
|
||
|
||
@pytest_asyncio.fixture() | ||
async def define_bash_func(testbed): | ||
tgen_dev, dent_devices = await tgen_utils_get_dent_devices_with_tgen(testbed, [], 4) | ||
if not tgen_dev or not dent_devices: | ||
pytest.skip('The testbed does not have enough dent with tgen connections') | ||
dent_dev = dent_devices[0] | ||
func_list = ['tcpdump_cpu_traps_rate', 'tcpdump_cpu_traps_rate_avg', 'get_cpu_traps_rate_code', | ||
'get_cpu_traps_rate_code_avg', 'get_devlink_cpu_traps_rate', 'get_devlink_cpu_traps_rate_avg'] | ||
listed_funcs = ' '.join(func_list) | ||
bashrc = '/root/.bashrc' | ||
backup = '/root/.bashrc.bak' | ||
|
||
res, _ = await dent_dev.run_cmd(f'type {listed_funcs} > /dev/null 2>&1') | ||
if res: | ||
dent_dev.applog.info(f'Bash func isnt defined: \n{listed_funcs} \nDefining func in .bashrc') | ||
rc, out = await dent_dev.run_cmd(f'cp {bashrc} {backup}', sudo=True) | ||
rc, out = await dent_dev.run_cmd(f"echo '{CODE}' >> {bashrc}", sudo=True) | ||
try: | ||
assert not rc | ||
except AssertionError: | ||
_, _ = await dent_dev.run_cmd(f'mv {backup} {bashrc}', sudo=True) | ||
pytest.skip('Skiping test due defining func failed with rc {}'.format(rc)) | ||
|
||
yield | ||
|
||
_, _ = await dent_dev.run_cmd(f'mv {backup} {bashrc}', sudo=True) |
Oops, something went wrong.