libamxrt  0.4.2
Ambiorix Run Time Library
test_amxrt_runtime.h File Reference
#include <amxrt/amxrt.h>
#include <amxc/amxc.h>
#include <amxp/amxp.h>
#include <amxd/amxd_object.h>
#include <amxo/amxo.h>

Go to the source code of this file.

Functions

int test_runtime_setup (UNUSED void **state)
 
int test_runtime_teardown (UNUSED void **state)
 
void test_runtime_start_prints_help_and_exits (UNUSED void **state)
 
void test_runtime_parses_default_odl (UNUSED void **state)
 
void test_runtime_parses_odls (UNUSED void **state)
 
void test_runtime_parses_odls_and_handle_events (UNUSED void **state)
 
void test_runtime_succeeds_when_no_odl (UNUSED void **state)
 
void test_runtime_fails_when_invalid_odl (UNUSED void **state)
 
void test_runtime_connects_to_uri (UNUSED void **state)
 
void test_runtime_cannot_load_backends (UNUSED void **state)
 
void test_runtime_cannot_connect_bus_uri (UNUSED void **state)
 
void test_runtime_creates_pid_file (UNUSED void **state)
 
void test_runtime_daemon_failed (UNUSED void **state)
 
void test_runtime_set_priority_failed (UNUSED void **state)
 
void test_runtime_parse_args_odl (UNUSED void **state)
 
void test_runtime_parse_args_wrong_odl (UNUSED void **state)
 
void test_runtime_no_pidfile (UNUSED void **state)
 
void test_runtime_parses_post_includes (UNUSED void **state)
 
void test_runtime_opens_syslog (UNUSED void **state)
 
void test_runtime_dumps_config (UNUSED void **state)
 
void test_runtime_enables_system_signals_list (UNUSED void **state)
 
void test_runtime_enables_system_signal (UNUSED void **state)
 
void test_runtime_forced_options_are_kept (UNUSED void **state)
 
void test_runtime_options_can_be_overwritten (UNUSED void **state)
 
void test_runtime_can_pass_option_path (UNUSED void **state)
 
void test_runtime_forced_options_with_path_are_kept (UNUSED void **state)
 
void test_runtime_can_pass_json_value_option (UNUSED void **state)
 
void test_runtime_fails_when_registering_dm_fails (UNUSED void **state)
 
void test_runtime_can_wait_for_objects (UNUSED void **state)
 
void test_runtime_wait_for_objects_can_fail (UNUSED void **state)
 
void test_runtime_can_suspend_events_while_waiting (UNUSED void **state)
 
void test_runtime_stops_el_when_registering_after_wait_fails (UNUSED void **state)
 
void test_runtime_can_create_listen_sockets (UNUSED void **state)
 
void test_runtime_connect_fails_if_no_backends (UNUSED void **state)
 

Function Documentation

◆ test_runtime_can_create_listen_sockets()

void test_runtime_can_create_listen_sockets ( UNUSED void **  state)

Definition at line 792 of file test_amxrt_runtime.c.

792  {
793  amxc_var_t* config = amxrt_get_config();
794  amxc_var_t* listen = GET_ARG(config, AMXRT_COPT_LISTEN);
795 
796  amxc_var_add(cstring_t, listen, "usp:/var/run/usp-ep.sock");
797  will_return(__wrap_amxb_be_load_multiple, 0);
798  will_return_always(__wrap_amxb_connect, 0);
799  will_return_always(__wrap_amxb_listen, 0);
800  will_return(__wrap_setpriority, 0);
801  will_return_always(__wrap_amxb_register, 0);
802  assert_int_equal(amxrt_connect(), 0);
803  assert_int_equal(amxrt_register_or_wait(), 0);
804 }
#define AMXRT_COPT_LISTEN
Definition: amxrt.h:89
amxc_var_t * amxrt_get_config(void)
Gets the htable variant containing the configuration options.
Definition: amxrt.c:301
int amxrt_connect(void)
Connects to all bus sockets.
Definition: amxrt.c:488
int amxrt_register_or_wait(void)
Register the data model or wait for required data model objects.
Definition: amxrt.c:389
config
Definition: test.odl:54
int __wrap_amxb_be_load_multiple(amxc_var_t *const bes)
int __wrap_amxb_register(amxb_bus_ctx_t *ctx, amxd_dm_t *dm)
int __wrap_amxb_connect(amxb_bus_ctx_t **ctx, const char *uri)
int __wrap_amxb_listen(amxb_bus_ctx_t **ctx, const char *uri)
int __wrap_setpriority(int which, id_t who, int value)

◆ test_runtime_can_pass_json_value_option()

void test_runtime_can_pass_json_value_option ( UNUSED void **  state)

Definition at line 661 of file test_amxrt_runtime.c.

