daniel has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/30938 )
Change subject: ctrl_if: Fix test ......................................................................
ctrl_if: Fix test
Change-Id: If35aa2340f69f9ac6178f07b7a4bbe392217a1f5 --- M src/Makefile.am M tests/Makefile.am M tests/ctrl/ctrl_test.c 3 files changed, 31 insertions(+), 9 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/38/30938/1
diff --git a/src/Makefile.am b/src/Makefile.am index ba0926e..1065dd4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -67,6 +67,7 @@ conv_acc_neon_impl.h \ crcXXgen.c.tpl \ stat_item_internal.h \ + osmo_io_internal.h \ $(NULL)
libosmocore_la_LDFLAGS = -version-info $(LIBVERSION) -no-undefined diff --git a/tests/Makefile.am b/tests/Makefile.am index 8c7e40a..0c12b25 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -114,6 +114,7 @@ abis_abis_test_LDADD = $(LDADD) $(top_builddir)/src/gsm/libosmogsm.la
ctrl_ctrl_test_SOURCES = ctrl/ctrl_test.c +ctrl_ctrl_test_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src ctrl_ctrl_test_LDADD = $(LDADD) \ $(top_builddir)/src/ctrl/libosmoctrl.la \ $(top_builddir)/src/gsm/libosmogsm.la \ diff --git a/tests/ctrl/ctrl_test.c b/tests/ctrl/ctrl_test.c index 1d4d4d7..074dfd7 100644 --- a/tests/ctrl/ctrl_test.c +++ b/tests/ctrl/ctrl_test.c @@ -4,6 +4,7 @@ #include <string.h> #include <stdbool.h>
+#include <osmocom/core/osmo_io.h> #include <osmocom/core/utils.h> #include <osmocom/ctrl/control_cmd.h> #include <osmocom/core/logging.h> @@ -11,6 +12,9 @@ #include <osmocom/core/application.h> #include <osmocom/gsm/protocol/ipaccess.h> #include <osmocom/ctrl/control_if.h> +#include <osmo_io_internal.h> + +extern struct iofd_backend_ops g_iofd_ops;
static void check_type(enum ctrl_type c) { @@ -109,13 +113,14 @@ msg = msgb_from_string(t->cmd_str); ctrl_handle_msg(ctrl, ccon, msg);
- if (llist_empty(&ccon->write_queue.msg_queue)) { + if (ccon->iofd->tx_queue.current_length == 0) { if (t->reply_str) { printf("Got no reply, but expected "%s"\n", osmo_escape_str(t->reply_str, -1)); OSMO_ASSERT(!t->reply_str); } } else { - struct msgb *sent_msg = msgb_dequeue(&ccon->write_queue.msg_queue); + struct iofd_msghdr *sent_msghdr = iofd_txqueue_dequeue(ccon->iofd); + struct msgb *sent_msg = sent_msghdr->msg; OSMO_ASSERT(sent_msg);
char *strbuf = talloc_size(sent_msg, msgb_l2len(sent_msg) + 1); @@ -126,8 +131,8 @@ OSMO_ASSERT(t->reply_str); OSMO_ASSERT(!strcmp(t->reply_str, strbuf)); msgb_free(sent_msg); + iofd_msghdr_free(sent_msghdr); } - osmo_wqueue_clear(&ccon->write_queue);
msgb_free(msg);
@@ -343,10 +348,11 @@ ctrl = ctrl_handle_alloc2(ctx, NULL, NULL, 0); ccon = talloc_zero(ctx, struct ctrl_connection);
- osmo_wqueue_init(&ccon->write_queue, 1); - - for (i = 0; i < ARRAY_SIZE(test_messages_list); i++) + for (i = 0; i < ARRAY_SIZE(test_messages_list); i++) { + ccon->iofd = osmo_iofd_setup(ccon, 0, 0, -1, "iofd test", OSMO_IO_FD_MODE_READ_WRITE, NULL, ccon, 0); assert_test(ctrl, ccon, &test_messages_list[i]); + osmo_iofd_close(ccon->iofd); + }
talloc_free(ccon); talloc_free(ctrl); @@ -405,8 +411,7 @@ ctrl = ctrl_handle_alloc2(ctx, NULL, NULL, 0); ccon = talloc_zero(ctx, struct ctrl_connection); INIT_LLIST_HEAD(&ccon->def_cmds); - - osmo_wqueue_init(&ccon->write_queue, 1); + ccon->iofd = osmo_iofd_setup(ccon, 0, 0, -1, "iofd test", OSMO_IO_FD_MODE_READ_WRITE, NULL, ccon, 0);
ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_test_defer);
@@ -431,7 +436,9 @@ ctrl_test_defer_cb(test_defer_cd);
/* simulate sending of the reply */ - osmo_wqueue_clear(&ccon->write_queue); + struct iofd_msghdr *msghdr = iofd_txqueue_dequeue(ccon->iofd); + msgb_free(msghdr->msg); + iofd_msghdr_free(msghdr);
/* And now the deferred cmd should be cleaned up completely. */ if (talloc_total_size(ctx) != ctx_size_before_defer) { @@ -460,8 +467,21 @@ .num_cat = ARRAY_SIZE(test_categories), };
+ +static void iofd_dummy_x_y(struct osmo_io_fd *iofd) +{ +} + int main(int argc, char **argv) { + /* Override the iofd backend functions */ + g_iofd_ops.setup = NULL; + g_iofd_ops.close = NULL; + g_iofd_ops.write_enable = iofd_dummy_x_y; + g_iofd_ops.write_disable = iofd_dummy_x_y; + g_iofd_ops.read_enable = iofd_dummy_x_y; + g_iofd_ops.read_disable = iofd_dummy_x_y; + ctx = talloc_named_const(NULL, 1, "ctrl_test"); osmo_init_logging2(ctx, &info); msgb_talloc_ctx_init(ctx, 0);