Amxb_Ubus  3.3.1
Ambiorix Ubus API
test_amxb_ubus_register.c File Reference
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <signal.h>
#include <amxc/amxc.h>
#include <amxp/amxp.h>
#include <amxd/amxd_dm.h>
#include <amxd/amxd_object.h>
#include <amxd/amxd_transaction.h>
#include <amxo/amxo.h>
#include <amxb/amxb.h>
#include <amxb/amxb_register.h>
#include "test_amxb_ubus_register.h"

Go to the source code of this file.

Functions

static void handle_events (void)
 
static const char * test_amxb_ubus_get_socket (void)
 
int test_amxb_ubus_register_setup (UNUSED void **state)
 
int test_amxb_ubus_register_teardown (UNUSED void **state)
 
void test_ubus_can_register_dm (UNUSED void **state)
 
void test_ubus_new_objects_are_registered (UNUSED void **state)
 
void test_ubus_new_root_objects_are_registered (UNUSED void **state)
 
void test_ubus_removed_objects_are_unregistered (UNUSED void **state)
 

Variables

static amxb_bus_ctx_t * bus_ctx = NULL
 
static amxd_dm_t dm
 
static amxo_parser_t parser
 

Function Documentation

◆ handle_events()

static void handle_events ( void  )
static

Definition at line 84 of file test_amxb_ubus_register.c.

84  {
85  printf("Handling events ");
86  while(amxp_signal_read() == 0) {
87  printf(".");
88  }
89  printf("\n");
90 }
Here is the caller graph for this function:

◆ test_amxb_ubus_get_socket()

static const char* test_amxb_ubus_get_socket ( void  )
static

Definition at line 92 of file test_amxb_ubus_register.c.

92  {
93  struct stat sb;
94  if(stat("/var/run/ubus.sock", &sb) == 0) {
95  return "ubus:/var/run/ubus.sock";
96  }
97  if(stat("/var/run/ubus/ubus.sock", &sb) == 0) {
98  return "ubus:/var/run/ubus/ubus.sock";
99  }
100  return NULL;
101 }
Here is the caller graph for this function:

◆ test_amxb_ubus_register_setup()

int test_amxb_ubus_register_setup ( UNUSED void **  state)

Definition at line 103 of file test_amxb_ubus_register.c.

103  {
104  const char* ubus_sock = test_amxb_ubus_get_socket();
105  printf("Ubus socket = %s\n", ubus_sock);
106 
107  assert_int_equal(amxd_dm_init(&dm), 0);
108  assert_int_equal(amxo_parser_init(&parser), 0);
109 
110  assert_int_equal(amxb_be_load("../mod-amxb-test-ubus.so"), 0);
111  assert_int_equal(amxb_connect(&bus_ctx, ubus_sock), 0);
112 
113  amxo_parser_parse_file(&parser, "../test_data/test_nemo.odl", amxd_dm_get_root(&dm));
114 
115  return 0;
116 }
static amxd_dm_t dm
static const char * test_amxb_ubus_get_socket(void)
static amxo_parser_t parser
static amxb_bus_ctx_t * bus_ctx
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_amxb_ubus_register_teardown()

int test_amxb_ubus_register_teardown ( UNUSED void **  state)

Definition at line 118 of file test_amxb_ubus_register.c.

118  {
119  amxd_dm_clean(&dm);
120  amxo_parser_clean(&parser);
121 
122  amxb_disconnect(bus_ctx);
123  amxb_free(&bus_ctx);
124 
125  amxb_be_remove_all();
126 
127  return 0;
128 }
Here is the caller graph for this function:

◆ test_ubus_can_register_dm()

void test_ubus_can_register_dm ( UNUSED void **  state)

Definition at line 130 of file test_amxb_ubus_register.c.

130  {
131  assert_int_equal(amxb_register(bus_ctx, &dm), 0);
132 }
Here is the caller graph for this function:

◆ test_ubus_new_objects_are_registered()

void test_ubus_new_objects_are_registered ( UNUSED void **  state)

Definition at line 134 of file test_amxb_ubus_register.c.

134  {
135  amxd_trans_t transaction;
136 
137  assert_int_equal(amxd_trans_init(&transaction), 0);
138  assert_int_equal(amxd_trans_select_pathf(&transaction, "NeMo.Intf."), 0);
139  assert_int_equal(amxd_trans_add_inst(&transaction, 99, "Inst1"), 0);
140  assert_int_equal(amxd_trans_apply(&transaction, &dm), 0);
141 
142  handle_events();
143 
144  assert_int_equal(system("ubus list NeMo.Intf.99"), 0);
145 
146  amxd_trans_clean(&transaction);
147 }
static void handle_events(void)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_ubus_new_root_objects_are_registered()

void test_ubus_new_root_objects_are_registered ( UNUSED void **  state)

Definition at line 149 of file test_amxb_ubus_register.c.

149  {
150  amxd_object_t* object = NULL;
151 
152  assert_int_equal(amxd_object_new(&object, amxd_object_singleton, "test_object"), 0);
153  assert_ptr_not_equal(object, NULL);
154  assert_int_equal(amxd_dm_add_root_object(&dm, object), 0);
155 
156  handle_events();
157 
158  assert_int_equal(system("ubus list test_object"), 0);
159 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_ubus_removed_objects_are_unregistered()

void test_ubus_removed_objects_are_unregistered ( UNUSED void **  state)

Definition at line 161 of file test_amxb_ubus_register.c.

161  {
162  amxd_trans_t transaction;
163 
164  assert_int_equal(amxd_trans_init(&transaction), 0);
165  assert_int_equal(amxd_trans_select_pathf(&transaction, "NeMo.Intf."), 0);
166  assert_int_equal(amxd_trans_del_inst(&transaction, 99, "Inst1"), 0);
167  assert_int_equal(amxd_trans_apply(&transaction, &dm), 0);
168 
169  handle_events();
170 
171  assert_int_not_equal(system("ubus list NeMo.Intf.99"), 0);
172 
173  amxd_trans_clean(&transaction);
174 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ bus_ctx

amxb_bus_ctx_t* bus_ctx = NULL
static

Definition at line 80 of file test_amxb_ubus_register.c.

◆ dm

amxd_dm_t dm
static

Definition at line 81 of file test_amxb_ubus_register.c.

◆ parser

amxo_parser_t parser
static

Definition at line 82 of file test_amxb_ubus_register.c.