Skip to content

Commit

Permalink
Add Devlink functional tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Lozovyy <andriy.lozovyy@plvision.eu>
  • Loading branch information
AndriyLozovyyPLV committed Apr 14, 2023
1 parent 3441f4d commit eec6fae
Show file tree
Hide file tree
Showing 6 changed files with 525 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
'suite_functional_acl': 'Functional ACL tests',
'suite_functional_qos': 'Functional QoS tests',
'suite_functional_l1': 'Functional L1 tests',
'suite_functional_devlink': 'Devlink functional tests',

}

PYTEST_SUITE_GROUPS = {
Expand Down Expand Up @@ -116,5 +118,6 @@
'suite_functional_qos',
'suite_functional_ipv4',
'suite_functional_ipv6',
'suite_functional_l1']
'suite_functional_l1',
'suite_functional_devlink']
}
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)
Loading

0 comments on commit eec6fae

Please sign in to comment.