Skip to content

Commit

Permalink
tests UPDATE load only required modules
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed Jun 5, 2024
1 parent ccf4bbc commit 5fb0ee9
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 18 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ set(LIBYANG_DEP_SOVERSION 3.0.0)
set(LIBYANG_DEP_SOVERSION_MAJOR 3)

# libnetconf2 required version
set(LIBNETCONF2_DEP_VERSION 3.1.1)
set(LIBNETCONF2_DEP_SOVERSION 4.2.0)
set(LIBNETCONF2_DEP_VERSION 3.3.0)
set(LIBNETCONF2_DEP_SOVERSION 4.3.0)
set(LIBNETCONF2_DEP_SOVERSION_MAJOR 4)

# sysrepo required version
Expand Down
83 changes: 83 additions & 0 deletions tests/np2_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,78 @@ setup_server_file_exists_wait(const char *path)
return 0;
}

int
np2_glob_test_setup_sess_ctx(struct nc_session *sess, const char **modules)
{
struct ly_ctx *ctx;
const char *all_features[] = {"*", NULL};
const char *sub_ntf_features[] = {"encode-xml", "replay", "subtree", "xpath", NULL};
uint32_t i;

ctx = (struct ly_ctx *)nc_session_get_ctx(sess);

/* base modules */
ly_ctx_set_searchdir(ctx, LN2_YANG_MODULE_DIR);
if (!ly_ctx_load_module(ctx, "ietf-netconf", "2013-09-29", all_features)) {
SETUP_FAIL_LOG;
return 1;
}
if (!ly_ctx_load_module(ctx, "ietf-netconf-with-defaults", "2011-06-01", NULL)) {
SETUP_FAIL_LOG;
return 1;
}
if (!ly_ctx_load_module(ctx, "ietf-yang-library", "2019-01-04", NULL)) {
SETUP_FAIL_LOG;
return 1;
}
if (!ly_ctx_load_module(ctx, "ietf-datastores", "2018-02-14", NULL)) {
SETUP_FAIL_LOG;
return 1;
}
if (!ly_ctx_load_module(ctx, "notifications", "2008-07-14", NULL)) {
SETUP_FAIL_LOG;
return 1;
}
if (!ly_ctx_load_module(ctx, "nc-notifications", "2008-07-14", NULL)) {
SETUP_FAIL_LOG;
return 1;
}
if (!ly_ctx_load_module(ctx, "ietf-netconf-notifications", "2012-02-06", NULL)) {
SETUP_FAIL_LOG;
return 1;
}
if (!ly_ctx_load_module(ctx, "ietf-netconf-nmda", "2019-01-07", all_features)) {
SETUP_FAIL_LOG;
return 1;
}
if (!ly_ctx_load_module(ctx, "ietf-subscribed-notifications", "2019-09-09", sub_ntf_features)) {
SETUP_FAIL_LOG;
return 1;
}
if (!ly_ctx_load_module(ctx, "ietf-yang-push", "2019-09-09", all_features)) {
SETUP_FAIL_LOG;
return 1;
}

/* test modules */
if (modules) {
for (i = 0; modules[i]; ++i) {
if (lys_parse_path(ctx, modules[i], LYS_IN_YANG, NULL)) {
SETUP_FAIL_LOG;
return 1;
}
}
}

/* schema-mount, uses the final context */
if (nc_client_set_new_session_context_schema_mount(sess)) {
SETUP_FAIL_LOG;
return 1;
}

return 0;
}

