pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/36593?usp=email )
Change subject: Move f_str_split() Osmocom_VTY_Functions.ttcn -> Misc_Helpers.ttcn ......................................................................
Move f_str_split() Osmocom_VTY_Functions.ttcn -> Misc_Helpers.ttcn
This is quite a generic string handling function which fits better in a generic utility file like Misc_Helpers.ttcn.
Change-Id: I54eff3eea60ed0624919baebfe0ff7393414d6b8 --- M library/Misc_Helpers.ttcn M library/Osmocom_VTY_Functions.ttcn M upf/UPF_Tests.ttcn 3 files changed, 39 insertions(+), 26 deletions(-)
Approvals: Jenkins Builder: Verified fixeria: Looks good to me, but someone else must approve osmith: Looks good to me, approved
diff --git a/library/Misc_Helpers.ttcn b/library/Misc_Helpers.ttcn index cbc1e70..fd2e7bb 100644 --- a/library/Misc_Helpers.ttcn +++ b/library/Misc_Helpers.ttcn @@ -79,4 +79,24 @@ return count; }
+type record of charstring ro_charstring; +function f_str_split(charstring str, charstring delim := "\n") return ro_charstring +{ + var integer pos := 0; + var ro_charstring parts := {}; + var integer delim_pos; + var integer end := lengthof(str); + while (pos < end) { + delim_pos := f_strstr(str, delim, pos); + if (delim_pos < 0) { + delim_pos := end; + } + if (delim_pos > pos) { + parts := parts & { substr(str, pos, delim_pos - pos) }; + } + pos := delim_pos + 1; + } + return parts; +} + } diff --git a/library/Osmocom_VTY_Functions.ttcn b/library/Osmocom_VTY_Functions.ttcn index 6b0883f..b982a8f 100644 --- a/library/Osmocom_VTY_Functions.ttcn +++ b/library/Osmocom_VTY_Functions.ttcn @@ -274,26 +274,7 @@ Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "talloc count mismatch"); }
-public function f_str_split(charstring str, charstring delim := "\n") return ro_charstring -{ - var integer pos := 0; - var ro_charstring parts := {}; - var integer delim_pos; - var integer end := lengthof(str); - while (pos < end) { - delim_pos := f_strstr(str, delim, pos); - if (delim_pos < 0) { - delim_pos := end; - } - if (delim_pos > pos) { - parts := parts & { substr(str, pos, delim_pos - pos) }; - } - pos := delim_pos + 1; - } - return parts; -} - -public function f_verify_talloc_bytes(TELNETasp_PT pt, ro_charstring object_strs, integer expect_bytes := 0, +public function f_verify_talloc_bytes(TELNETasp_PT pt, Misc_Helpers.ro_charstring object_strs, integer expect_bytes := 0, integer attempts := 5, float wait_time := 3.0) { var charstring show_cmd := "show talloc-context application brief"; @@ -302,7 +283,7 @@ attempts := attempts - 1; var charstring ret := f_vty_transceive_ret(pt, show_cmd);
- var ro_charstring lines := f_str_split(ret); + var Misc_Helpers.ro_charstring lines := f_str_split(ret);
var boolean ok := true; for (var integer i := 0; i < lengthof(object_strs); i := i + 1) { @@ -315,7 +296,7 @@ if (f_strstr(line, object_str) < 0) { continue; } - var ro_charstring tokens := f_str_split(line, " "); + var Misc_Helpers.ro_charstring tokens := f_str_split(line, " "); if (lengthof(tokens) < 4) { continue; } diff --git a/upf/UPF_Tests.ttcn b/upf/UPF_Tests.ttcn index 140e81b..cb8c489 100644 --- a/upf/UPF_Tests.ttcn +++ b/upf/UPF_Tests.ttcn @@ -125,7 +125,7 @@ if (not f_get_name_val(token, str, name)) { return false; } - var ro_charstring nrl := f_str_split(token, delim); + var Misc_Helpers.ro_charstring nrl := f_str_split(token, delim); if (lengthof(nrl) != 2) { return false; } @@ -270,7 +270,7 @@
private function f_vty_get_gtp_actions(TELNETasp_PT vty_pt) return GTP_Action_List { var charstring gtp_str := f_vty_transceive_ret(vty_pt, "show gtp"); - var ro_charstring lines := f_str_split(gtp_str, "\n"); + var Misc_Helpers.ro_charstring lines := f_str_split(gtp_str, "\n"); var GTP_Action_List gtps := {}; for (var integer i := 0; i < lengthof(lines); i := i + 1) { var charstring line := lines[i]; @@ -399,7 +399,7 @@
private function f_vty_get_sessions(TELNETasp_PT vty_pt) return PFCP_Session_Status_List { var charstring sessions_str := f_vty_transceive_ret(vty_pt, "show session"); - var ro_charstring lines := f_str_split(sessions_str, "\n"); + var Misc_Helpers.ro_charstring lines := f_str_split(sessions_str, "\n"); var PFCP_Session_Status_List sessions := {}; for (var integer i := 0; i < lengthof(lines); i := i + 1) { var charstring line := lines[i]; @@ -483,7 +483,7 @@ setverdict(pass); }
-private function f_vty_netinst_cfg(TELNETasp_PT vty_pt, ro_charstring netinst_cmds) +private function f_vty_netinst_cfg(TELNETasp_PT vty_pt, Misc_Helpers.ro_charstring netinst_cmds) { f_vty_enter_config(vty_pt); f_vty_transceive(vty_pt, "netinst");