aboutsummaryrefslogtreecommitdiffstats
path: root/tests/fsm
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-03-31 16:34:49 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2018-04-09 17:57:15 +0200
commita64c45a03e3b318b5fdc93c960670d89a5745271 (patch)
tree2b89c218d75ccfa85c5faed719f1373f7bff9223 /tests/fsm
parent6e8c0884729eedbf4fc66414b67300d505ac17bb (diff)
add osmo_fsm_inst_update_id_f()
In the osmo-msc, I would like to set the subscr conn FSM identifier by a string format, to include the type of Complete Layer 3 that is taking place. I could each time talloc a string and free it again. This API is more convenient. From osmo_fsm_inst_update_id(), call osmo_fsm_inst_update_id_f() with "%s" (or pass NULL). Put the name updating into separate static update_name() function to clarify. Adjust the error message for erratic ID: don't say "allocate", it might be from an update. Adjust test expectation. Change-Id: I76743a7642f2449fd33350691ac8ebbf4400371d
Diffstat (limited to 'tests/fsm')
-rw-r--r--tests/fsm/fsm_test.c24
-rw-r--r--tests/fsm/fsm_test.err27
2 files changed, 51 insertions, 0 deletions
diff --git a/tests/fsm/fsm_test.c b/tests/fsm/fsm_test.c
index 859b78dc..e34164cf 100644
--- a/tests/fsm/fsm_test.c
+++ b/tests/fsm/fsm_test.c
@@ -237,6 +237,30 @@ do { \
test_id("invalid.id", -EINVAL, "(arbitrary_id)");
+ fprintf(stderr, "--- id format tests...\n");
+/* Update the id, assert the proper rc, and expect a resulting fsm inst name + lookup */
+#define test_id_f(expect_rc, expect_name_suffix, new_id_fmt, args...) do { \
+ int rc; \
+ fprintf(stderr, "osmo_fsm_inst_update_id_f(%s, " #args ")\n", \
+ osmo_quote_str(new_id_fmt, -1)); \
+ rc = osmo_fsm_inst_update_id_f(fi, new_id_fmt, ## args); \
+ fprintf(stderr, " rc == %d", rc); \
+ if (rc == (expect_rc)) \
+ fprintf(stderr, ", ok\n"); \
+ else { \
+ fprintf(stderr, ", ERROR: expected rc == %d\n", expect_rc); \
+ OSMO_ASSERT(rc == expect_rc); \
+ } \
+ assert_name("Test_FSM" expect_name_suffix); \
+ }while (0)
+
+ test_id_f(-EINVAL, "(arbitrary_id)", "format%cid", '.');
+ test_id_f(-EINVAL, "(arbitrary_id)", "%s", "");
+ test_id_f(0, "(format23id42)", "format%xid%d", 0x23, 42);
+ test_id_f(0, "", NULL);
+ test_id_f(0, "", NULL);
+ test_id_f(0, "(arbitrary_id)", "%s%c%s", "arbitrary", '_', "id");
+
fprintf(stderr, "\n--- %s() done\n\n", __func__);
osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REQUEST, NULL);
diff --git a/tests/fsm/fsm_test.err b/tests/fsm/fsm_test.err
index 3e01d48b..3237def5 100644
--- a/tests/fsm/fsm_test.err
+++ b/tests/fsm/fsm_test.err
@@ -47,6 +47,33 @@ Attempting to set illegal id for FSM instance of type 'Test_FSM': "invalid.id"
 rc == -22, ok
osmo_fsm_inst_name() == "Test_FSM(arbitrary_id)"
osmo_fsm_inst_find_by_name("Test_FSM(arbitrary_id)") == fi
+--- id format tests...
+osmo_fsm_inst_update_id_f("format%cid", '.')
+Attempting to set illegal id for FSM instance of type 'Test_FSM': "format.id"
+ rc == -22, ok
+ osmo_fsm_inst_name() == "Test_FSM(arbitrary_id)"
+ osmo_fsm_inst_find_by_name("Test_FSM(arbitrary_id)") == fi
+osmo_fsm_inst_update_id_f("%s", "")
+Attempting to set illegal id for FSM instance of type 'Test_FSM': ""
+ rc == -22, ok
+ osmo_fsm_inst_name() == "Test_FSM(arbitrary_id)"
+ osmo_fsm_inst_find_by_name("Test_FSM(arbitrary_id)") == fi
+osmo_fsm_inst_update_id_f("format%xid%d", 0x23, 42)
+ rc == 0, ok
+ osmo_fsm_inst_name() == "Test_FSM(format23id42)"
+ osmo_fsm_inst_find_by_name("Test_FSM(format23id42)") == fi
+osmo_fsm_inst_update_id_f(NULL, )
+ rc == 0, ok
+ osmo_fsm_inst_name() == "Test_FSM"
+ osmo_fsm_inst_find_by_name("Test_FSM") == fi
+osmo_fsm_inst_update_id_f(NULL, )
+ rc == 0, ok
+ osmo_fsm_inst_name() == "Test_FSM"
+ osmo_fsm_inst_find_by_name("Test_FSM") == fi
+osmo_fsm_inst_update_id_f("%s%c%s", "arbitrary", '_', "id")
+ rc == 0, ok
+ osmo_fsm_inst_name() == "Test_FSM(arbitrary_id)"
+ osmo_fsm_inst_find_by_name("Test_FSM(arbitrary_id)") == fi
--- test_id_api() done