Amxb_Ubus  3.3.1
Ambiorix Ubus API
test_amxb_ubus_has.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 <amxb/amxb.h>
#include "test_amxb_ubus_has.h"

Go to the source code of this file.

Functions

static const char * test_amxb_ubus_get_socket (void)
 
int test_amxb_ubus_has_setup (UNUSED void **state)
 
int test_amxb_ubus_has_teardown (UNUSED void **state)
 
void test_ubus_has (UNUSED void **state)
 

Variables

static amxb_bus_ctx_t * bus_ctx = NULL
 

Function Documentation

◆ test_amxb_ubus_get_socket()

static const char* test_amxb_ubus_get_socket ( void  )
static

Definition at line 78 of file test_amxb_ubus_has.c.

78  {
79  struct stat sb;
80  if(stat("/var/run/ubus.sock", &sb) == 0) {
81  return "ubus:/var/run/ubus.sock";
82  }
83  if(stat("/var/run/ubus/ubus.sock", &sb) == 0) {
84  return "ubus:/var/run/ubus/ubus.sock";
85  }
86  return NULL;
87 }
Here is the caller graph for this function:

◆ test_amxb_ubus_has_setup()

int test_amxb_ubus_has_setup ( UNUSED void **  state)

Definition at line 89 of file test_amxb_ubus_has.c.

89  {
90  amxc_string_t txt;
91  const char* ubus_sock = test_amxb_ubus_get_socket();
92  printf("Ubus socket = %s\n", ubus_sock);
93 
94  amxc_string_init(&txt, 0);
95 
96  amxc_string_reset(&txt);
97  amxc_string_setf(&txt, "amxrt -u ubus: -B ../mod-amxb-test-ubus.so -A ../test_data/test_nemo.odl &");
98  system(amxc_string_get(&txt, 0));
99 
100  amxc_string_clean(&txt);
101 
102  assert_int_equal(amxb_be_load("../mod-amxb-test-ubus.so"), 0);
103  assert_int_equal(amxb_connect(&bus_ctx, ubus_sock), 0);
104 
105  sleep(1);
106 
107  return 0;
108 }
static const char * test_amxb_ubus_get_socket(void)
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_has_teardown()

int test_amxb_ubus_has_teardown ( UNUSED void **  state)

Definition at line 110 of file test_amxb_ubus_has.c.

110  {
111  amxb_disconnect(bus_ctx);
112  amxb_free(&bus_ctx);
113 
114  system("killall amxrt");
115 
116  amxb_be_remove_all();
117  unlink("test_config.odl");
118 
119  return 0;
120 }
Here is the caller graph for this function:

◆ test_ubus_has()

void test_ubus_has ( UNUSED void **  state)

Definition at line 122 of file test_amxb_ubus_has.c.

122  {
123  assert_ptr_equal(amxb_be_who_has("NeMo.Intf."), bus_ctx);
124  assert_null(amxb_be_who_has("Device.Wifi."));
125  assert_null(amxb_be_who_has(NULL));
126  assert_null(amxb_be_who_has(""));
127 }
Here is the caller graph for this function:

Variable Documentation

◆ bus_ctx

amxb_bus_ctx_t* bus_ctx = NULL
static

Definition at line 76 of file test_amxb_ubus_has.c.