661  {
662  char* argv[] = {"amxrt", "-B b", "-u",
663  "dummy://127.0.0.1:1970",
664  "-o", "my-table.my-key.2={\"key1\":true, \"key2\":[1,2,3], \"key3\":\"abc\"}",
665  "./test.odl" };
666 
667  amxd_dm_t* dm = amxrt_get_dm();
668  amxc_var_t* config = amxrt_get_config();
669  amxc_var_t* cfg = NULL;
670 
671  amxd_dm_init(dm);
672  optind = 1;
673  write(dummy_ctx.data_pipe[1], "s", 1);
674  will_return(__wrap_amxb_be_load_multiple, 0);
675  will_return_always(__wrap_amxb_connect, 0);
676  will_return(__wrap_setpriority, 0);
677  will_return_always(__wrap_amxb_register, 0);
678  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
679 
680  cfg = GETP_ARG(config, "my-table.my-key.2.key1");
681  assert_true(amxc_var_constcast(bool, cfg));
682  cfg = GETP_ARG(config, "my-table.my-key.2.key2.0");
683  assert_int_equal(amxc_var_dyncast(uint32_t, cfg), 1);
684  cfg = GETP_ARG(config, "my-table.my-key.2.key2.1");
685  assert_int_equal(amxc_var_dyncast(uint32_t, cfg), 2);
686  cfg = GETP_ARG(config, "my-table.my-key.2.key2.2");
687  assert_int_equal(amxc_var_dyncast(uint32_t, cfg), 3);
688  cfg = GETP_ARG(config, "my-table.my-key.2.key3");
689  assert_string_equal(amxc_var_constcast(cstring_t, cfg), "abc");
690 
691  amxd_dm_clean(dm);
692 }
int amxrt(int argc, char *argv[], amxrt_arg_fn_t fn)
This function can create full ambiorix application (data model provider or client).
Definition: amxrt.c:334
amxd_dm_t * amxrt_get_dm(void)
Gets the runtime data model storage.
Definition: amxrt.c:309
static dummy_bus_t dummy_ctx

◆ test_runtime_can_pass_option_path()

void test_runtime_can_pass_option_path ( UNUSED void **  state)

Definition at line 604 of file test_amxrt_runtime.c.

604  {
605  char* argv[] = {"amxrt", "-B b", "-u",
606  "dummy://127.0.0.1:1970",
607  "-o", "my-table.my-key.0=123",
608  "-o", "my-table.my-key.1=true",
609  "./test.odl" };
610 
611  amxd_dm_t* dm = amxrt_get_dm();
612  amxc_var_t* config = amxrt_get_config();
613  amxc_var_t* cfg = NULL;
614 
615  amxd_dm_init(dm);
616  optind = 1;
617  write(dummy_ctx.data_pipe[1], "s", 1);
618  will_return(__wrap_amxb_be_load_multiple, 0);
619  will_return_always(__wrap_amxb_connect, 0);
620  will_return(__wrap_setpriority, 0);
621  will_return_always(__wrap_amxb_register, 0);
622  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
623 
624  cfg = GETP_ARG(config, "my-table.my-key.0");
625  assert_int_equal(amxc_var_dyncast(int32_t, cfg), 123);
626  cfg = GETP_ARG(config, "my-table.my-key.1");
627  assert_true(GET_BOOL(cfg, NULL));
628 
629  amxd_dm_clean(dm);
630 }

◆ test_runtime_can_suspend_events_while_waiting()

void test_runtime_can_suspend_events_while_waiting ( UNUSED void **  state)

Definition at line 750 of file test_amxrt_runtime.c.

750  {
751  char* argv[] = {"amxrt", "-B b", "-u", "dummy://127.0.0.1:1970", "-R", "NetDev.", "test.odl" };
752 
753  amxd_dm_t* dm = amxrt_get_dm();
754  amxc_var_t* config = amxrt_get_config();
755 
756  amxd_dm_init(dm);
757  optind = 1;
758  will_return(__wrap_amxb_be_load_multiple, 0);
759  will_return_always(__wrap_amxb_connect, 0);
760  will_return(__wrap_setpriority, 0);
761  will_return_always(__wrap_amxb_wait_for_object, 0);
762  amxc_var_add_key(bool, config, AMXRT_COPT_SUSPEND, true);
763  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
764 
765  will_return_always(__wrap_amxb_register, 0);
766  amxp_sigmngr_trigger_signal(NULL, "wait:done", NULL);
767 
768  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_SUSPEND), false);
769 
770  amxd_dm_clean(dm);
771 }
#define AMXRT_COPT_SUSPEND
Definition: amxrt.h:101
int __wrap_amxb_wait_for_object(const char *object)

◆ test_runtime_can_wait_for_objects()

void test_runtime_can_wait_for_objects ( UNUSED void **  state)

Definition at line 711 of file test_amxrt_runtime.c.

711  {
712  char* argv[] = {"amxrt", "-B b", "-u", "dummy://127.0.0.1:1970", "-R", "NetDev.", "test.odl" };
713 
714  amxd_dm_t* dm = amxrt_get_dm();
715 
716  amxd_dm_init(dm);
717  optind = 1;
718  will_return(__wrap_amxb_be_load_multiple, 0);
719  will_return_always(__wrap_amxb_connect, 0);
720  will_return(__wrap_setpriority, 0);
721  will_return(__wrap_amxb_wait_for_object, 0);
722  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
723 
724  will_return_always(__wrap_amxb_register, 0);
725  amxp_sigmngr_trigger_signal(NULL, "wait:done", NULL);
726 
727  amxd_dm_clean(dm);
728 }

