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