int
np2_glob_test_setup_server(void **state, const char *test_name, const char **modules)
{
Expand Down Expand Up @@ -317,18 +389,29 @@ np2_glob_test_setup_server(void **state, const char *test_name, const char **mod
}
nc_client_set_schema_searchpath(NP_TEST_MODULE_DIR);

/* disable automatic YANG retrieval */
nc_client_set_new_session_context_autofill(0);

/* create NETCONF sessions */
st->nc_sess = nc_connect_unix(st->socket_path, NULL);
if (!st->nc_sess) {
SETUP_FAIL_LOG;
return 1;
}
if (np2_glob_test_setup_sess_ctx(st->nc_sess, modules)) {
SETUP_FAIL_LOG;
return 1;
}

st->nc_sess2 = nc_connect_unix(st->socket_path, NULL);
if (!st->nc_sess2) {
SETUP_FAIL_LOG;
return 1;
}
if (np2_glob_test_setup_sess_ctx(st->nc_sess2, modules)) {
SETUP_FAIL_LOG;
return 1;
}

return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/np2_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ void np2_glob_test_setup_test_name(char *buf);

int np2_glob_test_setup_env(const char *test_name);

int np2_glob_test_setup_sess_ctx(struct nc_session *sess, const char **modules);

int np2_glob_test_setup_server(void **state, const char *test_name, const char **modules);

int np2_glob_test_teardown_notif(const char *test_name);
Expand Down
7 changes: 5 additions & 2 deletions tests/test_confirmed_commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ notif_check_cc_timeout(struct np2_test *st, uint32_t expected_timeout)
}
}

static const char *test_modules[] = {NP_TEST_MODULE_DIR "/edit1.yang", NULL};

static int
local_setup(void **state)
{
struct np2_test *st;
char test_name[256];
const char *modules[] = {NP_TEST_MODULE_DIR "/edit1.yang", NULL};
int rc;

/* get test name */
Expand All @@ -124,7 +125,7 @@ local_setup(void **state)
assert_int_equal(rc, 0);

/* setup netopeer2 server */
rc = np2_glob_test_setup_server(state, test_name, modules);
rc = np2_glob_test_setup_server(state, test_name, test_modules);
assert_int_equal(rc, 0);
st = *state;

Expand Down Expand Up @@ -611,6 +612,7 @@ test_rollback_disconnect(void **state)
/* create a new session */
ncs = nc_connect_unix(st->socket_path, NULL);
assert_non_null(ncs);
np2_glob_test_setup_sess_ctx(ncs, test_modules);

/* send a confirmed-commit rpc with 60s timeout */
st->rpc = nc_rpc_commit(1, 60, NULL, NULL, NC_PARAMTYPE_CONST);
Expand Down Expand Up @@ -800,6 +802,7 @@ test_cancel_persist(void **state)
/* start a new NC session */
nc_sess = nc_connect_unix(st->socket_path, NULL);
assert_non_null(nc_sess);
np2_glob_test_setup_sess_ctx(nc_sess, test_modules);

/* send a confirmed-commit rpc with persist */
st->rpc = nc_rpc_commit(1, 0, persist, NULL, NC_PARAMTYPE_CONST);
Expand Down
2 changes: 2 additions & 0 deletions tests/test_parallel_sessions.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ send_get_thread(void *arg)
/* create a NETCONF session */
nc_sess = nc_connect_unix(targ->st->socket_path, NULL);
assert_non_null(nc_sess);
np2_glob_test_setup_sess_ctx(nc_sess, NULL);

pthread_barrier_wait(&targ->barrier);

/* send get rpc */
Expand Down
6 changes: 4 additions & 2 deletions tests/test_sub_ntf.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@
#include "np2_test.h"
#include "np2_test_config.h"

static const char *test_modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL};

static int
local_setup(void **state)
{
struct np2_test *st;
char test_name[256];
const char *modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL};
int rc;

/* get test name */
Expand All @@ -48,7 +49,7 @@ local_setup(void **state)
assert_int_equal(rc, 0);

/* setup netopeer2 server */
rc = np2_glob_test_setup_server(state, test_name, modules);
rc = np2_glob_test_setup_server(state, test_name, test_modules);
assert_int_equal(rc, 0);
st = *state;

Expand All @@ -75,6 +76,7 @@ teardown_common(void **state)
nc_session_free(st->nc_sess, NULL);
st->nc_sess = nc_connect_unix(st->socket_path, NULL);
assert_non_null(st->nc_sess);
np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules);

