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

Add memory usage checker for the stress route test #14240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
47 changes: 47 additions & 0 deletions tests/stress/test_stress_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def test_announce_withdraw_route(duthosts, localhost, tbinfo, get_function_conpl

loop_times = LOOP_TIMES_LEVEL_MAP[normalized_level]

frr_demons_to_check = ['bgpd', 'zebra']
start_time_frr_daemon_memory = get_frr_daemon_memory_usage(duthost, frr_demons_to_check)
logging.info(f"memory usage at start: {start_time_frr_daemon_memory}")

while loop_times > 0:
announce_withdraw_routes(duthost, namespace, localhost, ptf_ip, topo_name)
loop_times -= 1
Expand All @@ -88,3 +92,46 @@ def test_announce_withdraw_route(duthosts, localhost, tbinfo, get_function_conpl
"ipv4 route used after is not equal to it used before")
pytest_assert(abs(ipv6_route_used_after - ipv6_route_used_before) < ALLOW_ROUTES_CHANGE_NUMS,
"ipv6 route used after is not equal to it used before")

end_time_frr_daemon_memory = get_frr_daemon_memory_usage(duthost, frr_demons_to_check)
logging.info(f"memory usage at end: {end_time_frr_daemon_memory}")
check_memory_usage_is_expected(duthost, frr_demons_to_check, start_time_frr_daemon_memory,
end_time_frr_daemon_memory)


def check_memory_usage_is_expected(duthost, frr_demons_to_check, start_time_frr_daemon_memory,
end_time_frr_daemon_memory):

unsupported_branches = ['202012', '202205', '202211', '202305', '202311', "20405"]
if duthost.os_version in unsupported_branches or duthost.sonic_release in unsupported_branches:
logger.info("Only check the memory usage after the 202405")
return ""
incr_frr_daemon_memory_threshold_dict = {
"bgpd": 100,
"zebra": 200
} # unit is MiB
for daemon in frr_demons_to_check:
logging.info(f"{daemon} memory usage at end: \n%s", end_time_frr_daemon_memory[daemon])

# Calculate diff in FRR daemon memory
incr_frr_daemon_memory = \
float(end_time_frr_daemon_memory[daemon]) - float(start_time_frr_daemon_memory[daemon])
logging.info(f"{daemon} absolute difference: %d", incr_frr_daemon_memory)
pytest_assert(incr_frr_daemon_memory < incr_frr_daemon_memory_threshold_dict[daemon],
f"The increase memory should not exceed than {incr_frr_daemon_memory_threshold_dict[daemon]} MiB")


def get_frr_daemon_memory_usage(duthost, daemon_list):
frr_daemon_memory_dict = {}
for daemon in daemon_list:
frr_daemon_memory_output = duthost.shell(f'vtysh -c "show memory {daemon}"')["stdout"]
logging.info(f"{daemon} memory status: \n%s", frr_daemon_memory_output)
output = duthost.shell(f'vtysh -c "show memory {daemon}" | grep "Free ordinary blocks"')["stdout"]
frr_daemon_memory = output.split()[-2]
unit = output.split()[-1]
if unit == "KiB":
frr_daemon_memory = frr_daemon_memory / 1000
elif unit == "GiB":
frr_daemon_memory = frr_daemon_memory * 1000
frr_daemon_memory_dict[daemon] = frr_daemon_memory
return frr_daemon_memory_dict
Loading