path: root/tests/ctrl/ctrl_test.c
AgeCommit message (Collapse)AuthorFilesLines
2021-02-04make use of OTC_GLOBAL when allocating library-internal contextsHarald Welte1-3/+4
As libosmcore is now managing the global talloc contexts, there's no point in having APIs where the user tells the library about which talloc contexts to use for a given sub-system. However, completely ignoring the talloc contexts passed in by existing applications would unfortunately break LeakSanitizer. It appears to track if any dynamically allocated pointeres are not stored anywhere, and that would be exactly the situation created here. So the new behavior is: Use the context passed in by an application, and fall back to the library-internal OTC_GLOBAL if none is passed in. Change-Id: I48f475efd3ee0d5120b8fc30861e852d1a6920b1
2019-07-08utils.h: require a semi colon after OSMO_ASSERTAlexander Couzens1-1/+1
When using `OSMO_ASSERT(exp);` clang will warn about an empty expression because the semi colon was superflous. Use do {} while (0) to enfore the need of a semi colon. This might break other test. Change-Id: I2272d29a81496164bebd1696a694383a28a86434
2018-07-16tests: ctrl: Test received ERROR messages are handled correctlyPau Espin Pedrol1-2/+20
Change-Id: I3c8e95aaa1ca222d4cd1395e548f8461bf9d4cd6
2018-04-05fix ctrl_test sanitizer issuesNeels Hofmeyr1-1/+12
Add logging to root ctx, add msgb ctx to root ctx, free wqueue to simulate the msgb being sent, and assert final talloc size. Change-Id: Ief3d5e7b6c4d781b3854e230e45a67d5281b94cd
2018-04-05ctrl: fix deferred commands (and hence fix osmo-bts-sysmo 'clock-info' cmd)Neels Hofmeyr1-4/+0
The CTRL interface has a ctrl_cmd_def_* API that allows deferring a CTRL command reply until later. However, the command handling currently fails to acknowledge this and deallocates the struct ctrl_cmd anyway. Fix: in struct ctrl_cmd, add a defer pointer to be populated by ctrl_cmd_def_make(). A cmd thus marked as deferred is not deallocated at the end of command handling. This fix needs no change in calling code. (Another idea was to return a different code than CTRL_CMD_HANDLED when the command is to be deferred, but that would require adjusting each user of ctrl_cmd_def_make(). The implicit marking is safer and easier.) Show that handling deferred commands is fixed by adjusting the expectations of ctrl_test.c's test_deferred_cmd() and removing the now obsolete exit_early label. One symptom of the breakage is that osmo-bts-sysmo crashes when asked to report a trx's clock-info, which is aggravated by the fact that the sysmobts-mgr does ask osmo-bts-sysmo for a clock-info. The crash appears since Id583b413f8b8bd16e5cf92a8a9e8663903646381 -- it looked like just fixing an obvious memory leak, which it did as shown by the unit test, but deferred ctrl commands actually relied on that leak. Both fixed now. Related: OS#3120 Change-Id: I24232be7dcf7be79f4def91ddc8b8f8005b56318
2018-04-05ctrl: test deferred cmd, show current failureNeels Hofmeyr1-0/+102
Handling a deferred command currently deallocates the struct ctrl_cmd upon exiting the initial command handling, while it should actually stay around for the asynchronous/deferred handling of the ctrl command. Show the current bug by means of a ctrl test. The test will be adjusted to expect the correct result when the bug is fixed in a subsequent commit (I24232be7dcf7be79f4def91ddc8b8f8005b56318). Change-Id: Ibbc847fc583bdd8e5e53a008258805e634ea12b4
2017-12-20ctrl: tighten CTRL input parsingNeels Hofmeyr1-64/+46
Validate that incoming CTRL commands... - have decimal IDs, - return error on trailing characters, - have invalid characters in variable identifiers, - send detailed error messages as reply to the requestor. Adjust ctrl_test.{c,ok}, which best show the change in behavior. Message handling causes log messages on stderr; previously, stderr was empty. Add '[ignore]' in testsuite.at so that the nonempty stderr doesn't cause test failures. Change-Id: I96a9b6b6a3a5e0b80513aa9eaa727ae8c9c7d7a1
2017-12-18ctrl: on parse errors, return a detailed message to senderNeels Hofmeyr1-1/+1
The recently added ctrl_cmd_parse2() returns non-NULL cmd with error messages upon parsing errors. In handle_control_read(), use ctrl_cmd_parse2() and send those back to the CTRL command sender as reply. Retain the previous "Command parser error" reply only in case ctrl_cmd_parse2() should return NULL, which shouldn't actually happen at all. Change-Id: Ie35a02555b76913bb12734a76fc40fde7ffb244d
2017-12-18ctrl_test: add two more current parsing bugs to prep for fixNeels Hofmeyr1-0/+16
Change-Id: Id11bc326be2f0bc2746a928354e416495a18baf7
2017-12-18ctrl: fix mem leak when handling GET_REPLY and SET_REPLYNeels Hofmeyr1-3/+2
In ctrl_handle_msg() (code recently propagated from handle_control_read()), talloc_free() the parsed ctrl_cmd in all code paths. In particular, a free was missing in case ctrl_cmd_handle() returns CTRL_CMD_HANDLED. CTRL_CMD_HANDLED is triggered by GET_REPLY / SET_REPLY parsing, as show by ctrl_test.c. With the memleak fixed, adjust expected test output and make a detected mem leak abort the test immediately. Change-Id: Id583b413f8b8bd16e5cf92a8a9e8663903646381
2017-12-18ctrl_test: show memleak when receiving GET_REPLY and SET_REPLY commandsNeels Hofmeyr1-2/+22
The "memleak!" output shows messages that lack a talloc_free() of the parsed ctrl command buffer. The leak shall be fixed in a subsequent patch. Change-Id: I2c3e4d08b769b9cd77593362ea36a28d681cd042
2017-12-18ctrl_test: expand to test message handling and detect mem leaksNeels Hofmeyr1-40/+129
Subsequent patches that tighten CTRL input validation will make the results more interesting. Change-Id: Idd4cc7d193db1a7d761f72ed33ed46eea450a78f
2017-12-18ctrl_test.c: replace print_escaped() with new osmo_escape_str()Neels Hofmeyr1-36/+4
Change-Id: I12d3828dcc925f97fde11c360f1d60f3bd8cad8b
2017-09-27CTRL: add unit tests for CTRL command parsingNeels Hofmeyr1-0/+251
This uncovers some interesting behavior of the CTRL interface which we may want to guard against in subsequent patches: trailing whitespace, ignored tokens, special characters as cmd->id. Change-Id: If7af06d50ca71fd528b08cd70310774d5a53f0f7
2017-06-13ctrl_test.c: fix build with GCC 7.1.1Vadim Yanitskiy1-1/+1
According to GCC's online docs: When an inline function is not static, then the compiler must assume that there may be calls from other source files; since a global symbol can be defined only once in any program, the function must not be defined in the other source files, so the calls therein cannot be integrated. Therefore, a non-static inline function is always compiled on its own in the usual fashion. There is no any (performance or size) benefit from 'inline' keyword in this particular file, so let's replace one by 'static'. Change-Id: I11e1f1cfea09c6f0cf8225239e782b551d3eb52f
2017-03-01Use value_string for ctrl_typeMax1-0/+36
Use value_string for enum ctrl_type instead of custom code. Add corresponding unit tests. Related: OS#1615 Change-Id: Icd4e96dd9f00876cb70b43cfcf42ab4f10311b28