◆ test_runtime_cannot_connect_bus_uri()

void test_runtime_cannot_connect_bus_uri ( UNUSED void **  state)

Definition at line 296 of file test_amxrt_runtime.c.

296  {
297  char* argv[] = {"amxrt", "-B b", "test.odl", "-u", "dummy://127.0.0.1:1970"};
298 
299  amxd_dm_t* dm = amxrt_get_dm();
300 
301  amxd_dm_init(dm);
302  optind = 1;
303  write(dummy_ctx.data_pipe[1], "s", 1);
304  will_return(__wrap_amxb_be_load_multiple, 0);
305  will_return_always(__wrap_amxb_connect, -1);
306  assert_int_not_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
307 
308  amxd_dm_clean(dm);
309 }

◆ test_runtime_cannot_load_backends()

void test_runtime_cannot_load_backends ( UNUSED void **  state)

Definition at line 282 of file test_amxrt_runtime.c.

282  {
283  char* argv[] = {"amxrt", "-B b", "test.odl"};
284 
285  amxd_dm_t* dm = amxrt_get_dm();
286 
287  amxd_dm_init(dm);
288  optind = 1;
289  write(dummy_ctx.data_pipe[1], "s", 1);
290  will_return(__wrap_amxb_be_load_multiple, -1);
291  assert_int_not_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
292 
293  amxd_dm_clean(dm);
294 }

◆ test_runtime_connect_fails_if_no_backends()

void test_runtime_connect_fails_if_no_backends ( UNUSED void **  state)

Definition at line 806 of file test_amxrt_runtime.c.

806  {
807  amxc_var_t* config = amxrt_get_config();
808  amxc_var_t* backends = GET_ARG(config, AMXRT_COPT_BACKENDS);
809 
810  amxc_var_set_type(backends, AMXC_VAR_ID_CSTRING);
811  assert_int_not_equal(amxrt_connect(), 0);
812  amxc_var_set_type(backends, AMXC_VAR_ID_LIST);
813  assert_int_not_equal(amxrt_connect(), 0);
814 }
#define AMXRT_COPT_BACKENDS
Definition: amxrt.h:75

◆ test_runtime_connects_to_uri()

void test_runtime_connects_to_uri ( UNUSED void **  state)

Definition at line 264 of file test_amxrt_runtime.c.

264  {
265  char* argv1[] = {"amxrt", "-B a", "-u", "dummy://127.0.0.1:1970", "test.odl"};
266 
267  amxd_dm_t* dm = amxrt_get_dm();
268 
269  amxd_dm_init(dm);
270  optind = 1;
271  write(dummy_ctx.data_pipe[1], "s", 1);
272  will_return(__wrap_amxb_be_load_multiple, 0);
273  will_return_always(__wrap_amxb_connect, 0);
274  will_return(__wrap_setpriority, 0);
275  will_return_always(__wrap_amxb_register, 0);
276 
277  assert_int_equal(amxrt(sizeof(argv1) / sizeof(argv1[0]), argv1, NULL), 0);
278 
279  amxd_dm_clean(dm);
280 }

◆ test_runtime_creates_pid_file()

void test_runtime_creates_pid_file ( UNUSED void **  state)

Definition at line 311 of file test_amxrt_runtime.c.

311  {
312  char* argv1[] = {"dummy_name", "-B a", "test.odl",
313  "-u", "dummy://127.0.0.1:1970"};
314  struct stat sb;
315  FILE* fp;
316  char* line = NULL;
317  size_t len = 0;
318  ssize_t read = 0;
319 
320  amxd_dm_t* dm = amxrt_get_dm();
321  amxc_var_t* config = amxrt_get_config();
322  amxc_var_t* name = GET_ARG(config, "name");
323  amxc_var_delete(&name);
324 
325  optind = 1;
326  system("sudo rm -rf /var/run/dummy_name");
327  system("sudo mkdir -p /var/run/dummy_name");
328  system("sudo chown $USER /var/run/dummy_name");
329  system("sudo chmod 777 /var/run/dummy_name");
330  system("ls -la /var/run/dummy_name");
331  system("echo $USER");
332 
333  will_return(__wrap_amxb_be_load_multiple, 0);
334  will_return(__wrap_setpriority, 0);
335  will_return_always(__wrap_amxb_connect, 0);
336 
337  amxd_dm_init(dm);
338  assert_int_equal(amxrt_init(sizeof(argv1) / sizeof(argv1[0]), argv1, NULL), 0);
339  assert_true(stat("/var/run/dummy_name.pid", &sb) == 0 ||
340  stat("/var/run/dummy_name/dummy_name.pid", &sb) == 0);
341 
342  if(stat("/var/run/dummy_name.pid", &sb) == 0) {
343  fp = fopen("/var/run/dummy_name.pid", "r");
344  } else {
345  fp = fopen("/var/run/dummy_name/dummy_name.pid", "r");
346  }
347  read = getline(&line, &len, fp);
348  assert_true(read > 0);
349  assert_int_equal(atol(line), getpid());
350  fclose(fp);
351  free(line);
352 
353  system("sudo rm -rf /var/run/dummy_name");
354  amxrt_stop();
355 
356  amxd_dm_clean(dm);
357 }
int amxrt_init(int argc, char *argv[], amxrt_arg_fn_t fn)
Initializes the ambiorix runtime.
Definition: amxrt.c:348
void amxrt_stop(void)
Stops the runtime.
Definition: amxrt.c:440