return 0;
}
Expand Down
8 changes: 6 additions & 2 deletions tests/test_sub_ntf_advanced.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
#include "np2_test.h"
#include "np2_test_config.h"

static const char *test_modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL};

static int
local_setup(void **state)
{
struct np2_test *st;
char test_name[256];
const char *modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL};
int rc;

/* get test name */
Expand All @@ -49,7 +50,7 @@ local_setup(void **state)
assert_int_equal(rc, 0);

/* setup netopeer2 server */
rc = np2_glob_test_setup_server(state, test_name, modules);
rc = np2_glob_test_setup_server(state, test_name, test_modules);
assert_int_equal(rc, 0);
st = *state;

Expand Down Expand Up @@ -80,6 +81,7 @@ teardown_common(void **state)
nc_session_free(st->nc_sess, NULL);
st->nc_sess = nc_connect_unix(st->socket_path, NULL);
assert_non_null(st->nc_sess);
np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules);

return 0;
}
Expand Down Expand Up @@ -358,6 +360,7 @@ test_deletesub_fail_diff_sess(void **state)
/* Create a new session */
tmp = nc_connect_unix(st->socket_path, NULL);
assert_non_null(tmp);
np2_glob_test_setup_sess_ctx(tmp, test_modules);

/* Try to delete it */
st->rpc = nc_rpc_deletesub(st->ntf_id);
Expand Down Expand Up @@ -925,6 +928,7 @@ test_killsub_diff_sess(void **state)
/* Create a new session */
tmp = nc_connect_unix(st->socket_path, NULL);
assert_non_null(tmp);
np2_glob_test_setup_sess_ctx(tmp, test_modules);

/* Kill it */
st->rpc = nc_rpc_killsub(st->ntf_id);
Expand Down
6 changes: 4 additions & 2 deletions tests/test_sub_ntf_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@
#include "np2_test.h"
#include "np2_test_config.h"

static const char *test_modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL};

static int
local_setup(void **state)
{
struct np2_test *st;
char test_name[256];
const char *modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL};
int rc;

/* get test name */
Expand All @@ -48,7 +49,7 @@ local_setup(void **state)
assert_int_equal(rc, 0);

/* setup netopeer2 server */
rc = np2_glob_test_setup_server(state, test_name, modules);
rc = np2_glob_test_setup_server(state, test_name, test_modules);
assert_int_equal(rc, 0);
st = *state;

Expand All @@ -75,6 +76,7 @@ teardown_common(void **state)
nc_session_free(st->nc_sess, NULL);
st->nc_sess = nc_connect_unix(st->socket_path, NULL);
assert_non_null(st->nc_sess);
np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules);

return 0;
}
Expand Down
8 changes: 6 additions & 2 deletions tests/test_subscribe_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "np2_test.h"
#include "np2_test_config.h"

static const char *test_modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL};

static void
setup_data(void **state)
{
Expand Down Expand Up @@ -59,6 +61,7 @@ reestablish_sub(void **state, const char *filter)
nc_session_free(st->nc_sess, NULL);
st->nc_sess = nc_connect_unix(st->socket_path, NULL);
assert_non_null(st->nc_sess);
np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules);

/* Get a subscription to receive notifications */
st->rpc = nc_rpc_subscribe(NULL, filter, NULL, NULL, NC_PARAMTYPE_CONST);
Expand All @@ -76,7 +79,6 @@ local_setup(void **state)
{
struct np2_test *st;
char test_name[256];
const char *modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL};
int rc;

/* get test name */
Expand All @@ -87,7 +89,7 @@ local_setup(void **state)
assert_int_equal(rc, 0);

/* setup netopeer2 server */
rc = np2_glob_test_setup_server(state, test_name, modules);
rc = np2_glob_test_setup_server(state, test_name, test_modules);
assert_int_equal(rc, 0);
st = *state;

