Amxb_Ubus  3.3.1
Ambiorix Ubus API
test_amxb_ubus_connect.c File Reference
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <setjmp.h>
#include <cmocka.h>
#include <sys/stat.h>
#include <amxc/amxc_variant.h>
#include <amxc/amxc_htable.h>
#include <amxc/amxc_lqueue.h>
#include <amxp/amxp_signal.h>
#include <amxp/amxp_slot.h>
#include <amxd/amxd_dm.h>
#include <amxb/amxb_error.h>
#include <amxb/amxb.h>
#include "amxb_ubus.h"
#include "test_amxb_ubus_connect.h"
#include <amxc/amxc_macros.h>

Go to the source code of this file.

Functions

static const char * test_amxb_ubus_get_socket (void)
 
void test_amxb_ubus_connect_disconnect (UNUSED void **state)
 
void test_amxb_ubus_get_fd (UNUSED void **state)
 
void test_amxb_info (UNUSED void **state)
 

Variables

static amxp_signal_mngr_t * sigmngr = NULL
 

Function Documentation

◆ test_amxb_info()

void test_amxb_info ( UNUSED void **  state)

Definition at line 153 of file test_amxb_ubus_connect.c.

153  {
154  amxb_be_info_t* info = NULL;
155 
156  info = amxb_be_info();
157 
158  assert_ptr_not_equal(info, NULL);
159  assert_ptr_not_equal(info->min_supported, NULL);
160  assert_ptr_not_equal(info->max_supported, NULL);
161  assert_ptr_not_equal(info->be_version, NULL);
162  assert_ptr_not_equal(info->name, NULL);
163 }
amxb_be_info_t * amxb_be_info(void)
Definition: amxb_ubus.c:442
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_amxb_ubus_connect_disconnect()

void test_amxb_ubus_connect_disconnect ( UNUSED void **  state)

Definition at line 94 of file test_amxb_ubus_connect.c.

94  {
95  void* bus_ctx1 = NULL;
96  void* bus_ctx2 = NULL;
97  const char* ubus_sock = test_amxb_ubus_get_socket();
98  printf("Ubus socket = %s\n", ubus_sock);
99 
100  amxp_sigmngr_new(&sigmngr);
101 
102  bus_ctx1 = amxb_ubus_connect(NULL, NULL, NULL, sigmngr);
103  assert_ptr_not_equal(bus_ctx1, NULL);
104  assert_int_equal(amxb_ubus_disconnect(bus_ctx1), 0);
105  amxb_ubus_free(bus_ctx1);
106 
107  bus_ctx1 = amxb_ubus_connect("", NULL, NULL, sigmngr);
108  assert_ptr_equal(bus_ctx1, NULL);
109 
110  bus_ctx1 = amxb_ubus_connect("", "", NULL, sigmngr);
111  assert_ptr_equal(bus_ctx1, NULL);
112 
113  bus_ctx1 = amxb_ubus_connect("localhost", NULL, NULL, sigmngr);
114  assert_ptr_equal(bus_ctx1, NULL);
115 
116  bus_ctx1 = amxb_ubus_connect("localhost", "", NULL, sigmngr);
117  assert_ptr_equal(bus_ctx1, NULL);
118 
119  bus_ctx1 = amxb_ubus_connect("localhost", "1970", NULL, sigmngr);
120  assert_ptr_equal(bus_ctx1, NULL);
121 
122  bus_ctx1 = amxb_ubus_connect(NULL, NULL, ubus_sock, sigmngr);
123  assert_ptr_not_equal(bus_ctx1, NULL);
124 
125  bus_ctx2 = amxb_ubus_connect("localhost", NULL, NULL, sigmngr);
126  assert_ptr_equal(bus_ctx2, NULL);
127 
128  bus_ctx2 = amxb_ubus_connect(NULL, NULL, ubus_sock, sigmngr);
129  assert_ptr_not_equal(bus_ctx2, NULL);
130 
131  assert_ptr_not_equal(bus_ctx1, bus_ctx2);
132 
133  assert_int_equal(amxb_ubus_disconnect(bus_ctx1), 0);
134  assert_int_equal(amxb_ubus_disconnect(bus_ctx2), 0);
135  amxb_ubus_free(bus_ctx1);
136  amxb_ubus_free(bus_ctx2);
137  amxp_sigmngr_delete(&sigmngr);
138 }
int PRIVATE amxb_ubus_disconnect(void *ctx)
Definition: amxb_ubus.c:262
void PRIVATE amxb_ubus_free(void *ctx)
Definition: amxb_ubus.c:316
void *PRIVATE amxb_ubus_connect(const char *host, const char *port, const char *path, amxp_signal_mngr_t *sigmngr)
Definition: amxb_ubus.c:222
static amxp_signal_mngr_t * sigmngr
static const char * test_amxb_ubus_get_socket(void)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_amxb_ubus_get_fd()

void test_amxb_ubus_get_fd ( UNUSED void **  state)

Definition at line 140 of file test_amxb_ubus_connect.c.

140  {
141  void* bus_ctx = NULL;
142  amxp_sigmngr_new(&sigmngr);
143  const char* ubus_sock = test_amxb_ubus_get_socket();
144 
145  bus_ctx = amxb_ubus_connect(NULL, NULL, ubus_sock, sigmngr);
146  assert_true(amxb_ubus_get_fd(bus_ctx) > -1);
147  assert_int_equal(amxb_ubus_disconnect(bus_ctx), 0);
149 
150  amxp_sigmngr_delete(&sigmngr);
151 }
int PRIVATE amxb_ubus_get_fd(void *ctx)
Definition: amxb_ubus.c:282
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_get_socket()

static const char* test_amxb_ubus_get_socket ( void  )
static

Definition at line 83 of file test_amxb_ubus_connect.c.

83  {
84  struct stat sb;
85  if(stat("/var/run/ubus.sock", &sb) == 0) {
86  return "/var/run/ubus.sock";
87  }
88  if(stat("/var/run/ubus/ubus.sock", &sb) == 0) {
89  return "/var/run/ubus/ubus.sock";
90  }
91  return NULL;
92 }
Here is the caller graph for this function:

Variable Documentation

◆ sigmngr

amxp_signal_mngr_t* sigmngr = NULL
static

Definition at line 81 of file test_amxb_ubus_connect.c.