Skip to content

Commit 73eddc6

Browse files
author
roman
committed
test schema UPDATE finish compiled ctx print test
1 parent 4268b7f commit 73eddc6

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

tests/utests/schema/test_schema.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,10 +1893,14 @@ test_lysc_path(void **state)
18931893
static void
18941894
test_compiled_print(void **state)
18951895
{
1896-
struct ly_ctx *pctx;
1897-
struct lyd_node *tree;
18981896
int size, fd;
1899-
void *mem, *mem_end;
1897+
void *mem, *mem_end, *printed_ctx_mem;
1898+
struct lyd_node *tree = NULL;
1899+
struct ly_ctx *printed_ctx = NULL;
1900+
1901+
/* recreate the context, get rid of all the plugins and use builtin/static only */
1902+
ly_ctx_destroy(UTEST_LYCTX);
1903+
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_BUILTIN_PLUGINS_ONLY | LY_CTX_STATIC_PLUGINS_ONLY, &UTEST_LYCTX));
19001904

19011905
/* load another module */
19021906
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1; namespace urn:c;prefix c;"
@@ -1937,20 +1941,27 @@ test_compiled_print(void **state)
19371941
assert_int_equal(LY_SUCCESS, ly_ctx_compiled_print(UTEST_LYCTX, mem, &mem_end));
19381942
assert_int_equal((char *)mem_end - (char *)mem, size);
19391943

1940-
/* use the printed context */
1941-
assert_int_equal(LY_SUCCESS, ly_ctx_new_printed(mem, &pctx));
1944+
/* remap the region and parse the context from mem */
1945+
munmap(mem, size);
1946+
1947+
/* mmap the same address again */
1948+
printed_ctx_mem = mmap(mem, size, PROT_READ, MAP_PRIVATE | MAP_FIXED_NOREPLACE, fd, 0);
1949+
assert_ptr_not_equal(printed_ctx_mem, MAP_FAILED);
1950+
1951+
/* create a new printed ctx from this address */
1952+
assert_int_equal(LY_SUCCESS, ly_ctx_new_printed(printed_ctx_mem, &printed_ctx));
19421953

1943-
/* use it to parse some data */
1944-
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(pctx,
1954+
/* try to parse data with it */
1955+
assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(printed_ctx,
19451956
"<a xmlns=\"urn:c\" xmlns:c=\"urn:c\">/c:b</a>"
19461957
"<b xmlns=\"urn:c\">true</b>"
19471958
"<c xmlns=\"urn:c\">ahoi</c>",
19481959
LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
19491960

19501961
/* cleanup */
1951-
lyd_free_siblings(tree);
1952-
ly_ctx_destroy(pctx);
1953-
munmap(mem, size);
1962+
lyd_free_all(tree);
1963+
ly_ctx_destroy(printed_ctx);
1964+
munmap(printed_ctx_mem, size);
19541965
close(fd);
19551966
shm_unlink("/ly_test_schema_ctx");
19561967
}

0 commit comments

Comments
 (0)