54 #include <sys/types.h>
67 #include <amxc/amxc.h>
68 #include <amxp/amxp.h>
70 #include <amxd/amxd_dm.h>
72 #include <amxb/amxb.h>
80 if(stat(
"/var/run/ubus.sock", &sb) == 0) {
81 return "ubus:/var/run/ubus.sock";
83 if(stat(
"/var/run/ubus/ubus.sock", &sb) == 0) {
84 return "ubus:/var/run/ubus/ubus.sock";
90 printf(
"Handling events \n");
94 while(amxp_signal_read() == 0) {
101 while(amxp_signal_read() == 0) {
112 printf(
"Ubus socket = %s\n", ubus_sock);
115 sigaddset(&mask, SIGALRM);
117 sigprocmask(SIG_BLOCK, &mask, NULL);
120 amxc_string_init(&txt, 0);
122 amxp_sigmngr_add_signal(NULL,
"config:changed");
124 amxc_string_reset(&txt);
125 amxc_string_setf(&txt,
"amxrt -u ubus: -B ../mod-amxb-test-ubus.so -A ../test_data/test_nemo.odl &");
126 system(amxc_string_get(&txt, 0));
128 amxc_string_clean(&txt);
130 assert_int_equal(amxb_be_load(
"../mod-amxb-test-ubus.so"), 0);
131 assert_int_equal(amxb_connect(&
bus_ctx, ubus_sock), 0);
142 system(
"killall amxrt");
144 amxb_be_remove_all();
150 UNUSED
const amxc_var_t*
const data,
151 UNUSED
void*
const priv) {
152 printf(
"Event recieved %s\n", sig_name);
162 assert_int_equal(amxb_subscribe(
bus_ctx,
"NeMo.Intf.", NULL,
test_event_cb, NULL), AMXB_STATUS_OK);
163 assert_int_equal(amxb_add(
bus_ctx,
"NeMo.Intf.", 5, NULL, NULL, &ret, 5), AMXB_STATUS_OK);
167 amxc_var_clean(&ret);
179 assert_int_equal(amxb_add(
bus_ctx,
"NeMo.Intf.", 6, NULL, NULL, &ret, 5), AMXB_STATUS_OK);
182 amxc_var_clean(&ret);
186 system(
"killall amxrt");
188 amxp_sigmngr_add_signal(NULL,
"wait:done");
189 amxp_slot_connect(NULL,
"wait:done", NULL,
test_event_cb, NULL);
190 assert_int_equal(amxb_wait_for_object(
"NeMo."), AMXB_STATUS_OK);
191 system(
"amxrt -u ubus: -B ../mod-amxb-test-ubus.so -A ../test_data/test_nemo.odl &");
201 amxc_var_t* ubus_config = NULL;
206 amxc_var_init(&config);
207 amxc_var_set_type(&config, AMXC_VAR_ID_HTABLE);
208 ubus_config = amxc_var_add_key(amxc_htable_t, &config,
"ubus", NULL);
209 amxc_var_add_key(
bool, ubus_config,
"watch-ubus-events",
true);
210 amxb_set_config(&config);
211 amxp_sigmngr_trigger_signal(NULL,
"config:changed", NULL);
214 assert_int_equal(amxb_subscribe(
bus_ctx,
"NeMo.Intf.", NULL,
test_event_cb, NULL), AMXB_STATUS_OK);
216 system(
"killall amxrt");
218 amxp_timers_calculate();
221 system(
"amxrt -u ubus: -B ../mod-amxb-test-ubus.so -A ../test_data/test_nemo.odl &");
224 amxp_timers_calculate();
226 assert_int_equal(amxb_add(
bus_ctx,
"NeMo.Intf.", 7, NULL, NULL, &ret, 5), AMXB_STATUS_OK);
229 amxp_timers_calculate();
232 assert_int_equal(amxb_add(
bus_ctx,
"NeMo.Intf.", 8, NULL, NULL, &ret, 5), AMXB_STATUS_OK);
235 amxb_set_config(NULL);
236 amxc_var_clean(&config);
237 amxc_var_clean(&ret);
void test_ubus_can_wait_for_object(UNUSED void **state)
void test_ubus_can_reactivate_subscriptions(UNUSED void **state)
static const char * test_amxb_ubus_get_socket(void)
void test_ubus_can_unsubscribe(UNUSED void **state)
int test_amxb_ubus_subscribe_setup(UNUSED void **state)
int test_amxb_ubus_subscribe_teardown(UNUSED void **state)
static amxb_bus_ctx_t * bus_ctx
void test_ubus_can_subscribe(UNUSED void **state)
static void test_event_cb(UNUSED const char *const sig_name, UNUSED const amxc_var_t *const data, UNUSED void *const priv)
static void handle_events(void)