summaryrefslogtreecommitdiffstats
path: root/tests/tdef/tdef_test.ok
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2019-01-26 20:36:12 +0100
committerNeels Hofmeyr <neels@hofmeyr.de>2019-02-04 18:52:16 +0100
commit0fd615fd7b701fc0b3fd7f96429691e3eaa5a877 (patch)
tree7c2885199ce93394c308e3399b4d76d843416505 /tests/tdef/tdef_test.ok
parent44c15b7a8fadff949e79be0b843ec9caca61901c (diff)
add osmo_tdef API, originally adopted from osmo-bsc T_def
Move T_def from osmo-bsc to libosmocore as osmo_tdef. Adjust naming to be more consistent. Upgrade to first class API: - add timer grouping - add generic vty support - add mising API doc - add C test - add VTY transcript tests, also as examples for using the API From osmo_fsm_inst_state_chg() API doc, cross reference to osmo_tdef API. The root reason for moving to libosmocore is that I want to use the mgw_endpoint_fsm in osmo-msc for inter-MSC handover, and hence want to move the FSM to libosmo-mgcp-client. This FSM uses the T_def from osmo-bsc. Though the mgw_endpoint_fsm's use of T_def is minimal, I intend to use the osmo_tdef API in osmo-msc (and probably elsewhere) as well. libosmocore is the most sensible place for this. osmo_tdef provides: - a list of Tnnnn (GSM) timers with description, unit and default value. - vty UI to allow users to configure non-default timeouts. - API to tie T timers to osmo_fsm states and set them on state transitions. - a few standard units (minute, second, millisecond) as well as a custom unit (which relies on the timer's human readable description to indicate the meaning of the value). - conversion for standard units: for example, some GSM timers are defined in minutes, while our FSM definitions need timeouts in seconds. Conversion is for convenience only and can be easily avoided via the custom unit. By keeping separate osmo_tdef arrays, several groups of timers can be kept separately. The VTY tests in tests/tdef/ showcase different schemes: - tests/vty/tdef_vty_test_config_root.c: Keep several timer definitions in separately named groups: showcase the osmo_tdef_vty_groups*() API. Each timer group exists exactly once. - tests/vty/tdef_vty_test_config_subnode.c: Keep a single list of timers without separate grouping. Put this list on a specific subnode below the CONFIG_NODE. There could be several separate subnodes with timers like this, i.e. continuing from this example, sets timers could be separated by placing timers in specific config subnodes instead of using the global group name. - tests/vty/tdef_vty_test_dynamic.c: Dynamically allocate timer definitions per each new created object. Thus there can be an arbitrary number of independent timer definitions, one per allocated object. T_def was introduced during the recent osmo-bsc refactoring for inter-BSC handover, and has proven useful: - without osmo_tdef, each invocation of osmo_fsm_inst_state_chg() needs to be programmed with the right timeout value, for all code paths that invoke this state change. It is a likely source of errors to get one of them wrong. By defining a T timer exactly for an FSM state, the caller can merely invoke the state change and trust on the original state definition to apply the correct timeout. - it is helpful to have a standardized config file UI to provide user configurable timeouts, instead of inventing new VTY commands for each separate application of T timer numbers. Change-Id: Ibd6b1ed7f1bd6e1f2e0fde53352055a4468f23e5
Diffstat (limited to 'tests/tdef/tdef_test.ok')
-rw-r--r--tests/tdef/tdef_test.ok184
1 files changed, 184 insertions, 0 deletions
diff --git a/tests/tdef/tdef_test.ok b/tests/tdef/tdef_test.ok
new file mode 100644
index 00000000..cf4b77f5
--- /dev/null
+++ b/tests/tdef/tdef_test.ok
@@ -0,0 +1,184 @@
+
+test_tdef_get()
+T1=100s
+osmo_tdef_get(1, s) = 100
+osmo_tdef_get(1, ms) = 100000
+osmo_tdef_get(1, m) = 2
+osmo_tdef_get(1, custom-unit) = 100
+T2=100ms
+osmo_tdef_get(2, s) = 1
+osmo_tdef_get(2, ms) = 100
+osmo_tdef_get(2, m) = 1
+osmo_tdef_get(2, custom-unit) = 100
+T3=100m
+osmo_tdef_get(3, s) = 6000
+osmo_tdef_get(3, ms) = 6000000
+osmo_tdef_get(3, m) = 100
+osmo_tdef_get(3, custom-unit) = 100
+T4=100custom-unit
+osmo_tdef_get(4, s) = 100
+osmo_tdef_get(4, ms) = 100
+osmo_tdef_get(4, m) = 100
+osmo_tdef_get(4, custom-unit) = 100
+T7=50s
+osmo_tdef_get(7, s) = 50
+osmo_tdef_get(7, ms) = 50000
+osmo_tdef_get(7, m) = 1
+osmo_tdef_get(7, custom-unit) = 50
+T8=300s
+osmo_tdef_get(8, s) = 300
+osmo_tdef_get(8, ms) = 300000
+osmo_tdef_get(8, m) = 5
+osmo_tdef_get(8, custom-unit) = 300
+T9=5m
+osmo_tdef_get(9, s) = 300
+osmo_tdef_get(9, ms) = 300000
+osmo_tdef_get(9, m) = 5
+osmo_tdef_get(9, custom-unit) = 5
+T10=20m
+osmo_tdef_get(10, s) = 1200
+osmo_tdef_get(10, ms) = 1200000
+osmo_tdef_get(10, m) = 20
+osmo_tdef_get(10, custom-unit) = 20
+T1000=2000ms
+osmo_tdef_get(1000, s) = 2
+osmo_tdef_get(1000, ms) = 2000
+osmo_tdef_get(1000, m) = 1
+osmo_tdef_get(1000, custom-unit) = 2000
+T1001=60000ms
+osmo_tdef_get(1001, s) = 60
+osmo_tdef_get(1001, ms) = 60000
+osmo_tdef_get(1001, m) = 1
+osmo_tdef_get(1001, custom-unit) = 60000
+T1002=307445734561825860m
+osmo_tdef_get(1002, s) = 18446744073709551600
+osmo_tdef_get(1002, ms) = 18446744073709551615
+osmo_tdef_get(1002, m) = 307445734561825860
+osmo_tdef_get(1002, custom-unit) = 307445734561825860
+T1003=18446744073709551615m
+osmo_tdef_get(1003, s) = 18446744073709551615
+osmo_tdef_get(1003, ms) = 18446744073709551615
+osmo_tdef_get(1003, m) = 18446744073709551615
+osmo_tdef_get(1003, custom-unit) = 18446744073709551615
+T1004=1ms
+osmo_tdef_get(1004, s) = 1
+osmo_tdef_get(1004, ms) = 1
+osmo_tdef_get(1004, m) = 1
+osmo_tdef_get(1004, custom-unit) = 1
+T1005=0ms
+osmo_tdef_get(1005, s) = 0
+osmo_tdef_get(1005, ms) = 0
+osmo_tdef_get(1005, m) = 0
+osmo_tdef_get(1005, custom-unit) = 0
+T1006=0s
+osmo_tdef_get(1006, s) = 0
+osmo_tdef_get(1006, ms) = 0
+osmo_tdef_get(1006, m) = 0
+osmo_tdef_get(1006, custom-unit) = 0
+T1007=0m
+osmo_tdef_get(1007, s) = 0
+osmo_tdef_get(1007, ms) = 0
+osmo_tdef_get(1007, m) = 0
+osmo_tdef_get(1007, custom-unit) = 0
+T1008=0custom-unit
+osmo_tdef_get(1008, s) = 0
+osmo_tdef_get(1008, ms) = 0
+osmo_tdef_get(1008, m) = 0
+osmo_tdef_get(1008, custom-unit) = 0
+T2147483647=18446744073709551615s
+osmo_tdef_get(2147483647, s) = 18446744073709551615
+osmo_tdef_get(2147483647, ms) = 18446744073709551615
+osmo_tdef_get(2147483647, m) = 307445734561825861
+osmo_tdef_get(2147483647, custom-unit) = 18446744073709551615
+T2147483646=18446744073709551614s
+osmo_tdef_get(2147483646, s) = 18446744073709551614
+osmo_tdef_get(2147483646, ms) = 18446744073709551615
+osmo_tdef_get(2147483646, m) = 307445734561825861
+osmo_tdef_get(2147483646, custom-unit) = 18446744073709551614
+T2147483645=9223372036854775807s
+osmo_tdef_get(2147483645, s) = 9223372036854775807
+osmo_tdef_get(2147483645, ms) = 18446744073709551615
+osmo_tdef_get(2147483645, m) = 153722867280912931
+osmo_tdef_get(2147483645, custom-unit) = 9223372036854775807
+T2147483644=18446744073709551615m
+osmo_tdef_get(2147483644, s) = 18446744073709551615
+osmo_tdef_get(2147483644, ms) = 18446744073709551615
+osmo_tdef_get(2147483644, m) = 18446744073709551615
+osmo_tdef_get(2147483644, custom-unit) = 18446744073709551615
+T-2147483648=18446744073709551615s
+osmo_tdef_get(-2147483648, s) = 18446744073709551615
+osmo_tdef_get(-2147483648, ms) = 18446744073709551615
+osmo_tdef_get(-2147483648, m) = 307445734561825861
+osmo_tdef_get(-2147483648, custom-unit) = 18446744073709551615
+T0=1custom-unit
+osmo_tdef_get(0, s) = 1
+osmo_tdef_get(0, ms) = 1
+osmo_tdef_get(0, m) = 1
+osmo_tdef_get(0, custom-unit) = 1
+T123=1s
+osmo_tdef_get(123, s) = 1
+osmo_tdef_get(123, ms) = 1000
+osmo_tdef_get(123, m) = 1
+osmo_tdef_get(123, custom-unit) = 1
+
+test_tdef_get_nonexisting()
+osmo_tdef_get(tdefs, 5, s, 999) = 999
+osmo_tdef_get(tdefs, 5, ms, 999) = 999
+osmo_tdef_get(tdefs, 5, m, 999) = 999
+osmo_tdef_get(tdefs, 5, custom-unit, 999) = 999
+
+test_tdef_set_and_get()
+setting 7 = 42
+T7=42s(def=50)
+osmo_tdef_get(7, ms) = 42000
+osmo_tdef_get(7, s) = 42
+osmo_tdef_get(7, m) = 1
+osmo_tdef_get(7, custom-unit) = 42
+setting 7 = 420
+T7=420s(def=50)
+osmo_tdef_get(7, ms) = 420000
+osmo_tdef_get(7, s) = 420
+osmo_tdef_get(7, m) = 7
+osmo_tdef_get(7, custom-unit) = 420
+resetting
+T7=50s
+osmo_tdef_get(7, s) = 50
+
+test_tdef_state_timeout()
+Total time passed: 0.000000 s
+state=A T=0, no timeout
+ --> A (configured as T1 100 s) rc=0; state=A T=1, 100.000000 s remaining
+ --> B (configured as T2 100 ms) rc=0; state=B T=2, 1.000000 s remaining
+ --> C (configured as T3 100 m) rc=0; state=C T=3, 6000.000000 s remaining
+ --> D (configured as T4 100 custom-unit) rc=0; state=D T=4, 100.000000 s remaining
+ --> G (configured as T7 50 s) rc=0; state=G T=7, 50.000000 s remaining
+ --> H (configured as T8 300 s) rc=0; state=H T=8, 300.000000 s remaining
+ --> I (configured as T9 5 m) rc=0; state=I T=9, 300.000000 s remaining
+ --> J (configured as T10 20 m) rc=0; state=J T=10, 1200.000000 s remaining
+- test keep_timer:
+Total time passed: 123.045678 s
+state=J T=10, 1076.954322 s remaining
+ --> K (configured as T0(keep_timer) 1 custom-unit) rc=0; state=K T=10, 1076.954322 s remaining
+ --> A (configured as T1 100 s) rc=0; state=A T=1, 100.000000 s remaining
+Total time passed: 146.091356 s
+state=A T=1, 76.954322 s remaining
+ --> K (configured as T0(keep_timer) 1 custom-unit) rc=0; state=K T=1, 76.954322 s remaining
+ --> A (configured as T1 100 s) rc=0; state=A T=1, 100.000000 s remaining
+Total time passed: 169.137034 s
+state=A T=1, 76.954322 s remaining
+ --> L (configured as T123(keep_timer) 1 s) rc=0; state=L T=123, 76.954322 s remaining
+- test large T:
+ --> M (configured as T2147483647 18446744073709551615 s) rc=0; state=M T=2147483647, 2147483647.000000 s remaining
+- test T<0:
+ --> N (configured as T-2147483648 18446744073709551615 s) rc=0; state=N T=-2147483648, 2147483647.000000 s remaining
+- test T=0:
+ --> O (no timer configured for this state)
+- test no timer:
+ --> X (no timer configured for this state)
+- test undefined timer, using default_val arg of osmo_tdef_fsm_inst_state_chg(), here passed as 999:
+ --> Y (configured as T666 18446744073709551615 -) rc=0; state=Y T=666, 999.000000 s remaining
+- test disallowed transition:
+ --> Z (no timer configured for this state)
+ --> B (configured as T2 100 ms) rc=0; state=B T=2, 1.000000 s remaining
+ --> C (configured as T3 100 m) rc=0; state=C T=3, 6000.000000 s remaining
+ --> D (configured as T4 100 custom-unit) rc=0; state=D T=4, 100.000000 s remaining