示例#1
0
static int
setup_f(void **state)
{
    struct state *st;
    const char *augschema = "ietf-ip";
    const char *typeschema = "iana-if-type";
    const char *ietfdir = TESTS_DIR"/schema/yin/ietf/";
    const struct lys_module *mod;

    (*state) = st = calloc(1, sizeof *st);
    if (!st) {
        fprintf(stderr, "Memory allocation error.\n");
        return -1;
    }

    /* libyang context */
    st->ctx = ly_ctx_new(ietfdir);
    if (!st->ctx) {
        fprintf(stderr, "Failed to create context.\n");
        goto error;
    }

    /* schema */
    mod = ly_ctx_load_module(st->ctx, augschema, NULL);
    if (!mod) {
        fprintf(stderr, "Failed to load data module \"%s\".\n", augschema);
        goto error;
    }
    lys_features_enable(mod, "*");

    mod = ly_ctx_get_module(st->ctx, "ietf-interfaces", NULL);
    if (!mod) {
        fprintf(stderr, "Failed to get data module \"ietf-interfaces\".\n");
        goto error;
    }
    lys_features_enable(mod, "*");

    mod = ly_ctx_load_module(st->ctx, typeschema, NULL);
    if (!mod) {
        fprintf(stderr, "Failed to load data module \"%s\".\n", typeschema);
        goto error;
    }

    /* data */
    st->dt = lyd_parse_mem(st->ctx, data, LYD_XML, LYD_OPT_CONFIG);
    if (!st->dt) {
        fprintf(stderr, "Failed to build the data tree.\n");
        goto error;
    }

    return 0;

error:
    ly_ctx_destroy(st->ctx, NULL);
    free(st);
    (*state) = NULL;

    return -1;
}
示例#2
0
void
createDataTreeLargeExampleModule(int list_count)
{
    struct ly_ctx *ctx = NULL;
    struct lyd_node *root = NULL, *node = NULL;

    ctx = ly_ctx_new(TEST_SCHEMA_SEARCH_DIR);
    assert_non_null(ctx);

    const struct lys_module *module = ly_ctx_load_module(ctx, "example-module", NULL);
    assert_non_null(module);

#define MAX_XP_LEN 100
    const char *template = "/example-module:container/list[key1='k1%d'][key2='k2%d']/leaf";
示例#3
0
void
new_nacm_config(test_nacm_cfg_t **nacm_config_p)
{
    test_nacm_cfg_t *nacm_config = NULL;

    nacm_config = calloc(1, sizeof *nacm_config);
    assert_non_null(nacm_config);

    nacm_config->ly_ctx = ly_ctx_new(TEST_SCHEMA_SEARCH_DIR);
    assert_non_null(nacm_config->ly_ctx);

    assert_non_null(ly_ctx_load_module(nacm_config->ly_ctx, "ietf-netconf-acm@2012-02-22", NULL));

    *nacm_config_p = nacm_config;
}
示例#4
0
void
createDataTreeExampleModule()
{
    struct ly_ctx *ctx = NULL;
    struct lyd_node *root = NULL;

    ctx = ly_ctx_new(TEST_SCHEMA_SEARCH_DIR);
    assert_non_null(ctx);

    const struct lys_module *module = ly_ctx_load_module(ctx, "example-module", NULL);
    assert_non_null(module);

#define XPATH "/example-module:container/list[key1='key1'][key2='key2']/leaf"

    root = lyd_new_path(NULL, ctx, XPATH, "Leaf value", 0);
    assert_int_equal(0, lyd_validate(&root, LYD_OPT_STRICT | LYD_OPT_CONFIG));
    assert_int_equal(SR_ERR_OK, sr_save_data_tree_file(EXAMPLE_MODULE_DATA_FILE_NAME, root));

    lyd_free_withsiblings(root);
    ly_ctx_destroy(ctx, NULL);
}
示例#5
0
static void
test_fullset(void **state)
{
    struct ly_ctx *ctx = *state;
    const struct lys_module *mod;
    char *buf = NULL;

    const char *tree_alldisabled = "module: features\n"
"   +--rw lst* [id] {not a}?\n"
"   |  +--rw id    string\n"
"   +--rw (ch)? {not (a and b)}?\n"
"   |  +--:(ch3)\n"
"   |     +--rw ch3?   string\n"
"   +--rw axml?   anyxml {not (a or b)}?\n";

    const char *tree_a = "module: features\n"
"   +--rw grp?    string\n"
"   +--rw cont! {a}?\n"
"   +--rw ll*     string {a or b}?\n"
"   +--rw (ch)? {not (a and b)}?\n"
"      +--:(ch1) {a}?\n"
"      |  +--rw ch1?   string\n"
"      +--:(ch3)\n"
"         +--rw ch3?   string\n";

    const char *tree_ab = "module: features\n"
"   +--rw grp?    string\n"
"   +--rw cont! {a}?\n"
"   +--rw lf?     string {a and b}?\n"
"   +--rw ll*     string {a or b}?\n";

    const char *tree_abaa = "module: features\n"
"   +--rw grp?    string\n"
"   +--rw cont! {a}?\n"
"   |  +--rw aug?   string\n"
"   +--rw lf?     string {a and b}?\n"
"   +--rw ll*     string {a or b}?\n"
"rpcs:\n"
"   +---x rpc1 {aa}?\n"
"notifications:\n"
"   +---n notif1 {aa}?\n";

    const char *tree_b = "module: features\n"
"   +--rw ll*     string {a or b}?\n"
"   +--rw lst* [id] {not a}?\n"
"   |  +--rw id    string\n"
"   +--rw (ch)? {not (a and b)}?\n"
"      +--:(ch2) {b}?\n"
"      |  +--rw ch2?   string\n"
"      +--:(ch3)\n"
"         +--rw ch3?   string\n";

    mod = ly_ctx_load_module(ctx, "features", NULL);
    assert_non_null(mod);

    lys_print_mem(&buf, mod, LYS_OUT_TREE, NULL);
    assert_non_null(buf);
    assert_string_equal(buf, tree_alldisabled);
    free(buf); buf = NULL;

    lys_features_enable(mod, "a");
    lys_print_mem(&buf, mod, LYS_OUT_TREE, NULL);
    assert_non_null(buf);
    assert_string_equal(buf, tree_a);
    free(buf); buf = NULL;

    lys_features_enable(mod, "b");
    lys_print_mem(&buf, mod, LYS_OUT_TREE, NULL);
    assert_non_null(buf);
    assert_string_equal(buf, tree_ab);
    free(buf); buf = NULL;

    lys_features_enable(mod, "aa");
    lys_print_mem(&buf, mod, LYS_OUT_TREE, NULL);
    assert_non_null(buf);
    assert_string_equal(buf, tree_abaa);
    free(buf); buf = NULL;

    lys_features_disable(mod, "a"); /* aa is also disabled by disabling a */
    lys_print_mem(&buf, mod, LYS_OUT_TREE, NULL);
    assert_non_null(buf);
    assert_string_equal(buf, tree_b);
    free(buf); buf = NULL;
}
示例#6
0
static int
setup_sessions(void **state)
{
    (void)state;
    struct ly_ctx *ctx;
    const struct lys_module *module;
    const struct lys_node *node;
    int sock[2];

    /* create ctx */
    ctx = ly_ctx_new(TESTS_DIR"../schemas");
    assert_non_null(ctx);

    /* load modules */
    module = ly_ctx_load_module(ctx, "ietf-netconf-acm", NULL);
    assert_non_null(module);

    module = ly_ctx_load_module(ctx, "ietf-netconf", NULL);
    assert_non_null(module);

    /* set RPC callbacks */
    node = lys_get_node(module, "/get");
    assert_non_null(node);
    lys_set_private(node, my_get_rpc_clb);

    node = lys_get_node(module, "/get-config");
    assert_non_null(node);
    lys_set_private(node, my_getconfig_rpc_clb);

    /* create communication channel */
    socketpair(AF_UNIX, SOCK_STREAM, 0, sock);

    nc_server_init(ctx);

    /* create server session */
    server_session = calloc(1, sizeof *server_session);
    server_session->status = NC_STATUS_RUNNING;
    server_session->side = NC_SERVER;
    server_session->id = 1;
    server_session->ti_type = NC_TI_FD;
    server_session->ti_lock = malloc(sizeof *server_session->ti_lock);
    pthread_mutex_init(server_session->ti_lock, NULL);
    server_session->ti.fd.in = sock[0];
    server_session->ti.fd.out = sock[0];
    server_session->ctx = ctx;
    server_session->flags = NC_SESSION_SHAREDCTX;

    /* create client session */
    client_session = calloc(1, sizeof *server_session);
    client_session->status = NC_STATUS_RUNNING;
    client_session->side = NC_CLIENT;
    client_session->id = 1;
    client_session->ti_type = NC_TI_FD;
    client_session->ti_lock = malloc(sizeof *client_session->ti_lock);
    pthread_mutex_init(client_session->ti_lock, NULL);
    client_session->ti.fd.in = sock[1];
    client_session->ti.fd.out = sock[1];
    client_session->ctx = ctx;
    client_session->flags = NC_SESSION_SHAREDCTX;
    client_session->msgid = 50;

    return 0;
}
示例#7
0
void
createDataTreeTestModule()
{
    struct ly_ctx *ctx = NULL;
    struct lyd_node *node = NULL;
    struct lyd_node *n = NULL;
    struct lyd_node *r = NULL;

    ctx = ly_ctx_new(TEST_SCHEMA_SEARCH_DIR);
    assert_non_null(ctx);

    const struct lys_module *module = ly_ctx_load_module(ctx, "test-module", NULL);
    assert_non_null(module);

    r = lyd_new(NULL, module, "main");
    assert_non_null(r);
    node = lyd_new_leaf(r, module, "enum", XP_TEST_MODULE_ENUM_VALUE);
    assert_non_null(node);
    node = lyd_new_leaf(r, module, "raw", XP_TEST_MODULE_RAW_VALUE);
    assert_non_null(node);

    /*Strict = 1, Recursive = 1, Loggin = 0*/
    node = lyd_new_leaf(r, module, "options", XP_TEST_MODULE_BITS_VALUE);
    assert_non_null(node);

    node = lyd_new_leaf(r, module, "dec64", XP_TEST_MODULE_DEC64_VALUE);
    assert_non_null(node);

    node = lyd_new_leaf(r, module, "i8", XP_TEST_MODULE_INT8_VALUE);
    assert_non_null(node);

    node = lyd_new_leaf(r, module, "i16", XP_TEST_MODULE_INT16_VALUE);
    assert_non_null(node);

    node = lyd_new_leaf(r, module, "i32", XP_TEST_MODULE_INT32_VALUE);
    assert_non_null(node);

    node = lyd_new_leaf(r, module, "i64", XP_TEST_MODULE_INT64_VALUE);
    assert_non_null(node);

    node = lyd_new_leaf(r, module, "ui8", XP_TEST_MODULE_UINT8_VALUE);
    assert_non_null(node);

    node = lyd_new_leaf(r, module, "ui16", XP_TEST_MODULE_UINT16_VALUE);
    assert_non_null(node);

    node = lyd_new_leaf(r, module, "ui32", XP_TEST_MODULE_UINT32_VALUE);
    assert_non_null(node);

    node = lyd_new_leaf(r, module, "ui64", XP_TEST_MODULE_INT64_VALUE);
    assert_non_null(node);

    node = lyd_new_leaf(r, module, "empty", XP_TEST_MODULE_EMPTY_VALUE);
    assert_non_null(node);

    node = lyd_new_leaf(r, module, "boolean", XP_TEST_MODULE_BOOL_VALUE);
    assert_non_null(node);

    node = lyd_new_leaf(r, module, "string", XP_TEST_MODULE_STRING_VALUE);
    assert_non_null(node);

    node = lyd_new_leaf(r, module, "id_ref", XP_TEST_MODULE_IDREF_VALUE);
    assert_non_null(node);

    /* leaf -list*/
    n = lyd_new_leaf(r, module, "numbers", "1");
    assert_non_null(n);

    n = lyd_new_leaf(r, module, "numbers", "2");
    assert_non_null(n);

    n = lyd_new_leaf(r, module, "numbers", "42");
    assert_non_null(n);

    /* list k1*/
    node = lyd_new(NULL, module, "list");
    assert_non_null(node);
    assert_int_equal(0,lyd_insert_after(r, node));

    n = lyd_new_leaf(node, module, "key", "k1");
    assert_non_null(n);

    n = lyd_new_leaf(node, module, "id_ref", "id_1");
    assert_non_null(n);

    n = lyd_new_leaf(node, module, "union", "42");
    assert_non_null(n);

    /* presence container*/
    n = lyd_new(node, module, "wireless");
    assert_non_null(n);

    /* list k2*/
    node = lyd_new(NULL, module, "list");
    assert_non_null(node);
    assert_int_equal(0, lyd_insert_after(r, node));

    n = lyd_new_leaf(node, module, "key", "k2");
    assert_non_null(n);

    n = lyd_new_leaf(node, module, "id_ref", "id_2");
    assert_non_null(n);

    n = lyd_new_leaf(node, module, "union", "infinity");
    assert_non_null(n);

    assert_int_equal(0, lyd_validate(&r, LYD_OPT_STRICT | LYD_OPT_CONFIG));
    assert_int_equal(SR_ERR_OK, sr_save_data_tree_file(TEST_MODULE_DATA_FILE_NAME, r));

    lyd_free_withsiblings(r);

    ly_ctx_destroy(ctx, NULL);

}