Expand Down Expand Up @@ -173,6 +175,7 @@ test_subtree_filter_no_matching_node(void **state)
nc_session_free(st->nc_sess, NULL);
st->nc_sess = nc_connect_unix(st->socket_path, NULL);
assert_non_null(st->nc_sess);
np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules);

/* Get a subscription to receive notifications */
st->rpc = nc_rpc_subscribe(NULL, filter, NULL, NULL, NC_PARAMTYPE_CONST);
Expand Down Expand Up @@ -307,6 +310,7 @@ test_xpath_filter_no_matching_node(void **state)
nc_session_free(st->nc_sess, NULL);
st->nc_sess = nc_connect_unix(st->socket_path, NULL);
assert_non_null(st->nc_sess);
np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules);

/* Get a subscription to receive notifications */
st->rpc = nc_rpc_subscribe(NULL, "/notif2:devices/device[name='Main']", NULL, NULL, NC_PARAMTYPE_CONST);
Expand Down
9 changes: 7 additions & 2 deletions tests/test_subscribe_param.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "np2_test.h"
#include "np2_test_config.h"

static const char *test_modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL};

static void
reestablish_sub(void **state, const char *stream, const char *start_time, const char *stop_time)
{
Expand All @@ -41,6 +43,7 @@ reestablish_sub(void **state, const char *stream, const char *start_time, const
nc_session_free(st->nc_sess, NULL);
st->nc_sess = nc_connect_unix(st->socket_path, NULL);
assert_non_null(st->nc_sess);
np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules);

/* Get a subscription to receive notifications */
st->rpc = nc_rpc_subscribe(stream, NULL, start_time, stop_time, NC_PARAMTYPE_CONST);
Expand Down Expand Up @@ -69,7 +72,6 @@ local_setup(void **state)
{
struct np2_test *st;
char test_name[256];
const char *modules[] = {NP_TEST_MODULE_DIR "/notif1.yang", NP_TEST_MODULE_DIR "/notif2.yang", NULL};
int rc;

/* get test name */
Expand All @@ -80,7 +82,7 @@ local_setup(void **state)
assert_int_equal(rc, 0);

/* setup netopeer2 server */
rc = np2_glob_test_setup_server(state, test_name, modules);
rc = np2_glob_test_setup_server(state, test_name, test_modules);
assert_int_equal(rc, 0);
st = *state;

Expand Down Expand Up @@ -148,6 +150,7 @@ test_stop_time_invalid(void **state)
nc_session_free(st->nc_sess, NULL);
st->nc_sess = nc_connect_unix(st->socket_path, NULL);
assert_non_null(st->nc_sess);
np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules);

/* Get a subscription to receive notifications */
st->rpc = nc_rpc_subscribe(NULL, NULL, start_time, stop_time, NC_PARAMTYPE_CONST);
Expand Down Expand Up @@ -187,6 +190,7 @@ test_start_time_invalid(void **state)
nc_session_free(st->nc_sess, NULL);
st->nc_sess = nc_connect_unix(st->socket_path, NULL);
assert_non_null(st->nc_sess);
np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules);

/* Get a subscription to receive notifications */
st->rpc = nc_rpc_subscribe(NULL, NULL, start_time, NULL, NC_PARAMTYPE_CONST);
Expand Down Expand Up @@ -224,6 +228,7 @@ test_stop_time_no_start_time(void **state)
nc_session_free(st->nc_sess, NULL);
st->nc_sess = nc_connect_unix(st->socket_path, NULL);
assert_non_null(st->nc_sess);
np2_glob_test_setup_sess_ctx(st->nc_sess, test_modules);

/* Get a subscription to receive notifications */
st->rpc = nc_rpc_subscribe(NULL, NULL, NULL, stop_time, NC_PARAMTYPE_CONST);
Expand Down
Loading

0 comments on commit 5fb0ee9

Please sign in to comment.