Daniel Willmann | d930474 | 2018-10-23 20:29:59 +0200 | [diff] [blame] | 1 | module Misc_Helpers { |
| 2 | |
Oliver Smith | 8b6d180 | 2021-11-26 13:30:13 +0100 | [diff] [blame] | 3 | modulepar { |
| 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 | */ |
| 16 | function f_osmo_repo_is(template charstring ver) return boolean { |
| 17 | return match(mp_osmo_repo, ver); |
| 18 | } |
| 19 | |
Daniel Willmann | d930474 | 2018-10-23 20:29:59 +0200 | [diff] [blame] | 20 | /* 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 | */ |
| 28 | function 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 Pedrol | 6a846bc | 2020-09-04 13:01:22 +0200 | [diff] [blame] | 45 | function 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 Willmann | d930474 | 2018-10-23 20:29:59 +0200 | [diff] [blame] | 54 | } |