◆ test_runtime_daemon_failed()

void test_runtime_daemon_failed ( UNUSED void **  state)

Definition at line 359 of file test_amxrt_runtime.c.

359  {
360  char* argv[] = {"amxrt", "-B b", "test.odl", "-D", "-u", "dummy://127.0.0.1:1970"};
361 
362  amxc_var_t* config = amxrt_get_config();
363  amxd_dm_t* dm = amxrt_get_dm();
364 
365  amxd_dm_init(dm);
366  optind = 1;
367  write(dummy_ctx.data_pipe[1], "s", 1);
368  will_return(__wrap_amxb_be_load_multiple, 0);
369  will_return(__wrap_daemon, -1);
370  assert_int_not_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
371 
372  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_DAEMON), false);
373  amxd_dm_clean(dm);
374 }
#define AMXRT_COPT_DAEMON
Definition: amxrt.h:82
int __wrap_daemon(int nochdir, int noclose)

◆ test_runtime_dumps_config()

void test_runtime_dumps_config ( UNUSED void **  state)

Definition at line 485 of file test_amxrt_runtime.c.

485  {
486  char* argv[] = {"amxrt", "-d", "test.odl", "-B b", "-u", "dummy://127.0.0.1:1970" };
487 
488  amxd_dm_t* dm = amxrt_get_dm();
489  amxc_var_t* config = amxrt_get_config();
490 
491  amxd_dm_init(dm);
492  optind = 1;
493  write(dummy_ctx.data_pipe[1], "s", 1);
494  will_return(__wrap_amxb_be_load_multiple, 0);
495  will_return_always(__wrap_amxb_connect, 0);
496  will_return(__wrap_setpriority, 0);
497  will_return_always(__wrap_amxb_register, 0);
498  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
499  assert_true(GET_BOOL(config, AMXRT_COPT_DUMP_CONFIG));
500  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_DUMP_CONFIG), false);
501 
502  amxd_dm_clean(dm);
503 }
#define AMXRT_COPT_DUMP_CONFIG
Definition: amxrt.h:91

◆ test_runtime_enables_system_signal()

void test_runtime_enables_system_signal ( UNUSED void **  state)

Definition at line 528 of file test_amxrt_runtime.c.

528  {
529  char* argv[] = {"amxrt", "-B b", "-u", "dummy://127.0.0.1:1970", "-O", "%config { system-signals = 17; }", "./test.odl" };
530 
531  amxd_dm_t* dm = amxrt_get_dm();
532  amxc_var_t* config = amxrt_get_config();
533  amxc_var_t* odl_string = NULL;
534 
535  amxd_dm_init(dm);
536  optind = 1;
537  write(dummy_ctx.data_pipe[1], "s", 1);
538  will_return(__wrap_amxb_be_load_multiple, 0);
539  will_return_always(__wrap_amxb_connect, 0);
540  will_return(__wrap_setpriority, 0);
541  will_return_always(__wrap_amxb_register, 0);
542  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
543  assert_true(amxp_syssig_is_enabled(17));
544  amxp_syssig_enable(17, false);
545 
546  odl_string = GET_ARG(config, AMXRT_COPT_ODL);
547  amxc_var_delete(&odl_string);
548  amxd_dm_clean(dm);
549 }
#define AMXRT_COPT_ODL
Definition: amxrt.h:81

◆ test_runtime_enables_system_signals_list()

void test_runtime_enables_system_signals_list ( UNUSED void **  state)

Definition at line 505 of file test_amxrt_runtime.c.

505  {
506  char* argv[] = {"amxrt", "-B b", "-u", "dummy://127.0.0.1:1970", "-O", "%config { system-signals = [ 17 ]; }", "./test.odl" };
507 
508  amxd_dm_t* dm = amxrt_get_dm();
509  amxc_var_t* config = amxrt_get_config();
510  amxc_var_t* odl_string = NULL;
511 
512  amxd_dm_init(dm);
513  optind = 1;
514  write(dummy_ctx.data_pipe[1], "s", 1);
515  will_return(__wrap_amxb_be_load_multiple, 0);
516  will_return_always(__wrap_amxb_connect, 0);
517  will_return(__wrap_setpriority, 0);
518  will_return_always(__wrap_amxb_register, 0);
519  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
520  assert_true(amxp_syssig_is_enabled(17));
521  amxp_syssig_enable(17, false);
522 
523  odl_string = GET_ARG(config, AMXRT_COPT_ODL);
524  amxc_var_delete(&odl_string);
525  amxd_dm_clean(dm);
526 }

