aboutsummaryrefslogtreecommitdiffstats
path: root/tests/tdef
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2020-11-04 20:00:38 +0100
committerlaforge <laforge@osmocom.org>2020-11-11 20:08:26 +0000
commit1b75e4bbd1780a1fbd949fe679cb908820188d3d (patch)
tree1d5644fa7ab67a6552205c27a3cd213b8ddfe25a /tests/tdef
parenta4939dc8461c0a2d8e67aa3bb95bfb73ad9225b7 (diff)
tdef: Introduce OSMO_TDEF_US unit
Some applications may need submillisecond timers, such as those interacting with modbus serial lines (RS-485, RTU), which require timers of values around 1.5 char-time (T1.5), where a data char is composed of 11 bits sent on the line: 1 start bit, 8 data bits, 1 stop bit, and and parity bit (or 2nd stop bits if no parity). For instance, for a baudrate of 9600: 1.5 * 11 / 9600 = 1.718 ms = 1718 us So having a granularity of MS is not enough here. Change-Id: I71848d7c1ee0649929ce07680ee7320bb2a42f0e
Diffstat (limited to 'tests/tdef')
-rw-r--r--tests/tdef/tdef_test.c10
-rw-r--r--tests/tdef/tdef_test.ok28
2 files changed, 36 insertions, 2 deletions
diff --git a/tests/tdef/tdef_test.c b/tests/tdef/tdef_test.c
index 9c0808ea..d874231a 100644
--- a/tests/tdef/tdef_test.c
+++ b/tests/tdef/tdef_test.c
@@ -54,6 +54,7 @@ static struct osmo_tdef tdefs[] = {
{ .T=1006, .default_val=0, .unit=OSMO_TDEF_S, .desc="zero s" },
{ .T=1007, .default_val=0, .unit=OSMO_TDEF_M, .desc="zero m" },
{ .T=1008, .default_val=0, .unit=OSMO_TDEF_CUSTOM, .desc="zero" },
+ { .T=1009, .default_val=0, .unit=OSMO_TDEF_US, .desc="zero us" },
{ .T=0, .default_val=1, .unit=OSMO_TDEF_CUSTOM, .desc="zero" },
@@ -111,7 +112,7 @@ static void test_tdef_get(bool test_range)
for (i = 0; i < ARRAY_SIZE(tdefs)-1; i++) {
unsigned int T = tdefs[i].T;
print_tdef_info(T);
- for (as_unit = OSMO_TDEF_S; as_unit <= OSMO_TDEF_CUSTOM; as_unit++) {
+ for (as_unit = OSMO_TDEF_S; as_unit <= OSMO_TDEF_US; as_unit++) {
print_tdef_get_short(tdefs, T, as_unit);
}
}
@@ -122,7 +123,7 @@ static void test_tdef_get(bool test_range)
for (i = 0; i < ARRAY_SIZE(tdefs_range)-1; i++) {
unsigned int T = tdefs_range[i].T;
print_tdef_info(T);
- for (as_unit = OSMO_TDEF_S; as_unit <= OSMO_TDEF_CUSTOM; as_unit++) {
+ for (as_unit = OSMO_TDEF_S; as_unit <= OSMO_TDEF_US; as_unit++) {
print_tdef_get_short(tdefs_range, T, as_unit);
}
}
@@ -136,6 +137,7 @@ static void test_tdef_get_nonexisting()
print_tdef_get(tdefs, 5, OSMO_TDEF_MS);
print_tdef_get(tdefs, 5, OSMO_TDEF_M);
print_tdef_get(tdefs, 5, OSMO_TDEF_CUSTOM);
+ print_tdef_get(tdefs, 5, OSMO_TDEF_US);
}
static void test_tdef_set_and_get()
@@ -152,6 +154,7 @@ static void test_tdef_set_and_get()
print_tdef_get_short(tdefs, 7, OSMO_TDEF_S);
print_tdef_get_short(tdefs, 7, OSMO_TDEF_M);
print_tdef_get_short(tdefs, 7, OSMO_TDEF_CUSTOM);
+ print_tdef_get_short(tdefs, 7, OSMO_TDEF_US);
printf("setting 7 = 420\n");
OSMO_ASSERT(osmo_tdef_set(tdefs, 7, 420, OSMO_TDEF_S) == 0);
@@ -160,6 +163,7 @@ static void test_tdef_set_and_get()
print_tdef_get_short(tdefs, 7, OSMO_TDEF_S);
print_tdef_get_short(tdefs, 7, OSMO_TDEF_M);
print_tdef_get_short(tdefs, 7, OSMO_TDEF_CUSTOM);
+ print_tdef_get_short(tdefs, 7, OSMO_TDEF_US);
printf("setting 7 = 10 (ERANGE)\n");
OSMO_ASSERT(!osmo_tdef_val_in_range(t, 10));
@@ -169,6 +173,7 @@ static void test_tdef_set_and_get()
print_tdef_get_short(tdefs, 7, OSMO_TDEF_S);
print_tdef_get_short(tdefs, 7, OSMO_TDEF_M);
print_tdef_get_short(tdefs, 7, OSMO_TDEF_CUSTOM);
+ print_tdef_get_short(tdefs, 7, OSMO_TDEF_US);
printf("setting 7 = 900 (ERANGE)\n");
OSMO_ASSERT(!osmo_tdef_val_in_range(t, 900));
@@ -178,6 +183,7 @@ static void test_tdef_set_and_get()
print_tdef_get_short(tdefs, 7, OSMO_TDEF_S);
print_tdef_get_short(tdefs, 7, OSMO_TDEF_M);
print_tdef_get_short(tdefs, 7, OSMO_TDEF_CUSTOM);
+ print_tdef_get_short(tdefs, 7, OSMO_TDEF_US);
printf("setting 23 = 50 (EEXIST)\n");
OSMO_ASSERT(osmo_tdef_set(tdefs, 23, 50, OSMO_TDEF_S) == -EEXIST);
diff --git a/tests/tdef/tdef_test.ok b/tests/tdef/tdef_test.ok
index 3c4a0930..1770968d 100644
--- a/tests/tdef/tdef_test.ok
+++ b/tests/tdef/tdef_test.ok
@@ -5,92 +5,116 @@ 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
+osmo_tdef_get(1, us) = 100000000
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
+osmo_tdef_get(2, us) = 100000
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
+osmo_tdef_get(3, us) = 6000000000
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
+osmo_tdef_get(4, us) = 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
+osmo_tdef_get(7, us) = 50000000
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
+osmo_tdef_get(8, us) = 300000000
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
+osmo_tdef_get(9, us) = 300000000
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
+osmo_tdef_get(10, us) = 1200000000
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
+osmo_tdef_get(1000, us) = 2000000
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
+osmo_tdef_get(1001, us) = 60000000
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
+osmo_tdef_get(1004, us) = 1000
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
+osmo_tdef_get(1005, us) = 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
+osmo_tdef_get(1006, us) = 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
+osmo_tdef_get(1007, us) = 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
+osmo_tdef_get(1008, us) = 0
+T1009=0us
+osmo_tdef_get(1009, s) = 0
+osmo_tdef_get(1009, ms) = 0
+osmo_tdef_get(1009, m) = 0
+osmo_tdef_get(1009, custom-unit) = 0
+osmo_tdef_get(1009, us) = 0
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
+osmo_tdef_get(0, us) = 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
+osmo_tdef_get(123, us) = 1000000
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
+osmo_tdef_get(tdefs, 5, us, 999) = 999
test_tdef_set_and_get()
setting 7 = 42
@@ -99,24 +123,28 @@ 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
+osmo_tdef_get(7, us) = 42000000
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
+osmo_tdef_get(7, us) = 420000000
setting 7 = 10 (ERANGE)
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
+osmo_tdef_get(7, us) = 420000000
setting 7 = 900 (ERANGE)
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
+osmo_tdef_get(7, us) = 420000000
setting 23 = 50 (EEXIST)
resetting
T7=50s