pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/40753?usp=email )
Change subject: pgw: Move to library/ high level APIs to run commands over UECUPS ......................................................................
pgw: Move to library/ high level APIs to run commands over UECUPS
This way the code can be reused by other testsuites more easily.
Change-Id: I49c98fd423e47e16ddfb9ae4612b18db21ca3fa4 --- M library/GTPv1U_Emulation.ttcnpp M pgw/PGW_Tests.ttcn 2 files changed, 98 insertions(+), 62 deletions(-)
Approvals: pespin: Looks good to me, approved Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve osmith: Looks good to me, but someone else must approve
diff --git a/library/GTPv1U_Emulation.ttcnpp b/library/GTPv1U_Emulation.ttcnpp index 8b76379..aa97210 100644 --- a/library/GTPv1U_Emulation.ttcnpp +++ b/library/GTPv1U_Emulation.ttcnpp @@ -389,6 +389,89 @@ } return res; } + +/*********************************************************************** + * High level APIs for user convenience + ***********************************************************************/ +/* start a program on the user plane side; return its PID */ +function f_gtp1u_start_prog(UECUPS_StartProgram sprog, + boolean redirect_output := false, + charstring redirect_output_path_prefix := "gtp1u_run_prog", + integer port_idx := 0) +runs on GTP1U_ConnHdlr return integer +{ + var charstring cmd := sprog.command; + /* Redirect stdout/stderr to the user-specified location */ + if (redirect_output) { + sprog.command := sprog.command & " 1>>" & redirect_output_path_prefix & ".prog.stdout"; + sprog.command := sprog.command & " 2>>" & redirect_output_path_prefix & ".prog.stderr"; + } + + log("Starting a program: ", cmd); + var UECUPS_StartProgramRes res := f_gtp1u_start_program(sprog, port_idx := port_idx); + if (res.result != OK) { + Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, + log2str("Unable to start program '", cmd, "'")); + } + log("Started program '", cmd, "' with PID ", res.pid); + return res.pid; +} + +/* wait for termination of a given PID with specified exit_code */ +function f_gtp1u_wait_term(integer pid, template (present) integer exit_code := 0, + float tout := 10.0, + integer port_idx := 0) runs on GTP1U_ConnHdlr +{ + var UECUPS_ProgramTermInd pti; + timer T := tout; + + T.start; + alt { + [] GTP1U[port_idx].receive(UECUPS_ProgramTermInd:{pid := pid, exit_code := exit_code}) { + setverdict(pass); + } + [] GTP1U[port_idx].receive(UECUPS_ProgramTermInd:?) -> value pti { + Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, + log2str("Received unexpected ProgramTermInd := ", pti)); + } + [] T.timeout { + Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, + log2str("timeout (", tout, " seconds) waiting for user-plane program PID ", pid, " termination")); + } + } +} + +/* execute a program and wait for result */ +function f_gtp1u_start_prog_wait(UECUPS_StartProgram sprog, + template (present) integer exit_code := 0, + float tout := 10.0, + boolean redirect_output := false, + charstring redirect_output_path_prefix := "gtp1u_run_prog", + integer port_idx := 0) +runs on GTP1U_ConnHdlr +{ + var integer pid := f_gtp1u_start_prog(sprog, redirect_output, redirect_output_path_prefix, port_idx); + f_gtp1u_wait_term(pid, exit_code, tout, port_idx); +} + +/* execute ping command and wait for result. sprog.command is filled in based on params. */ +function f_gtp1u_ping4(UECUPS_StartProgram sprog, + charstring host, integer interval := 1, integer count := 10, + template (omit) charstring src_ip := omit, + boolean redirect_output := false, + charstring redirect_output_path_prefix := "gtp1u_run_prog", + integer port_idx := 0) runs on GTP1U_ConnHdlr +{ + var charstring ping :="ping -c " & int2str(count) & " -i " & int2str(interval); + + if (isvalue(src_ip)) { + ping := ping & " -I " & valueof(src_ip); + } + ping := ping & " " & host; + sprog.command := ping; + f_gtp1u_start_prog_wait(sprog, 0, int2float(5 + interval*count), + redirect_output, redirect_output_path_prefix, port_idx); +} #endif
} diff --git a/pgw/PGW_Tests.ttcn b/pgw/PGW_Tests.ttcn index 16ac9ee..c63568e 100644 --- a/pgw/PGW_Tests.ttcn +++ b/pgw/PGW_Tests.ttcn @@ -898,9 +898,8 @@ } }
-/* start a program on the user plane side; return its PID */ -private function f_start_prog(charstring command, boolean redirect_output := true) -runs on PGW_Session_CT return integer + +private function f_run_prog_init(charstring command) runs on PGW_Session_CT return UECUPS_StartProgram { var UECUPS_StartProgram sprog := { command := command, @@ -908,76 +907,30 @@ run_as_user := mp_run_prog_as_user, tun_netns_name := g_pars.tun_netns_name }; + return sprog; +} + +private function f_run_prog_unique_log_path() runs on PGW_Session_CT return charstring +{ + var charstring id := testcasename() & "-" & hex2str(g_pars.imsi) & "-" & int2str(g_start_prog_count); + var charstring prefix := mp_run_prog_log_path & "/" & id; g_start_prog_count := g_start_prog_count + 1; - - /* Redirect stdout/stderr to the user-specified location */ - if (redirect_output) { - var charstring id := testcasename() & "-" & hex2str(g_pars.imsi) & "-" & int2str(g_start_prog_count); - var charstring prefix := mp_run_prog_log_path & "/" & id; - sprog.command := sprog.command & " 1>>" & prefix & ".prog.stdout"; - sprog.command := sprog.command & " 2>>" & prefix & ".prog.stderr"; - } - - log("Starting a program: ", command); - var UECUPS_StartProgramRes res := f_gtp1u_start_program(sprog); - if (res.result != OK) { - Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, - log2str("Unable to start program '", command, "'")); - } - log("Started program '", command, "' with PID ", res.pid); - return res.pid; -} - -/* wait for termination of a given PID with specified exit_code */ -private function f_wait_term(integer pid, template (present) integer exit_code := 0, - float tout := 10.0) runs on PGW_Session_CT -{ - var UECUPS_ProgramTermInd pti; - timer T := tout; - - T.start; - alt { - [] GTP1U[0].receive(UECUPS_ProgramTermInd:{pid := pid, exit_code := exit_code}) { - setverdict(pass); - } - [] GTP1U[0].receive(UECUPS_ProgramTermInd:?) -> value pti { - Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, - log2str("Received unexpected ProgramTermInd := ", pti)); - } - [] T.timeout { - Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, - log2str("timeout (", tout, " seconds) waiting for user-plane program PID ", pid, " termination")); - } - } -} - -/* execute a program and wait for result */ -private function f_start_prog_wait(charstring command, - template integer exit_code := 0, - float tout := 10.0, - boolean redirect_output := true) -runs on PGW_Session_CT -{ - var integer pid := f_start_prog(command, redirect_output); - f_wait_term(pid, exit_code, tout); + return prefix; }
/* execute ping command and wait for result */ private function f_ping4(charstring host, integer interval := 1, integer count := 10) runs on PGW_Session_CT { - var charstring ping :="ping -c " & int2str(count) & " -i " & int2str(interval); - if (not isbound(g_ip4_addr)) { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "f_ping4(): g_ip4_addr is unset!"); } - ping := ping & " -I " & f_inet_ntoa(g_ip4_addr); - ping := ping & " " & host; - f_start_prog_wait(ping, tout := int2float(5 + interval*count)); + /* command will be filled in by f_gtp1u_ping4() below: */ + var UECUPS_StartProgram sprog := f_run_prog_init(""); + f_gtp1u_ping4(sprog, host, interval, count, f_inet_ntoa(g_ip4_addr), + redirect_output := true, + redirect_output_path_prefix := f_run_prog_unique_log_path()); }
- - - /* send echo request; expect response */ testcase TC_tx_echo() runs on PGW_Test_CT { timer T := 5.0;