◆ test_runtime_fails_when_invalid_odl()

void test_runtime_fails_when_invalid_odl ( UNUSED void **  state)

Definition at line 251 of file test_amxrt_runtime.c.

251  {
252  char* argv1[] = {"amxrt", "-B a", "-u", "dummy://127.0.0.1:1970", "invalid.odl"};
253 
254  amxd_dm_t* dm = amxrt_get_dm();
255 
256  amxd_dm_init(dm);
257  optind = 1;
258  write(dummy_ctx.data_pipe[1], "s", 1);
259  assert_int_not_equal(amxrt(sizeof(argv1) / sizeof(argv1[0]), argv1, NULL), 0);
260 
261  amxd_dm_clean(dm);
262 }

◆ test_runtime_fails_when_registering_dm_fails()

void test_runtime_fails_when_registering_dm_fails ( UNUSED void **  state)

Definition at line 694 of file test_amxrt_runtime.c.

694  {
695  char* argv[] = {"amxrt", "-B b", "-u", "dummy://127.0.0.1:1970", "test.odl" };
696 
697  amxd_dm_t* dm = amxrt_get_dm();
698 
699  amxd_dm_init(dm);
700  write(dummy_ctx.data_pipe[1], "s", 1);
701  optind = 1;
702  will_return(__wrap_amxb_be_load_multiple, 0);
703  will_return_always(__wrap_amxb_connect, 0);
704  will_return(__wrap_setpriority, 0);
705  will_return_always(__wrap_amxb_register, -1);
706  assert_int_not_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
707 
708  amxd_dm_clean(dm);
709 }

◆ test_runtime_forced_options_are_kept()

void test_runtime_forced_options_are_kept ( UNUSED void **  state)

Definition at line 551 of file test_amxrt_runtime.c.

551  {
552  char* argv[] = {"amxrt", "-B b", "-u",
553  "dummy://127.0.0.1:1970",
554  "-F", "my-option=123",
555  "-O", "%config { my-option = 666; }", "./test.odl" };
556 
557  amxd_dm_t* dm = amxrt_get_dm();
558  amxc_var_t* config = amxrt_get_config();
559  amxc_var_t* odl_string = NULL;
560 
561  amxd_dm_init(dm);
562  optind = 1;
563  write(dummy_ctx.data_pipe[1], "s", 1);
564  will_return(__wrap_amxb_be_load_multiple, 0);
565  will_return_always(__wrap_amxb_connect, 0);
566  will_return(__wrap_setpriority, 0);
567  will_return_always(__wrap_amxb_register, 0);
568 
569  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
570 
571  assert_int_equal(GET_INT32(config, "my-option"), 123);
572  odl_string = GET_ARG(config, AMXRT_COPT_ODL);
573  amxc_var_delete(&odl_string);
574 
575  amxd_dm_clean(dm);
576 }

◆ test_runtime_forced_options_with_path_are_kept()

void test_runtime_forced_options_with_path_are_kept ( UNUSED void **  state)

Definition at line 632 of file test_amxrt_runtime.c.

632  {
633  char* argv[] = {"amxrt", "-B b", "-u",
634  "dummy://127.0.0.1:1970",
635  "-F", "my-table.odl-key=xyz",
636  "-O", "%config{ my-table = { odl-key=\"abc\" }; }",
637  "./test.odl" };
638 
639  amxd_dm_t* dm = amxrt_get_dm();
640  amxc_var_t* config = amxrt_get_config();
641  amxc_var_t* cfg = NULL;
642  amxc_var_t* odl_string = NULL;
643 
644  amxd_dm_init(dm);
645  optind = 1;
646  write(dummy_ctx.data_pipe[1], "s", 1);
647  will_return(__wrap_amxb_be_load_multiple, 0);
648  will_return_always(__wrap_amxb_connect, 0);
649  will_return(__wrap_setpriority, 0);
650  will_return_always(__wrap_amxb_register, 0);
651  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
652 
653  cfg = GETP_ARG(config, "my-table.odl-key");
654  assert_string_equal(GET_CHAR(cfg, NULL), "xyz");
655  odl_string = GET_ARG(config, AMXRT_COPT_ODL);
656  amxc_var_delete(&odl_string);
657 
658  amxd_dm_clean(dm);
659 }

◆ test_runtime_no_pidfile()

void test_runtime_no_pidfile ( UNUSED void **  state)

Definition at line 431 of file test_amxrt_runtime.c.

