blob: f23123810138cb1e5bd67a64762e946df018ac7d [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;
375 char *buf;
376 (void)arg;
377
378 /* wait for the RPC callback to be called */
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100379 pthread_mutex_lock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200380 while (glob_state != 1) {
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100381 pthread_mutex_unlock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200382 usleep(1000);
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100383 pthread_mutex_lock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200384 }
385
386 /* create notif */
Michal Vasko77367452021-02-16 16:32:18 +0100387 lyd_new_path(NULL, ctx, "/nc-notifications:notificationComplete", NULL, 0, &notif_tree);
Michal Vasko131120a2018-05-29 15:44:02 +0200388 assert_non_null(notif_tree);
389 buf = malloc(64);
390 assert_non_null(buf);
391 notif = nc_server_notif_new(notif_tree, nc_time2datetime(time(NULL), NULL, buf), NC_PARAMTYPE_FREE);
392 assert_non_null(notif);
393
394 /* send notif */
395 nc_session_set_notif_status(server_session, 1);
396 msg_type = nc_server_notif_send(server_session, notif, 100);
397 nc_server_notif_free(notif);
398 assert_int_equal(msg_type, NC_MSG_NOTIF);
399
400 /* update state */
401 glob_state = 2;
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100402 pthread_mutex_unlock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200403
404 return NULL;
405}
406
Michal Vasko294d4c62016-02-01 10:10:27 +0100407static void
Michal Vasko58d152f2016-02-01 11:44:49 +0100408test_send_recv_notif(void)
Michal Vasko294d4c62016-02-01 10:10:27 +0100409{
Michal Vasko131120a2018-05-29 15:44:02 +0200410 int ret;
411 pthread_t tid;
412 uint64_t msgid;
413 NC_MSG_TYPE msgtype;
414 struct nc_rpc *rpc;
Michal Vasko77367452021-02-16 16:32:18 +0100415 struct lyd_node *envp, *op;
Michal Vasko131120a2018-05-29 15:44:02 +0200416 struct nc_pollsession *ps;
Michal Vasko294d4c62016-02-01 10:10:27 +0100417
Michal Vasko131120a2018-05-29 15:44:02 +0200418 /* client RPC */
419 rpc = nc_rpc_commit(0, 0, NULL, NULL, 0);
420 assert_non_null(rpc);
421
422 msgtype = nc_send_rpc(client_session, rpc, 0, &msgid);
423 assert_int_equal(msgtype, NC_MSG_RPC);
424
425 /* client subscription */
426 ret = nc_recv_notif_dispatch(client_session, test_notif_clb);
427 assert_int_equal(ret, 0);
428
429 /* create server */
430 ps = nc_ps_new();
431 assert_non_null(ps);
432 nc_ps_add_session(ps, server_session);
433
434 /* server will send a notification */
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100435 pthread_mutex_lock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200436 glob_state = 0;
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100437 pthread_mutex_unlock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200438 ret = pthread_create(&tid, NULL, server_send_notif_thread, NULL);
439 assert_int_equal(ret, 0);
440
441 /* server blocked on RPC */
442 ret = nc_ps_poll(ps, 0, NULL);
443 assert_int_equal(ret, NC_PSPOLL_RPC);
444
445 /* RPC, notification finished fine */
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100446 pthread_mutex_lock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200447 assert_int_equal(glob_state, 3);
Michal Vaskobbaa9b22019-03-14 12:35:43 +0100448 pthread_mutex_unlock(&state_lock);
Michal Vasko131120a2018-05-29 15:44:02 +0200449
450 /* server finished */
451 ret = pthread_join(tid, NULL);
452 assert_int_equal(ret, 0);
453 nc_ps_free(ps);
454
455 /* client reply */
Michal Vasko77367452021-02-16 16:32:18 +0100456 msgtype = nc_recv_reply(client_session, rpc, msgid, 0, &envp, &op);
Michal Vasko131120a2018-05-29 15:44:02 +0200457 assert_int_equal(msgtype, NC_MSG_REPLY);
Michal Vasko131120a2018-05-29 15:44:02 +0200458 nc_rpc_free(rpc);
Michal Vasko77367452021-02-16 16:32:18 +0100459
460 assert_string_equal(LYD_NAME(lyd_child(envp)), "ok");
461 lyd_free_tree(envp);
462 assert_null(op);
Michal Vasko131120a2018-05-29 15:44:02 +0200463}
464
465static void
466test_send_recv_notif_10(void **state)
467{
468 (void)state;
469
470 server_session->version = NC_VERSION_10;
471 client_session->version = NC_VERSION_10;
472
473 test_send_recv_notif();
474}
475
476static void
477test_send_recv_notif_11(void **state)
478{
479 (void)state;
480
481 server_session->version = NC_VERSION_11;
482 client_session->version = NC_VERSION_11;
483
484 test_send_recv_notif();
485}
Michal Vasko294d4c62016-02-01 10:10:27 +0100486
487int
488main(void)
489{
Michal Vasko8c5518b2016-03-01 12:35:13 +0100490 int ret;
491 const struct lys_module *module;
Michal Vasko77367452021-02-16 16:32:18 +0100492 struct lysc_node *node;
493 const char *nc_features[] = {"candidate", NULL};
Michal Vasko8c5518b2016-03-01 12:35:13 +0100494
495 /* create ctx */
Michal Vasko77367452021-02-16 16:32:18 +0100496 ly_ctx_new(TESTS_DIR"/data/modules", 0, &ctx);
Michal Vasko8c5518b2016-03-01 12:35:13 +0100497 assert_non_null(ctx);
498
499 /* load modules */
Michal Vasko77367452021-02-16 16:32:18 +0100500 module = ly_ctx_load_module(ctx, "ietf-netconf-acm", NULL, NULL);
Michal Vasko8c5518b2016-03-01 12:35:13 +0100501 assert_non_null(module);
502
Michal Vasko77367452021-02-16 16:32:18 +0100503 module = ly_ctx_load_module(ctx, "ietf-netconf", NULL, nc_features);
Michal Vasko8c5518b2016-03-01 12:35:13 +0100504 assert_non_null(module);
Michal Vasko131120a2018-05-29 15:44:02 +0200505
Michal Vasko77367452021-02-16 16:32:18 +0100506 module = ly_ctx_load_module(ctx, "nc-notifications", NULL, NULL);
Michal Vasko131120a2018-05-29 15:44:02 +0200507 assert_non_null(module);
Michal Vasko8c5518b2016-03-01 12:35:13 +0100508
509 /* set RPC callbacks */
Michal Vasko77367452021-02-16 16:32:18 +0100510 node = (struct lysc_node *)lys_find_path(module->ctx, NULL, "/ietf-netconf:get", 0);
Michal Vasko88639e92017-08-03 14:38:10 +0200511 assert_non_null(node);
Michal Vasko77367452021-02-16 16:32:18 +0100512 node->priv = my_get_rpc_clb;
Michal Vasko88639e92017-08-03 14:38:10 +0200513
Michal Vasko77367452021-02-16 16:32:18 +0100514 node = (struct lysc_node *)lys_find_path(module->ctx, NULL, "/ietf-netconf:get-config", 0);
Michal Vasko88639e92017-08-03 14:38:10 +0200515 assert_non_null(node);
Michal Vasko77367452021-02-16 16:32:18 +0100516 node->priv = my_getconfig_rpc_clb;
Michal Vasko8c5518b2016-03-01 12:35:13 +0100517
Michal Vasko77367452021-02-16 16:32:18 +0100518 node = (struct lysc_node *)lys_find_path(module->ctx, NULL, "/ietf-netconf:commit", 0);
Michal Vasko131120a2018-05-29 15:44:02 +0200519 assert_non_null(node);
Michal Vasko77367452021-02-16 16:32:18 +0100520 node->priv = my_commit_rpc_clb;
Michal Vasko131120a2018-05-29 15:44:02 +0200521
Michal Vasko8c5518b2016-03-01 12:35:13 +0100522 nc_server_init(ctx);
523
Michal Vasko294d4c62016-02-01 10:10:27 +0100524 const struct CMUnitTest comm[] = {
Michal Vasko58d152f2016-02-01 11:44:49 +0100525 cmocka_unit_test_setup_teardown(test_send_recv_ok_10, setup_sessions, teardown_sessions),
526 cmocka_unit_test_setup_teardown(test_send_recv_error_10, setup_sessions, teardown_sessions),
527 cmocka_unit_test_setup_teardown(test_send_recv_data_10, setup_sessions, teardown_sessions),
Michal Vasko131120a2018-05-29 15:44:02 +0200528 cmocka_unit_test_setup_teardown(test_send_recv_notif_10, setup_sessions, teardown_sessions),
Michal Vasko58d152f2016-02-01 11:44:49 +0100529 cmocka_unit_test_setup_teardown(test_send_recv_ok_11, setup_sessions, teardown_sessions),
530 cmocka_unit_test_setup_teardown(test_send_recv_error_11, setup_sessions, teardown_sessions),
Michal Vasko131120a2018-05-29 15:44:02 +0200531 cmocka_unit_test_setup_teardown(test_send_recv_data_11, setup_sessions, teardown_sessions),
532 cmocka_unit_test_setup_teardown(test_send_recv_notif_11, setup_sessions, teardown_sessions),
Michal Vasko294d4c62016-02-01 10:10:27 +0100533 };
534
Michal Vasko8c5518b2016-03-01 12:35:13 +0100535 ret = cmocka_run_group_tests(comm, NULL, NULL);
536
537 nc_server_destroy();
538 ly_ctx_destroy(ctx, NULL);
539
540 return ret;
Michal Vasko294d4c62016-02-01 10:10:27 +0100541}