blob: 66ab168a0bfd228c083b763b2ceccaa8cd27b2bf [file] [log] [blame]
Michal Vasko294d4c62016-02-01 10:10:27 +01001/**
Michal Vasko7227f352016-02-01 12:11:40 +01002 * \file test_fd_comm.c
Michal Vasko294d4c62016-02-01 10:10:27 +01003 * \author Michal Vasko <mvasko@cesnet.cz>
Michal Vasko7227f352016-02-01 12:11:40 +01004 * \brief libnetconf2 tests - file descriptor basic RPC communication
Michal Vasko294d4c62016-02-01 10:10:27 +01005 *
6 * Copyright (c) 2015 CESNET, z.s.p.o.
7 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +01008 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
Michal Vaskoad1cc6a2016-02-26 15:06:06 +010011 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +010012 * https://opensource.org/licenses/BSD-3-Clause
Michal Vasko294d4c62016-02-01 10:10:27 +010013 */
14
15#include <errno.h>
16#include <fcntl.h>
17#include <pthread.h>
18#include <setjmp.h>
19#include <stdarg.h>
20#include <stddef.h>
21#include <stdint.h>
22#include <stdlib.h>
23#include <unistd.h>
24#include <string.h>
25#include <sys/stat.h>
26#include <sys/types.h>
27#include <sys/socket.h>
28
29#include <cmocka.h>
30#include <libyang/libyang.h>
31
32#include <session_client.h>
33#include <session_server.h>
34#include <session_p.h>
35#include <messages_p.h>
Jan Kundrátcf15d6c2017-10-26 18:07:56 +020036#include "tests/config.h"
Michal Vasko294d4c62016-02-01 10:10:27 +010037
38struct nc_session *server_session;
39struct nc_session *client_session;
Michal Vasko8c5518b2016-03-01 12:35:13 +010040struct ly_ctx *ctx;
Michal Vaskobbaa9b22019-03-14 12:35:43 +010041pthread_mutex_t state_lock = PTHREAD_MUTEX_INITIALIZER;
42int glob_state;
Michal Vasko294d4c62016-02-01 10:10:27 +010043
44struct nc_server_reply *
45my_get_rpc_clb(struct lyd_node *rpc, struct nc_session *session)
46{
47 assert_string_equal(rpc->schema->name, "get");
48 assert_ptr_equal(session, server_session);
49
50 return nc_server_reply_ok();
51}
52
53struct nc_server_reply *
54my_getconfig_rpc_clb(struct lyd_node *rpc, struct nc_session *session)
55{
56 struct lyd_node *data;
Michal Vasko294d4c62016-02-01 10:10:27 +010057
58 assert_string_equal(rpc->schema->name, "get-config");
59 assert_ptr_equal(session, server_session);
60
Michal Vasko77367452021-02-16 16:32:18 +010061 lyd_new_path(NULL, session->ctx, "/ietf-netconf:get-config/data", NULL, LYD_NEW_PATH_OUTPUT, &data);
Michal Vasko294d4c62016-02-01 10:10:27 +010062 assert_non_null(data);
63
Radek Krejci36dfdb32016-09-01 16:56:35 +020064 return nc_server_reply_data(data, NC_WD_EXPLICIT, NC_PARAMTYPE_FREE);
Michal Vasko294d4c62016-02-01 10:10:27 +010065}
66
Michal Vasko131120a2018-05-29 15:44:02 +020067struct nc_server_reply *
68my_commit_rpc_clb(struct lyd_node *rpc, struct nc_session *session)
69{
70 assert_string_equal(rpc->schema->name, "commit");
71 assert_ptr_equal(session, server_session);
72
73 /* update state */
Michal Vaskobbaa9b22019-03-14 12:35:43 +010074 pthread_mutex_lock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +020075 glob_state = 1;
76
77 /* wait until the client receives the notification */
78 while (glob_state != 3) {
Michal Vaskobbaa9b22019-03-14 12:35:43 +010079 pthread_mutex_unlock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +020080 usleep(100000);
Michal Vaskobbaa9b22019-03-14 12:35:43 +010081 pthread_mutex_lock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +020082 }
Michal Vaskobbaa9b22019-03-14 12:35:43 +010083 pthread_mutex_unlock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +020084
85 return nc_server_reply_ok();
86}
87
88static struct nc_session *
89test_new_session(NC_SIDE side)
90{
91 struct nc_session *sess;
92
93 sess = calloc(1, sizeof *sess);
94 if (!sess) {
95 return NULL;
96 }
97
98 sess->side = side;
99
100 if (side == NC_SERVER) {
Michal Vaskoacf98472021-02-04 15:33:57 +0100101 pthread_mutex_init(&sess->opts.server.rpc_lock, NULL);
102 pthread_cond_init(&sess->opts.server.rpc_cond, NULL);
103 sess->opts.server.rpc_inuse = 0;
Michal Vasko131120a2018-05-29 15:44:02 +0200104 }
105
106 sess->io_lock = malloc(sizeof *sess->io_lock);
107 if (!sess->io_lock) {
108 goto error;
109 }
110 pthread_mutex_init(sess->io_lock, NULL);
111
112 return sess;
113
114error:
Michal Vasko131120a2018-05-29 15:44:02 +0200115 free(sess);
116 return NULL;
117}
118
Michal Vasko294d4c62016-02-01 10:10:27 +0100119static int
120setup_sessions(void **state)
121{
122 (void)state;
Michal Vasko294d4c62016-02-01 10:10:27 +0100123 int sock[2];
124
Michal Vasko294d4c62016-02-01 10:10:27 +0100125 /* create communication channel */
126 socketpair(AF_UNIX, SOCK_STREAM, 0, sock);
127
Michal Vasko294d4c62016-02-01 10:10:27 +0100128 /* create server session */
Michal Vasko131120a2018-05-29 15:44:02 +0200129 server_session = test_new_session(NC_SERVER);
Michal Vasko294d4c62016-02-01 10:10:27 +0100130 server_session->status = NC_STATUS_RUNNING;
Michal Vasko294d4c62016-02-01 10:10:27 +0100131 server_session->id = 1;
Michal Vasko294d4c62016-02-01 10:10:27 +0100132 server_session->ti_type = NC_TI_FD;
Michal Vasko294d4c62016-02-01 10:10:27 +0100133 server_session->ti.fd.in = sock[0];
134 server_session->ti.fd.out = sock[0];
135 server_session->ctx = ctx;
136 server_session->flags = NC_SESSION_SHAREDCTX;
137
138 /* create client session */
Michal Vasko131120a2018-05-29 15:44:02 +0200139 client_session = test_new_session(NC_CLIENT);
Michal Vasko294d4c62016-02-01 10:10:27 +0100140 client_session->status = NC_STATUS_RUNNING;
Michal Vasko294d4c62016-02-01 10:10:27 +0100141 client_session->id = 1;
Michal Vasko294d4c62016-02-01 10:10:27 +0100142 client_session->ti_type = NC_TI_FD;
Michal Vasko294d4c62016-02-01 10:10:27 +0100143 client_session->ti.fd.in = sock[1];
144 client_session->ti.fd.out = sock[1];
145 client_session->ctx = ctx;
146 client_session->flags = NC_SESSION_SHAREDCTX;
Michal Vasko338f8472016-10-13 15:01:27 +0200147 client_session->opts.client.msgid = 50;
Michal Vasko294d4c62016-02-01 10:10:27 +0100148
149 return 0;
150}
151
152static int
153teardown_sessions(void **state)
154{
155 (void)state;
156
Michal Vasko294d4c62016-02-01 10:10:27 +0100157 close(server_session->ti.fd.in);
Michal Vasko77367452021-02-16 16:32:18 +0100158 server_session->ti.fd.in = -1;
Michal Vasko131120a2018-05-29 15:44:02 +0200159 nc_session_free(server_session, NULL);
Michal Vasko294d4c62016-02-01 10:10:27 +0100160
161 close(client_session->ti.fd.in);
Michal Vasko77367452021-02-16 16:32:18 +0100162 client_session->ti.fd.in = -1;
Michal Vasko131120a2018-05-29 15:44:02 +0200163 nc_session_free(client_session, NULL);
Michal Vasko294d4c62016-02-01 10:10:27 +0100164
165 return 0;
166}
167
168static void
Michal Vasko58d152f2016-02-01 11:44:49 +0100169test_send_recv_ok(void)
Michal Vasko294d4c62016-02-01 10:10:27 +0100170{
Michal Vasko294d4c62016-02-01 10:10:27 +0100171 int ret;
172 uint64_t msgid;
173 NC_MSG_TYPE msgtype;
174 struct nc_rpc *rpc;
Michal Vasko77367452021-02-16 16:32:18 +0100175 struct lyd_node *envp, *op;
Michal Vasko294d4c62016-02-01 10:10:27 +0100176 struct nc_pollsession *ps;
177
178 /* client RPC */
179 rpc = nc_rpc_get(NULL, 0, 0);
180 assert_non_null(rpc);
181
182 msgtype = nc_send_rpc(client_session, rpc, 0, &msgid);
183 assert_int_equal(msgtype, NC_MSG_RPC);
184
185 /* server RPC, send reply */
186 ps = nc_ps_new();
187 assert_non_null(ps);
188 nc_ps_add_session(ps, server_session);
189
Michal Vasko71090fc2016-05-24 16:37:28 +0200190 ret = nc_ps_poll(ps, 0, NULL);
191 assert_int_equal(ret, NC_PSPOLL_RPC);
Michal Vasko294d4c62016-02-01 10:10:27 +0100192
193 /* server finished */
194 nc_ps_free(ps);
195
196 /* client reply */
Michal Vasko77367452021-02-16 16:32:18 +0100197 msgtype = nc_recv_reply(client_session, rpc, msgid, 0, &envp, &op);
Michal Vasko294d4c62016-02-01 10:10:27 +0100198 assert_int_equal(msgtype, NC_MSG_REPLY);
199
200 nc_rpc_free(rpc);
Michal Vasko77367452021-02-16 16:32:18 +0100201 assert_null(op);
202 assert_string_equal(LYD_NAME(lyd_child(envp)), "ok");
203 lyd_free_tree(envp);
Michal Vasko294d4c62016-02-01 10:10:27 +0100204}
205
206static void
Michal Vasko58d152f2016-02-01 11:44:49 +0100207test_send_recv_ok_10(void **state)
Michal Vasko294d4c62016-02-01 10:10:27 +0100208{
209 (void)state;
Michal Vasko58d152f2016-02-01 11:44:49 +0100210
211 server_session->version = NC_VERSION_10;
212 client_session->version = NC_VERSION_10;
213
214 test_send_recv_ok();
215}
216
217static void
218test_send_recv_ok_11(void **state)
219{
220 (void)state;
221
222 server_session->version = NC_VERSION_11;
223 client_session->version = NC_VERSION_11;
224
225 test_send_recv_ok();
226}
227
228static void
229test_send_recv_error(void)
230{
Michal Vasko294d4c62016-02-01 10:10:27 +0100231 int ret;
232 uint64_t msgid;
233 NC_MSG_TYPE msgtype;
234 struct nc_rpc *rpc;
Michal Vasko77367452021-02-16 16:32:18 +0100235 struct lyd_node *envp, *op, *node;
Michal Vasko294d4c62016-02-01 10:10:27 +0100236 struct nc_pollsession *ps;
237
238 /* client RPC */
239 rpc = nc_rpc_kill(1);
240 assert_non_null(rpc);
241
242 msgtype = nc_send_rpc(client_session, rpc, 0, &msgid);
243 assert_int_equal(msgtype, NC_MSG_RPC);
244
245 /* server RPC, send reply */
246 ps = nc_ps_new();
247 assert_non_null(ps);
248 nc_ps_add_session(ps, server_session);
249
Michal Vasko71090fc2016-05-24 16:37:28 +0200250 ret = nc_ps_poll(ps, 0, NULL);
251 assert_int_equal(ret, NC_PSPOLL_RPC | NC_PSPOLL_REPLY_ERROR);
Michal Vasko294d4c62016-02-01 10:10:27 +0100252
253 /* server finished */
254 nc_ps_free(ps);
255
256 /* client reply */
Michal Vasko77367452021-02-16 16:32:18 +0100257 msgtype = nc_recv_reply(client_session, rpc, msgid, 0, &envp, &op);
Michal Vasko294d4c62016-02-01 10:10:27 +0100258 assert_int_equal(msgtype, NC_MSG_REPLY);
259
260 nc_rpc_free(rpc);
Michal Vasko77367452021-02-16 16:32:18 +0100261 assert_string_equal(LYD_NAME(lyd_child(envp)), "rpc-error");
262 lyd_find_sibling_opaq_next(lyd_child(lyd_child(envp)), "error-tag", &node);
263 assert_non_null(node);
264 assert_string_equal(((struct lyd_node_opaq *)node)->value, "operation-not-supported");
265 lyd_free_tree(envp);
266 assert_null(op);
Michal Vasko294d4c62016-02-01 10:10:27 +0100267}
268
269static void
Michal Vasko58d152f2016-02-01 11:44:49 +0100270test_send_recv_error_10(void **state)
Michal Vasko294d4c62016-02-01 10:10:27 +0100271{
272 (void)state;
Michal Vasko58d152f2016-02-01 11:44:49 +0100273
274 server_session->version = NC_VERSION_10;
275 client_session->version = NC_VERSION_10;
276
277 test_send_recv_error();
278}
279
280static void
281test_send_recv_error_11(void **state)
282{
283 (void)state;
284
285 server_session->version = NC_VERSION_11;
286 client_session->version = NC_VERSION_11;
287
288 test_send_recv_error();
289}
290
291static void
292test_send_recv_data(void)
293{
Michal Vasko294d4c62016-02-01 10:10:27 +0100294 int ret;
295 uint64_t msgid;
296 NC_MSG_TYPE msgtype;
297 struct nc_rpc *rpc;
Michal Vasko77367452021-02-16 16:32:18 +0100298 struct lyd_node *envp, *op;
Michal Vasko294d4c62016-02-01 10:10:27 +0100299 struct nc_pollsession *ps;
300
301 /* client RPC */
302 rpc = nc_rpc_getconfig(NC_DATASTORE_RUNNING, NULL, 0, 0);
303 assert_non_null(rpc);
304
305 msgtype = nc_send_rpc(client_session, rpc, 0, &msgid);
306 assert_int_equal(msgtype, NC_MSG_RPC);
307
308 /* server RPC, send reply */
309 ps = nc_ps_new();
310 assert_non_null(ps);
311 nc_ps_add_session(ps, server_session);
312
Michal Vasko71090fc2016-05-24 16:37:28 +0200313 ret = nc_ps_poll(ps, 0, NULL);
314 assert_int_equal(ret, NC_PSPOLL_RPC);
Michal Vasko294d4c62016-02-01 10:10:27 +0100315
316 /* server finished */
317 nc_ps_free(ps);
318
319 /* client reply */
Michal Vasko77367452021-02-16 16:32:18 +0100320 msgtype = nc_recv_reply(client_session, rpc, msgid, 0, &envp, &op);
Michal Vasko294d4c62016-02-01 10:10:27 +0100321 assert_int_equal(msgtype, NC_MSG_REPLY);
322
323 nc_rpc_free(rpc);
Michal Vasko77367452021-02-16 16:32:18 +0100324 assert_non_null(envp);
325 lyd_free_tree(envp);
326 assert_non_null(op);
327 lyd_free_tree(op);
Michal Vasko294d4c62016-02-01 10:10:27 +0100328}
329
Michal Vasko58d152f2016-02-01 11:44:49 +0100330static void
331test_send_recv_data_10(void **state)
332{
333 (void)state;
334
335 server_session->version = NC_VERSION_10;
336 client_session->version = NC_VERSION_10;
337
338 test_send_recv_data();
339}
340
341static void
342test_send_recv_data_11(void **state)
343{
344 (void)state;
345
346 server_session->version = NC_VERSION_11;
347 client_session->version = NC_VERSION_11;
348
349 test_send_recv_data();
350}
351
Michal Vasko131120a2018-05-29 15:44:02 +0200352static void
Michal Vasko77367452021-02-16 16:32:18 +0100353test_notif_clb(struct nc_session *session, const struct lyd_node *UNUSED(envp), const struct lyd_node *op)
Michal Vasko131120a2018-05-29 15:44:02 +0200354{
355 assert_ptr_equal(session, client_session);
Michal Vasko77367452021-02-16 16:32:18 +0100356 assert_string_equal(op->schema->name, "notificationComplete");
Michal Vasko131120a2018-05-29 15:44:02 +0200357
358 /* client notification received, update state */
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100359 pthread_mutex_lock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200360 while (glob_state != 2) {
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100361 pthread_mutex_unlock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200362 usleep(1000);
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100363 pthread_mutex_lock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200364 }
365 glob_state = 3;
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100366 pthread_mutex_unlock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200367}
368
369static void *
370server_send_notif_thread(void *arg)
371{
372 NC_MSG_TYPE msg_type;
373 struct lyd_node *notif_tree;
374 struct nc_server_notif *notif;
Michal Vasko49eb3f42021-05-19 10:20:57 +0200375 struct timespec ts;
Michal Vasko131120a2018-05-29 15:44:02 +0200376 char *buf;
377 (void)arg;
378
379 /* wait for the RPC callback to be called */
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100380 pthread_mutex_lock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200381 while (glob_state != 1) {
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100382 pthread_mutex_unlock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200383 usleep(1000);
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100384 pthread_mutex_lock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200385 }
386
387 /* create notif */
Michal Vasko77367452021-02-16 16:32:18 +0100388 lyd_new_path(NULL, ctx, "/nc-notifications:notificationComplete", NULL, 0, &notif_tree);
Michal Vasko131120a2018-05-29 15:44:02 +0200389 assert_non_null(notif_tree);
Michal Vasko49eb3f42021-05-19 10:20:57 +0200390 clock_gettime(CLOCK_REALTIME, &ts);
Michal Vaskod7fb6df2021-05-19 11:27:35 +0200391 ly_time_ts2str(&ts, &buf);
392 notif = nc_server_notif_new(notif_tree, buf, NC_PARAMTYPE_FREE);
Michal Vasko131120a2018-05-29 15:44:02 +0200393 assert_non_null(notif);
394
395 /* send notif */
Michal Vasko71dbd772021-03-23 14:08:37 +0100396 nc_session_inc_notif_status(server_session);
Michal Vasko131120a2018-05-29 15:44:02 +0200397 msg_type = nc_server_notif_send(server_session, notif, 100);
398 nc_server_notif_free(notif);
399 assert_int_equal(msg_type, NC_MSG_NOTIF);
400
401 /* update state */
402 glob_state = 2;
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100403 pthread_mutex_unlock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200404
405 return NULL;
406}
407
Michal Vasko294d4c62016-02-01 10:10:27 +0100408static void
Michal Vasko58d152f2016-02-01 11:44:49 +0100409test_send_recv_notif(void)
Michal Vasko294d4c62016-02-01 10:10:27 +0100410{
Michal Vasko131120a2018-05-29 15:44:02 +0200411 int ret;
412 pthread_t tid;
413 uint64_t msgid;
414 NC_MSG_TYPE msgtype;
415 struct nc_rpc *rpc;
Michal Vasko77367452021-02-16 16:32:18 +0100416 struct lyd_node *envp, *op;
Michal Vasko131120a2018-05-29 15:44:02 +0200417 struct nc_pollsession *ps;
Michal Vasko294d4c62016-02-01 10:10:27 +0100418
Michal Vasko131120a2018-05-29 15:44:02 +0200419 /* client RPC */
420 rpc = nc_rpc_commit(0, 0, NULL, NULL, 0);
421 assert_non_null(rpc);
422
423 msgtype = nc_send_rpc(client_session, rpc, 0, &msgid);
424 assert_int_equal(msgtype, NC_MSG_RPC);
425
426 /* client subscription */
427 ret = nc_recv_notif_dispatch(client_session, test_notif_clb);
428 assert_int_equal(ret, 0);
429
430 /* create server */
431 ps = nc_ps_new();
432 assert_non_null(ps);
433 nc_ps_add_session(ps, server_session);
434
435 /* server will send a notification */
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100436 pthread_mutex_lock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200437 glob_state = 0;
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100438 pthread_mutex_unlock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200439 ret = pthread_create(&tid, NULL, server_send_notif_thread, NULL);
440 assert_int_equal(ret, 0);
441
442 /* server blocked on RPC */
443 ret = nc_ps_poll(ps, 0, NULL);
444 assert_int_equal(ret, NC_PSPOLL_RPC);
445
446 /* RPC, notification finished fine */
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100447 pthread_mutex_lock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200448 assert_int_equal(glob_state, 3);
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100449 pthread_mutex_unlock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200450
451 /* server finished */
452 ret = pthread_join(tid, NULL);
453 assert_int_equal(ret, 0);
454 nc_ps_free(ps);
455
456 /* client reply */
Michal Vasko77367452021-02-16 16:32:18 +0100457 msgtype = nc_recv_reply(client_session, rpc, msgid, 0, &envp, &op);
Michal Vasko131120a2018-05-29 15:44:02 +0200458 assert_int_equal(msgtype, NC_MSG_REPLY);
Michal Vasko131120a2018-05-29 15:44:02 +0200459 nc_rpc_free(rpc);
Michal Vasko77367452021-02-16 16:32:18 +0100460
461 assert_string_equal(LYD_NAME(lyd_child(envp)), "ok");
462 lyd_free_tree(envp);
463 assert_null(op);
Michal Vasko131120a2018-05-29 15:44:02 +0200464}
465
466static void
467test_send_recv_notif_10(void **state)
468{
469 (void)state;
470
471 server_session->version = NC_VERSION_10;
472 client_session->version = NC_VERSION_10;
473
474 test_send_recv_notif();
475}
476
477static void
478test_send_recv_notif_11(void **state)
479{
480 (void)state;
481
482 server_session->version = NC_VERSION_11;
483 client_session->version = NC_VERSION_11;
484
485 test_send_recv_notif();
486}
Michal Vasko294d4c62016-02-01 10:10:27 +0100487
488int
489main(void)
490{
Michal Vasko8c5518b2016-03-01 12:35:13 +0100491 int ret;
492 const struct lys_module *module;
Michal Vasko77367452021-02-16 16:32:18 +0100493 struct lysc_node *node;
494 const char *nc_features[] = {"candidate", NULL};
Michal Vasko8c5518b2016-03-01 12:35:13 +0100495
496 /* create ctx */
Michal Vasko77367452021-02-16 16:32:18 +0100497 ly_ctx_new(TESTS_DIR"/data/modules", 0, &ctx);
Michal Vasko8c5518b2016-03-01 12:35:13 +0100498 assert_non_null(ctx);
499
500 /* load modules */
Michal Vasko77367452021-02-16 16:32:18 +0100501 module = ly_ctx_load_module(ctx, "ietf-netconf-acm", NULL, NULL);
Michal Vasko8c5518b2016-03-01 12:35:13 +0100502 assert_non_null(module);
503
Michal Vasko77367452021-02-16 16:32:18 +0100504 module = ly_ctx_load_module(ctx, "ietf-netconf", NULL, nc_features);
Michal Vasko8c5518b2016-03-01 12:35:13 +0100505 assert_non_null(module);
Michal Vasko131120a2018-05-29 15:44:02 +0200506
Michal Vasko77367452021-02-16 16:32:18 +0100507 module = ly_ctx_load_module(ctx, "nc-notifications", NULL, NULL);
Michal Vasko131120a2018-05-29 15:44:02 +0200508 assert_non_null(module);
Michal Vasko8c5518b2016-03-01 12:35:13 +0100509
510 /* set RPC callbacks */
Michal Vasko77367452021-02-16 16:32:18 +0100511 node = (struct lysc_node *)lys_find_path(module->ctx, NULL, "/ietf-netconf:get", 0);
Michal Vasko88639e92017-08-03 14:38:10 +0200512 assert_non_null(node);
Michal Vasko77367452021-02-16 16:32:18 +0100513 node->priv = my_get_rpc_clb;
Michal Vasko88639e92017-08-03 14:38:10 +0200514
Michal Vasko77367452021-02-16 16:32:18 +0100515 node = (struct lysc_node *)lys_find_path(module->ctx, NULL, "/ietf-netconf:get-config", 0);
Michal Vasko88639e92017-08-03 14:38:10 +0200516 assert_non_null(node);
Michal Vasko77367452021-02-16 16:32:18 +0100517 node->priv = my_getconfig_rpc_clb;
Michal Vasko8c5518b2016-03-01 12:35:13 +0100518
Michal Vasko77367452021-02-16 16:32:18 +0100519 node = (struct lysc_node *)lys_find_path(module->ctx, NULL, "/ietf-netconf:commit", 0);
Michal Vasko131120a2018-05-29 15:44:02 +0200520 assert_non_null(node);
Michal Vasko77367452021-02-16 16:32:18 +0100521 node->priv = my_commit_rpc_clb;
Michal Vasko131120a2018-05-29 15:44:02 +0200522
Michal Vasko8c5518b2016-03-01 12:35:13 +0100523 nc_server_init(ctx);
524
Michal Vasko294d4c62016-02-01 10:10:27 +0100525 const struct CMUnitTest comm[] = {
Michal Vasko58d152f2016-02-01 11:44:49 +0100526 cmocka_unit_test_setup_teardown(test_send_recv_ok_10, setup_sessions, teardown_sessions),
527 cmocka_unit_test_setup_teardown(test_send_recv_error_10, setup_sessions, teardown_sessions),
528 cmocka_unit_test_setup_teardown(test_send_recv_data_10, setup_sessions, teardown_sessions),
Michal Vasko131120a2018-05-29 15:44:02 +0200529 cmocka_unit_test_setup_teardown(test_send_recv_notif_10, setup_sessions, teardown_sessions),
Michal Vasko58d152f2016-02-01 11:44:49 +0100530 cmocka_unit_test_setup_teardown(test_send_recv_ok_11, setup_sessions, teardown_sessions),
531 cmocka_unit_test_setup_teardown(test_send_recv_error_11, setup_sessions, teardown_sessions),
Michal Vasko131120a2018-05-29 15:44:02 +0200532 cmocka_unit_test_setup_teardown(test_send_recv_data_11, setup_sessions, teardown_sessions),
533 cmocka_unit_test_setup_teardown(test_send_recv_notif_11, setup_sessions, teardown_sessions),
Michal Vasko294d4c62016-02-01 10:10:27 +0100534 };
535
Michal Vasko8c5518b2016-03-01 12:35:13 +0100536 ret = cmocka_run_group_tests(comm, NULL, NULL);
537
538 nc_server_destroy();
Michal Vasko1dcb7642021-04-14 15:28:23 +0200539 ly_ctx_destroy(ctx);
Michal Vasko8c5518b2016-03-01 12:35:13 +0100540
541 return ret;
Michal Vasko294d4c62016-02-01 10:10:27 +0100542}