431  {
432  char* argv[] = {"amxrt", "-B b", "test.odl", "-N", "-u", "dummy://127.0.0.1:1970"};
433 
434  amxd_dm_t* dm = amxrt_get_dm();
435 
436  amxd_dm_init(dm);
437  optind = 1;
438  write(dummy_ctx.data_pipe[1], "s", 1);
439  will_return_always(__wrap_amxb_connect, 0);
440  will_return(__wrap_amxb_be_load_multiple, 0);
441  will_return(__wrap_setpriority, 0);
442  will_return_always(__wrap_amxb_register, 0);
443  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
444 
445  amxd_dm_clean(dm);
446 }

◆ test_runtime_opens_syslog()

void test_runtime_opens_syslog ( UNUSED void **  state)

Definition at line 465 of file test_amxrt_runtime.c.

465  {
466  char* argv[] = {"amxrt", "-l", "test.odl", "-B b", "-u", "dummy://127.0.0.1:1970" };
467 
468  amxd_dm_t* dm = amxrt_get_dm();
469  amxc_var_t* config = amxrt_get_config();
470 
471  amxd_dm_init(dm);
472  optind = 1;
473  write(dummy_ctx.data_pipe[1], "s", 1);
474  will_return(__wrap_amxb_be_load_multiple, 0);
475  will_return_always(__wrap_amxb_connect, 0);
476  will_return(__wrap_setpriority, 0);
477  will_return_always(__wrap_amxb_register, 0);
478  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
479  assert_true(GET_BOOL(config, AMXRT_COPT_LOG));
480  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_LOG), false);
481 
482  amxd_dm_clean(dm);
483 }
#define AMXRT_COPT_LOG
Definition: amxrt.h:98

◆ test_runtime_options_can_be_overwritten()

void test_runtime_options_can_be_overwritten ( UNUSED void **  state)

Definition at line 578 of file test_amxrt_runtime.c.

578  {
579  char* argv[] = {"amxrt", "-B b", "-u",
580  "dummy://127.0.0.1:1970",
581  "-o", "my-option=123",
582  "-O", "%config { my-option = 666; }", "./test.odl" };
583 
584  amxd_dm_t* dm = amxrt_get_dm();
585  amxc_var_t* config = amxrt_get_config();
586  amxc_var_t* odl_string = NULL;
587 
588  amxd_dm_init(dm);
589  optind = 1;
590  write(dummy_ctx.data_pipe[1], "s", 1);
591  will_return(__wrap_amxb_be_load_multiple, 0);
592  will_return_always(__wrap_amxb_connect, 0);
593  will_return(__wrap_setpriority, 0);
594  will_return_always(__wrap_amxb_register, 0);
595  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
596 
597  assert_int_equal(GET_INT32(config, "my-option"), 999);
598  odl_string = GET_ARG(config, AMXRT_COPT_ODL);
599  amxc_var_delete(&odl_string);
600 
601  amxd_dm_clean(dm);
602 }

◆ test_runtime_parse_args_odl()

void test_runtime_parse_args_odl ( UNUSED void **  state)

Definition at line 394 of file test_amxrt_runtime.c.

394  {
395  char* argv[] = {"amxrt", "-B b", "test.odl", "-O", "%define {object TestObject2 {string Text = \"Hallo World\";}}",
396  "-u", "dummy://127.0.0.1:1970"};
397 
398  amxc_var_t* config = amxrt_get_config();
399  amxd_dm_t* dm = amxrt_get_dm();
400  amxc_var_t* odl_string = NULL;
401 
402  amxd_dm_init(dm);
403  optind = 1;
404  write(dummy_ctx.data_pipe[1], "s", 1);
405  will_return_always(__wrap_amxb_connect, 0);
406  will_return(__wrap_amxb_be_load_multiple, 0);
407  will_return(__wrap_setpriority, 0);
408  will_return_always(__wrap_amxb_register, 0);
409  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
410 
411  odl_string = GET_ARG(config, AMXRT_COPT_ODL);
412  amxc_var_delete(&odl_string);
413  amxd_dm_clean(dm);
414 }

◆ test_runtime_parse_args_wrong_odl()

void test_runtime_parse_args_wrong_odl ( UNUSED void **  state)

Definition at line 416 of file test_amxrt_runtime.c.

416  {
417  char* argv[] = {"amxrt", "-B b", "test.odl", "-O", "%define {object TestObject2 {string Text = \"Hallo World\";}"}; //invalid odl string
418  amxc_var_t* config = amxrt_get_config();
419  amxd_dm_t* dm = amxrt_get_dm();
420  amxc_var_t* odl_string = NULL;
421 
422  amxd_dm_init(dm);
423  optind = 1;
424  assert_int_not_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
425 
426  odl_string = GET_ARG(config, AMXRT_COPT_ODL);
427  amxc_var_delete(&odl_string);
428  amxd_dm_clean(dm);
429 }

◆ test_runtime_parses_default_odl()

void test_runtime_parses_default_odl ( UNUSED void **  state)

Definition at line 157 of file test_amxrt_runtime.c.

