blob: dda2c2c16916a2bff5e02e0be74fe6cd17f52c41 [file] [log] [blame]
Daniel Willmannd9304742018-10-23 20:29:59 +02001module Misc_Helpers {
2
Pau Espin Pedrola16a6b62024-03-21 16:19:07 +01003import from Native_Functions all;
4
Oliver Smith8b6d1802021-11-26 13:30:13 +01005modulepar {
6 charstring mp_osmo_repo := "nightly";
7}
8
9/* Test the Osmocom repository (nightly, latest, 2021q4, ...), from which the
10 * SUT is running (OS#4878). Usage examples:
11 * if (Misc_Helpers.f_osmo_repo_is("nightly")) {
12 * ...
13 * }
14 * if (Misc_Helpers.f_osmo_repo_is(("nightly", "2021q4"))) {
15 * ...
16 * }
17 */
18function f_osmo_repo_is(template charstring ver) return boolean {
19 return match(mp_osmo_repo, ver);
20}
21
Daniel Willmannd9304742018-10-23 20:29:59 +020022/* Try to properly shutdown a testcase.
23 * The reliable method to stop a testcase without running into dynamic
24 * testcase errors due to unconnected ports receiving messages is to call
25 * all component.stop before terminating. However, this can only be called
26 * from the mtc! So in case we want to terminate from a component that is not
27 * the mtc we try to do the next best thing which is calling mtc.stop and
28 * hoping for the best.
29 */
30function f_shutdown(charstring file, integer line, verdicttype verdict := none,
31 charstring text := "") {
32 if (verdict != none) {
33 text := file & ":" & int2str(line) & " : " & text
34 setverdict(verdict, text);
35 }
36
37 log("Stopping testcase execution from ", file, ":", line)
38 if (self == mtc) {
39 /* Properly stop all ports before disconnecting them. This avoids
40 * running into the dynamic testcase error due to messages arriving on
41 * unconnected ports. */
42 all component.stop;
43 }
44 mtc.stop
45}
46
Pau Espin Pedrol6a846bc2020-09-04 13:01:22 +020047function f_addr_is_ipv6(charstring addr) return boolean {
48 for (var integer i := 0; i < lengthof(addr); i := i + 1) {
49 if (addr[i] == ":") {
50 return true;
51 }
52 }
53 return false;
54}
55
Pau Espin Pedrola16a6b62024-03-21 16:19:07 +010056function f_addrstr2addr(charstring addr) return octetstring {
57 if (f_addr_is_ipv6(addr)) {
58 return f_inet6_addr(addr);
59 } else {
60 return f_inet_addr(addr);
61 }
62}
63
Daniel Willmannd9304742018-10-23 20:29:59 +020064}