157  {
158  char* argv1[] = {"amxrt", "-B dymmy", "-u", "dummy://127.0.0.1:1970"};
159  char* argv2[] = {"test-plugin", "-B fake", "-u", "dummy://127.0.0.1:1970"};
160 
161  amxd_dm_t* dm = amxrt_get_dm();
162  amxc_var_t* config = amxrt_get_config();
163  amxc_var_t* prefix = GET_ARG(config, "prefix");
164 
165  char* current_wd = getcwd(NULL, 0);
166 
167  will_return_always(__wrap_amxb_be_load_multiple, 0);
168  will_return_always(__wrap_setpriority, 0);
169  will_return_always(__wrap_amxb_connect, 0);
170  will_return_always(__wrap_amxb_register, 0);
171 
172  amxc_var_set(cstring_t, prefix, current_wd);
173 
174  amxd_dm_init(dm);
175  optind = 1;
176  write(dummy_ctx.data_pipe[1], "s", 1);
177  assert_int_equal(amxrt(sizeof(argv1) / sizeof(argv1[0]), argv1, NULL), 0);
178  amxd_dm_clean(dm);
179 
180  amxd_dm_init(dm);
181  optind = 1;
182  write(dummy_ctx.data_pipe[1], "s", 1);
183  amxc_var_set(cstring_t, prefix, current_wd);
184  assert_int_equal(amxrt(sizeof(argv2) / sizeof(argv2[0]), argv2, NULL), 0);
185  amxd_dm_clean(dm);
186 
187  amxc_var_set(cstring_t, prefix, "");
188 
189  free(current_wd);
190 }

◆ test_runtime_parses_odls()

void test_runtime_parses_odls ( UNUSED void **  state)

Definition at line 192 of file test_amxrt_runtime.c.

192  {
193  char* argv[] = {"amxrt", "-B b", "-u", "dummy://127.0.0.1:1970",
194  "test.odl", "etc/amx/amxrt/amxrt.odl", "etc/amx/test-plugin/test-plugin.odl"};
195 
196  amxd_dm_t* dm = amxrt_get_dm();
197 
198  will_return(__wrap_amxb_be_load_multiple, 0);
199  will_return_always(__wrap_amxb_connect, 0);
200  will_return_always(__wrap_setpriority, 0);
201  will_return_always(__wrap_amxb_register, 0);
202 
203  amxd_dm_init(dm);
204  optind = 1;
205  write(dummy_ctx.data_pipe[1], "s", 1);
206  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
207 
208  amxd_dm_clean(dm);
209 }

◆ test_runtime_parses_odls_and_handle_events()

void test_runtime_parses_odls_and_handle_events ( UNUSED void **  state)

Definition at line 211 of file test_amxrt_runtime.c.

211  {
212  char* argv[] = {"amxrt", "-B b", "-u", "dummy://127.0.0.1:1970",
213  "test.odl", "-E", "etc/amx/amxrt/amxrt.odl", "etc/amx/test-plugin/test-plugin.odl"};
214 
215  amxd_dm_t* dm = amxrt_get_dm();
216  amxc_var_t* config = amxrt_get_config();
217 
218  will_return(__wrap_amxb_be_load_multiple, 0);
219  will_return_always(__wrap_amxb_connect, 0);
220  will_return_always(__wrap_setpriority, 0);
221  will_return_always(__wrap_amxb_register, 0);
222 
223  amxd_dm_init(dm);
224  optind = 1;
225  write(dummy_ctx.data_pipe[1], "s", 1);
226  amxc_var_add_key(bool, config, AMXRT_COPT_HANDLE_EVENTS, true);
227  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
228  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_HANDLE_EVENTS), false);
229 
230  amxd_dm_clean(dm);
231 }
#define AMXRT_COPT_HANDLE_EVENTS
Definition: amxrt.h:100

◆ test_runtime_parses_post_includes()

void test_runtime_parses_post_includes ( UNUSED void **  state)

Definition at line 448 of file test_amxrt_runtime.c.

448  {
449  char* argv[] = {"amxrt", "-B b", "-u", "dummy://127.0.0.1:1970", "post_include.odl" };
450 
451  amxd_dm_t* dm = amxrt_get_dm();
452 
453  amxd_dm_init(dm);
454  optind = 1;
455  write(dummy_ctx.data_pipe[1], "s", 1);
456  will_return(__wrap_amxb_be_load_multiple, 0);
457  will_return_always(__wrap_amxb_connect, 0);
458  will_return(__wrap_setpriority, 0);
459  will_return_always(__wrap_amxb_register, 0);
460  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
461 
462  amxd_dm_clean(dm);
463 }

◆ test_runtime_set_priority_failed()

void test_runtime_set_priority_failed ( UNUSED void **  state)

Definition at line 376 of file test_amxrt_runtime.c.

376  {
377  char* argv[] = {"amxrt", "-B b", "-D", "-u", "dummy://127.0.0.1:1970", "test.odl"};
378 
379  amxc_var_t* config = amxrt_get_config();
380  amxd_dm_t* dm = amxrt_get_dm();
381 
382  amxd_dm_init(dm);
383  optind = 1;
384  will_return(__wrap_amxb_be_load_multiple, 0);
385  will_return(__wrap_daemon, 0);
386  will_return(__wrap_setpriority, -1);
387  will_return_always(__wrap_amxb_connect, 0);
388  assert_int_not_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
389 
390  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_DAEMON), false);
391  amxd_dm_clean(dm);
392 }

◆ test_runtime_setup()

int test_runtime_setup ( UNUSED void **  state)

Definition at line 129 of file test_amxrt_runtime.c.

129  {
130  amxd_dm_t* dm = NULL;
131  amxrt_new();
132  dm = amxrt_get_dm();
133  memset(&dummy_ctx.ctx, 0, sizeof(amxb_bus_ctx_t));
134  amxp_sigmngr_init(&dummy_ctx.ctx.sigmngr);
135  amxc_htable_init(&dummy_ctx.ctx.subscriptions, 5);
136  amxd_dm_clean(dm);
137  assert_int_equal(pipe(dummy_ctx.data_pipe), 0);
138  return 0;
139 }
void amxrt_new(void)
Create the ambiorix runtime.
Definition: amxrt.c:313
amxb_bus_ctx_t ctx

◆ test_runtime_start_prints_help_and_exits()

void test_runtime_start_prints_help_and_exits ( UNUSED void **  state)

Definition at line 150 of file test_amxrt_runtime.c.

150  {
151  char* argv[] = {"amxrt", "-h"};
152 
153  optind = 1;
154  assert_int_not_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
155 }

◆ test_runtime_stops_el_when_registering_after_wait_fails()

void test_runtime_stops_el_when_registering_after_wait_fails ( UNUSED void **  state)

Definition at line 773 of file test_amxrt_runtime.c.

773  {
774  char* argv[] = {"amxrt", "-B b", "-u", "dummy://127.0.0.1:1970", "-R", "NetDev.", "test.odl" };
775 
776  amxd_dm_t* dm = amxrt_get_dm();
777 
778  amxd_dm_init(dm);
779  optind = 1;
780  will_return(__wrap_amxb_be_load_multiple, 0);
781  will_return_always(__wrap_amxb_connect, 0);
782  will_return(__wrap_setpriority, 0);
783  will_return_always(__wrap_amxb_register, -1);
784  will_return(__wrap_amxb_wait_for_object, 0);
785 
786  assert_int_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
787  amxp_sigmngr_trigger_signal(NULL, "wait:done", NULL);
788 
789  amxd_dm_clean(dm);
790 }

◆ test_runtime_succeeds_when_no_odl()

void test_runtime_succeeds_when_no_odl ( UNUSED void **  state)

Definition at line 233 of file test_amxrt_runtime.c.

233  {
234  char* argv1[] = {"amxrt", "-B a", "-u", "dummy://127.0.0.1:1970"};
235 
236  amxd_dm_t* dm = amxrt_get_dm();
237 
238  will_return(__wrap_amxb_be_load_multiple, 0);
239  will_return_always(__wrap_amxb_connect, 0);
240  will_return_always(__wrap_setpriority, 0);
241  will_return_always(__wrap_amxb_register, 0);
242 
243  amxd_dm_init(dm);
244  optind = 1;
245  write(dummy_ctx.data_pipe[1], "s", 1);
246  assert_int_equal(amxrt(sizeof(argv1) / sizeof(argv1[0]), argv1, NULL), 0);
247 
248  amxd_dm_clean(dm);
249 }

◆ test_runtime_teardown()

int test_runtime_teardown ( UNUSED void **  state)

Definition at line 141 of file test_amxrt_runtime.c.

141  {
142  close(dummy_ctx.data_pipe[0]);
143  close(dummy_ctx.data_pipe[1]);
144  amxp_sigmngr_clean(&dummy_ctx.ctx.sigmngr);
145  amxc_htable_clean(&dummy_ctx.ctx.subscriptions, NULL);
146  amxrt_delete();
147  return 0;
148 }
void amxrt_delete(void)
Clean-up ambiorix runtime.
Definition: amxrt.c:378

◆ test_runtime_wait_for_objects_can_fail()

void test_runtime_wait_for_objects_can_fail ( UNUSED void **  state)

Definition at line 730 of file test_amxrt_runtime.c.

730  {
731  char* argv[] = {"amxrt", "-B b", "-u", "dummy://127.0.0.1:1970", "-R", "NetDev.", "test.odl" };
732 
733  amxd_dm_t* dm = amxrt_get_dm();
734 
735  amxd_dm_init(dm);
736  optind = 1;
737  will_return(__wrap_amxb_be_load_multiple, 0);
738  will_return_always(__wrap_amxb_connect, 0);
739  will_return(__wrap_setpriority, 0);
740  will_return(__wrap_amxb_wait_for_object, -1);
741 
742  assert_int_not_equal(amxrt(sizeof(argv) / sizeof(argv[0]), argv, NULL), 0);
743 
744  will_return_always(__wrap_amxb_register, 0);
745  amxp_sigmngr_trigger_signal(NULL, "wait:done", NULL);
746 
747  amxd_dm_clean(dm);
748 }