utests data REFACTOR put repetitive commands into macros
diff --git a/tests/utests/schema/test_parser_yang.c b/tests/utests/schema/test_parser_yang.c
index c107e76..3b9c81e 100644
--- a/tests/utests/schema/test_parser_yang.c
+++ b/tests/utests/schema/test_parser_yang.c
@@ -3,7 +3,7 @@
  * @author: Radek Krejci <rkrejci@cesnet.cz>
  * @brief unit tests for functions from parser_yang.c
  *
- * Copyright (c) 2018 CESNET, z.s.p.o.
+ * Copyright (c) 2018-2020 CESNET, z.s.p.o.
  *
  * This source code is licensed under BSD 3-Clause License (the "License").
  * You may not use this file except in compliance with the License.
@@ -11,6 +11,8 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -21,7 +23,6 @@
 #include "schema_compile.h"
 #include "tree_schema.h"
 #include "tree_schema_internal.h"
-#include "utests.h"
 
 /* originally static functions from tree_schema_free.c and parser_yang.c */
 void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext);
@@ -63,103 +64,53 @@
 LY_ERR parse_when(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_when **when_p);
 LY_ERR parse_type_enum_value_pos(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt val_kw, int64_t *value, uint16_t *flags, struct lysp_ext_instance **exts);
 
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-static void
-logger_setup(void)
-{
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
+struct lys_yang_parser_ctx *YCTX;
 
 static int
-setup_f(void **state)
+setup(void **state)
 {
-    struct lys_yang_parser_ctx *pctx;
-    LY_ERR ret;
+    UTEST_SETUP;
 
-    logger_setup();
+    /* allocate parser context */
+    YCTX = calloc(1, sizeof(*YCTX));
+    YCTX->format = LYS_IN_YANG;
+    YCTX->pos_type = LY_VLOG_LINE;
+    YCTX->line = 1;
 
-    pctx = calloc(1, sizeof *pctx);
-    pctx->format = LYS_IN_YANG;
-    pctx->pos_type = LY_VLOG_LINE;
-    pctx->line = 1;
+    /* allocate new parsed module */
+    YCTX->parsed_mod = calloc(1, sizeof *YCTX->parsed_mod);
 
-    pctx->parsed_mod = calloc(1, sizeof *pctx->parsed_mod);
-    pctx->parsed_mod->mod = calloc(1, sizeof *pctx->parsed_mod->mod);
-    pctx->parsed_mod->mod->parsed = pctx->parsed_mod;
-    ret = ly_ctx_new(NULL, 0, &pctx->parsed_mod->mod->ctx);
-    if (ret) {
-        return ret;
-    }
+    /* allocate new module */
+    YCTX->parsed_mod->mod = calloc(1, sizeof *YCTX->parsed_mod->mod);
+    YCTX->parsed_mod->mod->ctx = UTEST_LYCTX;
+    YCTX->parsed_mod->mod->parsed = YCTX->parsed_mod;
 
-    *state = pctx;
     return 0;
 }
 
 static int
-teardown_f(void **state)
+teardown(void **state)
 {
-    struct lys_yang_parser_ctx *pctx = *state;
-    struct ly_ctx *ctx = pctx->parsed_mod->mod->ctx;
+    lys_module_free(YCTX->parsed_mod->mod, NULL);
+    free(YCTX);
+    YCTX = NULL;
 
-    lys_module_free(pctx->parsed_mod->mod, NULL);
-    ly_ctx_destroy(ctx, NULL);
-    free(pctx);
+    UTEST_TEARDOWN;
 
     return 0;
 }
 
 #define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
     in.current = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, FUNC(ctx, &in, RESULT)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
+    assert_int_equal(LY_EVALID, FUNC(YCTX, &in, RESULT)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number "LINE".");\
     CLEANUP
-
 static void
 test_helpers(void **state)
 {
     struct ly_in in = {0};
     char *buf, *p;
     size_t len, size;
-    struct lys_yang_parser_ctx *ctx = *state;
     uint8_t prefix = 0;
 
     /* storing into buffer */
@@ -177,28 +128,28 @@
     /* invalid first characters */
     len = 0;
     in.current = "2invalid";
-    assert_int_equal(LY_EVALID, buf_store_char(ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    assert_int_equal(LY_EVALID, buf_store_char(YCTX, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     in.current = ".invalid";
-    assert_int_equal(LY_EVALID, buf_store_char(ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    assert_int_equal(LY_EVALID, buf_store_char(YCTX, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     in.current = "-invalid";
-    assert_int_equal(LY_EVALID, buf_store_char(ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    assert_int_equal(LY_EVALID, buf_store_char(YCTX, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     /* invalid following characters */
     len = 3; /* number of characters read before the str content */
     in.current = "!";
-    assert_int_equal(LY_EVALID, buf_store_char(ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    assert_int_equal(LY_EVALID, buf_store_char(YCTX, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     in.current = ":";
-    assert_int_equal(LY_EVALID, buf_store_char(ctx, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    assert_int_equal(LY_EVALID, buf_store_char(YCTX, &in, Y_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     /* valid colon for prefixed identifiers */
     len = size = 0;
     p = NULL;
     prefix = 0;
     in.current = "x:id";
-    assert_int_equal(LY_SUCCESS, buf_store_char(ctx, &in, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 0, &prefix));
+    assert_int_equal(LY_SUCCESS, buf_store_char(YCTX, &in, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 0, &prefix));
     assert_int_equal(1, len);
     assert_null(buf);
     assert_string_equal(":id", in.current);
     assert_int_equal('x', p[len - 1]);
-    assert_int_equal(LY_SUCCESS, buf_store_char(ctx, &in, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
+    assert_int_equal(LY_SUCCESS, buf_store_char(YCTX, &in, Y_PREF_IDENTIF_ARG, &p, &len, &buf, &size, 1, &prefix));
     assert_int_equal(2, len);
     assert_string_equal("id", in.current);
     assert_int_equal(':', p[len - 1]);
@@ -206,208 +157,176 @@
     prefix = 0;
 
     /* checking identifiers */
-    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)ctx, ':', 0, NULL));
-    logbuf_assert("Invalid identifier character ':' (0x003a). Line number 1.");
-    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)ctx, '#', 1, NULL));
-    logbuf_assert("Invalid identifier first character '#' (0x0023). Line number 1.");
+    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)YCTX, ':', 0, NULL));
+    CHECK_LOG_CTX("Invalid identifier character ':' (0x003a).", "Line number 1.");
+    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)YCTX, '#', 1, NULL));
+    CHECK_LOG_CTX("Invalid identifier first character '#' (0x0023).", "Line number 1.");
 
-    assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)ctx, 'a', 1, &prefix));
+    assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)YCTX, 'a', 1, &prefix));
     assert_int_equal(0, prefix);
-    assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)ctx, ':', 0, &prefix));
+    assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)YCTX, ':', 0, &prefix));
     assert_int_equal(1, prefix);
-    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)ctx, ':', 0, &prefix));
+    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)YCTX, ':', 0, &prefix));
     assert_int_equal(1, prefix);
-    assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)ctx, 'b', 0, &prefix));
+    assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)YCTX, 'b', 0, &prefix));
     assert_int_equal(2, prefix);
     /* second colon is invalid */
-    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)ctx, ':', 0, &prefix));
-    logbuf_assert("Invalid identifier character ':' (0x003a). Line number 1.");
+    assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)YCTX, ':', 0, &prefix));
+    CHECK_LOG_CTX("Invalid identifier character ':' (0x003a).", "Line number 1.");
 }
 
+#define TEST_GET_ARGUMENT_SUCCESS(INPUT_TEXT, CTX, ARG_TYPE, EXPECT_WORD, EXPECT_LEN, EXPECT_CURRENT)\
+    {\
+        const char * text  = INPUT_TEXT;\
+        in.current = text;\
+        assert_int_equal(LY_SUCCESS, get_argument(CTX, &in, Y_MAYBE_STR_ARG, NULL, &word, &buf, &len));\
+        assert_string_equal(word, EXPECT_WORD);\
+        assert_int_equal(len, EXPECT_LEN);\
+        assert_string_equal(EXPECT_CURRENT, in.current);\
+    }
+
 static void
 test_comments(void **state)
 {
     struct ly_in in = {0};
-    struct lys_yang_parser_ctx *ctx = *state;
     char *word, *buf;
     size_t len;
+    const char *in_text;
 
-    in.current = " // this is a text of / one * line */ comment\nargument;";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_string_equal("argument;", word);
+    // in.current = " // this is a text of / one * line */ comment\nargument;";
+    in_text = " // this is a text of / one * line */ comment\nargument;";
+    TEST_GET_ARGUMENT_SUCCESS(in_text, YCTX, Y_STR_ARG, "argument;", 8, ";");
     assert_null(buf);
-    assert_int_equal(8, len);
 
-    in.current = "/* this is a \n * text // of / block * comment */\"arg\" + \"ume\" \n + \n \"nt\";";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_string_equal("argument", word);
+    in_text = "/* this is a \n * text // of / block * comment */\"arg\" + \"ume\" \n + \n \"nt\";";
+    TEST_GET_ARGUMENT_SUCCESS(in_text, YCTX, Y_STR_ARG, "argument", 8, ";");
     assert_ptr_equal(buf, word);
-    assert_int_equal(8, len);
     free(word);
 
     in.current = " this is one line comment on last line";
-    assert_int_equal(LY_SUCCESS, skip_comment(ctx, &in, 1));
+    assert_int_equal(LY_SUCCESS, skip_comment(YCTX, &in, 1));
     assert_true(in.current[0] == '\0');
 
     in.current = " this is a not terminated comment x";
-    assert_int_equal(LY_EVALID, skip_comment(ctx, &in, 2));
-    logbuf_assert("Unexpected end-of-input, non-terminated comment. Line number 5.");
+    assert_int_equal(LY_EVALID, skip_comment(YCTX, &in, 2));
+    CHECK_LOG_CTX("Unexpected end-of-input, non-terminated comment.", "Line number 5.");
     assert_true(in.current[0] == '\0');
 }
 
 static void
 test_arg(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct ly_in in = {0};
     char *word, *buf;
     size_t len;
 
     /* missing argument */
     in.current = ";";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_MAYBE_STR_ARG, NULL, &word, &buf, &len));
+    assert_int_equal(LY_SUCCESS, get_argument(YCTX, &in, Y_MAYBE_STR_ARG, NULL, &word, &buf, &len));
     assert_null(word);
 
     in.current = "{";
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Invalid character sequence \"{\", expected an argument. Line number 1.");
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_STR_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Invalid character sequence \"{\", expected an argument.", "Line number 1.");
 
     /* invalid escape sequence */
     in.current = "\"\\s\"";
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Double-quoted string unknown special character \'\\s\'. Line number 1.");
-    in.current = "\'\\s\'"; /* valid, since it is not an escape sequence in single quoted string */
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_int_equal(2, len);
-    assert_string_equal("\\s\'", word);
-    assert_int_equal('\0', in.current[0]); /* input has been eaten */
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_STR_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Double-quoted string unknown special character \'\\s\'.", "Line number 1.");
+
+    TEST_GET_ARGUMENT_SUCCESS("\'\\s\'", YCTX, Y_STR_ARG, "\\s\'", 2, "");
 
     /* invalid character after the argument */
     in.current = "hello\"";
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Invalid character sequence \"\"\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1.");
-    in.current = "hello}";
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Invalid character sequence \"}\", expected unquoted string character, optsep, semicolon or opening brace. Line number 1.");
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_STR_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Invalid character sequence \"\"\", expected unquoted string character, optsep, semicolon or opening brace.", "Line number 1.");
 
+    in.current = "hello}";
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_STR_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Invalid character sequence \"}\", expected unquoted string character, optsep, semicolon or opening brace.", "Line number 1.");
     /* invalid identifier-ref-arg-str */
     in.current = "pre:pre:value";
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Invalid identifier character ':' (0x003a).", "Line number 1.");
 
     in.current = "\"\";"; /* empty identifier is not allowed */
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_IDENTIF_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Statement argument is required. Line number 1.");
-    logbuf_clean();
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_IDENTIF_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Statement argument is required.", "Line number 1.");
+
     in.current = "\"\";"; /* empty reference identifier is not allowed */
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Statement argument is required. Line number 1.");
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_PREF_IDENTIF_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Statement argument is required.", "Line number 1.");
 
-    in.current = "hello/x\t"; /* slash is not an invalid character */
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_int_equal(7, len);
-    assert_string_equal("hello/x\t", word);
-
+    /* slash is not an invalid character */
+    TEST_GET_ARGUMENT_SUCCESS("hello/x\t", YCTX, Y_STR_ARG, "hello/x\t", 7, "\t");
     assert_null(buf);
 
     /* different quoting */
-    in.current = "hello ";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_null(buf);
-    assert_int_equal(5, len);
-    assert_string_equal("hello ", word);
+    TEST_GET_ARGUMENT_SUCCESS("hello/x\t", YCTX, Y_STR_ARG, "hello/x\t", 7, "\t");
 
-    in.current = "hello/*comment*/\n";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_null(buf);
-    assert_int_equal(5, len);
-    assert_false(strncmp("hello", word, len));
+    TEST_GET_ARGUMENT_SUCCESS("hello ", YCTX, Y_STR_ARG, "hello ", 5, " ");
 
-    in.current = "\"hello\\n\\t\\\"\\\\\";";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_non_null(buf);
-    assert_int_equal(9, len);
-    assert_string_equal("hello\n\t\"\\", word);
+    TEST_GET_ARGUMENT_SUCCESS("hello/*comment*/\n", YCTX, Y_STR_ARG, "hello/*comment*/\n", 5, "\n");
+
+    TEST_GET_ARGUMENT_SUCCESS("\"hello\\n\\t\\\"\\\\\";", YCTX, Y_STR_ARG, "hello\n\t\"\\", 9, ";");
     free(buf);
 
-    ctx->indent = 14;
-    in.current = "\"hello \t\n\t\t world!\"";
+    YCTX->indent = 14;
     /* - space and tabs before newline are stripped out
      * - space and tabs after newline (indentation) are stripped out
      */
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_non_null(buf);
-    assert_ptr_equal(word, buf);
-    assert_int_equal(14, len);
-    assert_string_equal("hello\n  world!", word);
+    TEST_GET_ARGUMENT_SUCCESS("\"hello \t\n\t\t world!\"", YCTX, Y_STR_ARG, "hello\n  world!", 14, "");
     free(buf);
-    /* In contrast to previous, the backslash-escaped tabs are expanded after trimming, so they are preserved */
-    ctx->indent = 14;
-    in.current = "\"hello \\t\n\t\\t world!\"";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_non_null(buf);
+
+/* In contrast to previous, the backslash-escaped tabs are expanded after trimming, so they are preserved */
+    YCTX->indent = 14;
+    TEST_GET_ARGUMENT_SUCCESS("\"hello \\t\n\t\\t world!\"", YCTX, Y_STR_ARG, "hello \t\n\t world!", 16, "");
     assert_ptr_equal(word, buf);
-    assert_int_equal(16, len);
-    assert_string_equal("hello \t\n\t world!", word);
     free(buf);
+
     /* Do not handle whitespaces after backslash-escaped newline as indentation */
-    ctx->indent = 14;
-    in.current = "\"hello\\n\t\t world!\"";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_non_null(buf);
+    YCTX->indent = 14;
+    TEST_GET_ARGUMENT_SUCCESS("\"hello\\n\t\t world!\"", YCTX, Y_STR_ARG, "hello\n\t\t world!", 15, "");
     assert_ptr_equal(word, buf);
-    assert_int_equal(15, len);
-    assert_string_equal("hello\n\t\t world!", word);
     free(buf);
 
-    ctx->indent = 14;
-    in.current = "\"hello\n \tworld!\"";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_non_null(buf);
+    YCTX->indent = 14;
+    TEST_GET_ARGUMENT_SUCCESS("\"hello\n \tworld!\"", YCTX, Y_STR_ARG, "hello\nworld!", 12, "");
     assert_ptr_equal(word, buf);
-    assert_int_equal(12, len);
-    assert_string_equal("hello\nworld!", word);
     free(buf);
 
-    in.current = "\'hello\'";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_null(buf);
-    assert_int_equal(5, len);
-    assert_false(strncmp("hello", word, 5));
+    TEST_GET_ARGUMENT_SUCCESS("\'hello\'", YCTX, Y_STR_ARG, "hello'", 5, "");
 
-    in.current = "\"hel\"  +\t\n\"lo\"";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
+    TEST_GET_ARGUMENT_SUCCESS("\"hel\"  +\t\n\"lo\"", YCTX, Y_STR_ARG, "hello", 5, "");
     assert_ptr_equal(word, buf);
-    assert_int_equal(5, len);
-    assert_string_equal("hello", word);
     free(buf);
+
     in.current = "\"hel\"  +\t\nlo"; /* unquoted the second part */
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Both string parts divided by '+' must be quoted. Line number 6.");
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_STR_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Both string parts divided by '+' must be quoted.", "Line number 6.");
 
-    in.current = "\'he\'\t\n+ \"llo\"";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_ptr_equal(word, buf);
-    assert_int_equal(5, len);
-    assert_string_equal("hello", word);
+    TEST_GET_ARGUMENT_SUCCESS("\'he\'\t\n+ \"llo\"", YCTX, Y_STR_ARG, "hello", 5, "");
     free(buf);
 
-    in.current = " \t\n\"he\"+\'llo\'";
-    assert_int_equal(LY_SUCCESS, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    assert_ptr_equal(word, buf);
-    assert_int_equal(5, len);
-    assert_string_equal("hello", word);
+    TEST_GET_ARGUMENT_SUCCESS(" \t\n\"he\"+\'llo\'", YCTX, Y_STR_ARG, "hello", 5, "");
     free(buf);
 
     /* missing argument */
     in.current = ";";
-    assert_int_equal(LY_EVALID, get_argument(ctx, &in, Y_STR_ARG, NULL, &word, &buf, &len));
-    logbuf_assert("Invalid character sequence \";\", expected an argument. Line number 8.");
+    assert_int_equal(LY_EVALID, get_argument(YCTX, &in, Y_STR_ARG, NULL, &word, &buf, &len));
+    CHECK_LOG_CTX("Invalid character sequence \";\", expected an argument.", "Line number 8.");
 }
 
+#define TEST_STMS_SUCCESS(INPUT_TEXT, CTX, ACTION, EXPECT_WORD)\
+                   in.current = INPUT_TEXT;\
+                   assert_int_equal(LY_SUCCESS, get_keyword(CTX, &in, &kw, &word, &len));\
+                   assert_int_equal(ACTION, kw);\
+                   assert_int_equal(strlen(EXPECT_WORD), len);\
+                   assert_true(0 == strncmp(EXPECT_WORD, word, len))
+
 static void
 test_stmts(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct ly_in in = {0};
     const char *p;
     enum ly_stmt kw;
@@ -415,418 +334,201 @@
     size_t len;
 
     in.current = "\n// comment\n\tinput\t{";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
+    assert_int_equal(LY_SUCCESS, get_keyword(YCTX, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_INPUT, kw);
     assert_int_equal(5, len);
     assert_string_equal("input\t{", word);
     assert_string_equal("\t{", in.current);
 
     in.current = "\t /* comment */\t output\n\t{";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
+    assert_int_equal(LY_SUCCESS, get_keyword(YCTX, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_OUTPUT, kw);
     assert_int_equal(6, len);
     assert_string_equal("output\n\t{", word);
     assert_string_equal("\n\t{", in.current);
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
+    assert_int_equal(LY_SUCCESS, get_keyword(YCTX, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_SYNTAX_LEFT_BRACE, kw);
     assert_int_equal(1, len);
     assert_string_equal("{", word);
     assert_string_equal("", in.current);
 
     in.current = "/input { "; /* invalid slash */
-    assert_int_equal(LY_EVALID, get_keyword(ctx, &in, &kw, &word, &len));
-    logbuf_assert("Invalid identifier first character '/'. Line number 4.");
+    assert_int_equal(LY_EVALID, get_keyword(YCTX, &in, &kw, &word, &len));
+    CHECK_LOG_CTX("Invalid identifier first character '/'.", "Line number 4.");
 
     in.current = "not-a-statement-nor-extension { "; /* invalid identifier */
-    assert_int_equal(LY_EVALID, get_keyword(ctx, &in, &kw, &word, &len));
-    logbuf_assert("Invalid character sequence \"not-a-statement-nor-extension\", expected a keyword. Line number 4.");
+    assert_int_equal(LY_EVALID, get_keyword(YCTX, &in, &kw, &word, &len));
+    CHECK_LOG_CTX("Invalid character sequence \"not-a-statement-nor-extension\", expected a keyword.", "Line number 4.");
 
     in.current = "path;"; /* missing sep after the keyword */
-    assert_int_equal(LY_EVALID, get_keyword(ctx, &in, &kw, &word, &len));
-    logbuf_assert("Invalid character sequence \"path;\", expected a keyword followed by a separator. Line number 4.");
+    assert_int_equal(LY_EVALID, get_keyword(YCTX, &in, &kw, &word, &len));
+    CHECK_LOG_CTX("Invalid character sequence \"path;\", expected a keyword followed by a separator.", "Line number 4.");
 
-    in.current = "action ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ACTION, kw);
-    assert_int_equal(6, len);
-    in.current = "anydata ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ANYDATA, kw);
-    assert_int_equal(7, len);
-    in.current = "anyxml ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ANYXML, kw);
-    assert_int_equal(6, len);
-    in.current = "argument ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ARGUMENT, kw);
-    assert_int_equal(8, len);
-    in.current = "augment ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_AUGMENT, kw);
-    assert_int_equal(7, len);
-    in.current = "base ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_BASE, kw);
-    assert_int_equal(4, len);
-    in.current = "belongs-to ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_BELONGS_TO, kw);
-    assert_int_equal(10, len);
-    in.current = "bit ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_BIT, kw);
-    assert_int_equal(3, len);
-    in.current = "case ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_CASE, kw);
-    assert_int_equal(4, len);
-    in.current = "choice ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_CHOICE, kw);
-    assert_int_equal(6, len);
-    in.current = "config ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_CONFIG, kw);
-    assert_int_equal(6, len);
-    in.current = "contact ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_CONTACT, kw);
-    assert_int_equal(7, len);
-    in.current = "container ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_CONTAINER, kw);
-    assert_int_equal(9, len);
-    in.current = "default ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_DEFAULT, kw);
-    assert_int_equal(7, len);
-    in.current = "description ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_DESCRIPTION, kw);
-    assert_int_equal(11, len);
-    in.current = "deviate ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_DEVIATE, kw);
-    assert_int_equal(7, len);
-    in.current = "deviation ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_DEVIATION, kw);
-    assert_int_equal(9, len);
-    in.current = "enum ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ENUM, kw);
-    assert_int_equal(4, len);
-    in.current = "error-app-tag ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ERROR_APP_TAG, kw);
-    assert_int_equal(13, len);
-    in.current = "error-message ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ERROR_MESSAGE, kw);
-    assert_int_equal(13, len);
-    in.current = "extension ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_EXTENSION, kw);
-    assert_int_equal(9, len);
-    in.current = "feature ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_FEATURE, kw);
-    assert_int_equal(7, len);
-    in.current = "fraction-digits ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_FRACTION_DIGITS, kw);
-    assert_int_equal(15, len);
-    in.current = "grouping ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_GROUPING, kw);
-    assert_int_equal(8, len);
-    in.current = "identity ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_IDENTITY, kw);
-    assert_int_equal(8, len);
-    in.current = "if-feature ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_IF_FEATURE, kw);
-    assert_int_equal(10, len);
-    in.current = "import ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_IMPORT, kw);
-    assert_int_equal(6, len);
-    in.current = "include ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_INCLUDE, kw);
-    assert_int_equal(7, len);
-    in.current = "input{";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_INPUT, kw);
-    assert_int_equal(5, len);
-    in.current = "key ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_KEY, kw);
-    assert_int_equal(3, len);
-    in.current = "leaf ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_LEAF, kw);
-    assert_int_equal(4, len);
-    in.current = "leaf-list ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_LEAF_LIST, kw);
-    assert_int_equal(9, len);
-    in.current = "length ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_LENGTH, kw);
-    assert_int_equal(6, len);
-    in.current = "list ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_LIST, kw);
-    assert_int_equal(4, len);
-    in.current = "mandatory ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_MANDATORY, kw);
-    assert_int_equal(9, len);
-    in.current = "max-elements ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_MAX_ELEMENTS, kw);
-    assert_int_equal(12, len);
-    in.current = "min-elements ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_MIN_ELEMENTS, kw);
-    assert_int_equal(12, len);
-    in.current = "modifier ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_MODIFIER, kw);
-    assert_int_equal(8, len);
-    in.current = "module ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_MODULE, kw);
-    assert_int_equal(6, len);
-    in.current = "must ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_MUST, kw);
-    assert_int_equal(4, len);
-    in.current = "namespace ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_NAMESPACE, kw);
-    assert_int_equal(9, len);
-    in.current = "notification ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_NOTIFICATION, kw);
-    assert_int_equal(12, len);
-    in.current = "ordered-by ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ORDERED_BY, kw);
-    assert_int_equal(10, len);
-    in.current = "organization ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_ORGANIZATION, kw);
-    assert_int_equal(12, len);
-    in.current = "output ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_OUTPUT, kw);
-    assert_int_equal(6, len);
-    in.current = "path ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_PATH, kw);
-    assert_int_equal(4, len);
-    in.current = "pattern ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_PATTERN, kw);
-    assert_int_equal(7, len);
-    in.current = "position ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_POSITION, kw);
-    assert_int_equal(8, len);
-    in.current = "prefix ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_PREFIX, kw);
-    assert_int_equal(6, len);
-    in.current = "presence ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_PRESENCE, kw);
-    assert_int_equal(8, len);
-    in.current = "range ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_RANGE, kw);
-    assert_int_equal(5, len);
-    in.current = "reference ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_REFERENCE, kw);
-    assert_int_equal(9, len);
-    in.current = "refine ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_REFINE, kw);
-    assert_int_equal(6, len);
-    in.current = "require-instance ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_REQUIRE_INSTANCE, kw);
-    assert_int_equal(16, len);
-    in.current = "revision ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_REVISION, kw);
-    assert_int_equal(8, len);
-    in.current = "revision-date ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_REVISION_DATE, kw);
-    assert_int_equal(13, len);
-    in.current = "rpc ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_RPC, kw);
-    assert_int_equal(3, len);
-    in.current = "status ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_STATUS, kw);
-    assert_int_equal(6, len);
-    in.current = "submodule ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_SUBMODULE, kw);
-    assert_int_equal(9, len);
-    in.current = "type ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_TYPE, kw);
-    assert_int_equal(4, len);
-    in.current = "typedef ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_TYPEDEF, kw);
-    assert_int_equal(7, len);
-    in.current = "unique ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_UNIQUE, kw);
-    assert_int_equal(6, len);
-    in.current = "units ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_UNITS, kw);
-    assert_int_equal(5, len);
-    in.current = "uses ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_USES, kw);
-    assert_int_equal(4, len);
-    in.current = "value ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_VALUE, kw);
-    assert_int_equal(5, len);
-    in.current = "when ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_WHEN, kw);
-    assert_int_equal(4, len);
-    in.current = "yang-version ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_YANG_VERSION, kw);
-    assert_int_equal(12, len);
-    in.current = "yin-element ";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_YIN_ELEMENT, kw);
-    assert_int_equal(11, len);
-    in.current = ";config false;";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_SYNTAX_SEMICOLON, kw);
-    assert_int_equal(1, len);
+    TEST_STMS_SUCCESS("action ", YCTX, LY_STMT_ACTION, "action");
+
+    TEST_STMS_SUCCESS("anydata ", YCTX, LY_STMT_ANYDATA, "anydata");
+    TEST_STMS_SUCCESS("anyxml ", YCTX, LY_STMT_ANYXML, "anyxml");
+    TEST_STMS_SUCCESS("argument ", YCTX, LY_STMT_ARGUMENT, "argument");
+    TEST_STMS_SUCCESS("augment ", YCTX, LY_STMT_AUGMENT, "augment");
+    TEST_STMS_SUCCESS("base ", YCTX, LY_STMT_BASE, "base");
+    TEST_STMS_SUCCESS("belongs-to ", YCTX, LY_STMT_BELONGS_TO, "belongs-to");
+    TEST_STMS_SUCCESS("bit ", YCTX, LY_STMT_BIT, "bit");
+    TEST_STMS_SUCCESS("case ", YCTX, LY_STMT_CASE, "case");
+    TEST_STMS_SUCCESS("choice ", YCTX, LY_STMT_CHOICE, "choice");
+    TEST_STMS_SUCCESS("config ", YCTX, LY_STMT_CONFIG, "config");
+    TEST_STMS_SUCCESS("contact ", YCTX, LY_STMT_CONTACT, "contact");
+    TEST_STMS_SUCCESS("container ", YCTX, LY_STMT_CONTAINER, "container");
+    TEST_STMS_SUCCESS("default ", YCTX, LY_STMT_DEFAULT, "default");
+    TEST_STMS_SUCCESS("description ", YCTX, LY_STMT_DESCRIPTION, "description");
+    TEST_STMS_SUCCESS("deviate ", YCTX, LY_STMT_DEVIATE, "deviate");
+    TEST_STMS_SUCCESS("deviation ", YCTX, LY_STMT_DEVIATION, "deviation");
+    TEST_STMS_SUCCESS("enum ", YCTX, LY_STMT_ENUM, "enum");
+    TEST_STMS_SUCCESS("error-app-tag ", YCTX, LY_STMT_ERROR_APP_TAG, "error-app-tag");
+    TEST_STMS_SUCCESS("error-message ", YCTX, LY_STMT_ERROR_MESSAGE, "error-message");
+    TEST_STMS_SUCCESS("extension ", YCTX, LY_STMT_EXTENSION, "extension");
+    TEST_STMS_SUCCESS("feature ", YCTX, LY_STMT_FEATURE, "feature");
+    TEST_STMS_SUCCESS("fraction-digits ", YCTX, LY_STMT_FRACTION_DIGITS, "fraction-digits");
+    TEST_STMS_SUCCESS("grouping ", YCTX, LY_STMT_GROUPING, "grouping");
+    TEST_STMS_SUCCESS("identity ", YCTX, LY_STMT_IDENTITY, "identity");
+    TEST_STMS_SUCCESS("if-feature ", YCTX, LY_STMT_IF_FEATURE, "if-feature");
+    TEST_STMS_SUCCESS("import ", YCTX, LY_STMT_IMPORT, "import");
+    TEST_STMS_SUCCESS("include ", YCTX, LY_STMT_INCLUDE, "include");
+    TEST_STMS_SUCCESS("input{", YCTX, LY_STMT_INPUT, "input");
+    TEST_STMS_SUCCESS("key ", YCTX, LY_STMT_KEY, "key");
+    TEST_STMS_SUCCESS("leaf ", YCTX, LY_STMT_LEAF, "leaf");
+    TEST_STMS_SUCCESS("leaf-list ", YCTX, LY_STMT_LEAF_LIST, "leaf-list");
+    TEST_STMS_SUCCESS("length ", YCTX, LY_STMT_LENGTH, "length");
+    TEST_STMS_SUCCESS("list ", YCTX, LY_STMT_LIST, "list");
+    TEST_STMS_SUCCESS("mandatory ", YCTX, LY_STMT_MANDATORY, "mandatory");
+    TEST_STMS_SUCCESS("max-elements ", YCTX, LY_STMT_MAX_ELEMENTS, "max-elements");
+    TEST_STMS_SUCCESS("min-elements ", YCTX, LY_STMT_MIN_ELEMENTS, "min-elements");
+    TEST_STMS_SUCCESS("modifier ", YCTX, LY_STMT_MODIFIER, "modifier");
+    TEST_STMS_SUCCESS("module ", YCTX, LY_STMT_MODULE, "module");
+    TEST_STMS_SUCCESS("must ", YCTX, LY_STMT_MUST, "must");
+    TEST_STMS_SUCCESS("namespace ", YCTX, LY_STMT_NAMESPACE, "namespace");
+    TEST_STMS_SUCCESS("notification ", YCTX, LY_STMT_NOTIFICATION, "notification");
+    TEST_STMS_SUCCESS("ordered-by ", YCTX, LY_STMT_ORDERED_BY, "ordered-by");
+    TEST_STMS_SUCCESS("organization ", YCTX, LY_STMT_ORGANIZATION, "organization");
+    TEST_STMS_SUCCESS("output ", YCTX, LY_STMT_OUTPUT, "output");
+    TEST_STMS_SUCCESS("path ", YCTX, LY_STMT_PATH, "path");
+    TEST_STMS_SUCCESS("pattern ", YCTX, LY_STMT_PATTERN, "pattern");
+    TEST_STMS_SUCCESS("position ", YCTX, LY_STMT_POSITION, "position");
+    TEST_STMS_SUCCESS("prefix ", YCTX, LY_STMT_PREFIX, "prefix");
+    TEST_STMS_SUCCESS("presence ", YCTX, LY_STMT_PRESENCE, "presence");
+    TEST_STMS_SUCCESS("range ", YCTX, LY_STMT_RANGE, "range");
+    TEST_STMS_SUCCESS("reference ", YCTX, LY_STMT_REFERENCE, "reference");
+    TEST_STMS_SUCCESS("refine ", YCTX, LY_STMT_REFINE, "refine");
+    TEST_STMS_SUCCESS("require-instance ", YCTX, LY_STMT_REQUIRE_INSTANCE, "require-instance");
+    TEST_STMS_SUCCESS("revision ", YCTX, LY_STMT_REVISION, "revision");
+    TEST_STMS_SUCCESS("revision-date ", YCTX, LY_STMT_REVISION_DATE, "revision-date");
+    TEST_STMS_SUCCESS("rpc ", YCTX, LY_STMT_RPC, "rpc");
+    TEST_STMS_SUCCESS("status ", YCTX, LY_STMT_STATUS, "status");
+    TEST_STMS_SUCCESS("submodule ", YCTX, LY_STMT_SUBMODULE, "submodule");
+    TEST_STMS_SUCCESS("type ", YCTX, LY_STMT_TYPE, "type");
+    TEST_STMS_SUCCESS("typedef ", YCTX, LY_STMT_TYPEDEF, "typedef");
+    TEST_STMS_SUCCESS("unique ", YCTX, LY_STMT_UNIQUE, "unique");
+    TEST_STMS_SUCCESS("units ", YCTX, LY_STMT_UNITS, "units");
+    TEST_STMS_SUCCESS("uses ", YCTX, LY_STMT_USES, "uses");
+    TEST_STMS_SUCCESS("value ", YCTX, LY_STMT_VALUE, "value");
+    TEST_STMS_SUCCESS("when ", YCTX, LY_STMT_WHEN, "when");
+    TEST_STMS_SUCCESS("yang-version ", YCTX, LY_STMT_YANG_VERSION, "yang-version");
+    TEST_STMS_SUCCESS("yin-element ", YCTX, LY_STMT_YIN_ELEMENT, "yin-element");
+    TEST_STMS_SUCCESS(";config false;", YCTX, LY_STMT_SYNTAX_SEMICOLON, ";");
     assert_string_equal("config false;", in.current);
-    in.current = "{ config false;";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_SYNTAX_LEFT_BRACE, kw);
-    assert_int_equal(1, len);
+    TEST_STMS_SUCCESS("{ config false;", YCTX, LY_STMT_SYNTAX_LEFT_BRACE, "{");
     assert_string_equal(" config false;", in.current);
-    in.current = "}";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
-    assert_int_equal(LY_STMT_SYNTAX_RIGHT_BRACE, kw);
-    assert_int_equal(1, len);
+    TEST_STMS_SUCCESS("}", YCTX, LY_STMT_SYNTAX_RIGHT_BRACE, "}");
     assert_string_equal("", in.current);
 
     /* geenric extension */
     in.current = p = "nacm:default-deny-write;";
-    assert_int_equal(LY_SUCCESS, get_keyword(ctx, &in, &kw, &word, &len));
+    assert_int_equal(LY_SUCCESS, get_keyword(YCTX, &in, &kw, &word, &len));
     assert_int_equal(LY_STMT_EXTENSION_INSTANCE, kw);
     assert_int_equal(23, len);
     assert_ptr_equal(p, word);
 }
 
+#define TEST_MINMAX_SUCCESS(INPUT_TEXT, CTX, TYPE, VALUE)\
+    in.current = INPUT_TEXT;\
+    if(TYPE == LYS_SET_MIN){\
+       assert_int_equal(LY_SUCCESS, parse_minelements(CTX, &in, &value, &flags, &ext));\
+    }\
+    if(TYPE == LYS_SET_MAX){\
+       assert_int_equal(LY_SUCCESS, parse_maxelements(CTX, &in, &value, &flags, &ext));\
+    }\
+    assert_int_equal(TYPE, flags);\
+    assert_int_equal(VALUE, value)
+
 static void
 test_minmax(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     uint16_t flags = 0;
     uint32_t value = 0;
     struct lysp_ext_instance *ext = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     in.current = " 1invalid; ...";
-    assert_int_equal(LY_EVALID, parse_minelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Invalid value \"1invalid\" of \"min-elements\". Line number 1.");
+    assert_int_equal(LY_EVALID, parse_minelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Invalid value \"1invalid\" of \"min-elements\".", "Line number 1.");
 
     flags = value = 0;
     in.current = " -1; ...";
-    assert_int_equal(LY_EVALID, parse_minelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Invalid value \"-1\" of \"min-elements\". Line number 1.");
+    assert_int_equal(LY_EVALID, parse_minelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Invalid value \"-1\" of \"min-elements\".", "Line number 1.");
 
     /* implementation limit */
     flags = value = 0;
     in.current = " 4294967296; ...";
-    assert_int_equal(LY_EVALID, parse_minelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Value \"4294967296\" is out of \"min-elements\" bounds. Line number 1.");
+    assert_int_equal(LY_EVALID, parse_minelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Value \"4294967296\" is out of \"min-elements\" bounds.", "Line number 1.");
 
     flags = value = 0;
-    in.current = " 1; ...";
-    assert_int_equal(LY_SUCCESS, parse_minelements(ctx, &in, &value, &flags, &ext));
-    assert_int_equal(LYS_SET_MIN, flags);
-    assert_int_equal(1, value);
+    TEST_MINMAX_SUCCESS(" 1; ...", YCTX, LYS_SET_MIN, 1);
 
     flags = value = 0;
-    in.current = " 1 {m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_minelements(ctx, &in, &value, &flags, &ext));
-    assert_int_equal(LYS_SET_MIN, flags);
-    assert_int_equal(1, value);
+    TEST_MINMAX_SUCCESS(" 1 {m:ext;} ...", YCTX, LYS_SET_MIN, 1);
     assert_non_null(ext);
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, ext, lysp_ext_instance_free);
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, ext, lysp_ext_instance_free);
     ext = NULL;
 
     flags = value = 0;
     in.current = " 1 {config true;} ...";
-    assert_int_equal(LY_EVALID, parse_minelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Invalid keyword \"config\" as a child of \"min-elements\". Line number 1.");
+    assert_int_equal(LY_EVALID, parse_minelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"min-elements\".", "Line number 1.");
 
     in.current = " 1invalid; ...";
-    assert_int_equal(LY_EVALID, parse_maxelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Invalid value \"1invalid\" of \"max-elements\". Line number 1.");
+    assert_int_equal(LY_EVALID, parse_maxelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Invalid value \"1invalid\" of \"max-elements\".", "Line number 1.");
 
     flags = value = 0;
     in.current = " -1; ...";
-    assert_int_equal(LY_EVALID, parse_maxelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Invalid value \"-1\" of \"max-elements\". Line number 1.");
+    assert_int_equal(LY_EVALID, parse_maxelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Invalid value \"-1\" of \"max-elements\".", "Line number 1.");
 
     /* implementation limit */
     flags = value = 0;
     in.current = " 4294967296; ...";
-    assert_int_equal(LY_EVALID, parse_maxelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Value \"4294967296\" is out of \"max-elements\" bounds. Line number 1.");
+    assert_int_equal(LY_EVALID, parse_maxelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Value \"4294967296\" is out of \"max-elements\" bounds.", "Line number 1.");
 
     flags = value = 0;
-    in.current = " 1; ...";
-    assert_int_equal(LY_SUCCESS, parse_maxelements(ctx, &in, &value, &flags, &ext));
-    assert_int_equal(LYS_SET_MAX, flags);
-    assert_int_equal(1, value);
+    TEST_MINMAX_SUCCESS(" 1; ...", YCTX, LYS_SET_MAX, 1);
 
     flags = value = 0;
-    in.current = " unbounded; ...";
-    assert_int_equal(LY_SUCCESS, parse_maxelements(ctx, &in, &value, &flags, &ext));
-    assert_int_equal(LYS_SET_MAX, flags);
-    assert_int_equal(0, value);
+    TEST_MINMAX_SUCCESS(" unbounded; ...", YCTX, LYS_SET_MAX, 0);
 
     flags = value = 0;
-    in.current = " 1 {m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_maxelements(ctx, &in, &value, &flags, &ext));
-    assert_int_equal(LYS_SET_MAX, flags);
-    assert_int_equal(1, value);
+    TEST_MINMAX_SUCCESS(" 1 {m:ext;} ...", YCTX, LYS_SET_MAX, 1);
     assert_non_null(ext);
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, ext, lysp_ext_instance_free);
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, ext, lysp_ext_instance_free);
     ext = NULL;
 
     flags = value = 0;
     in.current = " 1 {config true;} ...";
-    assert_int_equal(LY_EVALID, parse_maxelements(ctx, &in, &value, &flags, &ext));
-    logbuf_assert("Invalid keyword \"config\" as a child of \"max-elements\". Line number 1.");
+    assert_int_equal(LY_EVALID, parse_maxelements(YCTX, &in, &value, &flags, &ext));
+    CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"max-elements\".", "Line number 1.");
 }
 
 static struct lysp_module *
@@ -872,51 +574,51 @@
 static void
 test_module(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_module *mod = NULL;
     struct lysp_submodule *submod = NULL;
     struct lys_module *m;
     struct ly_in in = {0};
     struct lys_glob_unres unres = {0};
+    struct lys_yang_parser_ctx *ctx_p;
 
-    mod = mod_renew(ctx);
+    mod = mod_renew(YCTX);
 
     /* missing mandatory substatements */
     in.current = " name {}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
     assert_string_equal("name", mod->mod->name);
-    logbuf_assert("Missing mandatory keyword \"namespace\" as a child of \"module\". Line number 1.");
-    mod = mod_renew(ctx);
+    CHECK_LOG_CTX("Missing mandatory keyword \"namespace\" as a child of \"module\".", "Line number 1.");
 
+    mod = mod_renew(YCTX);
     in.current = " name {namespace urn:x;}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
     assert_string_equal("urn:x", mod->mod->ns);
-    logbuf_assert("Missing mandatory keyword \"prefix\" as a child of \"module\". Line number 1.");
-    mod = mod_renew(ctx);
+    CHECK_LOG_CTX("Missing mandatory keyword \"prefix\" as a child of \"module\".", "Line number 1.");
+    mod = mod_renew(YCTX);
 
     in.current = " name {namespace urn:x;prefix \"x\";}";
-    assert_int_equal(LY_SUCCESS, parse_module(ctx, &in, mod));
+    assert_int_equal(LY_SUCCESS, parse_module(YCTX, &in, mod));
     assert_string_equal("x", mod->mod->prefix);
-    mod = mod_renew(ctx);
+    mod = mod_renew(YCTX);
 
 #define SCHEMA_BEGINNING " name {yang-version 1.1;namespace urn:x;prefix \"x\";"
 #define SCHEMA_BEGINNING2 " name {namespace urn:x;prefix \"x\";"
 #define TEST_NODE(NODETYPE, INPUT, NAME) \
         in.current = SCHEMA_BEGINNING INPUT; \
-        assert_int_equal(LY_SUCCESS, parse_module(ctx, &in, mod)); \
+        assert_int_equal(LY_SUCCESS, parse_module(YCTX, &in, mod)); \
         assert_non_null(mod->data); \
         assert_int_equal(NODETYPE, mod->data->nodetype); \
         assert_string_equal(NAME, mod->data->name); \
-        mod = mod_renew(ctx);
+        mod = mod_renew(YCTX);
 #define TEST_GENERIC(INPUT, TARGET, TEST) \
         in.current = SCHEMA_BEGINNING INPUT; \
-        assert_int_equal(LY_SUCCESS, parse_module(ctx, &in, mod)); \
+        assert_int_equal(LY_SUCCESS, parse_module(YCTX, &in, mod)); \
         assert_non_null(TARGET); \
         TEST; \
-        mod = mod_renew(ctx);
+        mod = mod_renew(YCTX);
 #define TEST_DUP(MEMBER, VALUE1, VALUE2, LINE) \
         TEST_DUP_GENERIC(SCHEMA_BEGINNING, MEMBER, VALUE1, VALUE2, \
-                         parse_module, mod, LINE, mod = mod_renew(ctx))
+                         parse_module, mod, LINE, mod = mod_renew(YCTX))
 
     /* duplicated namespace, prefix */
     TEST_DUP("namespace", "y", "z", "1");
@@ -928,9 +630,9 @@
 
     /* not allowed in module (submodule-specific) */
     in.current = SCHEMA_BEGINNING "belongs-to master {prefix m;}}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
-    logbuf_assert("Invalid keyword \"belongs-to\" as a child of \"module\". Line number 1.");
-    mod = mod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
+    CHECK_LOG_CTX("Invalid keyword \"belongs-to\" as a child of \"module\".", "Line number 1.");
+    mod = mod_renew(YCTX);
 
     /* anydata */
     TEST_NODE(LYS_ANYDATA, "anydata test;}", "test");
@@ -965,39 +667,37 @@
     TEST_GENERIC("identity test;}", mod->identities,
             assert_string_equal("test", mod->identities[0].name));
     /* import */
-    ly_ctx_set_module_imp_clb(ctx->parsed_mod->mod->ctx, test_imp_clb, "module zzz { namespace urn:zzz; prefix z;}");
+    ly_ctx_set_module_imp_clb(YCTX->parsed_mod->mod->ctx, test_imp_clb, "module zzz { namespace urn:zzz; prefix z;}");
     TEST_GENERIC("import zzz {prefix z;}}", mod->imports,
             assert_string_equal("zzz", mod->imports[0].name));
 
     /* import - prefix collision */
     in.current = SCHEMA_BEGINNING "import zzz {prefix x;}}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
-    logbuf_assert("Prefix \"x\" already used as module prefix. Line number 2.");
-    mod = mod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
+    CHECK_LOG_CTX("Prefix \"x\" already used as module prefix.", "Line number 2.");
+    mod = mod_renew(YCTX);
+
     in.current = SCHEMA_BEGINNING "import zzz {prefix y;}import zzz {prefix y;}}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
-    logbuf_assert("Prefix \"y\" already used to import \"zzz\" module. Line number 2.");
-    mod = mod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
+    CHECK_LOG_CTX("Prefix \"y\" already used to import \"zzz\" module.", "Line number 2.");
+
+    mod = mod_renew(YCTX);
     in.current = "module name10 {yang-version 1.1;namespace urn:x;prefix \"x\";import zzz {prefix y;}import zzz {prefix z;}}";
-    assert_int_equal(lys_parse_mem(ctx->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("Single revision of the module \"zzz\" imported twice.");
+    assert_int_equal(lys_parse_mem(YCTX->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX("Single revision of the module \"zzz\" imported twice.", NULL);
 
     /* include */
-    store = 1;
-    ly_ctx_set_module_imp_clb(ctx->parsed_mod->mod->ctx, test_imp_clb, "module xxx { namespace urn:xxx; prefix x;}");
+    ly_ctx_set_module_imp_clb(YCTX->parsed_mod->mod->ctx, test_imp_clb, "module xxx { namespace urn:xxx; prefix x;}");
     in.current = "module" SCHEMA_BEGINNING "include xxx;}";
-    assert_int_equal(lys_parse_mem(ctx->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
-    logbuf_assert("Input data contains module in situation when a submodule is expected.");
-    store = -1;
+    assert_int_equal(lys_parse_mem(YCTX->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Including \"xxx\" submodule into \"name\" failed.", NULL);
 
-    store = 1;
-    ly_ctx_set_module_imp_clb(ctx->parsed_mod->mod->ctx, test_imp_clb, "submodule xxx {belongs-to wrong-name {prefix w;}}");
+    ly_ctx_set_module_imp_clb(YCTX->parsed_mod->mod->ctx, test_imp_clb, "submodule xxx {belongs-to wrong-name {prefix w;}}");
     in.current = "module" SCHEMA_BEGINNING "include xxx;}";
-    assert_int_equal(lys_parse_mem(ctx->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
-    logbuf_assert("Submodule \"belongs-to\" value \"wrong-name\" does not match its module name \"name\". Line number 1.");
-    store = -1;
+    assert_int_equal(lys_parse_mem(YCTX->parsed_mod->mod->ctx, in.current, LYS_IN_YANG, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Including \"xxx\" submodule into \"name\" failed.", NULL);
 
-    ly_ctx_set_module_imp_clb(ctx->parsed_mod->mod->ctx, test_imp_clb, "submodule xxx {belongs-to name {prefix x;}}");
+    ly_ctx_set_module_imp_clb(YCTX->parsed_mod->mod->ctx, test_imp_clb, "submodule xxx {belongs-to name {prefix x;}}");
     TEST_GENERIC("include xxx;}", mod->includes,
             assert_string_equal("xxx", mod->includes[0].name));
 
@@ -1029,44 +729,43 @@
     TEST_NODE(LYS_USES, "uses test;}", "test");
     /* yang-version */
     in.current = SCHEMA_BEGINNING2 "\n\tyang-version 10;}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
-    logbuf_assert("Invalid value \"10\" of \"yang-version\". Line number 3.");
-    mod = mod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
+    CHECK_LOG_CTX("Invalid value \"10\" of \"yang-version\".", "Line number 3.");
+    mod = mod_renew(YCTX);
     in.current = SCHEMA_BEGINNING2 "yang-version 1;yang-version 1.1;}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
-    logbuf_assert("Duplicate keyword \"yang-version\". Line number 3.");
-    mod = mod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
+    CHECK_LOG_CTX("Duplicate keyword \"yang-version\".", "Line number 3.");
+    mod = mod_renew(YCTX);
     in.current = SCHEMA_BEGINNING2 "yang-version 1;}";
-    assert_int_equal(LY_SUCCESS, parse_module(ctx, &in, mod));
+    assert_int_equal(LY_SUCCESS, parse_module(YCTX, &in, mod));
     assert_int_equal(1, mod->version);
-    mod = mod_renew(ctx);
+    mod = mod_renew(YCTX);
     in.current = SCHEMA_BEGINNING2 "yang-version \"1.1\";}";
-    assert_int_equal(LY_SUCCESS, parse_module(ctx, &in, mod));
+    assert_int_equal(LY_SUCCESS, parse_module(YCTX, &in, mod));
     assert_int_equal(2, mod->version);
-    mod = mod_renew(ctx);
+    mod = mod_renew(YCTX);
 
-    struct lys_yang_parser_ctx *ctx_p = NULL;
     in.current = "module " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
     m = calloc(1, sizeof *m);
-    m->ctx = ctx->parsed_mod->mod->ctx;
+    m->ctx = YCTX->parsed_mod->mod->ctx;
     assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m, &unres));
-    logbuf_assert("Trailing garbage \"module q {names...\" after module, expected end-of-input. Line number 1.");
+    CHECK_LOG_CTX("Trailing garbage \"module q {names...\" after module, expected end-of-input.", "Line number 1.");
     yang_parser_ctx_free(ctx_p);
     lys_module_free(m, NULL);
 
     in.current = "prefix " SCHEMA_BEGINNING "}";
     m = calloc(1, sizeof *m);
-    m->ctx = ctx->parsed_mod->mod->ctx;
+    m->ctx = YCTX->parsed_mod->mod->ctx;
     assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m, &unres));
-    logbuf_assert("Invalid keyword \"prefix\", expected \"module\" or \"submodule\". Line number 1.");
+    CHECK_LOG_CTX("Invalid keyword \"prefix\", expected \"module\" or \"submodule\".", "Line number 1.");
     yang_parser_ctx_free(ctx_p);
     lys_module_free(m, NULL);
 
     in.current = "module " SCHEMA_BEGINNING "leaf enum {type enumeration {enum seven { position 7;}}}}";
     m = calloc(1, sizeof *m);
-    m->ctx = ctx->parsed_mod->mod->ctx;
+    m->ctx = YCTX->parsed_mod->mod->ctx;
     assert_int_equal(LY_EVALID, yang_parse_module(&ctx_p, &in, m, &unres));
-    logbuf_assert("Invalid keyword \"position\" as a child of \"enum\". Line number 1.");
+    CHECK_LOG_CTX("Invalid keyword \"position\" as a child of \"enum\".", "Line number 1.");
     yang_parser_ctx_free(ctx_p);
     lys_module_free(m, NULL);
 
@@ -1074,57 +773,58 @@
     TEST_GENERIC("prefix:test;}", mod->exts,
             assert_string_equal("prefix:test", mod->exts[0].name);
             assert_int_equal(LYEXT_SUBSTMT_SELF, mod->exts[0].insubstmt));
-    mod = mod_renew(ctx);
+    mod = mod_renew(YCTX);
 
     /* invalid substatement */
     in.current = SCHEMA_BEGINNING "must false;}";
-    assert_int_equal(LY_EVALID, parse_module(ctx, &in, mod));
-    logbuf_assert("Invalid keyword \"must\" as a child of \"module\". Line number 3.");
+    assert_int_equal(LY_EVALID, parse_module(YCTX, &in, mod));
+    CHECK_LOG_CTX("Invalid keyword \"must\" as a child of \"module\".", "Line number 3.");
 
     /* submodule */
-    submod = submod_renew(ctx);
+    submod = submod_renew(YCTX);
 
     /* missing mandatory substatements */
     in.current = " subname {}";
-    assert_int_equal(LY_EVALID, parse_submodule(ctx, &in, submod));
+    assert_int_equal(LY_EVALID, parse_submodule(YCTX, &in, submod));
+    CHECK_LOG_CTX("Missing mandatory keyword \"belongs-to\" as a child of \"submodule\".", "Line number 3.");
     assert_string_equal("subname", submod->name);
-    logbuf_assert("Missing mandatory keyword \"belongs-to\" as a child of \"submodule\". Line number 3.");
-    submod = submod_renew(ctx);
+
+    submod = submod_renew(YCTX);
 
     in.current = " subname {belongs-to name {prefix x;}}";
-    assert_int_equal(LY_SUCCESS, parse_submodule(ctx, &in, submod));
+    assert_int_equal(LY_SUCCESS, parse_submodule(YCTX, &in, submod));
     assert_string_equal("name", submod->mod->name);
-    submod = submod_renew(ctx);
+    submod = submod_renew(YCTX);
 
 #undef SCHEMA_BEGINNING
 #define SCHEMA_BEGINNING " subname {belongs-to name {prefix x;}"
 
     /* duplicated namespace, prefix */
     in.current = " subname {belongs-to name {prefix x;}belongs-to module1;belongs-to module2;} ...";
-    assert_int_equal(LY_EVALID, parse_submodule(ctx, &in, submod)); \
-    logbuf_assert("Duplicate keyword \"belongs-to\". Line number 3."); \
-    submod = submod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_submodule(YCTX, &in, submod));
+    CHECK_LOG_CTX("Duplicate keyword \"belongs-to\".", "Line number 3.");
+    submod = submod_renew(YCTX);
 
     /* not allowed in submodule (module-specific) */
     in.current = SCHEMA_BEGINNING "namespace \"urn:z\";}";
-    assert_int_equal(LY_EVALID, parse_submodule(ctx, &in, submod));
-    logbuf_assert("Invalid keyword \"namespace\" as a child of \"submodule\". Line number 3.");
-    submod = submod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_submodule(YCTX, &in, submod));
+    CHECK_LOG_CTX("Invalid keyword \"namespace\" as a child of \"submodule\".", "Line number 3.");
+    submod = submod_renew(YCTX);
     in.current = SCHEMA_BEGINNING "prefix m;}}";
-    assert_int_equal(LY_EVALID, parse_submodule(ctx, &in, submod));
-    logbuf_assert("Invalid keyword \"prefix\" as a child of \"submodule\". Line number 3.");
-    submod = submod_renew(ctx);
+    assert_int_equal(LY_EVALID, parse_submodule(YCTX, &in, submod));
+    CHECK_LOG_CTX("Invalid keyword \"prefix\" as a child of \"submodule\".", "Line number 3.");
+    submod = submod_renew(YCTX);
 
     in.current = "submodule " SCHEMA_BEGINNING "} module q {namespace urn:q;prefixq;}";
-    assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, ctx->parsed_mod->mod->ctx, (struct lys_parser_ctx *)ctx, &in, &submod));
+    assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, YCTX->parsed_mod->mod->ctx, (struct lys_parser_ctx *)YCTX, &in, &submod));
+    CHECK_LOG_CTX("Trailing garbage \"module q {names...\" after submodule, expected end-of-input.", "Line number 1.");
     yang_parser_ctx_free(ctx_p);
-    logbuf_assert("Trailing garbage \"module q {names...\" after submodule, expected end-of-input. Line number 1.");
 
     in.current = "prefix " SCHEMA_BEGINNING "}";
-    assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, ctx->parsed_mod->mod->ctx, (struct lys_parser_ctx *)ctx, &in, &submod));
+    assert_int_equal(LY_EVALID, yang_parse_submodule(&ctx_p, YCTX->parsed_mod->mod->ctx, (struct lys_parser_ctx *)YCTX, &in, &submod));
+    CHECK_LOG_CTX("Invalid keyword \"prefix\", expected \"module\" or \"submodule\".", "Line number 1.");
     yang_parser_ctx_free(ctx_p);
-    logbuf_assert("Invalid keyword \"prefix\", expected \"module\" or \"submodule\". Line number 1.");
-    submod = submod_renew(ctx);
+    submod = submod_renew(YCTX);
 
 #undef TEST_GENERIC
 #undef TEST_NODE
@@ -1135,54 +835,58 @@
 static void
 test_deviation(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_deviation *d = NULL;
     struct ly_in in = {0};
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     TEST_DUP_GENERIC(" test {deviate not-supported;", MEMBER, VALUE1, VALUE2, parse_deviation, \
-                     &d, "1", FREE_ARRAY(ctx->parsed_mod->mod->ctx, d, lysp_deviation_free); d = NULL)
+                     &d, "1", FREE_ARRAY(YCTX->parsed_mod->mod->ctx, d, lysp_deviation_free); d = NULL)
 
     TEST_DUP("description", "a", "b");
     TEST_DUP("reference", "a", "b");
 
     /* full content */
     in.current = " test {deviate not-supported;description text;reference \'another text\';prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviation(ctx, &in, &d));
+    assert_int_equal(LY_SUCCESS, parse_deviation(YCTX, &in, &d));
     assert_non_null(d);
     assert_string_equal(" ...", in.current);
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, d, lysp_deviation_free);
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, d, lysp_deviation_free);
     d = NULL;
 
     /* missing mandatory substatement */
     in.current = " test {description text;}";
-    assert_int_equal(LY_EVALID, parse_deviation(ctx, &in, &d));
-    logbuf_assert("Missing mandatory keyword \"deviate\" as a child of \"deviation\". Line number 1.");
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, d, lysp_deviation_free);
+    assert_int_equal(LY_EVALID, parse_deviation(YCTX, &in, &d));
+    CHECK_LOG_CTX("Missing mandatory keyword \"deviate\" as a child of \"deviation\".", "Line number 1.");
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, d, lysp_deviation_free);
     d = NULL;
 
     /* invalid substatement */
     in.current = " test {deviate not-supported; status obsolete;}";
-    assert_int_equal(LY_EVALID, parse_deviation(ctx, &in, &d));
-    logbuf_assert("Invalid keyword \"status\" as a child of \"deviation\". Line number 1.");
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, d, lysp_deviation_free);
+    assert_int_equal(LY_EVALID, parse_deviation(YCTX, &in, &d));
+    CHECK_LOG_CTX("Invalid keyword \"status\" as a child of \"deviation\".", "Line number 1.");
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, d, lysp_deviation_free);
     d = NULL;
-
 #undef TEST_DUP
 }
 
+#define TEST_DEVIATE_SUCCESS(INPUT_TEXT, REMAIN_TEXT)\
+                    in.current = INPUT_TEXT;\
+                    assert_int_equal(LY_SUCCESS, parse_deviate(YCTX, &in, &d));\
+                    assert_non_null(d);\
+                    assert_string_equal(REMAIN_TEXT, in.current);\
+                    lysp_deviate_free(YCTX->parsed_mod->mod->ctx, d); free(d); d = NULL
+
 static void
 test_deviate(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_deviate *d = NULL;
     struct ly_in in = {0};
 
     /* invalid cardinality */
 #define TEST_DUP(TYPE, MEMBER, VALUE1, VALUE2) \
     TEST_DUP_GENERIC(TYPE" {", MEMBER, VALUE1, VALUE2, parse_deviate, \
-                     &d, "1", lysp_deviate_free(ctx->parsed_mod->mod->ctx, d); free(d); d = NULL)
+                     &d, "1", lysp_deviate_free(YCTX->parsed_mod->mod->ctx, d); free(d); d = NULL)
 
     TEST_DUP("add", "config", "true", "false");
     TEST_DUP("replace", "default", "int8", "uint8");
@@ -1193,33 +897,17 @@
     TEST_DUP("add", "units", "kilometers", "miles");
 
     /* full contents */
-    in.current = " not-supported {prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviate(ctx, &in, &d));
-    assert_non_null(d);
-    assert_string_equal(" ...", in.current);
-    lysp_deviate_free(ctx->parsed_mod->mod->ctx, d); free(d); d = NULL;
-    in.current = " add {units meters; must 1; must 2; unique x; unique y; default a; default b; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviate(ctx, &in, &d));
-    assert_non_null(d);
-    assert_string_equal(" ...", in.current);
-    lysp_deviate_free(ctx->parsed_mod->mod->ctx, d); free(d); d = NULL;
-    in.current = " delete {units meters; must 1; must 2; unique x; unique y; default a; default b; prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviate(ctx, &in, &d));
-    assert_non_null(d);
-    assert_string_equal(" ...", in.current);
-    lysp_deviate_free(ctx->parsed_mod->mod->ctx, d); free(d); d = NULL;
-    in.current = " replace {type string; units meters; default a; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_deviate(ctx, &in, &d));
-    assert_non_null(d);
-    assert_string_equal(" ...", in.current);
-    lysp_deviate_free(ctx->parsed_mod->mod->ctx, d); free(d); d = NULL;
+    TEST_DEVIATE_SUCCESS(" not-supported {prefix:ext;} ...", " ...");
+    TEST_DEVIATE_SUCCESS(" add {units meters; must 1; must 2; unique x; unique y; default a; default b; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...", " ...");
+    TEST_DEVIATE_SUCCESS(" delete {units meters; must 1; must 2; unique x; unique y; default a; default b; prefix:ext;} ...", " ...");
+    TEST_DEVIATE_SUCCESS(" replace {type string; units meters; default a; config true; mandatory true; min-elements 1; max-elements 2; prefix:ext;} ...", " ...");
 
     /* invalid substatements */
 #define TEST_NOT_SUP(DEV, STMT, VALUE) \
     in.current = " "DEV" {"STMT" "VALUE";}..."; \
-    assert_int_equal(LY_EVALID, parse_deviate(ctx, &in, &d)); \
-    logbuf_assert("Deviate \""DEV"\" does not support keyword \""STMT"\". Line number 1."); \
-    lysp_deviate_free(ctx->parsed_mod->mod->ctx, d); free(d); d = NULL
+    assert_int_equal(LY_EVALID, parse_deviate(YCTX, &in, &d)); \
+    CHECK_LOG_CTX("Deviate \""DEV"\" does not support keyword \""STMT"\".", "Line number 1.");\
+    lysp_deviate_free(YCTX->parsed_mod->mod->ctx, d); free(d); d = NULL
 
     TEST_NOT_SUP("not-supported", "units", "meters");
     TEST_NOT_SUP("not-supported", "must", "1");
@@ -1240,10 +928,9 @@
     TEST_NOT_SUP("replace", "unique", "a");
 
     in.current = " nonsence; ...";
-    assert_int_equal(LY_EVALID, parse_deviate(ctx, &in, &d));
-    logbuf_assert("Invalid value \"nonsence\" of \"deviate\". Line number 1.");
+    assert_int_equal(LY_EVALID, parse_deviate(YCTX, &in, &d));
+    CHECK_LOG_CTX("Invalid value \"nonsence\" of \"deviate\".", "Line number 1.");\
     assert_null(d);
-
 #undef TEST_NOT_SUP
 #undef TEST_DUP
 }
@@ -1251,18 +938,17 @@
 static void
 test_container(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_container *c = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "cont {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_container(ctx, &in, NULL, (struct lysp_node**)&c)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)c); c = NULL;
+    assert_int_equal(LY_EVALID, parse_container(YCTX, &in, NULL, (struct lysp_node**)&c)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)c); c = NULL;
 
     TEST_DUP("config", "true", "false");
     TEST_DUP("description", "text1", "text2");
@@ -1275,58 +961,48 @@
     /* full content */
     in.current = "cont {action x;anydata any;anyxml anyxml; choice ch;config false;container c;description test;grouping g;if-feature f; leaf l {type string;}"
             "leaf-list ll {type string;} list li;must 'expr';notification not; presence true; reference test;status current;typedef t {type int8;}uses g;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_container(ctx, &in, NULL, (struct lysp_node **)&c));
-    assert_non_null(c);
-    assert_int_equal(LYS_CONTAINER, c->nodetype);
-    assert_string_equal("cont", c->name);
+    assert_int_equal(LY_SUCCESS, parse_container(YCTX, &in, NULL, (struct lysp_node **)&c));
+    CHECK_LYSP_NODE(c, "test", 1, LYS_CONFIG_R | LYS_STATUS_CURR, 1, "cont", 0, LYS_CONTAINER, 0, "test", 1);
     assert_non_null(c->actions);
     assert_non_null(c->child);
-    assert_string_equal("test", c->dsc);
-    assert_non_null(c->exts);
     assert_non_null(c->groupings);
-    assert_non_null(c->iffeatures);
     assert_non_null(c->musts);
     assert_non_null(c->notifs);
     assert_string_equal("true", c->presence);
-    assert_string_equal("test", c->ref);
     assert_non_null(c->typedefs);
-    assert_non_null(c->when);
-    assert_null(c->parent);
-    assert_null(c->next);
-    assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR, c->flags);
-    ly_set_erase(&ctx->tpdfs_nodes, NULL);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
+    ly_set_erase(&YCTX->tpdfs_nodes, NULL);
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
 
     /* invalid */
     in.current = " cont {augment /root;} ...";
-    assert_int_equal(LY_EVALID, parse_container(ctx, &in, NULL, (struct lysp_node **)&c));
-    logbuf_assert("Invalid keyword \"augment\" as a child of \"container\". Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
+    assert_int_equal(LY_EVALID, parse_container(YCTX, &in, NULL, (struct lysp_node **)&c));
+    CHECK_LOG_CTX("Invalid keyword \"augment\" as a child of \"container\".", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
     in.current = " cont {nonsence true;} ...";
-    assert_int_equal(LY_EVALID, parse_container(ctx, &in, NULL, (struct lysp_node **)&c));
-    logbuf_assert("Invalid character sequence \"nonsence\", expected a keyword. Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
+    assert_int_equal(LY_EVALID, parse_container(YCTX, &in, NULL, (struct lysp_node **)&c));
+    CHECK_LOG_CTX("Invalid character sequence \"nonsence\", expected a keyword.", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
 
-    ctx->parsed_mod->version = 1; /* simulate YANG 1.0 */
+    YCTX->parsed_mod->version = 1; /* simulate YANG 1.0 */
     in.current = " cont {action x;} ...";
-    assert_int_equal(LY_EVALID, parse_container(ctx, &in, NULL, (struct lysp_node **)&c));
-    logbuf_assert("Invalid keyword \"action\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
+    assert_int_equal(LY_EVALID, parse_container(YCTX, &in, NULL, (struct lysp_node **)&c));
+    CHECK_LOG_CTX("Invalid keyword \"action\" as a child of \"container\" - "
+            "the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c); c = NULL;
 }
 
 static void
 test_leaf(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_leaf *l = NULL;
     struct ly_in in = {0};
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_leaf(ctx, &in, NULL, (struct lysp_node**)&l)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)l); l = NULL;
+    assert_int_equal(LY_EVALID, parse_leaf(YCTX, &in, NULL, (struct lysp_node**)&l)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)l); l = NULL;
 
     TEST_DUP("config", "true", "false");
     TEST_DUP("default", "x", "y");
@@ -1342,56 +1018,42 @@
     /* full content - without mandatory which is mutual exclusive with default */
     in.current = "l {config false;default \"xxx\";description test;if-feature f;"
             "must 'expr';reference test;status current;type string; units yyy;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_leaf(ctx, &in, NULL, (struct lysp_node **)&l));
-    assert_non_null(l);
-    assert_int_equal(LYS_LEAF, l->nodetype);
-    assert_string_equal("l", l->name);
-    assert_string_equal("test", l->dsc);
+    assert_int_equal(LY_SUCCESS, parse_leaf(YCTX, &in, NULL, (struct lysp_node **)&l));
+    CHECK_LYSP_NODE(l, "test", 1, LYS_CONFIG_R | LYS_STATUS_CURR, 1, "l", 0, LYS_LEAF, 0, "test", 1);
     assert_string_equal("xxx", l->dflt.str);
     assert_string_equal("yyy", l->units);
     assert_string_equal("string", l->type.name);
-    assert_non_null(l->exts);
-    assert_non_null(l->iffeatures);
     assert_non_null(l->musts);
-    assert_string_equal("test", l->ref);
-    assert_non_null(l->when);
-    assert_null(l->parent);
-    assert_null(l->next);
-    assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR, l->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
 
     /* full content - now with mandatory */
     in.current = "l {mandatory true; type string;} ...";
-    assert_int_equal(LY_SUCCESS, parse_leaf(ctx, &in, NULL, (struct lysp_node **)&l));
-    assert_non_null(l);
-    assert_int_equal(LYS_LEAF, l->nodetype);
-    assert_string_equal("l", l->name);
+    assert_int_equal(LY_SUCCESS, parse_leaf(YCTX, &in, NULL, (struct lysp_node **)&l));
+    CHECK_LYSP_NODE(l, NULL, 0, LYS_MAND_TRUE, 0, "l", 0, LYS_LEAF, 0, NULL, 0);
     assert_string_equal("string", l->type.name);
-    assert_int_equal(LYS_MAND_TRUE, l->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
 
     /* invalid */
     in.current = " l {description \"missing type\";} ...";
-    assert_int_equal(LY_EVALID, parse_leaf(ctx, &in, NULL, (struct lysp_node **)&l));
-    logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf\". Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+    assert_int_equal(LY_EVALID, parse_leaf(YCTX, &in, NULL, (struct lysp_node **)&l));
+    CHECK_LOG_CTX("Missing mandatory keyword \"type\" as a child of \"leaf\".", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
 }
 
 static void
 test_leaflist(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_leaflist *ll = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "ll {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_leaflist(ctx, &in, NULL, (struct lysp_node**)&ll)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)ll); ll = NULL;
+    assert_int_equal(LY_EVALID, parse_leaflist(YCTX, &in, NULL, (struct lysp_node**)&ll)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)ll); ll = NULL;
 
     TEST_DUP("config", "true", "false");
     TEST_DUP("description", "text1", "text2");
@@ -1409,11 +1071,8 @@
     in.current = "ll {config false;default \"xxx\"; default \"yyy\";description test;if-feature f;"
             "max-elements 10;must 'expr';ordered-by user;reference test;"
             "status current;type string; units zzz;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_leaflist(ctx, &in, NULL, (struct lysp_node **)&ll));
-    assert_non_null(ll);
-    assert_int_equal(LYS_LEAFLIST, ll->nodetype);
-    assert_string_equal("ll", ll->name);
-    assert_string_equal("test", ll->dsc);
+    assert_int_equal(LY_SUCCESS, parse_leaflist(YCTX, &in, NULL, (struct lysp_node **)&ll));
+    CHECK_LYSP_NODE(ll, "test", 1, 0x446, 1, "ll", 0, LYS_LEAFLIST, 0, "test", 1);
     assert_non_null(ll->dflts);
     assert_int_equal(2, LY_ARRAY_COUNT(ll->dflts));
     assert_string_equal("xxx", ll->dflts[0].str);
@@ -1422,56 +1081,47 @@
     assert_int_equal(10, ll->max);
     assert_int_equal(0, ll->min);
     assert_string_equal("string", ll->type.name);
-    assert_non_null(ll->exts);
-    assert_non_null(ll->iffeatures);
     assert_non_null(ll->musts);
-    assert_string_equal("test", ll->ref);
-    assert_non_null(ll->when);
-    assert_null(ll->parent);
-    assert_null(ll->next);
     assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_USER | LYS_SET_MAX, ll->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
 
     /* full content - now with min-elements */
     in.current = "ll {min-elements 10; type string;} ...";
-    assert_int_equal(LY_SUCCESS, parse_leaflist(ctx, &in, NULL, (struct lysp_node **)&ll));
-    assert_non_null(ll);
-    assert_int_equal(LYS_LEAFLIST, ll->nodetype);
-    assert_string_equal("ll", ll->name);
+    assert_int_equal(LY_SUCCESS, parse_leaflist(YCTX, &in, NULL, (struct lysp_node **)&ll));
+    CHECK_LYSP_NODE(ll, NULL, 0, 0x200, 0, "ll", 0, LYS_LEAFLIST, 0, NULL, 0);
     assert_string_equal("string", ll->type.name);
     assert_int_equal(0, ll->max);
     assert_int_equal(10, ll->min);
     assert_int_equal(LYS_SET_MIN, ll->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
 
     /* invalid */
     in.current = " ll {description \"missing type\";} ...";
-    assert_int_equal(LY_EVALID, parse_leaflist(ctx, &in, NULL, (struct lysp_node **)&ll));
-    logbuf_assert("Missing mandatory keyword \"type\" as a child of \"leaf-list\". Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+    assert_int_equal(LY_EVALID, parse_leaflist(YCTX, &in, NULL, (struct lysp_node **)&ll));
+    CHECK_LOG_CTX("Missing mandatory keyword \"type\" as a child of \"leaf-list\".", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
 
-    ctx->parsed_mod->version = 1; /* simulate YANG 1.0 - default statement is not allowed */
+    YCTX->parsed_mod->version = 1; /* simulate YANG 1.0 - default statement is not allowed */
     in.current = " ll {default xx; type string;} ...";
-    assert_int_equal(LY_EVALID, parse_leaflist(ctx, &in, NULL, (struct lysp_node **)&ll));
-    logbuf_assert("Invalid keyword \"default\" as a child of \"leaf-list\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
+    assert_int_equal(LY_EVALID, parse_leaflist(YCTX, &in, NULL, (struct lysp_node **)&ll));
+    CHECK_LOG_CTX("Invalid keyword \"default\" as a child of \"leaf-list\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ll); ll = NULL;
 }
 
 static void
 test_list(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_list *l = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_list(ctx, &in, NULL, (struct lysp_node**)&l)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)l); l = NULL;
+    assert_int_equal(LY_EVALID, parse_list(YCTX, &in, NULL, (struct lysp_node**)&l)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)l); l = NULL;
 
     TEST_DUP("config", "true", "false");
     TEST_DUP("description", "text1", "text2");
@@ -1488,11 +1138,9 @@
     in.current = "l {action x;anydata any;anyxml anyxml; choice ch;config false;container c;description test;grouping g;if-feature f; key l; leaf l {type string;}"
             "leaf-list ll {type string;} list li;max-elements 10; min-elements 1;must 'expr';notification not; ordered-by system; reference test;"
             "status current;typedef t {type int8;}unique xxx;unique yyy;uses g;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_list(ctx, &in, NULL, (struct lysp_node **)&l));
-    assert_non_null(l);
-    assert_int_equal(LYS_LIST, l->nodetype);
-    assert_string_equal("l", l->name);
-    assert_string_equal("test", l->dsc);
+    assert_int_equal(LY_SUCCESS, parse_list(YCTX, &in, NULL, (struct lysp_node **)&l));
+    CHECK_LYSP_NODE(l, "test", 1, LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_MAX | LYS_SET_MIN, 1, "l",
+            0, LYS_LIST, 0, "test", 1);
     assert_string_equal("l", l->key);
     assert_non_null(l->uniques);
     assert_int_equal(2, LY_ARRAY_COUNT(l->uniques));
@@ -1500,40 +1148,32 @@
     assert_string_equal("yyy", l->uniques[1].str);
     assert_int_equal(10, l->max);
     assert_int_equal(1, l->min);
-    assert_non_null(l->exts);
-    assert_non_null(l->iffeatures);
     assert_non_null(l->musts);
-    assert_string_equal("test", l->ref);
-    assert_non_null(l->when);
-    assert_null(l->parent);
-    assert_null(l->next);
-    assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_MAX | LYS_SET_MIN, l->flags);
-    ly_set_erase(&ctx->tpdfs_nodes, NULL);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+    ly_set_erase(&YCTX->tpdfs_nodes, NULL);
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
 
     /* invalid content */
-    ctx->parsed_mod->version = 1; /* simulate YANG 1.0 */
+    YCTX->parsed_mod->version = 1; /* simulate YANG 1.0 */
     in.current = "l {action x;} ...";
-    assert_int_equal(LY_EVALID, parse_list(ctx, &in, NULL, (struct lysp_node **)&l));
-    logbuf_assert("Invalid keyword \"action\" as a child of \"list\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+    assert_int_equal(LY_EVALID, parse_list(YCTX, &in, NULL, (struct lysp_node **)&l));
+    CHECK_LOG_CTX("Invalid keyword \"action\" as a child of \"list\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
 }
 
 static void
 test_choice(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_choice *ch = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "ch {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_choice(ctx, &in, NULL, (struct lysp_node**)&ch)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)ch); ch = NULL;
+    assert_int_equal(LY_EVALID, parse_choice(YCTX, &in, NULL, (struct lysp_node**)&ch)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)ch); ch = NULL;
 
     TEST_DUP("config", "true", "false");
     TEST_DUP("default", "a", "b");
@@ -1547,46 +1187,32 @@
     /* full content - without default due to a collision with mandatory */
     in.current = "ch {anydata any;anyxml anyxml; case c;choice ch;config false;container c;description test;if-feature f;leaf l {type string;}"
             "leaf-list ll {type string;} list li;mandatory true;reference test;status current;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_choice(ctx, &in, NULL, (struct lysp_node **)&ch));
-    assert_non_null(ch);
-    assert_int_equal(LYS_CHOICE, ch->nodetype);
-    assert_string_equal("ch", ch->name);
-    assert_string_equal("test", ch->dsc);
-    assert_non_null(ch->exts);
-    assert_non_null(ch->iffeatures);
-    assert_string_equal("test", ch->ref);
-    assert_non_null(ch->when);
-    assert_null(ch->parent);
-    assert_null(ch->next);
-    assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE, ch->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)ch); ch = NULL;
+    assert_int_equal(LY_SUCCESS, parse_choice(YCTX, &in, NULL, (struct lysp_node **)&ch));
+    CHECK_LYSP_NODE(ch, "test", 1, LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE, 1, "ch", 0, LYS_CHOICE, 0, "test", 1);
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ch); ch = NULL;
 
     /* full content - the default missing from the previous node */
     in.current = "ch {default c;case c;} ...";
-    assert_int_equal(LY_SUCCESS, parse_choice(ctx, &in, NULL, (struct lysp_node **)&ch));
-    assert_non_null(ch);
-    assert_int_equal(LYS_CHOICE, ch->nodetype);
-    assert_string_equal("ch", ch->name);
+    assert_int_equal(LY_SUCCESS, parse_choice(YCTX, &in, NULL, (struct lysp_node **)&ch));
+    CHECK_LYSP_NODE(ch, NULL, 0, 0, 0, "ch", 0, LYS_CHOICE, 0, NULL, 0);
     assert_string_equal("c", ch->dflt.str);
-    assert_int_equal(0, ch->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)ch); ch = NULL;
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)ch); ch = NULL;
 }
 
 static void
 test_case(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_case *cs = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "cs {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_case(ctx, &in, NULL, (struct lysp_node**)&cs)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)cs); cs = NULL;
+    assert_int_equal(LY_EVALID, parse_case(YCTX, &in, NULL, (struct lysp_node**)&cs)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)cs); cs = NULL;
 
     TEST_DUP("description", "text1", "text2");
     TEST_DUP("reference", "1", "2");
@@ -1597,46 +1223,35 @@
     /* full content */
     in.current = "cs {anydata any;anyxml anyxml; choice ch;container c;description test;if-feature f;leaf l {type string;}"
             "leaf-list ll {type string;} list li;reference test;status current;uses grp;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_case(ctx, &in, NULL, (struct lysp_node **)&cs));
-    assert_non_null(cs);
-    assert_int_equal(LYS_CASE, cs->nodetype);
-    assert_string_equal("cs", cs->name);
-    assert_string_equal("test", cs->dsc);
-    assert_non_null(cs->exts);
-    assert_non_null(cs->iffeatures);
-    assert_string_equal("test", cs->ref);
-    assert_non_null(cs->when);
-    assert_null(cs->parent);
-    assert_null(cs->next);
-    assert_int_equal(LYS_STATUS_CURR, cs->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)cs); cs = NULL;
+    assert_int_equal(LY_SUCCESS, parse_case(YCTX, &in, NULL, (struct lysp_node **)&cs));
+    CHECK_LYSP_NODE(cs, "test", 1, LYS_STATUS_CURR, 1, "cs", 0, LYS_CASE, 0, "test", 1);
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)cs); cs = NULL;
 
     /* invalid content */
     in.current = "cs {config true} ...";
-    assert_int_equal(LY_EVALID, parse_case(ctx, &in, NULL, (struct lysp_node **)&cs));
-    logbuf_assert("Invalid keyword \"config\" as a child of \"case\". Line number 1.");
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)cs); cs = NULL;
+    assert_int_equal(LY_EVALID, parse_case(YCTX, &in, NULL, (struct lysp_node **)&cs));
+    CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"case\".", "Line number 1.");
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)cs); cs = NULL;
 }
 
 static void
 test_any(void **state, enum ly_stmt kw)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_anydata *any = NULL;
     struct ly_in in = {0};
 
     if (kw == LY_STMT_ANYDATA) {
-        ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+        YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
     } else {
-        ctx->parsed_mod->version = 1; /* simulate YANG 1.0 */
+        YCTX->parsed_mod->version = 1; /* simulate YANG 1.0 */
     }
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_any(ctx, &in, kw, NULL, (struct lysp_node**)&any)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)any); any = NULL;
+    assert_int_equal(LY_EVALID, parse_any(YCTX, &in, kw, NULL, (struct lysp_node**)&any)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)any); any = NULL;
 
     TEST_DUP("config", "true", "false");
     TEST_DUP("description", "text1", "text2");
@@ -1648,20 +1263,12 @@
 
     /* full content */
     in.current = "any {config true;description test;if-feature f;mandatory true;must 'expr';reference test;status current;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_any(ctx, &in, kw, NULL, (struct lysp_node **)&any));
-    assert_non_null(any);
-    assert_int_equal(kw == LY_STMT_ANYDATA ? LYS_ANYDATA : LYS_ANYXML, any->nodetype);
-    assert_string_equal("any", any->name);
-    assert_string_equal("test", any->dsc);
-    assert_non_null(any->exts);
-    assert_non_null(any->iffeatures);
+    assert_int_equal(LY_SUCCESS, parse_any(YCTX, &in, kw, NULL, (struct lysp_node **)&any));
+    // CHECK_LYSP_NODE(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, TYPE, PARENT, REF, WHEN)
+    uint16_t node_type = kw == LY_STMT_ANYDATA ? LYS_ANYDATA : LYS_ANYXML;
+    CHECK_LYSP_NODE(any, "test", 1, LYS_CONFIG_W | LYS_STATUS_CURR | LYS_MAND_TRUE, 1, "any", 0, node_type, 0, "test", 1);
     assert_non_null(any->musts);
-    assert_string_equal("test", any->ref);
-    assert_non_null(any->when);
-    assert_null(any->parent);
-    assert_null(any->next);
-    assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR | LYS_MAND_TRUE, any->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)any); any = NULL;
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)any); any = NULL;
 }
 
 static void
@@ -1679,18 +1286,17 @@
 static void
 test_grouping(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_grp *grp = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_grouping(ctx, &in, NULL, &grp)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
+    assert_int_equal(LY_EVALID, parse_grouping(YCTX, &in, NULL, &grp)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
 
     TEST_DUP("description", "text1", "text2");
     TEST_DUP("reference", "1", "2");
@@ -1700,7 +1306,7 @@
     /* full content */
     in.current = "grp {action x;anydata any;anyxml anyxml; choice ch;container c;description test;grouping g;leaf l {type string;}"
             "leaf-list ll {type string;} list li;notification not;reference test;status current;typedef t {type int8;}uses g;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_grouping(ctx, &in, NULL, &grp));
+    assert_int_equal(LY_SUCCESS, parse_grouping(YCTX, &in, NULL, &grp));
     assert_non_null(grp);
     assert_int_equal(LYS_GROUPING, grp->nodetype);
     assert_string_equal("grp", grp->name);
@@ -1709,37 +1315,36 @@
     assert_string_equal("test", grp->ref);
     assert_null(grp->parent);
     assert_int_equal(LYS_STATUS_CURR, grp->flags);
-    ly_set_erase(&ctx->tpdfs_nodes, NULL);
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
+    ly_set_erase(&YCTX->tpdfs_nodes, NULL);
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
 
     /* invalid content */
     in.current = "grp {config true} ...";
-    assert_int_equal(LY_EVALID, parse_grouping(ctx, &in, NULL, &grp));
-    logbuf_assert("Invalid keyword \"config\" as a child of \"grouping\". Line number 1.");
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
+    assert_int_equal(LY_EVALID, parse_grouping(YCTX, &in, NULL, &grp));
+    CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"grouping\".", "Line number 1.");
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
 
     in.current = "grp {must 'expr'} ...";
-    assert_int_equal(LY_EVALID, parse_grouping(ctx, &in, NULL, &grp));
-    logbuf_assert("Invalid keyword \"must\" as a child of \"grouping\". Line number 1.");
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
+    assert_int_equal(LY_EVALID, parse_grouping(YCTX, &in, NULL, &grp));
+    CHECK_LOG_CTX("Invalid keyword \"must\" as a child of \"grouping\".", "Line number 1.");
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, grp, lysp_grp_free); grp = NULL;
 }
 
 static void
 test_action(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_action *rpcs = NULL;
     struct lysp_node_container *c = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_action(ctx, &in, NULL, &rpcs)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, rpcs, lysp_action_free); rpcs = NULL;
+    assert_int_equal(LY_EVALID, parse_action(YCTX, &in, NULL, &rpcs)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, rpcs, lysp_action_free); rpcs = NULL;
 
     TEST_DUP("description", "text1", "text2");
     TEST_DUP("input", "{leaf l1 {type empty;}} description a", "{leaf l2 {type empty;}} description a");
@@ -1750,13 +1355,13 @@
 
     /* full content */
     in.current = "top;";
-    assert_int_equal(LY_SUCCESS, parse_container(ctx, &in, NULL, (struct lysp_node **)&c));
+    assert_int_equal(LY_SUCCESS, parse_container(YCTX, &in, NULL, (struct lysp_node **)&c));
     in.current = "func {description test;grouping grp;if-feature f;reference test;status current;typedef mytype {type int8;} m:ext;"
             "input {anydata a1; anyxml a2; choice ch; container c; grouping grp; leaf l {type int8;} leaf-list ll {type int8;}"
             " list li; must 1; typedef mytypei {type int8;} uses grp; m:ext;}"
             "output {anydata a1; anyxml a2; choice ch; container c; grouping grp; leaf l {type int8;} leaf-list ll {type int8;}"
             " list li; must 1; typedef mytypeo {type int8;} uses grp; m:ext;}} ...";
-    assert_int_equal(LY_SUCCESS, parse_action(ctx, &in, (struct lysp_node *)c, &rpcs));
+    assert_int_equal(LY_SUCCESS, parse_action(YCTX, &in, (struct lysp_node *)c, &rpcs));
     assert_non_null(rpcs);
     assert_int_equal(LYS_ACTION, rpcs->nodetype);
     assert_string_equal("func", rpcs->name);
@@ -1782,34 +1387,33 @@
     assert_non_null(rpcs->output.typedefs);
     assert_non_null(rpcs->output.data);
 
-    ly_set_erase(&ctx->tpdfs_nodes, NULL);
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, rpcs, lysp_action_free); rpcs = NULL;
+    ly_set_erase(&YCTX->tpdfs_nodes, NULL);
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, rpcs, lysp_action_free); rpcs = NULL;
 
     /* invalid content */
     in.current = "func {config true} ...";
-    assert_int_equal(LY_EVALID, parse_action(ctx, &in, NULL, &rpcs));
-    logbuf_assert("Invalid keyword \"config\" as a child of \"rpc\". Line number 1.");
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, rpcs, lysp_action_free); rpcs = NULL;
+    assert_int_equal(LY_EVALID, parse_action(YCTX, &in, NULL, &rpcs));
+    CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"rpc\".", "Line number 1.");
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, rpcs, lysp_action_free); rpcs = NULL;
 
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)c);
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c);
 }
 
 static void
 test_notification(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_notif *notifs = NULL;
     struct lysp_node_container *c = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "func {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_notif(ctx, &in, NULL, &notifs)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, notifs, lysp_notif_free); notifs = NULL;
+    assert_int_equal(LY_EVALID, parse_notif(YCTX, &in, NULL, &notifs)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, notifs, lysp_notif_free); notifs = NULL;
 
     TEST_DUP("description", "text1", "text2");
     TEST_DUP("reference", "1", "2");
@@ -1818,10 +1422,10 @@
 
     /* full content */
     in.current = "top;";
-    assert_int_equal(LY_SUCCESS, parse_container(ctx, &in, NULL, (struct lysp_node **)&c));
+    assert_int_equal(LY_SUCCESS, parse_container(YCTX, &in, NULL, (struct lysp_node **)&c));
     in.current = "ntf {anydata a1; anyxml a2; choice ch; container c; description test; grouping grp; if-feature f; leaf l {type int8;}"
             "leaf-list ll {type int8;} list li; must 1; reference test; status current; typedef mytype {type int8;} uses grp; m:ext;}";
-    assert_int_equal(LY_SUCCESS, parse_notif(ctx, &in, (struct lysp_node *)c, &notifs));
+    assert_int_equal(LY_SUCCESS, parse_notif(YCTX, &in, (struct lysp_node *)c, &notifs));
     assert_non_null(notifs);
     assert_int_equal(LYS_NOTIF, notifs->nodetype);
     assert_string_equal("ntf", notifs->name);
@@ -1835,33 +1439,32 @@
     assert_non_null(notifs->data);
     assert_int_equal(LYS_STATUS_CURR, notifs->flags);
 
-    ly_set_erase(&ctx->tpdfs_nodes, NULL);
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, notifs, lysp_notif_free); notifs = NULL;
+    ly_set_erase(&YCTX->tpdfs_nodes, NULL);
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, notifs, lysp_notif_free); notifs = NULL;
 
     /* invalid content */
     in.current = "ntf {config true} ...";
-    assert_int_equal(LY_EVALID, parse_notif(ctx, &in, NULL, &notifs));
-    logbuf_assert("Invalid keyword \"config\" as a child of \"notification\". Line number 1.");
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, notifs, lysp_notif_free); notifs = NULL;
+    assert_int_equal(LY_EVALID, parse_notif(YCTX, &in, NULL, &notifs));
+    CHECK_LOG_CTX("Invalid keyword \"config\" as a child of \"notification\".", "Line number 1.");
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, notifs, lysp_notif_free); notifs = NULL;
 
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)c);
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)c);
 }
 
 static void
 test_uses(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_node_uses *u = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_uses(ctx, &in, NULL, (struct lysp_node**)&u)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node*)u); u = NULL;
+    assert_int_equal(LY_EVALID, parse_uses(YCTX, &in, NULL, (struct lysp_node**)&u)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node*)u); u = NULL;
 
     TEST_DUP("description", "text1", "text2");
     TEST_DUP("reference", "1", "2");
@@ -1871,38 +1474,27 @@
 
     /* full content */
     in.current = "grpref {augment some/node;description test;if-feature f;reference test;refine some/other/node;status current;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_uses(ctx, &in, NULL, (struct lysp_node **)&u));
-    assert_non_null(u);
-    assert_int_equal(LYS_USES, u->nodetype);
-    assert_string_equal("grpref", u->name);
-    assert_string_equal("test", u->dsc);
-    assert_non_null(u->exts);
-    assert_non_null(u->iffeatures);
-    assert_string_equal("test", u->ref);
+    assert_int_equal(LY_SUCCESS, parse_uses(YCTX, &in, NULL, (struct lysp_node **)&u));
+    CHECK_LYSP_NODE(u, "test", 1, LYS_STATUS_CURR, 1, "grpref", 0, LYS_USES, 0, "test", 1);
     assert_non_null(u->augments);
     assert_non_null(u->refines);
-    assert_non_null(u->when);
-    assert_null(u->parent);
-    assert_null(u->next);
-    assert_int_equal(LYS_STATUS_CURR, u->flags);
-    lysp_node_free(ctx->parsed_mod->mod->ctx, (struct lysp_node *)u); u = NULL;
+    lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)u); u = NULL;
 }
 
 static void
 test_augment(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_augment *a = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_augment(ctx, &in, NULL, &a)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, a, lysp_augment_free); a = NULL;
+    assert_int_equal(LY_EVALID, parse_augment(YCTX, &in, NULL, &a)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, a, lysp_augment_free); a = NULL;
 
     TEST_DUP("description", "text1", "text2");
     TEST_DUP("reference", "1", "2");
@@ -1913,7 +1505,7 @@
     /* full content */
     in.current = "/target/nodeid {action x; anydata any;anyxml anyxml; case cs; choice ch;container c;description test;if-feature f;leaf l {type string;}"
             "leaf-list ll {type string;} list li;notification not;reference test;status current;uses g;when true;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_augment(ctx, &in, NULL, &a));
+    assert_int_equal(LY_SUCCESS, parse_augment(YCTX, &in, NULL, &a));
     assert_non_null(a);
     assert_int_equal(LYS_AUGMENT, a->nodetype);
     assert_string_equal("/target/nodeid", a->nodeid);
@@ -1924,24 +1516,23 @@
     assert_non_null(a->when);
     assert_null(a->parent);
     assert_int_equal(LYS_STATUS_CURR, a->flags);
-    FREE_ARRAY(ctx->parsed_mod->mod->ctx, a, lysp_augment_free); a = NULL;
+    FREE_ARRAY(YCTX->parsed_mod->mod->ctx, a, lysp_augment_free); a = NULL;
 }
 
 static void
 test_when(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct lysp_when *w = NULL;
     struct ly_in in = {0};
 
-    ctx->parsed_mod->version = 2; /* simulate YANG 1.1 */
+    YCTX->parsed_mod->version = 2; /* simulate YANG 1.1 */
 
     /* invalid cardinality */
 #define TEST_DUP(MEMBER, VALUE1, VALUE2) \
     in.current = "l {" MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, parse_when(ctx, &in, &w)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number 1."); \
-    FREE_MEMBER(ctx->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
+    assert_int_equal(LY_EVALID, parse_when(YCTX, &in, &w)); \
+    CHECK_LOG_CTX("Duplicate keyword \""MEMBER"\".", "Line number 1."); \
+    FREE_MEMBER(YCTX->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
 
     TEST_DUP("description", "text1", "text2");
     TEST_DUP("reference", "1", "2");
@@ -1949,68 +1540,67 @@
 
     /* full content */
     in.current = "expression {description test;reference test;m:ext;} ...";
-    assert_int_equal(LY_SUCCESS, parse_when(ctx, &in, &w));
+    assert_int_equal(LY_SUCCESS, parse_when(YCTX, &in, &w));
     assert_non_null(w);
     assert_string_equal("expression", w->cond);
     assert_string_equal("test", w->dsc);
     assert_string_equal("test", w->ref);
     assert_non_null(w->exts);
-    FREE_MEMBER(ctx->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
+    FREE_MEMBER(YCTX->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
 
     /* empty condition */
     in.current = "\"\";";
-    assert_int_equal(LY_SUCCESS, parse_when(ctx, &in, &w));
-    logbuf_assert("Empty argument of when statement does not make sense.");
+    assert_int_equal(LY_SUCCESS, parse_when(YCTX, &in, &w));
+    CHECK_LOG_CTX("Empty argument of when statement does not make sense.", NULL);
     assert_non_null(w);
     assert_string_equal("", w->cond);
-    FREE_MEMBER(ctx->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
+    FREE_MEMBER(YCTX->parsed_mod->mod->ctx, w, lysp_when_free); w = NULL;
 }
 
 static void
 test_value(void **state)
 {
-    struct lys_yang_parser_ctx *ctx = *state;
     struct ly_in in = {0};
     int64_t val = 0;
     uint16_t flags = 0;
 
     in.current = "-0;";
-    assert_int_equal(parse_type_enum_value_pos(ctx, &in, LY_STMT_VALUE, &val, &flags, NULL), LY_SUCCESS);
+    assert_int_equal(parse_type_enum_value_pos(YCTX, &in, LY_STMT_VALUE, &val, &flags, NULL), LY_SUCCESS);
     assert_int_equal(val, 0);
 
     in.current = "-0;";
     flags = 0;
-    assert_int_equal(parse_type_enum_value_pos(ctx, &in, LY_STMT_POSITION, &val, &flags, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"-0\" of \"position\". Line number 1.");
+    assert_int_equal(parse_type_enum_value_pos(YCTX, &in, LY_STMT_POSITION, &val, &flags, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"-0\" of \"position\".", "Line number 1.");
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_helpers, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_comments, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_arg, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_stmts, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_minmax, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_module, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_deviation, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_deviate, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_container, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_leaf, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_leaflist, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_list, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_choice, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_case, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_anydata, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_anyxml, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_action, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_notification, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_grouping, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_uses, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_augment, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_when, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_value, setup_f, teardown_f),
+        UTEST(test_helpers, setup, teardown),
+        UTEST(test_comments, setup, teardown),
+        UTEST(test_arg, setup, teardown),
+        UTEST(test_stmts, setup, teardown),
+        UTEST(test_minmax, setup, teardown),
+        UTEST(test_module, setup, teardown),
+        UTEST(test_deviation, setup, teardown),
+        UTEST(test_deviate, setup, teardown),
+        UTEST(test_container, setup, teardown),
+        UTEST(test_leaf, setup, teardown),
+        UTEST(test_leaflist, setup, teardown),
+        UTEST(test_list, setup, teardown),
+        UTEST(test_choice, setup, teardown),
+        UTEST(test_case, setup, teardown),
+        UTEST(test_anydata, setup, teardown),
+        UTEST(test_anyxml, setup, teardown),
+        UTEST(test_action, setup, teardown),
+        UTEST(test_notification, setup, teardown),
+        UTEST(test_grouping, setup, teardown),
+        UTEST(test_uses, setup, teardown),
+        UTEST(test_augment, setup, teardown),
+        UTEST(test_when, setup, teardown),
+        UTEST(test_value, setup, teardown),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/schema/test_parser_yin.c b/tests/utests/schema/test_parser_yin.c
index fe33de4..5adcf3a 100644
--- a/tests/utests/schema/test_parser_yin.c
+++ b/tests/utests/schema/test_parser_yin.c
@@ -3,7 +3,7 @@
  * @author David Sedlák <xsedla1d@stud.fit.vutbr.cz>
  * @brief unit tests for functions from parser_yin.c
  *
- * Copyright (c) 2015 - 2019 CESNET, z.s.p.o.
+ * Copyright (c) 2015 - 2020 CESNET, z.s.p.o.
  *
  * This source code is licensed under BSD 3-Clause License (the "License").
  * You may not use this file except in compliance with the License.
@@ -11,6 +11,8 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include <stdbool.h>
 #include <stdio.h>
@@ -22,7 +24,6 @@
 #include "schema_compile.h"
 #include "tree_schema.h"
 #include "tree_schema_internal.h"
-#include "utests.h"
 #include "xml.h"
 #include "xpath.h"
 
@@ -122,251 +123,153 @@
 #define ELEMENT_WRAPPER_START "<status xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
 #define ELEMENT_WRAPPER_END "</status>"
 
-struct test_parser_yin_state {
-    struct ly_ctx *ctx;
-    struct lys_yin_parser_ctx *yin_ctx;
-    struct ly_in *in;
-    bool finished_correctly;
-};
+#define TEST_1_CHECK_LYSP_EXT_INSTANCE(NODE, INSUBSTMT)\
+    CHECK_LYSP_EXT_INSTANCE((NODE), NULL, 1, NULL, INSUBSTMT, 0, "urn:example:extensions:c-define", 0, 0x2, 0x1)
 
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
-
-#define TEST_DUP_GENERIC(PREFIX, MEMBER, VALUE1, VALUE2, FUNC, RESULT, LINE, CLEANUP) \
-    str = PREFIX MEMBER" "VALUE1";"MEMBER" "VALUE2";} ..."; \
-    assert_int_equal(LY_EVALID, FUNC(&ctx, &str, RESULT)); \
-    logbuf_assert("Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
-    CLEANUP
-
-int
-setup_ly_ctx(void **state)
-{
-    struct test_parser_yin_state *st = NULL;
-
-    /* allocate state variable */
-    (*state) = st = calloc(1, sizeof(*st));
-    if (!st) {
-        fprintf(stderr, "Memmory allocation failed");
-        return EXIT_FAILURE;
-    }
-
-    /* create new libyang context */
-    ly_ctx_new(NULL, 0, &st->ctx);
-
-    return EXIT_SUCCESS;
-}
-
-int
-destroy_ly_ctx(void **state)
-{
-    struct test_parser_yin_state *st = *state;
-
-    ly_ctx_destroy(st->ctx, NULL);
-    free(st);
-
-    return EXIT_SUCCESS;
-}
+struct lys_yin_parser_ctx *YCTX;
 
 static int
-setup_f(void **state)
+setup_ctx(void **state)
 {
-    struct test_parser_yin_state *st = *state;
-
-#if ENABLE_LOGGER_CHECKING
-    /* setup logger */
-    ly_set_log_clb(logger, 1);
-#endif
-
     /* allocate parser context */
-    st->yin_ctx = calloc(1, sizeof(*st->yin_ctx));
-    st->yin_ctx->format = LYS_IN_YIN;
+    YCTX = calloc(1, sizeof(*YCTX));
+    YCTX->format = LYS_IN_YIN;
 
     /* allocate new parsed module */
-    st->yin_ctx->parsed_mod = calloc(1, sizeof *st->yin_ctx->parsed_mod);
+    YCTX->parsed_mod = calloc(1, sizeof *YCTX->parsed_mod);
 
     /* allocate new module */
-    st->yin_ctx->parsed_mod->mod = calloc(1, sizeof *st->yin_ctx->parsed_mod->mod);
-    st->yin_ctx->parsed_mod->mod->ctx = st->ctx;
-    st->yin_ctx->parsed_mod->mod->parsed = st->yin_ctx->parsed_mod;
+    YCTX->parsed_mod->mod = calloc(1, sizeof *YCTX->parsed_mod->mod);
+    YCTX->parsed_mod->mod->ctx = UTEST_LYCTX;
+    YCTX->parsed_mod->mod->parsed = YCTX->parsed_mod;
 
-    st->in = NULL;
-
-    return EXIT_SUCCESS;
+    return 0;
 }
 
 static int
-teardown_f(void **state)
+setup(void **state)
 {
-    struct test_parser_yin_state *st = *(struct test_parser_yin_state **)state;
+    UTEST_SETUP;
 
-#if ENABLE_LOGGER_CHECKING
-    /* teardown logger */
-    if (!st->finished_correctly && (logbuf[0] != '\0')) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
+    setup_ctx(state);
 
-    lyxml_ctx_free(st->yin_ctx->xmlctx);
-    lys_module_free(st->yin_ctx->parsed_mod->mod, NULL);
-    free(st->yin_ctx);
-    ly_in_free(st->in, 0);
-
-    return EXIT_SUCCESS;
-}
-
-static struct test_parser_yin_state *
-reset_state(void **state)
-{
-    ((struct test_parser_yin_state *)*state)->finished_correctly = true;
-    logbuf[0] = '\0';
-    teardown_f(state);
-    setup_f(state);
-
-    return *state;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
+    return 0;
 }
 
 static int
-setup_element_test(void **state)
+teardown_ctx(void **UNUSED(state))
 {
-    struct test_parser_yin_state *st;
+    lyxml_ctx_free(YCTX->xmlctx);
+    lys_module_free(YCTX->parsed_mod->mod, NULL);
+    free(YCTX);
+    YCTX = NULL;
 
-    setup_f(state);
-    st = *state;
-
-    lydict_insert(st->ctx, "module-name", 0, &st->yin_ctx->parsed_mod->mod->name);
-
-    return EXIT_SUCCESS;
+    return 0;
 }
 
+static int
+teardown(void **state)
+{
+    teardown_ctx(state);
+
+    UTEST_TEARDOWN;
+
+    return 0;
+}
+
+#define RESET_STATE \
+    ly_in_free(UTEST_IN, 0); \
+    UTEST_IN = NULL; \
+    teardown_ctx(state); \
+    setup_ctx(state)
+
 static void
 test_yin_match_keyword(void **state)
 {
-    struct test_parser_yin_state *st = *state;
-
     const char *prefix;
     size_t prefix_len;
+
     /* create mock yin namespace in xml context */
-    const char *data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />";
+    ly_in_new_memory("<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" />", &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
+    prefix = YCTX->xmlctx->prefix;
+    prefix_len = YCTX->xmlctx->prefix_len;
 
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-    prefix = st->yin_ctx->xmlctx->prefix;
-    prefix_len = st->yin_ctx->xmlctx->prefix_len;
-
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_APP_TAG);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "fraction-digits", strlen("fraction-digits"), prefix,  prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION);
-    assert_int_equal(yin_match_keyword(st->yin_ctx, "yin-element", strlen("yin-element"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YIN_ELEMENT);
-
-    st->finished_correctly = true;
+    assert_int_equal(yin_match_keyword(YCTX, "anydatax", strlen("anydatax"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
+    assert_int_equal(yin_match_keyword(YCTX, "asdasd", strlen("asdasd"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
+    assert_int_equal(yin_match_keyword(YCTX, "", 0, prefix, prefix_len, LY_STMT_NONE), LY_STMT_NONE);
+    assert_int_equal(yin_match_keyword(YCTX, "anydata", strlen("anydata"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYDATA);
+    assert_int_equal(yin_match_keyword(YCTX, "anyxml", strlen("anyxml"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ANYXML);
+    assert_int_equal(yin_match_keyword(YCTX, "argument", strlen("argument"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ARGUMENT);
+    assert_int_equal(yin_match_keyword(YCTX, "augment", strlen("augment"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_AUGMENT);
+    assert_int_equal(yin_match_keyword(YCTX, "base", strlen("base"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BASE);
+    assert_int_equal(yin_match_keyword(YCTX, "belongs-to", strlen("belongs-to"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BELONGS_TO);
+    assert_int_equal(yin_match_keyword(YCTX, "bit", strlen("bit"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_BIT);
+    assert_int_equal(yin_match_keyword(YCTX, "case", strlen("case"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CASE);
+    assert_int_equal(yin_match_keyword(YCTX, "choice", strlen("choice"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CHOICE);
+    assert_int_equal(yin_match_keyword(YCTX, "config", strlen("config"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONFIG);
+    assert_int_equal(yin_match_keyword(YCTX, "contact", strlen("contact"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTACT);
+    assert_int_equal(yin_match_keyword(YCTX, "container", strlen("container"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_CONTAINER);
+    assert_int_equal(yin_match_keyword(YCTX, "default", strlen("default"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEFAULT);
+    assert_int_equal(yin_match_keyword(YCTX, "description", strlen("description"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DESCRIPTION);
+    assert_int_equal(yin_match_keyword(YCTX, "deviate", strlen("deviate"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATE);
+    assert_int_equal(yin_match_keyword(YCTX, "deviation", strlen("deviation"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_DEVIATION);
+    assert_int_equal(yin_match_keyword(YCTX, "enum", strlen("enum"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ENUM);
+    assert_int_equal(yin_match_keyword(YCTX, "error-app-tag", strlen("error-app-tag"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_APP_TAG);
+    assert_int_equal(yin_match_keyword(YCTX, "error-message", strlen("error-message"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ERROR_MESSAGE);
+    assert_int_equal(yin_match_keyword(YCTX, "extension", strlen("extension"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_EXTENSION);
+    assert_int_equal(yin_match_keyword(YCTX, "feature", strlen("feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_FEATURE);
+    assert_int_equal(yin_match_keyword(YCTX, "fraction-digits", strlen("fraction-digits"), prefix,  prefix_len, LY_STMT_NONE), LY_STMT_FRACTION_DIGITS);
+    assert_int_equal(yin_match_keyword(YCTX, "grouping", strlen("grouping"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_GROUPING);
+    assert_int_equal(yin_match_keyword(YCTX, "identity", strlen("identity"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IDENTITY);
+    assert_int_equal(yin_match_keyword(YCTX, "if-feature", strlen("if-feature"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IF_FEATURE);
+    assert_int_equal(yin_match_keyword(YCTX, "import", strlen("import"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_IMPORT);
+    assert_int_equal(yin_match_keyword(YCTX, "include", strlen("include"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INCLUDE);
+    assert_int_equal(yin_match_keyword(YCTX, "input", strlen("input"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_INPUT);
+    assert_int_equal(yin_match_keyword(YCTX, "key", strlen("key"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_KEY);
+    assert_int_equal(yin_match_keyword(YCTX, "leaf", strlen("leaf"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF);
+    assert_int_equal(yin_match_keyword(YCTX, "leaf-list", strlen("leaf-list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LEAF_LIST);
+    assert_int_equal(yin_match_keyword(YCTX, "length", strlen("length"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LENGTH);
+    assert_int_equal(yin_match_keyword(YCTX, "list", strlen("list"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_LIST);
+    assert_int_equal(yin_match_keyword(YCTX, "mandatory", strlen("mandatory"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MANDATORY);
+    assert_int_equal(yin_match_keyword(YCTX, "max-elements", strlen("max-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MAX_ELEMENTS);
+    assert_int_equal(yin_match_keyword(YCTX, "min-elements", strlen("min-elements"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MIN_ELEMENTS);
+    assert_int_equal(yin_match_keyword(YCTX, "modifier", strlen("modifier"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODIFIER);
+    assert_int_equal(yin_match_keyword(YCTX, "module", strlen("module"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MODULE);
+    assert_int_equal(yin_match_keyword(YCTX, "must", strlen("must"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_MUST);
+    assert_int_equal(yin_match_keyword(YCTX, "namespace", strlen("namespace"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NAMESPACE);
+    assert_int_equal(yin_match_keyword(YCTX, "notification", strlen("notification"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_NOTIFICATION);
+    assert_int_equal(yin_match_keyword(YCTX, "ordered-by", strlen("ordered-by"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORDERED_BY);
+    assert_int_equal(yin_match_keyword(YCTX, "organization", strlen("organization"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_ORGANIZATION);
+    assert_int_equal(yin_match_keyword(YCTX, "output", strlen("output"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_OUTPUT);
+    assert_int_equal(yin_match_keyword(YCTX, "path", strlen("path"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATH);
+    assert_int_equal(yin_match_keyword(YCTX, "pattern", strlen("pattern"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PATTERN);
+    assert_int_equal(yin_match_keyword(YCTX, "position", strlen("position"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_POSITION);
+    assert_int_equal(yin_match_keyword(YCTX, "prefix", strlen("prefix"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PREFIX);
+    assert_int_equal(yin_match_keyword(YCTX, "presence", strlen("presence"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_PRESENCE);
+    assert_int_equal(yin_match_keyword(YCTX, "range", strlen("range"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RANGE);
+    assert_int_equal(yin_match_keyword(YCTX, "reference", strlen("reference"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFERENCE);
+    assert_int_equal(yin_match_keyword(YCTX, "refine", strlen("refine"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REFINE);
+    assert_int_equal(yin_match_keyword(YCTX, "require-instance", strlen("require-instance"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REQUIRE_INSTANCE);
+    assert_int_equal(yin_match_keyword(YCTX, "revision", strlen("revision"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION);
+    assert_int_equal(yin_match_keyword(YCTX, "revision-date", strlen("revision-date"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_REVISION_DATE);
+    assert_int_equal(yin_match_keyword(YCTX, "rpc", strlen("rpc"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_RPC);
+    assert_int_equal(yin_match_keyword(YCTX, "status", strlen("status"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_STATUS);
+    assert_int_equal(yin_match_keyword(YCTX, "submodule", strlen("submodule"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_SUBMODULE);
+    assert_int_equal(yin_match_keyword(YCTX, "type", strlen("type"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPE);
+    assert_int_equal(yin_match_keyword(YCTX, "typedef", strlen("typedef"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_TYPEDEF);
+    assert_int_equal(yin_match_keyword(YCTX, "unique", strlen("unique"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNIQUE);
+    assert_int_equal(yin_match_keyword(YCTX, "units", strlen("units"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_UNITS);
+    assert_int_equal(yin_match_keyword(YCTX, "uses", strlen("uses"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_USES);
+    assert_int_equal(yin_match_keyword(YCTX, "value", strlen("value"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_VALUE);
+    assert_int_equal(yin_match_keyword(YCTX, "when", strlen("when"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_WHEN);
+    assert_int_equal(yin_match_keyword(YCTX, "yang-version", strlen("yang-version"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YANG_VERSION);
+    assert_int_equal(yin_match_keyword(YCTX, "yin-element", strlen("yin-element"), prefix, prefix_len, LY_STMT_NONE), LY_STMT_YIN_ELEMENT);
 }
 
 static void
-test_yin_match_argument_name(void **state)
+test_yin_match_argument_name(void **UNUSED(state))
 {
-    (void)state; /* unused */
-
     assert_int_equal(yin_match_argument_name("", 5), YIN_ARG_UNKNOWN);
     assert_int_equal(yin_match_argument_name("qwertyasd", 5), YIN_ARG_UNKNOWN);
     assert_int_equal(yin_match_argument_name("conditionasd", 8), YIN_ARG_UNKNOWN);
@@ -384,95 +287,87 @@
 static void
 test_yin_parse_element_generic(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     struct lysp_ext_instance exts;
     LY_ERR ret;
+    const char *arg;
+    const char *stmt;
+    const char *data;
 
     memset(&exts, 0, sizeof(exts));
 
-    const char *data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
+    data = "<myext:elem attr=\"value\" xmlns:myext=\"urn:example:extensions\">text_value</myext:elem>";
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
 
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-
-    ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child);
+    ret = yin_parse_element_generic(YCTX, LY_STMT_EXTENSION_INSTANCE, &exts.child);
     assert_int_equal(ret, LY_SUCCESS);
-    assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE);
-    assert_string_equal(exts.child->stmt, "urn:example:extensions:elem");
-    assert_string_equal(exts.child->arg, "text_value");
-    assert_string_equal(exts.child->child->stmt, "attr");
-    assert_string_equal(exts.child->child->arg, "value");
-    assert_true(exts.child->child->flags & LYS_YIN_ATTR);
-    lysp_ext_instance_free(st->ctx, &exts);
-    st = reset_state(state);
+    assert_int_equal(YCTX->xmlctx->status, LYXML_ELEM_CLOSE);
+    stmt = "urn:example:extensions:elem";
+    arg = "text_value";
+    CHECK_LYSP_STMT(exts.child, arg, 1, 0, 0x45, 0, stmt);
+    stmt = "attr";
+    arg = "value";
+    CHECK_LYSP_STMT(exts.child->child, arg, 0, 0x400, 0, 0, stmt);
+    lysp_ext_instance_free(UTEST_LYCTX, &exts);
+    RESET_STATE;
 
     data = "<myext:elem xmlns:myext=\"urn:example:extensions\"></myext:elem>";
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
 
-    ret = yin_parse_element_generic(st->yin_ctx, LY_STMT_EXTENSION_INSTANCE, &exts.child);
+    ret = yin_parse_element_generic(YCTX, LY_STMT_EXTENSION_INSTANCE, &exts.child);
     assert_int_equal(ret, LY_SUCCESS);
-    assert_int_equal(st->yin_ctx->xmlctx->status, LYXML_ELEM_CLOSE);
-    assert_string_equal(exts.child->stmt, "urn:example:extensions:elem");
-    assert_null(exts.child->child);
-    assert_null(exts.child->arg);
-    lysp_ext_instance_free(st->ctx, &exts);
-
-    st->finished_correctly = true;
+    assert_int_equal(YCTX->xmlctx->status, LYXML_ELEM_CLOSE);
+    stmt = "urn:example:extensions:elem";
+    CHECK_LYSP_STMT(exts.child, NULL, 0, 0x0, 0x45, 0, stmt);
+    lysp_ext_instance_free(UTEST_LYCTX, &exts);
 }
 
 static void
 test_yin_parse_extension_instance(void **state)
 {
     LY_ERR ret;
-    struct test_parser_yin_state *st = *state;
     struct lysp_ext_instance *exts = NULL;
+    struct lysp_stmt *act_child;
     const char *data = "<myext:ext value1=\"test\" value=\"test2\" xmlns:myext=\"urn:example:extensions\"><myext:subelem>text</myext:subelem></myext:ext>";
+    const char *exts_name;
+    const char *stmt = "value1";
+    const char *arg = "test";
 
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
 
-    ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
+    ret = yin_parse_extension_instance(YCTX, LYEXT_SUBSTMT_CONTACT, 0, &exts);
     assert_int_equal(ret, LY_SUCCESS);
-    assert_string_equal(exts->name, "urn:example:extensions:ext");
-    assert_int_equal(exts->insubstmt_index, 0);
-    assert_true(exts->insubstmt == LYEXT_SUBSTMT_CONTACT);
-    assert_true(exts->yin & LYS_YIN);
-    assert_string_equal(exts->child->stmt, "value1");
-    assert_string_equal(exts->child->arg, "test");
-    assert_null(exts->child->child);
-    assert_true(exts->child->flags & LYS_YIN_ATTR);
-    assert_string_equal(exts->child->next->stmt, "value");
-    assert_string_equal(exts->child->next->arg, "test2");
-    assert_null(exts->child->next->child);
-    assert_true(exts->child->next->flags & LYS_YIN_ATTR);
+    exts_name = "urn:example:extensions:ext";
+    CHECK_LYSP_EXT_INSTANCE(exts, NULL, 1, NULL,
+            LYEXT_SUBSTMT_CONTACT, 0, exts_name, 0, 0x2, LYS_YIN);
 
-    assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:subelem");
-    assert_string_equal(exts->child->next->next->arg, "text");
-    assert_null(exts->child->next->next->child);
-    assert_null(exts->child->next->next->next);
-    assert_false(exts->child->next->next->flags & LYS_YIN_ATTR);
-    lysp_ext_instance_free(st->ctx, exts);
+    CHECK_LYSP_STMT(exts->child, arg, 0, LYS_YIN_ATTR, 0, 1, stmt);
+    stmt = "value";
+    arg = "test2";
+    CHECK_LYSP_STMT(exts->child->next, arg, 0, LYS_YIN_ATTR, 0, 1, stmt);
+    stmt = "urn:example:extensions:subelem";
+    arg = "text";
+    CHECK_LYSP_STMT(exts->child->next->next, arg, 0, 0, 0x45, 0, stmt);
+    lysp_ext_instance_free(UTEST_LYCTX, exts);
     LY_ARRAY_FREE(exts);
     exts = NULL;
-    st = reset_state(state);
+    RESET_STATE;
 
     data = "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" />";
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
 
-    ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
+    ret = yin_parse_extension_instance(YCTX, LYEXT_SUBSTMT_CONTACT, 0, &exts);
     assert_int_equal(ret, LY_SUCCESS);
-    assert_string_equal(exts->name, "urn:example:extensions:extension-elem");
-    assert_null(exts->argument);
-    assert_null(exts->child);
-    assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
-    assert_int_equal(exts->insubstmt_index, 0);
-    assert_true(exts->yin & LYS_YIN);
-    lysp_ext_instance_free(st->ctx, exts);
+    exts_name = "urn:example:extensions:extension-elem";
+    CHECK_LYSP_EXT_INSTANCE(exts, NULL, 0, NULL,
+            LYEXT_SUBSTMT_CONTACT, 0, exts_name, 0, 0x2, LYS_YIN);
+    lysp_ext_instance_free(UTEST_LYCTX, exts);
     LY_ARRAY_FREE(exts);
     exts = NULL;
-    st = reset_state(state);
+    RESET_STATE;
 
     data =
             "<myext:ext attr1=\"text1\" attr2=\"text2\" xmlns:myext=\"urn:example:extensions\">\n"
@@ -484,71 +379,65 @@
             "     </myext:ext-sub2>\n"
             "     <myext:ext-sub3 attr3=\"text3\"></myext:ext-sub3>\n"
             "</myext:ext>";
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
 
-    ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
+    ret = yin_parse_extension_instance(YCTX, LYEXT_SUBSTMT_CONTACT, 0, &exts);
     assert_int_equal(ret, LY_SUCCESS);
 
-    assert_string_equal(exts->name, "urn:example:extensions:ext");
-    assert_null(exts->argument);
-    assert_int_equal(exts->insubstmt, LYEXT_SUBSTMT_CONTACT);
-    assert_int_equal(exts->insubstmt_index, 0);
-    assert_true(exts->yin & LYS_YIN);
-    assert_string_equal(exts->child->stmt, "attr1");
-    assert_string_equal(exts->child->arg, "text1");
-    assert_null(exts->child->child);
-    assert_true(exts->child->flags & LYS_YIN_ATTR);
+    exts_name = "urn:example:extensions:ext";
+    CHECK_LYSP_EXT_INSTANCE(exts, NULL, 1, NULL,
+            LYEXT_SUBSTMT_CONTACT, 0, exts_name, 0, 0x2, LYS_YIN);
 
-    assert_string_equal(exts->child->next->stmt, "attr2");
-    assert_string_equal(exts->child->next->arg, "text2");
-    assert_null(exts->child->next->child);
-    assert_true(exts->child->next->flags & LYS_YIN_ATTR);
+    stmt = "attr1";
+    arg = "text1";
+    act_child = exts->child;
+    CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0x0, 1, stmt);
+    stmt = "attr2";
+    arg = "text2";
+    act_child = act_child->next;
+    CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0x0, 1, stmt);
+    stmt = "urn:example:extensions:ext-sub1";
+    arg = NULL;
+    act_child = act_child->next;
+    CHECK_LYSP_STMT(act_child, arg, NULL, 0, 0x45, 1, stmt);
+    stmt = "urn:example:extensions:ext-sub2";
+    arg = NULL;
+    act_child = act_child->next;
+    CHECK_LYSP_STMT(act_child, arg, 1, 0, 0x45, 1, stmt);
 
-    assert_string_equal(exts->child->next->next->stmt, "urn:example:extensions:ext-sub1");
-    assert_null(exts->child->next->next->arg);
-    assert_null(exts->child->next->next->child);
-    assert_int_equal(exts->child->next->next->flags, 0);
+    stmt = "sattr1";
+    arg = "stext2";
+    act_child = act_child->child;
+    CHECK_LYSP_STMT(act_child, arg, NULL, LYS_YIN_ATTR, 0, 1, stmt);
+    stmt = "urn:example:extensions:ext-sub21";
+    arg = NULL;
+    act_child = act_child->next;
+    CHECK_LYSP_STMT(act_child, arg, 1, 0, 0x45, 0, stmt);
 
-    assert_string_equal(exts->child->next->next->next->stmt, "urn:example:extensions:ext-sub2");
-    assert_null(exts->child->next->next->next->arg);
-    assert_int_equal(exts->child->next->next->next->flags, 0);
-    assert_string_equal(exts->child->next->next->next->child->stmt, "sattr1");
-    assert_string_equal(exts->child->next->next->next->child->arg, "stext2");
-    assert_null(exts->child->next->next->next->child->child);
-    assert_true(exts->child->next->next->next->child->flags & LYS_YIN_ATTR);
+    stmt = "urn:example:extensions:ext-sub211";
+    arg = NULL;
+    act_child = act_child->child;
+    CHECK_LYSP_STMT(act_child, arg, 1, 0, 0x45, 0, stmt);
 
-    assert_string_equal(exts->child->next->next->next->child->next->stmt, "urn:example:extensions:ext-sub21");
-    assert_null(exts->child->next->next->next->child->next->arg);
-    assert_null(exts->child->next->next->next->child->next->next);
-    assert_int_equal(exts->child->next->next->next->child->next->flags, 0);
+    stmt = "sattr21";
+    arg = "text21";
+    act_child = act_child->child;
+    CHECK_LYSP_STMT(act_child, arg, 0, LYS_YIN_ATTR, 0, 0, stmt);
 
-    assert_string_equal(exts->child->next->next->next->child->next->child->stmt, "urn:example:extensions:ext-sub211");
-    assert_null(exts->child->next->next->next->child->next->child->arg);
-    assert_int_equal(exts->child->next->next->next->child->next->child->flags, 0);
-    assert_null(exts->child->next->next->next->child->next->child->next);
+    stmt = "urn:example:extensions:ext-sub3";
+    arg = NULL;
+    act_child = exts->child->next->next->next->next;
+    CHECK_LYSP_STMT(act_child, arg, 1, 0, 0x45, 0, stmt);
+    stmt = "attr3";
+    arg = "text3";
+    act_child = act_child->child;
+    CHECK_LYSP_STMT(act_child, arg, 0, LYS_YIN_ATTR, 0, 0, stmt);
 
-    assert_string_equal(exts->child->next->next->next->child->next->child->child->stmt, "sattr21");
-    assert_string_equal(exts->child->next->next->next->child->next->child->child->arg, "text21");
-    assert_null(exts->child->next->next->next->child->next->child->child->next);
-    assert_null(exts->child->next->next->next->child->next->child->child->child);
-    assert_true(exts->child->next->next->next->child->next->child->child->flags & LYS_YIN_ATTR);
-
-    assert_string_equal(exts->child->next->next->next->next->stmt, "urn:example:extensions:ext-sub3");
-    assert_null(exts->child->next->next->next->next->arg);
-    assert_null(exts->child->next->next->next->next->next);
-    assert_int_equal(exts->child->next->next->next->next->flags, 0);
-
-    assert_string_equal(exts->child->next->next->next->next->child->stmt, "attr3");
-    assert_string_equal(exts->child->next->next->next->next->child->arg, "text3");
-    assert_null(exts->child->next->next->next->next->child->next);
-    assert_null(exts->child->next->next->next->next->child->child);
-    assert_true(exts->child->next->next->next->next->child->flags & LYS_YIN_ATTR);
-
-    lysp_ext_instance_free(st->ctx, exts);
+    lysp_ext_instance_free(UTEST_LYCTX, exts);
     LY_ARRAY_FREE(exts);
     exts = NULL;
-    st = reset_state(state);
+    RESET_STATE;
 
     data =
             "<myext:extension-elem xmlns:myext=\"urn:example:extensions\" xmlns:yin=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
@@ -564,10 +453,10 @@
             "     <yin:description><yin:text>contact-val</yin:text></yin:description>\n"
             "     <yin:error-message><yin:value>err-msg</yin:value></yin:error-message>\n"
             "</myext:extension-elem>";
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
 
-    ret = yin_parse_extension_instance(st->yin_ctx, LYEXT_SUBSTMT_CONTACT, 0, &exts);
+    ret = yin_parse_extension_instance(YCTX, LYEXT_SUBSTMT_CONTACT, 0, &exts);
     assert_int_equal(ret, LY_SUCCESS);
     assert_string_equal(exts->child->arg, "act-name");
     assert_string_equal(exts->child->next->arg, "target");
@@ -579,18 +468,15 @@
     assert_string_equal(exts->child->next->next->next->next->next->next->next->arg, "data");
     assert_string_equal(exts->child->next->next->next->next->next->next->next->next->arg, "tag");
     assert_string_equal(exts->child->next->next->next->next->next->next->next->next->next->arg, "contact-val");
-    lysp_ext_instance_free(st->ctx, exts);
+    lysp_ext_instance_free(UTEST_LYCTX, exts);
     LY_ARRAY_FREE(exts);
     exts = NULL;
-    st = reset_state(state);
-
-    st->finished_correctly = true;
+    RESET_STATE;
 }
 
 static void
 test_yin_parse_content(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     LY_ERR ret = LY_SUCCESS;
     const char *data =
             "<prefix value=\"a_mod\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
@@ -627,7 +513,7 @@
             "</prefix>";
     struct lysp_ext_instance *exts = NULL;
     const char **if_features = NULL;
-    const char *value, *err_msg, *app_tag, *units;
+    const char *value, *error_message, *app_tag, *units;
     struct lysp_qname def = {0};
     struct lysp_ext *ext_def = NULL;
     struct lysp_when *when_p = NULL;
@@ -635,18 +521,18 @@
     struct lysp_type req_type = {}, range_type = {}, len_type = {}, patter_type = {}, enum_type = {};
     uint16_t config = 0;
 
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-    lyxml_ctx_next(st->yin_ctx->xmlctx);
-    lyxml_ctx_next(st->yin_ctx->xmlctx);
-    lyxml_ctx_next(st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
+    lyxml_ctx_next(YCTX->xmlctx);
+    lyxml_ctx_next(YCTX->xmlctx);
+    lyxml_ctx_next(YCTX->xmlctx);
 
     struct yin_subelement subelems[17] = {
         {LY_STMT_CONFIG, &config, 0},
         {LY_STMT_DEFAULT, &def, YIN_SUBELEM_UNIQUE},
         {LY_STMT_ENUM, &enum_type, 0},
         {LY_STMT_ERROR_APP_TAG, &app_tag, YIN_SUBELEM_UNIQUE},
-        {LY_STMT_ERROR_MESSAGE, &err_msg, 0},
+        {LY_STMT_ERROR_MESSAGE, &error_message, 0},
         {LY_STMT_EXTENSION, &ext_def, 0},
         {LY_STMT_IF_FEATURE, &if_features, 0},
         {LY_STMT_LENGTH, &len_type, 0},
@@ -661,47 +547,49 @@
         {LY_STMT_ARG_TEXT, &value, 0}
     };
 
-    ret = yin_parse_content(st->yin_ctx, subelems, 17, LY_STMT_PREFIX, NULL, &exts);
+    ret = yin_parse_content(YCTX, subelems, 17, LY_STMT_PREFIX, NULL, &exts);
     assert_int_equal(ret, LY_SUCCESS);
     /* check parsed values */
     assert_string_equal(def.str, "default-value");
-    assert_string_equal(exts->name, "urn:example:extensions:custom");
-    assert_string_equal(exts->argument, "totally amazing extension");
+    const char *exts_name = "urn:example:extensions:custom";
+    const char *exts_arg = "totally amazing extension";
+
+    CHECK_LYSP_EXT_INSTANCE(exts, exts_arg, 0, NULL,
+            LYEXT_SUBSTMT_PREFIX, 0, exts_name, 0, 0x1, 0x1);
     assert_string_equal(value, "wsefsdf");
     assert_string_equal(units, "radians");
     assert_string_equal(when_p->cond, "condition...");
     assert_string_equal(when_p->dsc, "when_desc");
     assert_string_equal(when_p->ref, "when_ref");
     assert_int_equal(config, LYS_CONFIG_W);
-    assert_int_equal(pos_enum.value, 25);
-    assert_true(pos_enum.flags & LYS_SET_VALUE);
-    assert_int_equal(val_enum.value, -5);
-    assert_true(val_enum.flags & LYS_SET_VALUE);
+    CHECK_LYSP_TYPE_ENUM(&pos_enum, NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 25);
+    CHECK_LYSP_TYPE_ENUM(&val_enum, NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -5);
     assert_int_equal(req_type.require_instance, 1);
     assert_true(req_type.flags &= LYS_SET_REQINST);
     assert_string_equal(range_type.range->arg.str, "5..10");
     assert_true(range_type.flags & LYS_SET_RANGE);
-    assert_string_equal(err_msg, "error-msg");
+    assert_string_equal(error_message, "error-msg");
     assert_string_equal(app_tag, "err-app-tag");
     assert_string_equal(enum_type.enums->name, "yay");
-    assert_string_equal(len_type.length->arg.str, "baf");
+    CHECK_LYSP_RESTR(len_type.length, "baf", NULL,
+            NULL, NULL, 0, NULL);
     assert_true(len_type.flags & LYS_SET_LENGTH);
     assert_string_equal(patter_type.patterns->arg.str, "\x015pattern");
     assert_true(patter_type.flags & LYS_SET_PATTERN);
     /* cleanup */
-    lysp_ext_instance_free(st->ctx, exts);
-    lysp_when_free(st->ctx, when_p);
-    lysp_ext_free(st->ctx, ext_def);
-    FREE_STRING(st->ctx, *if_features);
-    FREE_STRING(st->ctx, err_msg);
-    FREE_STRING(st->ctx, app_tag);
-    FREE_STRING(st->ctx, units);
-    FREE_STRING(st->ctx, patter_type.patterns->arg.str);
-    FREE_STRING(st->ctx, def.str);
-    FREE_STRING(st->ctx, range_type.range->arg.str);
-    FREE_STRING(st->ctx, len_type.length->arg.str);
-    FREE_STRING(st->ctx, enum_type.enums->name);
-    FREE_STRING(st->ctx, value);
+    lysp_ext_instance_free(UTEST_LYCTX, exts);
+    lysp_when_free(UTEST_LYCTX, when_p);
+    lysp_ext_free(UTEST_LYCTX, ext_def);
+    FREE_STRING(UTEST_LYCTX, *if_features);
+    FREE_STRING(UTEST_LYCTX, error_message);
+    FREE_STRING(UTEST_LYCTX, app_tag);
+    FREE_STRING(UTEST_LYCTX, units);
+    FREE_STRING(UTEST_LYCTX, patter_type.patterns->arg.str);
+    FREE_STRING(UTEST_LYCTX, def.str);
+    FREE_STRING(UTEST_LYCTX, range_type.range->arg.str);
+    FREE_STRING(UTEST_LYCTX, len_type.length->arg.str);
+    FREE_STRING(UTEST_LYCTX, enum_type.enums->name);
+    FREE_STRING(UTEST_LYCTX, value);
     LY_ARRAY_FREE(if_features);
     LY_ARRAY_FREE(exts);
     LY_ARRAY_FREE(ext_def);
@@ -710,7 +598,7 @@
     free(when_p);
     free(range_type.range);
     free(len_type.length);
-    st = reset_state(state);
+    RESET_STATE;
 
     /* test unique subelem */
     const char *prefix_value;
@@ -722,16 +610,16 @@
             "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
             "<text xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">wsefsdf</text>"
             ELEMENT_WRAPPER_END;
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-    lyxml_ctx_next(st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
+    lyxml_ctx_next(YCTX->xmlctx);
 
-    ret = yin_parse_content(st->yin_ctx, subelems2, 2, LY_STMT_STATUS, NULL, &exts);
+    ret = yin_parse_content(YCTX, subelems2, 2, LY_STMT_STATUS, NULL, &exts);
     assert_int_equal(ret, LY_EVALID);
-    logbuf_assert("Redefinition of \"text\" sub-element in \"status\" element. Line number 1.");
-    lydict_remove(st->ctx, prefix_value);
-    lydict_remove(st->ctx, value);
-    st = reset_state(state);
+    CHECK_LOG_CTX("Redefinition of \"text\" sub-element in \"status\" element.", "Line number 1.");
+    lydict_remove(UTEST_LYCTX, prefix_value);
+    lydict_remove(UTEST_LYCTX, value);
+    RESET_STATE;
 
     /* test first subelem */
     data = ELEMENT_WRAPPER_START
@@ -742,67 +630,62 @@
     struct yin_subelement subelems3[2] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_UNIQUE},
         {LY_STMT_ARG_TEXT, &value, YIN_SUBELEM_FIRST}};
 
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-    lyxml_ctx_next(st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
+    lyxml_ctx_next(YCTX->xmlctx);
 
-    ret = yin_parse_content(st->yin_ctx, subelems3, 2, LY_STMT_STATUS, NULL, &exts);
+    ret = yin_parse_content(YCTX, subelems3, 2, LY_STMT_STATUS, NULL, &exts);
     assert_int_equal(ret, LY_EVALID);
-    logbuf_assert("Sub-element \"text\" of \"status\" element must be defined as it's first sub-element. Line number 1.");
-    lydict_remove(st->ctx, prefix_value);
-    st = reset_state(state);
+    CHECK_LOG_CTX("Sub-element \"text\" of \"status\" element must be defined as it's first sub-element.", "Line number 1.");
+    lydict_remove(UTEST_LYCTX, prefix_value);
+    RESET_STATE;
 
     /* test mandatory subelem */
     data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
     struct yin_subelement subelems4[1] = {{LY_STMT_PREFIX, &prefix_value, YIN_SUBELEM_MANDATORY | YIN_SUBELEM_UNIQUE}};
 
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-    lyxml_ctx_next(st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
+    lyxml_ctx_next(YCTX->xmlctx);
 
-    ret = yin_parse_content(st->yin_ctx, subelems4, 1, LY_STMT_STATUS, NULL, &exts);
+    ret = yin_parse_content(YCTX, subelems4, 1, LY_STMT_STATUS, NULL, &exts);
     assert_int_equal(ret, LY_EVALID);
-    logbuf_assert("Missing mandatory sub-element \"prefix\" of \"status\" element. Line number 1.");
-
-    st->finished_correctly = true;
+    CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"status\" element.", "Line number 1.");
 }
 
 static void
 test_validate_value(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data = ELEMENT_WRAPPER_START ELEMENT_WRAPPER_END;
 
     /* create some XML context */
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-    st->yin_ctx->xmlctx->status = LYXML_ELEM_CONTENT;
-    st->yin_ctx->xmlctx->dynamic = 0;
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
+    YCTX->xmlctx->status = LYXML_ELEM_CONTENT;
+    YCTX->xmlctx->dynamic = 0;
 
-    st->yin_ctx->xmlctx->value = "#invalid";
-    st->yin_ctx->xmlctx->value_len = 8;
-    assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID);
-    logbuf_assert("Invalid identifier character '#' (0x0023). Line number 1.");
+    YCTX->xmlctx->value = "#invalid";
+    YCTX->xmlctx->value_len = 8;
+    assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID);
+    CHECK_LOG_CTX("Invalid identifier character '#' (0x0023).", "Line number 1.");
 
-    st->yin_ctx->xmlctx->value = "";
-    st->yin_ctx->xmlctx->value_len = 0;
-    assert_int_equal(yin_validate_value(st->yin_ctx, Y_STR_ARG), LY_SUCCESS);
+    YCTX->xmlctx->value = "";
+    YCTX->xmlctx->value_len = 0;
+    assert_int_equal(yin_validate_value(YCTX, Y_STR_ARG), LY_SUCCESS);
 
-    st->yin_ctx->xmlctx->value = "pre:b";
-    st->yin_ctx->xmlctx->value_len = 5;
-    assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID);
-    assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_SUCCESS);
+    YCTX->xmlctx->value = "pre:b";
+    YCTX->xmlctx->value_len = 5;
+    assert_int_equal(yin_validate_value(YCTX, Y_IDENTIF_ARG), LY_EVALID);
+    assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_SUCCESS);
 
-    st->yin_ctx->xmlctx->value = "pre:pre:b";
-    st->yin_ctx->xmlctx->value_len = 9;
-    assert_int_equal(yin_validate_value(st->yin_ctx, Y_PREF_IDENTIF_ARG), LY_EVALID);
-
-    st->finished_correctly = true;
+    YCTX->xmlctx->value = "pre:pre:b";
+    YCTX->xmlctx->value_len = 9;
+    assert_int_equal(yin_validate_value(YCTX, Y_PREF_IDENTIF_ARG), LY_EVALID);
 }
 
 /* helper function to simplify unit test of each element using parse_content function */
 LY_ERR
-test_element_helper(struct test_parser_yin_state *st, const char *data, void *dest, const char **text, struct lysp_ext_instance **exts)
+test_element_helper(void **state, const char *data, void *dest, const char **text, struct lysp_ext_instance **exts)
 {
     const char *name, *prefix;
     size_t name_len, prefix_len;
@@ -881,21 +764,21 @@
         {LY_STMT_ARG_VALUE, dest, 0}
     };
 
-    ly_in_new_memory(data, &st->in);
-    lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx);
-    prefix = st->yin_ctx->xmlctx->prefix;
-    prefix_len = st->yin_ctx->xmlctx->prefix_len;
-    name = st->yin_ctx->xmlctx->name;
-    name_len = st->yin_ctx->xmlctx->name_len;
-    lyxml_ctx_next(st->yin_ctx->xmlctx);
+    ly_in_new_memory(data, &UTEST_IN);
+    lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx);
+    prefix = YCTX->xmlctx->prefix;
+    prefix_len = YCTX->xmlctx->prefix_len;
+    name = YCTX->xmlctx->name;
+    name_len = YCTX->xmlctx->name_len;
+    lyxml_ctx_next(YCTX->xmlctx);
 
-    ret = yin_parse_content(st->yin_ctx, subelems, 71, yin_match_keyword(st->yin_ctx, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts);
+    ret = yin_parse_content(YCTX, subelems, 71, yin_match_keyword(YCTX, name, name_len, prefix, prefix_len, LY_STMT_NONE), text, exts);
 
     /* free parser and input */
-    lyxml_ctx_free(st->yin_ctx->xmlctx);
-    st->yin_ctx->xmlctx = NULL;
-    ly_in_free(st->in, 0);
-    st->in = NULL;
+    lyxml_ctx_free(YCTX->xmlctx);
+    YCTX->xmlctx = NULL;
+    ly_in_free(UTEST_IN, 0);
+    UTEST_IN = NULL;
     return ret;
 }
 
@@ -904,7 +787,6 @@
 static void
 test_enum_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     struct lysp_type type = {};
     const char *data;
 
@@ -918,34 +800,27 @@
             "     " EXT_SUBELEM "\n"
             "</enum>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.enums->name, "enum-name");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE;
+
+    CHECK_LYSP_TYPE_ENUM(type.enums, "desc...", 1, flags, 1, "enum-name", "ref...", 55);
     assert_string_equal(type.enums->iffeatures[0].str, "feature");
-    assert_int_equal(type.enums->value, 55);
-    assert_true((type.enums->flags & LYS_STATUS_DEPRC) && (type.enums->flags & LYS_SET_VALUE));
-    assert_string_equal(type.enums->dsc, "desc...");
-    assert_string_equal(type.enums->ref, "ref...");
-    assert_string_equal(type.enums->exts->name, "urn:example:extensions:c-define");
-    assert_int_equal(type.enums->exts->insubstmt_index, 0);
-    assert_int_equal(type.enums->exts->insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_type_free(st->ctx, &type);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(type.enums->exts, LYEXT_SUBSTMT_SELF);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof type);
 
     data = ELEMENT_WRAPPER_START
             "<enum name=\"enum-name\"></enum>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
     assert_string_equal(type.enums->name, "enum-name");
-    lysp_type_free(st->ctx, &type);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof type);
-
-    st->finished_correctly = true;
 }
 
 static void
 test_bit_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     struct lysp_type type = {};
     const char *data;
 
@@ -959,34 +834,27 @@
             EXT_SUBELEM
             "</bit>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.bits->name, "bit-name");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    uint16_t flags = LYS_STATUS_DEPRC | LYS_SET_VALUE;
+
+    CHECK_LYSP_TYPE_ENUM(type.bits, "desc...", 1, flags, 1, "bit-name", "ref...", 55);
     assert_string_equal(type.bits->iffeatures[0].str, "feature");
-    assert_int_equal(type.bits->value, 55);
-    assert_true((type.bits->flags & LYS_STATUS_DEPRC) && (type.bits->flags & LYS_SET_VALUE));
-    assert_string_equal(type.bits->dsc, "desc...");
-    assert_string_equal(type.bits->ref, "ref...");
-    assert_string_equal(type.bits->exts->name, "urn:example:extensions:c-define");
-    assert_int_equal(type.bits->exts->insubstmt_index, 0);
-    assert_int_equal(type.bits->exts->insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_type_free(st->ctx, &type);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(type.bits->exts, LYEXT_SUBSTMT_SELF);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof type);
 
     data = ELEMENT_WRAPPER_START
             "<bit name=\"bit-name\"> </bit>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.bits->name, "bit-name");
-    lysp_type_free(st->ctx, &type);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_TYPE_ENUM(type.bits, NULL, 0, 0, 0, "bit-name", NULL, 0);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof type);
-
-    st->finished_correctly = true;
 }
 
 static void
 test_meta_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     char *value = NULL;
     const char *data;
     struct lysp_ext_instance *exts = NULL;
@@ -995,16 +863,13 @@
     data = ELEMENT_WRAPPER_START
             "<organization><text>organization...</text>" EXT_SUBELEM EXT_SUBELEM "</organization>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
-    assert_string_equal(exts[1].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[1].insubstmt_index, 0);
-    assert_int_equal(exts[1].insubstmt, LYEXT_SUBSTMT_ORGANIZATION);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_ORGANIZATION);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[1]), LYEXT_SUBSTMT_ORGANIZATION);
+
     assert_string_equal(value, "organization...");
-    FREE_STRING(st->ctx, value);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    FREE_STRING(UTEST_LYCTX, value);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     value = NULL;
     exts = NULL;
 
@@ -1012,13 +877,11 @@
     data = ELEMENT_WRAPPER_START
             "<contact><text>contact...</text>" EXT_SUBELEM "</contact>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONTACT);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_CONTACT);
     assert_string_equal(value, "contact...");
-    FREE_STRING(st->ctx, value);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    FREE_STRING(UTEST_LYCTX, value);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
     value = NULL;
 
@@ -1026,66 +889,59 @@
     data = ELEMENT_WRAPPER_START
             "<description><text>description...</text>" EXT_SUBELEM "</description>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_DESCRIPTION);
     assert_string_equal(value, "description...");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DESCRIPTION);
-    FREE_STRING(st->ctx, value);
+    FREE_STRING(UTEST_LYCTX, value);
     value = NULL;
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
 
     /* reference element */
     data = ELEMENT_WRAPPER_START
             "<reference><text>reference...</text>" EXT_SUBELEM "</reference>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
     assert_string_equal(value, "reference...");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REFERENCE);
-    FREE_STRING(st->ctx, value);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_REFERENCE);
+    FREE_STRING(UTEST_LYCTX, value);
     value = NULL;
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
 
     /* reference element */
     data = ELEMENT_WRAPPER_START
             "<reference invalid=\"text\"><text>reference...</text>" "</reference>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
-    logbuf_assert("Unexpected attribute \"invalid\" of \"reference\" element. Line number 1.");
-    FREE_STRING(st->ctx, value);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
+    CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"reference\" element.", "Line number 1.");
+    FREE_STRING(UTEST_LYCTX, value);
     value = NULL;
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
 
     /* missing text subelement */
     data = ELEMENT_WRAPPER_START
             "<reference>reference...</reference>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
-    logbuf_assert("Missing mandatory sub-element \"text\" of \"reference\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory sub-element \"text\" of \"reference\" element.", "Line number 1.");
 
     /* reference element */
     data = ELEMENT_WRAPPER_START
             "<reference>" EXT_SUBELEM "<text>reference...</text></reference>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_EVALID);
-    logbuf_assert("Sub-element \"text\" of \"reference\" element must be defined as it's first sub-element. Line number 1.");
-    FREE_STRING(st->ctx, value);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_EVALID);
+    CHECK_LOG_CTX("Sub-element \"text\" of \"reference\" element must be defined as it's first sub-element.", "Line number 1.");
+    FREE_STRING(UTEST_LYCTX, value);
     value = NULL;
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_import_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_import *imports = NULL;
     struct import_meta imp_meta = {"prefix", &imports};
@@ -1100,16 +956,11 @@
             "    <reference><text>import reference</text></reference>\n"
             "</import>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(imports->name, "a");
-    assert_string_equal(imports->prefix, "a_mod");
-    assert_string_equal(imports->rev, "2015-01-01");
-    assert_string_equal(imports->dsc, "import description");
-    assert_string_equal(imports->ref, "import reference");
-    assert_string_equal(imports->exts->name, "urn:example:extensions:c-define");
-    assert_int_equal(imports->exts->insubstmt, LYEXT_SUBSTMT_SELF);
-    assert_int_equal(imports->exts->insubstmt_index, 0);
-    FREE_ARRAY(st->ctx, imports, lysp_import_free);
+    assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_IMPORT(imports, "import description", 1, "a",
+            "a_mod", "import reference", "2015-01-01");
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(imports->exts, LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
     imports = NULL;
 
     /* min subelems */
@@ -1118,16 +969,17 @@
             "    <prefix value=\"a_mod\"/>\n"
             "</import>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(imports->prefix, "a_mod");
-    FREE_ARRAY(st->ctx, imports, lysp_import_free);
+    assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_IMPORT(imports, NULL, 0, "a",
+            "a_mod", NULL, "");
+    FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
     imports = NULL;
 
     /* invalid (missing prefix) */
     data = ELEMENT_WRAPPER_START "<import module=\"a\"></import>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory sub-element \"prefix\" of \"import\" element. Line number 1.");
-    FREE_ARRAY(st->ctx, imports, lysp_import_free);
+    assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"import\" element.", "Line number 1.");
+    FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
     imports = NULL;
 
     /* invalid reused prefix */
@@ -1136,9 +988,9 @@
             "    <prefix value=\"prefix\"/>\n"
             "</import>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Prefix \"prefix\" already used as module prefix. Line number 3.");
-    FREE_ARRAY(st->ctx, imports, lysp_import_free);
+    assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Prefix \"prefix\" already used as module prefix.", "Line number 3.");
+    FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
     imports = NULL;
 
     data = ELEMENT_WRAPPER_START
@@ -1147,52 +999,47 @@
             "</import>\n"
             "<import module=\"a\">\n"
             "    <prefix value=\"a\"/>\n"
-            "</import>"
+            "</import>\n"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &imp_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Prefix \"a\" already used to import \"a\" module. Line number 6.");
-    FREE_ARRAY(st->ctx, imports, lysp_import_free);
+    assert_int_equal(test_element_helper(state, data, &imp_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Prefix \"a\" already used to import \"a\" module.", "Line number 6.");
+    FREE_ARRAY(UTEST_LYCTX, imports, lysp_import_free);
     imports = NULL;
-    st->finished_correctly = true;
 }
 
 static void
 test_status_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     uint16_t flags = 0;
     struct lysp_ext_instance *exts = NULL;
 
     /* test valid values */
     data = ELEMENT_WRAPPER_START "<status value=\"current\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
     assert_true(flags & LYS_STATUS_CURR);
 
     data = ELEMENT_WRAPPER_START "<status value=\"deprecated\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
     assert_true(flags & LYS_STATUS_DEPRC);
 
     data = ELEMENT_WRAPPER_START "<status value=\"obsolete\">"EXT_SUBELEM "</status>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
     assert_true(flags & LYS_STATUS_OBSLT);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_STATUS);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_STATUS);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
 
     /* test invalid value */
     data = ELEMENT_WRAPPER_START "<status value=\"invalid\"></status>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. Valid values are \"current\", \"deprecated\" and \"obsolete\". Line number 1.");
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"status\" element. "
+            "Valid values are \"current\", \"deprecated\" and \"obsolete\".", "Line number 1.");
 }
 
 static void
 test_ext_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_ext *ext = NULL;
 
@@ -1206,119 +1053,99 @@
             EXT_SUBELEM
             "</extension>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(ext->name, "ext_name");
-    assert_string_equal(ext->argument, "arg");
-    assert_true(ext->flags & LYS_STATUS_CURR);
-    assert_string_equal(ext->dsc, "ext_desc");
-    assert_string_equal(ext->ref, "ext_ref");
-    assert_string_equal(ext->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(ext->exts[0].insubstmt_index, 0);
-    assert_int_equal(ext->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_ext_free(st->ctx, ext);
+    assert_int_equal(test_element_helper(state, data, &ext, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_EXT(ext, "arg", 0, "ext_desc", 1, LYS_STATUS_CURR, "ext_name", "ext_ref");
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(ext->exts[0]), LYEXT_SUBSTMT_SELF);
+    lysp_ext_free(UTEST_LYCTX, ext);
     LY_ARRAY_FREE(ext);
     ext = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<extension name=\"ext_name\"></extension>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &ext, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(ext->name, "ext_name");
-    lysp_ext_free(st->ctx, ext);
+    assert_int_equal(test_element_helper(state, data, &ext, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_EXT(ext, NULL, 0, NULL, 0, 0, "ext_name", NULL);
+    lysp_ext_free(UTEST_LYCTX, ext);
     LY_ARRAY_FREE(ext);
     ext = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_yin_element_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     uint16_t flags = 0;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<yin-element value=\"true\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
     assert_true(flags & LYS_YINELEM_TRUE);
 
     data = ELEMENT_WRAPPER_START "<yin-element value=\"false\">" EXT_SUBELEM "</yin-element>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
     assert_true(flags & LYS_YINELEM_TRUE);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_YINELEM);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_YINELEM);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
 
     data = ELEMENT_WRAPPER_START "<yin-element value=\"invalid\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
     assert_true(flags & LYS_YINELEM_TRUE);
-    logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. Valid values are \"true\" and \"false\". Line number 1.");
-    st->finished_correctly = true;
+    CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"yin-element\" element. "
+            "Valid values are \"true\" and \"false\".", "Line number 1.");
 }
 
 static void
 test_yangversion_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     uint8_t version = 0;
     struct lysp_ext_instance *exts = NULL;
 
     /* valid values */
     data = ELEMENT_WRAPPER_START "<yang-version value=\"1\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_SUCCESS);
     assert_true(version & LYS_VERSION_1_0);
 
     data = ELEMENT_WRAPPER_START "<yang-version value=\"1.1\">" EXT_SUBELEM "</yang-version>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &version, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &version, NULL, &exts), LY_SUCCESS);
     assert_true(version & LYS_VERSION_1_1);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_VERSION);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_VERSION);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
 
     /* invalid value */
     data = ELEMENT_WRAPPER_START "<yang-version value=\"version\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &version, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. Valid values are \"1\" and \"1.1\". Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &version, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"version\" of \"value\" attribute in \"yang-version\" element. "
+            "Valid values are \"1\" and \"1.1\".", "Line number 1.");
 }
 
 static void
 test_mandatory_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     uint16_t man = 0;
     struct lysp_ext_instance *exts = NULL;
 
     /* valid values */
     data = ELEMENT_WRAPPER_START "<mandatory value=\"true\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &man, NULL, NULL), LY_SUCCESS);
     assert_int_equal(man, LYS_MAND_TRUE);
     man = 0;
 
     data = ELEMENT_WRAPPER_START "<mandatory value=\"false\">" EXT_SUBELEM "</mandatory>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &man, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &man, NULL, &exts), LY_SUCCESS);
     assert_int_equal(man, LYS_MAND_FALSE);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MANDATORY);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_MANDATORY);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
 
     data = ELEMENT_WRAPPER_START "<mandatory value=\"invalid\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &man, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"mandatory\" element. Valid values are \"true\" and \"false\". Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &man, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"mandatory\" element. "
+            "Valid values are \"true\" and \"false\".", "Line number 1.");
 }
 
 static void
 test_argument_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     uint16_t flags = 0;
     const char *arg;
@@ -1332,16 +1159,14 @@
             EXT_SUBELEM
             "</argument>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, &exts), LY_SUCCESS);
     assert_string_equal(arg, "arg-name");
     assert_true(flags & LYS_YINELEM_TRUE);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ARGUMENT);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_ARGUMENT);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
     flags = 0;
-    FREE_STRING(st->ctx, arg);
+    FREE_STRING(UTEST_LYCTX, arg);
     arg = NULL;
 
     /* min subelems */
@@ -1349,18 +1174,15 @@
             "<argument name=\"arg\">"
             "</argument>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &arg_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &arg_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(arg, "arg");
     assert_true(flags == 0);
-    FREE_STRING(st->ctx, arg);
-
-    st->finished_correctly = true;
+    FREE_STRING(UTEST_LYCTX, arg);
 }
 
 static void
 test_base_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char **bases = NULL;
     struct lysp_ext_instance *exts = NULL;
@@ -1372,14 +1194,12 @@
             EXT_SUBELEM
             "     </base>\n"
             "</identity>";
-    assert_int_equal(test_element_helper(st, data, &bases, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &bases, NULL, &exts), LY_SUCCESS);
     assert_string_equal(*bases, "base-name");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_BASE);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, *bases);
+    FREE_STRING(UTEST_LYCTX, *bases);
     LY_ARRAY_FREE(bases);
 
     /* as type subelement */
@@ -1388,232 +1208,195 @@
             EXT_SUBELEM
             "     </base>\n"
             "</type>";
-    assert_int_equal(test_element_helper(st, data, &type, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, &exts), LY_SUCCESS);
     assert_string_equal(*type.bases, "base-name");
     assert_true(type.flags & LYS_SET_BASE);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BASE);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_BASE);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, *type.bases);
+    FREE_STRING(UTEST_LYCTX, *type.bases);
     LY_ARRAY_FREE(type.bases);
-
-    st->finished_correctly = true;
 }
 
 static void
 test_belongsto_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_submodule submod;
     struct lysp_ext_instance *exts = NULL;
 
+    lydict_insert(UTEST_LYCTX, "module-name", 0, &YCTX->parsed_mod->mod->name);
+
     data = ELEMENT_WRAPPER_START
             "<belongs-to module=\"module-name\"><prefix value=\"pref\"/>"EXT_SUBELEM "</belongs-to>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &submod, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &submod, NULL, &exts), LY_SUCCESS);
     assert_string_equal(submod.prefix, "pref");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_BELONGSTO);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_BELONGSTO);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, submod.prefix);
+    FREE_STRING(UTEST_LYCTX, submod.prefix);
 
     data = ELEMENT_WRAPPER_START "<belongs-to module=\"module-name\"></belongs-to>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &submod, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &submod, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory sub-element \"prefix\" of \"belongs-to\" element.", "Line number 1.");
 }
 
 static void
 test_config_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     uint16_t flags = 0;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<config value=\"true\">" EXT_SUBELEM "</config>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
     assert_true(flags & LYS_CONFIG_W);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_CONFIG);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_CONFIG);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
     flags = 0;
 
     data = ELEMENT_WRAPPER_START "<config value=\"false\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
     assert_true(flags & LYS_CONFIG_R);
     flags = 0;
 
     data = ELEMENT_WRAPPER_START "<config value=\"invalid\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. Valid values are \"true\" and \"false\". Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"config\" element. "
+            "Valid values are \"true\" and \"false\".", "Line number 1.");
 }
 
 static void
 test_default_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_qname val = {0};
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<default value=\"defaul-value\">"EXT_SUBELEM "</default>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
     assert_string_equal(val.str, "defaul-value");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_DEFAULT);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]), LYEXT_SUBSTMT_DEFAULT);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, val.str);
+    FREE_STRING(UTEST_LYCTX, val.str);
     val.str = NULL;
 
     data = ELEMENT_WRAPPER_START "<default/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory attribute value of default element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory attribute value of default element.", "Line number 1.");
 }
 
 static void
 test_err_app_tag_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *val = NULL;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<error-app-tag value=\"val\">"EXT_SUBELEM "</error-app-tag>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
     assert_string_equal(val, "val");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRTAG);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_ERRTAG);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, val);
+    FREE_STRING(UTEST_LYCTX, val);
     val = NULL;
 
     data = ELEMENT_WRAPPER_START "<error-app-tag/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory attribute value of error-app-tag element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory attribute value of error-app-tag element.", "Line number 1.");
 }
 
 static void
 test_err_msg_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *val = NULL;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<error-message><value>val</value>"EXT_SUBELEM "</error-message>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
     assert_string_equal(val, "val");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ERRMSG);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_ERRMSG);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, val);
+    FREE_STRING(UTEST_LYCTX, val);
 
     data = ELEMENT_WRAPPER_START "<error-message></error-message>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory sub-element \"value\" of \"error-message\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory sub-element \"value\" of \"error-message\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<error-message invalid=\"text\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
-    logbuf_assert("Unexpected attribute \"invalid\" of \"error-message\" element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Unexpected attribute \"invalid\" of \"error-message\" element.", "Line number 1.");
 }
 
 static void
 test_fracdigits_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_type type = {};
 
     /* valid value */
     data = ELEMENT_WRAPPER_START "<fraction-digits value=\"10\">"EXT_SUBELEM "</fraction-digits>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(type.exts[0].insubstmt_index, 0);
-    assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_FRACDIGITS);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]),  LYEXT_SUBSTMT_FRACDIGITS);
     assert_int_equal(type.fraction_digits, 10);
     assert_true(type.flags & LYS_SET_FRDIGITS);
-    FREE_ARRAY(st->ctx, type.exts, lysp_ext_instance_free);
+    FREE_ARRAY(UTEST_LYCTX, type.exts, lysp_ext_instance_free);
 
     /* invalid values */
     data = ELEMENT_WRAPPER_START "<fraction-digits value=\"-1\"></fraction-digits>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"-1\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<fraction-digits value=\"02\"></fraction-digits>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"02\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<fraction-digits value=\"1p\"></fraction-digits>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"1p\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<fraction-digits value=\"19\"></fraction-digits>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"19\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<fraction-digits value=\"999999999999999999\"></fraction-digits>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"999999999999999999\" of \"value\" attribute in \"fraction-digits\" element.", "Line number 1.");
 }
 
 static void
 test_iffeature_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char **iffeatures = NULL;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<if-feature name=\"local-storage\">"EXT_SUBELEM "</if-feature>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, &exts), LY_SUCCESS);
     assert_string_equal(*iffeatures, "local-storage");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_IFFEATURE);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_IFFEATURE);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, *iffeatures);
+    FREE_STRING(UTEST_LYCTX, *iffeatures);
     LY_ARRAY_FREE(iffeatures);
     iffeatures = NULL;
 
     data = ELEMENT_WRAPPER_START "<if-feature/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &iffeatures, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory attribute name of if-feature element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &iffeatures, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory attribute name of if-feature element.", "Line number 1.");
     LY_ARRAY_FREE(iffeatures);
     iffeatures = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_length_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_type type = {};
 
@@ -1627,17 +1410,12 @@
             EXT_SUBELEM
             "</length>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.length->arg.str, "length-str");
-    assert_string_equal(type.length->emsg, "err-msg");
-    assert_string_equal(type.length->eapptag, "err-app-tag");
-    assert_string_equal(type.length->dsc, "desc");
-    assert_string_equal(type.length->ref, "ref");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_RESTR(type.length, "length-str", "desc",
+            "err-app-tag", "err-msg", 1, "ref");
     assert_true(type.flags & LYS_SET_LENGTH);
-    assert_string_equal(type.length->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(type.length->exts[0].insubstmt_index, 0);
-    assert_int_equal(type.length->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_type_free(st->ctx, &type);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.length->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
 
     /* min subelems */
@@ -1645,78 +1423,67 @@
             "<length value=\"length-str\">"
             "</length>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.length->arg.str, "length-str");
-    lysp_type_free(st->ctx, &type);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_RESTR(type.length, "length-str", NULL,
+            NULL, NULL, 0, NULL);
+    lysp_type_free(UTEST_LYCTX, &type);
     assert_true(type.flags & LYS_SET_LENGTH);
     memset(&type, 0, sizeof(type));
 
     data = ELEMENT_WRAPPER_START "<length></length>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory attribute value of length element. Line number 1.");
-    lysp_type_free(st->ctx, &type);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory attribute value of length element.", "Line number 1.");
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
-
-    st->finished_correctly = true;
 }
 
 static void
 test_modifier_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *pat;
     struct lysp_ext_instance *exts = NULL;
 
-    assert_int_equal(LY_SUCCESS, lydict_insert(st->ctx, "\006pattern", 8, &pat));
+    assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\006pattern", 8, &pat));
     data = ELEMENT_WRAPPER_START "<modifier value=\"invert-match\">" EXT_SUBELEM "</modifier>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &pat, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &pat, NULL, &exts), LY_SUCCESS);
     assert_string_equal(pat, "\x015pattern");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_MODIFIER);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_MODIFIER);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, pat);
+    FREE_STRING(UTEST_LYCTX, pat);
 
-    assert_int_equal(LY_SUCCESS, lydict_insert(st->ctx, "\006pattern", 8, &pat));
+    assert_int_equal(LY_SUCCESS, lydict_insert(UTEST_LYCTX, "\006pattern", 8, &pat));
     data = ELEMENT_WRAPPER_START "<modifier value=\"invert\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &pat, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. Only valid value is \"invert-match\". Line number 1.");
-    FREE_STRING(st->ctx, pat);
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &pat, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"invert\" of \"value\" attribute in \"modifier\" element. "
+            "Only valid value is \"invert-match\".", "Line number 1.");
+    FREE_STRING(UTEST_LYCTX, pat);
 }
 
 static void
 test_namespace_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *ns;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<namespace uri=\"ns\">" EXT_SUBELEM "</namespace>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &ns, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &ns, NULL, &exts), LY_SUCCESS);
     assert_string_equal(ns, "ns");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_NAMESPACE);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_NAMESPACE);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, ns);
+    FREE_STRING(UTEST_LYCTX, ns);
 
     data = ELEMENT_WRAPPER_START "<namespace/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &ns, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory attribute uri of namespace element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &ns, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory attribute uri of namespace element.", "Line number 1.");
 }
 
 static void
 test_pattern_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_type type = {};
 
@@ -1731,145 +1498,119 @@
             EXT_SUBELEM
             "</pattern>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
     assert_true(type.flags & LYS_SET_PATTERN);
-    assert_string_equal(type.patterns->arg.str, "\x015super_pattern");
-    assert_string_equal(type.patterns->dsc, "\"pattern-desc\"");
-    assert_string_equal(type.patterns->eapptag, "err-app-tag-value");
-    assert_string_equal(type.patterns->emsg, "err-msg-value");
-    assert_string_equal(type.patterns->ref, "pattern-ref");
-    assert_string_equal(type.patterns->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(type.patterns->exts[0].insubstmt_index, 0);
-    assert_int_equal(type.patterns->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_type_free(st->ctx, &type);
+    CHECK_LYSP_RESTR(type.patterns, "\x015super_pattern", "\"pattern-desc\"",
+            "err-app-tag-value", "err-msg-value", 1, "pattern-ref");
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.patterns->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<pattern value=\"pattern\"> </pattern>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.patterns->arg.str, "\x006pattern");
-    lysp_type_free(st->ctx, &type);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_RESTR(type.patterns, "\x006pattern", NULL, NULL, NULL, 0, NULL);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
-
-    st->finished_correctly = true;
 }
 
 static void
 test_value_position_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_type_enum en = {};
 
     /* valid values */
     data = ELEMENT_WRAPPER_START "<value value=\"55\">" EXT_SUBELEM "</value>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
-    assert_int_equal(en.value, 55);
-    assert_true(en.flags & LYS_SET_VALUE);
-    assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(en.exts[0].insubstmt_index, 0);
-    assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_VALUE);
-    FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_TYPE_ENUM(&(en), NULL, 1, LYS_SET_VALUE, 0, NULL, NULL, 55);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(en.exts[0]),  LYEXT_SUBSTMT_VALUE);
+    FREE_ARRAY(UTEST_LYCTX, en.exts, lysp_ext_instance_free);
     memset(&en, 0, sizeof(en));
 
     data = ELEMENT_WRAPPER_START "<value value=\"-55\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
-    assert_int_equal(en.value, -55);
-    assert_true(en.flags & LYS_SET_VALUE);
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, -55);
     memset(&en, 0, sizeof(en));
 
     data = ELEMENT_WRAPPER_START "<value value=\"0\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
-    assert_int_equal(en.value, 0);
-    assert_true(en.flags & LYS_SET_VALUE);
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
     memset(&en, 0, sizeof(en));
 
     data = ELEMENT_WRAPPER_START "<value value=\"-0\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
-    assert_int_equal(en.value, 0);
-    assert_true(en.flags & LYS_SET_VALUE);
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
     memset(&en, 0, sizeof(en));
 
     /* valid positions */
     data = ELEMENT_WRAPPER_START "<position value=\"55\">" EXT_SUBELEM "</position>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
-    assert_int_equal(en.value, 55);
-    assert_true(en.flags & LYS_SET_VALUE);
-    assert_string_equal(en.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(en.exts[0].insubstmt_index, 0);
-    assert_int_equal(en.exts[0].insubstmt, LYEXT_SUBSTMT_POSITION);
-    FREE_ARRAY(st->ctx, en.exts, lysp_ext_instance_free);
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_TYPE_ENUM(&(en), NULL, 1, LYS_SET_VALUE, 0, NULL, NULL, 55);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(en.exts[0]),  LYEXT_SUBSTMT_POSITION);
+    FREE_ARRAY(UTEST_LYCTX, en.exts, lysp_ext_instance_free);
     memset(&en, 0, sizeof(en));
 
     data = ELEMENT_WRAPPER_START "<position value=\"0\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_SUCCESS);
-    assert_int_equal(en.value, 0);
-    assert_true(en.flags & LYS_SET_VALUE);
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_TYPE_ENUM(&(en), NULL, 0, LYS_SET_VALUE, 0, NULL, NULL, 0);
     memset(&en, 0, sizeof(en));
 
     /* invalid values */
     data = ELEMENT_WRAPPER_START "<value value=\"99999999999999999999999\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"99999999999999999999999\" of \"value\" attribute in \"value\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<value value=\"1k\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"1k\" of \"value\" attribute in \"value\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"1k\" of \"value\" attribute in \"value\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<value value=\"\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"\" of \"value\" attribute in \"value\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"value\" element.", "Line number 1.");
 
     /*invalid positions */
     data = ELEMENT_WRAPPER_START "<position value=\"-5\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"-5\" of \"value\" attribute in \"position\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"-5\" of \"value\" attribute in \"position\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<position value=\"-0\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"-0\" of \"value\" attribute in \"position\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"-0\" of \"value\" attribute in \"position\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<position value=\"99999999999999999999\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"99999999999999999999\" of \"value\" attribute in \"position\" element.", "Line number 1.");
 
     data = ELEMENT_WRAPPER_START "<position value=\"\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &en, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"\" of \"value\" attribute in \"position\" element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &en, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"position\" element.", "Line number 1.");
 }
 
 static void
 test_prefix_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *value = NULL;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<prefix value=\"pref\">" EXT_SUBELEM "</prefix>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, &exts), LY_SUCCESS);
     assert_string_equal(value, "pref");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PREFIX);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_PREFIX);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
     exts = NULL;
-    FREE_STRING(st->ctx, value);
+    FREE_STRING(UTEST_LYCTX, value);
 
     data = ELEMENT_WRAPPER_START "<prefix value=\"pref\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &value, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &value, NULL, NULL), LY_SUCCESS);
     assert_string_equal(value, "pref");
-    FREE_STRING(st->ctx, value);
-
-    st->finished_correctly = true;
+    FREE_STRING(UTEST_LYCTX, value);
 }
 
 static void
 test_range_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_type type = {};
 
@@ -1883,147 +1624,121 @@
             EXT_SUBELEM
             "</range>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.range->arg.str, "range-str");
-    assert_string_equal(type.range->dsc, "desc");
-    assert_string_equal(type.range->eapptag, "err-app-tag");
-    assert_string_equal(type.range->emsg, "err-msg");
-    assert_string_equal(type.range->ref, "ref");
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_RESTR(type.range, "range-str", "desc",
+            "err-app-tag", "err-msg", 1, "ref");
     assert_true(type.flags & LYS_SET_RANGE);
-    assert_string_equal(type.range->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(type.range->exts[0].insubstmt_index, 0);
-    assert_int_equal(type.range->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_type_free(st->ctx, &type);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.range->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<range value=\"range-str\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(type.range->arg.str, "range-str");
-    lysp_type_free(st->ctx, &type);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_RESTR(type.range, "range-str", NULL,
+            NULL, NULL, 0, NULL);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
-
-    st->finished_correctly = true;
 }
 
 static void
 test_reqinstance_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_type type = {};
 
     data = ELEMENT_WRAPPER_START "<require-instance value=\"true\">" EXT_SUBELEM "</require-instance>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
     assert_int_equal(type.require_instance, 1);
     assert_true(type.flags & LYS_SET_REQINST);
-    assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(type.exts[0].insubstmt_index, 0);
-    assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_REQINSTANCE);
-    lysp_type_free(st->ctx, &type);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]),  LYEXT_SUBSTMT_REQINSTANCE);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
 
     data = ELEMENT_WRAPPER_START "<require-instance value=\"false\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
     assert_int_equal(type.require_instance, 0);
     assert_true(type.flags & LYS_SET_REQINST);
     memset(&type, 0, sizeof(type));
 
     data = ELEMENT_WRAPPER_START "<require-instance value=\"invalid\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_EVALID);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_EVALID);
     memset(&type, 0, sizeof(type));
-    logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. Valid values are \"true\" and \"false\". Line number 1.");
-
-    st->finished_correctly = true;
+    CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"require-instance\" element. "
+            "Valid values are \"true\" and \"false\".", "Line number 1.");
 }
 
 static void
 test_revision_date_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     char rev[LY_REV_SIZE];
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\">"EXT_SUBELEM "</revision-date>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, rev, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, rev, NULL, &exts), LY_SUCCESS);
     assert_string_equal(rev, "2000-01-01");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_REVISIONDATE);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_REVISIONDATE);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
 
     data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-01-01\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_SUCCESS);
     assert_string_equal(rev, "2000-01-01");
 
     data = ELEMENT_WRAPPER_START "<revision-date date=\"2000-50-05\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, rev, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"2000-50-05\" of \"revision-date\". Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, rev, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"2000-50-05\" of \"revision-date\".", "Line number 1.");
 }
 
 static void
 test_unique_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char **values = NULL;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<unique tag=\"tag\">"EXT_SUBELEM "</unique>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &values, NULL, &exts), LY_SUCCESS);
     assert_string_equal(*values, "tag");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNIQUE);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
-    FREE_STRING(st->ctx, *values);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_UNIQUE);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
+    FREE_STRING(UTEST_LYCTX, *values);
     LY_ARRAY_FREE(values);
     values = NULL;
 
     data = ELEMENT_WRAPPER_START "<unique tag=\"tag\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS);
     assert_string_equal(*values, "tag");
-    FREE_STRING(st->ctx, *values);
+    FREE_STRING(UTEST_LYCTX, *values);
     LY_ARRAY_FREE(values);
     values = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_units_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *values = NULL;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<units name=\"name\">"EXT_SUBELEM "</units>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &values, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &values, NULL, &exts), LY_SUCCESS);
     assert_string_equal(values, "name");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_UNITS);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
-    FREE_STRING(st->ctx, values);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_UNITS);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
+    FREE_STRING(UTEST_LYCTX, values);
     values = NULL;
 
     data = ELEMENT_WRAPPER_START "<units name=\"name\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &values, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &values, NULL, NULL), LY_SUCCESS);
     assert_string_equal(values, "name");
-    FREE_STRING(st->ctx, values);
+    FREE_STRING(UTEST_LYCTX, values);
     values = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_when_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_when *when = NULL;
 
@@ -2034,56 +1749,46 @@
             EXT_SUBELEM
             "</when>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(when->cond, "cond");
-    assert_string_equal(when->dsc, "desc");
-    assert_string_equal(when->ref, "ref");
-    assert_string_equal(when->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(when->exts[0].insubstmt_index, 0);
-    assert_int_equal(when->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_when_free(st->ctx, when);
+    assert_int_equal(test_element_helper(state, data, &when, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_WHEN(when, "cond", "desc", 1, "ref");
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(when->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_when_free(UTEST_LYCTX, when);
     free(when);
     when = NULL;
 
     data = ELEMENT_WRAPPER_START "<when condition=\"cond\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &when, NULL, NULL), LY_SUCCESS);
-    assert_string_equal(when->cond, "cond");
-    lysp_when_free(st->ctx, when);
+    assert_int_equal(test_element_helper(state, data, &when, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_WHEN(when, "cond", NULL, 0, NULL);
+    lysp_when_free(UTEST_LYCTX, when);
     free(when);
     when = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_yin_text_value_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *val;
 
     data = ELEMENT_WRAPPER_START "<text>text</text>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
     assert_string_equal(val, "text");
-    FREE_STRING(st->ctx, val);
+    FREE_STRING(UTEST_LYCTX, val);
 
     data = "<error-message xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <value>text</value> </error-message>";
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
     assert_string_equal(val, "text");
-    FREE_STRING(st->ctx, val);
+    FREE_STRING(UTEST_LYCTX, val);
 
     data = ELEMENT_WRAPPER_START "<text></text>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
     assert_string_equal("", val);
-    FREE_STRING(st->ctx, val);
-
-    st->finished_correctly = true;
+    FREE_STRING(UTEST_LYCTX, val);
 }
 
 static void
 test_type_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_type type = {};
 
@@ -2103,21 +1808,22 @@
             EXT_SUBELEM
             "</type>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
     assert_string_equal(type.name, "type-name");
     assert_string_equal(*type.bases, "base-name");
     assert_string_equal(type.bits->name,  "bit");
     assert_string_equal(type.enums->name,  "enum");
     assert_int_equal(type.fraction_digits, 2);
-    assert_string_equal(type.length->arg.str, "length");
+    CHECK_LYSP_RESTR(type.length, "length", NULL,
+            NULL, NULL, 0, NULL);
     assert_string_equal(type.path->expr, "/path");
-    assert_string_equal(type.patterns->arg.str, "\006pattern");
-    assert_string_equal(type.range->arg.str, "range");
+    CHECK_LYSP_RESTR(type.patterns, "\006pattern", NULL,
+            NULL, NULL, 0, NULL);
+    CHECK_LYSP_RESTR(type.range, "range", NULL,
+            NULL, NULL, 0, NULL);
     assert_int_equal(type.require_instance, 1);
     assert_string_equal(type.types->name, "sub-type-name");
-    assert_string_equal(type.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(type.exts[0].insubstmt_index, 0);
-    assert_int_equal(type.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(type.exts[0]),  LYEXT_SUBSTMT_SELF);
     assert_true(type.flags & LYS_SET_BASE);
     assert_true(type.flags & LYS_SET_BIT);
     assert_true(type.flags & LYS_SET_ENUM);
@@ -2128,168 +1834,144 @@
     assert_true(type.flags & LYS_SET_RANGE);
     assert_true(type.flags & LYS_SET_REQINST);
     assert_true(type.flags & LYS_SET_TYPE);
-    lysp_type_free(st->ctx, &type);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<type name=\"type-name\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &type, NULL, NULL), LY_SUCCESS);
-    lysp_type_free(st->ctx, &type);
+    assert_int_equal(test_element_helper(state, data, &type, NULL, NULL), LY_SUCCESS);
+    lysp_type_free(UTEST_LYCTX, &type);
     memset(&type, 0, sizeof(type));
-
-    st->finished_correctly = true;
 }
 
 static void
 test_max_elems_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node_list list = {};
     struct lysp_node_leaflist llist = {};
     struct lysp_refine refine = {};
 
     data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"unbounded\">"EXT_SUBELEM "</max-elements> </refine>";
-    assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
     assert_int_equal(refine.max, 0);
     assert_true(refine.flags & LYS_SET_MAX);
-    assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(refine.exts[0].insubstmt_index, 0);
-    assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
-    FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refine.exts[0]),  LYEXT_SUBSTMT_MAX);
+    FREE_ARRAY(UTEST_LYCTX, refine.exts, lysp_ext_instance_free);
 
     data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"5\">"EXT_SUBELEM "</max-elements> </list>";
-    assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_SUCCESS);
     assert_int_equal(list.max, 5);
-    assert_true(list.flags & LYS_SET_MAX);
-    assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(list.exts[0].insubstmt_index, 0);
-    assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
-    FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
+    CHECK_LYSP_NODE(&list, NULL, 1, LYS_SET_MAX, 0, NULL, 0, LYS_UNKNOWN, NULL, NULL, 0);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(list.exts[0]),  LYEXT_SUBSTMT_MAX);
+    FREE_ARRAY(UTEST_LYCTX, list.exts, lysp_ext_instance_free);
 
     data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"85\">"EXT_SUBELEM "</max-elements> </leaf-list>";
-    assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_SUCCESS);
     assert_int_equal(llist.max, 85);
-    assert_true(llist.flags & LYS_SET_MAX);
-    assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(llist.exts[0].insubstmt_index, 0);
-    assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MAX);
-    FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
+    CHECK_LYSP_NODE(&llist, NULL, 1, LYS_SET_MAX, 0, NULL, 0, LYS_UNKNOWN, NULL, NULL, 0);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(llist.exts[0]),  LYEXT_SUBSTMT_MAX);
+    FREE_ARRAY(UTEST_LYCTX, llist.exts, lysp_ext_instance_free);
 
     data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"10\"/> </refine>";
-    assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
     assert_int_equal(refine.max, 10);
     assert_true(refine.flags & LYS_SET_MAX);
 
     data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"0\"/> </list>";
-    assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"0\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
 
     data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"-10\"/> </list>";
-    assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"-10\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
 
     data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"k\"/> </list>";
-    assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"k\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
 
     data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <max-elements value=\"u12\"/> </list>";
-    assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"u12\" of \"value\" attribute in \"max-elements\" element.", "Line number 1.");
 }
 
 static void
 test_min_elems_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node_list list = {};
     struct lysp_node_leaflist llist = {};
     struct lysp_refine refine = {};
 
     data = "<refine xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"0\">"EXT_SUBELEM "</min-elements> </refine>";
-    assert_int_equal(test_element_helper(st, data, &refine, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &refine, NULL, NULL), LY_SUCCESS);
     assert_int_equal(refine.min, 0);
     assert_true(refine.flags & LYS_SET_MIN);
-    assert_string_equal(refine.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(refine.exts[0].insubstmt_index, 0);
-    assert_int_equal(refine.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
-    FREE_ARRAY(st->ctx, refine.exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refine.exts[0]),  LYEXT_SUBSTMT_MIN);
+    FREE_ARRAY(UTEST_LYCTX, refine.exts, lysp_ext_instance_free);
 
     data = "<list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"41\">"EXT_SUBELEM "</min-elements> </list>";
-    assert_int_equal(test_element_helper(st, data, &list, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &list, NULL, NULL), LY_SUCCESS);
     assert_int_equal(list.min, 41);
     assert_true(list.flags & LYS_SET_MIN);
-    assert_string_equal(list.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(list.exts[0].insubstmt_index, 0);
-    assert_int_equal(list.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
-    FREE_ARRAY(st->ctx, list.exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(list.exts[0]),  LYEXT_SUBSTMT_MIN);
+    FREE_ARRAY(UTEST_LYCTX, list.exts, lysp_ext_instance_free);
 
     data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"50\">"EXT_SUBELEM "</min-elements> </leaf-list>";
-    assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_SUCCESS);
     assert_int_equal(llist.min, 50);
     assert_true(llist.flags & LYS_SET_MIN);
-    assert_string_equal(llist.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(llist.exts[0].insubstmt_index, 0);
-    assert_int_equal(llist.exts[0].insubstmt, LYEXT_SUBSTMT_MIN);
-    FREE_ARRAY(st->ctx, llist.exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(llist.exts[0]),  LYEXT_SUBSTMT_MIN);
+    FREE_ARRAY(UTEST_LYCTX, llist.exts, lysp_ext_instance_free);
 
     data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"-5\"/> </leaf-list>";
-    assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
-    logbuf_assert("Value \"-5\" of \"value\" attribute in \"min-elements\" element is out of bounds. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Value \"-5\" of \"value\" attribute in \"min-elements\" element is out of bounds.", "Line number 1.");
 
     data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"99999999999999999\"/> </leaf-list>";
-    assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
-    logbuf_assert("Value \"99999999999999999\" of \"value\" attribute in \"min-elements\" element is out of bounds. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Value \"99999999999999999\" of \"value\" attribute in \"min-elements\" element is out of bounds.", "Line number 1.");
 
     data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"5k\"/> </leaf-list>";
-    assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"5k\" of \"value\" attribute in \"min-elements\" element.", "Line number 1.");
 
     data = "<leaf-list xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\"> <min-elements value=\"05\"/> </leaf-list>";
-    assert_int_equal(test_element_helper(st, data, &llist, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &llist, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"05\" of \"value\" attribute in \"min-elements\" element.", "Line number 1.");
 }
 
 static void
 test_ordby_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     uint16_t flags = 0;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<ordered-by value=\"system\">"EXT_SUBELEM "</ordered-by>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, &exts), LY_SUCCESS);
     assert_true(flags & LYS_ORDBY_SYSTEM);
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_ORDEREDBY);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_ORDEREDBY);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
 
     data = ELEMENT_WRAPPER_START "<ordered-by value=\"user\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_SUCCESS);
     assert_true(flags & LYS_ORDBY_USER);
 
     data = ELEMENT_WRAPPER_START "<ordered-by value=\"inv\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &flags, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. Valid values are \"system\" and \"user\". Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &flags, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"inv\" of \"value\" attribute in \"ordered-by\" element. "
+            "Valid values are \"system\" and \"user\".", "Line number 1.");
 }
 
 static void
 test_any_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
     struct lysp_node_anydata *parsed = NULL;
+    uint16_t flags;
 
     /* anyxml max subelems */
     data = ELEMENT_WRAPPER_START
@@ -2305,23 +1987,15 @@
             EXT_SUBELEM
             "</anyxml>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_anydata *)siblings;
-    assert_null(parsed->parent);
-    assert_int_equal(parsed->nodetype, LYS_ANYXML);
-    assert_true(parsed->flags & LYS_CONFIG_W);
-    assert_true(parsed->flags & LYS_MAND_TRUE);
-    assert_true(parsed->flags & LYS_STATUS_DEPRC);
-    assert_null(parsed->next);
-    assert_string_equal(parsed->name, "any-name");
-    assert_string_equal(parsed->dsc, "desc");
-    assert_string_equal(parsed->ref, "ref");
-    assert_string_equal(parsed->when->cond, "when-cond");
+    flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "any-name", 0, LYS_ANYXML, 0, "ref", 1);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "feature");
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     /* anydata max subelems */
@@ -2338,47 +2012,36 @@
             EXT_SUBELEM
             "</anydata>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_anydata *)siblings;
-    assert_null(parsed->parent);
-    assert_int_equal(parsed->nodetype, LYS_ANYDATA);
-    assert_true(parsed->flags & LYS_CONFIG_W);
-    assert_true(parsed->flags & LYS_MAND_TRUE);
-    assert_true(parsed->flags & LYS_STATUS_DEPRC);
-    assert_null(parsed->next);
-    assert_string_equal(parsed->name, "any-name");
-    assert_string_equal(parsed->dsc, "desc");
-    assert_string_equal(parsed->ref, "ref");
-    assert_string_equal(parsed->when->cond, "when-cond");
+    flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "any-name", 0, LYS_ANYDATA, 0, "ref", 1);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "feature");
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     /* min subelems */
     node_meta.parent = (void *)0x10;
     data = ELEMENT_WRAPPER_START "<anydata name=\"any-name\"> </anydata>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_anydata *)siblings;
     assert_ptr_equal(parsed->parent, node_meta.parent);
-    assert_int_equal(parsed->nodetype, LYS_ANYDATA);
-    assert_null(parsed->next);
-    assert_null(parsed->exts);
-    lysp_node_free(st->ctx, siblings);
-
-    st->finished_correctly = true;
+    CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
+            "any-name", 0, LYS_ANYDATA, 1, NULL, 0);
+    lysp_node_free(UTEST_LYCTX, siblings);
 }
 
 static void
 test_leaf_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
     struct lysp_node_leaf *parsed = NULL;
+    uint16_t flags;
 
     /* max elements */
     data = ELEMENT_WRAPPER_START
@@ -2397,49 +2060,39 @@
             EXT_SUBELEM
             "</leaf>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_leaf *)siblings;
-    assert_null(parsed->parent);
-    assert_int_equal(parsed->nodetype, LYS_LEAF);
-    assert_true(parsed->flags & LYS_CONFIG_W);
-    assert_true(parsed->flags & LYS_MAND_TRUE);
-    assert_true(parsed->flags & LYS_STATUS_DEPRC);
-    assert_null(parsed->next);
-    assert_string_equal(parsed->name, "leaf");
-    assert_string_equal(parsed->dsc, "desc");
-    assert_string_equal(parsed->ref, "ref");
-    assert_string_equal(parsed->when->cond, "when-cond");
+    flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_DEPRC;
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "leaf", 0, LYS_LEAF, 0, "ref", 1);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "feature");
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
     assert_string_equal(parsed->musts->arg.str, "must-cond");
     assert_string_equal(parsed->type.name, "type");
     assert_string_equal(parsed->units, "uni");
     assert_string_equal(parsed->dflt.str, "def-val");
-    lysp_node_free(st->ctx, siblings);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     /* min elements */
     data = ELEMENT_WRAPPER_START "<leaf name=\"leaf\"> <type name=\"type\"/> </leaf>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_leaf *)siblings;
     assert_string_equal(parsed->name, "leaf");
     assert_string_equal(parsed->type.name, "type");
-    lysp_node_free(st->ctx, siblings);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_leaf_list_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {.parent = NULL, .nodes = &siblings};
     struct lysp_node_leaflist *parsed = NULL;
+    uint16_t flags;
 
     data = ELEMENT_WRAPPER_START
             "<leaf-list name=\"llist\">\n"
@@ -2459,29 +2112,21 @@
             EXT_SUBELEM
             "</leaf-list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_leaflist *)siblings;
+    flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MAX;
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
+    CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
     assert_string_equal(parsed->dflts[0].str, "def-val0");
     assert_string_equal(parsed->dflts[1].str, "def-val1");
-    assert_string_equal(parsed->dsc, "desc");
     assert_string_equal(parsed->iffeatures[0].str, "feature");
     assert_int_equal(parsed->max, 5);
-    assert_string_equal(parsed->musts->arg.str, "must-cond");
-    assert_string_equal(parsed->name, "llist");
-    assert_null(parsed->next);
-    assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
-    assert_null(parsed->parent);
-    assert_string_equal(parsed->ref, "ref");
     assert_string_equal(parsed->type.name, "type");
     assert_string_equal(parsed->units, "uni");
-    assert_string_equal(parsed->when->cond, "when-cond");
-    assert_true(parsed->flags & LYS_CONFIG_W);
-    assert_true(parsed->flags & LYS_ORDBY_USER);
-    assert_true(parsed->flags & LYS_STATUS_CURR);
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     data = ELEMENT_WRAPPER_START
@@ -2500,27 +2145,19 @@
             EXT_SUBELEM
             "</leaf-list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_leaflist *)siblings;
-    assert_string_equal(parsed->dsc, "desc");
+    flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN;
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
+    CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "feature");
     assert_int_equal(parsed->min, 5);
-    assert_string_equal(parsed->musts->arg.str, "must-cond");
-    assert_string_equal(parsed->name, "llist");
-    assert_null(parsed->next);
-    assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
-    assert_null(parsed->parent);
-    assert_string_equal(parsed->ref, "ref");
     assert_string_equal(parsed->type.name, "type");
     assert_string_equal(parsed->units, "uni");
-    assert_string_equal(parsed->when->cond, "when-cond");
-    assert_true(parsed->flags & LYS_CONFIG_W);
-    assert_true(parsed->flags & LYS_ORDBY_USER);
-    assert_true(parsed->flags & LYS_STATUS_CURR);
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     data = ELEMENT_WRAPPER_START
@@ -2539,25 +2176,19 @@
             "    <when condition=\"when-cond\"/>\n"
             "</leaf-list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_leaflist *)siblings;
-    assert_string_equal(parsed->dsc, "desc");
+    flags = LYS_CONFIG_W | LYS_ORDBY_USER | LYS_STATUS_CURR | LYS_SET_MIN | LYS_SET_MAX;
+    CHECK_LYSP_NODE(parsed, "desc", 0, flags, 1,
+            "llist", 0, LYS_LEAFLIST, 0, "ref", 1);
+    CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "feature");
     assert_int_equal(parsed->min, 5);
     assert_int_equal(parsed->max, 15);
-    assert_string_equal(parsed->musts->arg.str, "must-cond");
-    assert_string_equal(parsed->name, "llist");
-    assert_null(parsed->next);
-    assert_int_equal(parsed->nodetype, LYS_LEAFLIST);
-    assert_null(parsed->parent);
-    assert_string_equal(parsed->ref, "ref");
     assert_string_equal(parsed->type.name, "type");
     assert_string_equal(parsed->units, "uni");
-    assert_string_equal(parsed->when->cond, "when-cond");
-    assert_true(parsed->flags & LYS_CONFIG_W);
-    assert_true(parsed->flags & LYS_ORDBY_USER);
-    assert_true(parsed->flags & LYS_STATUS_CURR);
-    lysp_node_free(st->ctx, siblings);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     data = ELEMENT_WRAPPER_START
@@ -2565,11 +2196,11 @@
             "    <type name=\"type\"/>\n"
             "</leaf-list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_leaflist *)siblings;
     assert_string_equal(parsed->name, "llist");
     assert_string_equal(parsed->type.name, "type");
-    lysp_node_free(st->ctx, siblings);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     /* invalid combinations */
@@ -2580,9 +2211,9 @@
             "    <type name=\"type\"/>"
             "</leaf-list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5. Line number 4.");
-    lysp_node_free(st->ctx, siblings);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid combination of min-elements and max-elements: min value 15 is bigger than the max value 5.", "Line number 4.");
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     data = ELEMENT_WRAPPER_START
@@ -2592,85 +2223,72 @@
             "    <type name=\"type\"/>\n"
             "</leaf-list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element. Line number 5.");
-    lysp_node_free(st->ctx, siblings);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid combination of sub-elemnts \"min-elements\" and \"default\" in \"leaf-list\" element.", "Line number 5.");
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     data = ELEMENT_WRAPPER_START
             "<leaf-list name=\"llist\">"
             "</leaf-list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory sub-element \"type\" of \"leaf-list\" element. Line number 1.");
-    lysp_node_free(st->ctx, siblings);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory sub-element \"type\" of \"leaf-list\" element.", "Line number 1.");
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_presence_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *val;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\">"EXT_SUBELEM "</presence>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
     assert_string_equal(val, "presence-val");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_PRESENCE);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
-    FREE_STRING(st->ctx, val);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_PRESENCE);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
+    FREE_STRING(UTEST_LYCTX, val);
 
     data = ELEMENT_WRAPPER_START "<presence value=\"presence-val\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
     assert_string_equal(val, "presence-val");
-    FREE_STRING(st->ctx, val);
+    FREE_STRING(UTEST_LYCTX, val);
 
     data = ELEMENT_WRAPPER_START "<presence/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory attribute value of presence element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory attribute value of presence element.", "Line number 1.");
 }
 
 static void
 test_key_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     const char *val;
     struct lysp_ext_instance *exts = NULL;
 
     data = ELEMENT_WRAPPER_START "<key value=\"key-value\">"EXT_SUBELEM "</key>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, &exts), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, &exts), LY_SUCCESS);
     assert_string_equal(val, "key-value");
-    assert_string_equal(exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(exts[0].insubstmt_index, 0);
-    assert_int_equal(exts[0].insubstmt, LYEXT_SUBSTMT_KEY);
-    FREE_ARRAY(st->ctx, exts, lysp_ext_instance_free);
-    FREE_STRING(st->ctx, val);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(exts[0]),  LYEXT_SUBSTMT_KEY);
+    FREE_ARRAY(UTEST_LYCTX, exts, lysp_ext_instance_free);
+    FREE_STRING(UTEST_LYCTX, val);
 
     data = ELEMENT_WRAPPER_START "<key value=\"key-value\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_SUCCESS);
     assert_string_equal(val, "key-value");
-    FREE_STRING(st->ctx, val);
+    FREE_STRING(UTEST_LYCTX, val);
 
     data = ELEMENT_WRAPPER_START "<key/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &val, NULL, NULL), LY_EVALID);
-    logbuf_assert("Missing mandatory attribute value of key element. Line number 1.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &val, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Missing mandatory attribute value of key element.", "Line number 1.");
 }
 
 static void
 test_typedef_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_tpdf *tpdfs = NULL;
     struct tree_node_meta typdef_meta = {NULL, (struct lysp_node **)&tpdfs};
@@ -2686,7 +2304,7 @@
             EXT_SUBELEM
             "</typedef>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(tpdfs[0].dflt.str, "def-val");
     assert_string_equal(tpdfs[0].dsc, "desc-text");
     assert_string_equal(tpdfs[0].name, "tpdf-name");
@@ -2694,10 +2312,8 @@
     assert_string_equal(tpdfs[0].type.name, "type");
     assert_string_equal(tpdfs[0].units, "uni");
     assert_true(tpdfs[0].flags & LYS_STATUS_CURR);
-    assert_string_equal(tpdfs[0].exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(tpdfs[0].exts[0].insubstmt_index, 0);
-    assert_int_equal(tpdfs[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(tpdfs[0].exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, tpdfs, lysp_tpdf_free);
     tpdfs = NULL;
 
     data = ELEMENT_WRAPPER_START
@@ -2705,19 +2321,16 @@
             "    <type name=\"type\"/>\n"
             "</typedef>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &typdef_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(tpdfs[0].name, "tpdf-name");
     assert_string_equal(tpdfs[0].type.name, "type");
-    FREE_ARRAY(st->ctx, tpdfs, lysp_tpdf_free);
+    FREE_ARRAY(UTEST_LYCTX, tpdfs, lysp_tpdf_free);
     tpdfs = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_refine_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_refine *refines = NULL;
 
@@ -2737,7 +2350,7 @@
             EXT_SUBELEM
             "</refine>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &refines, NULL, NULL), LY_SUCCESS);
     assert_string_equal(refines->nodeid, "target");
     assert_string_equal(refines->dflts[0].str, "def");
     assert_string_equal(refines->dsc, "desc");
@@ -2749,26 +2362,21 @@
     assert_string_equal(refines->musts->arg.str, "cond");
     assert_string_equal(refines->presence, "presence");
     assert_string_equal(refines->ref, "ref");
-    assert_string_equal(refines->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(refines->exts[0].insubstmt_index, 0);
-    assert_int_equal(refines->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, refines, lysp_refine_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(refines->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, refines, lysp_refine_free);
     refines = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<refine target-node=\"target\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &refines, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &refines, NULL, NULL), LY_SUCCESS);
     assert_string_equal(refines->nodeid, "target");
-    FREE_ARRAY(st->ctx, refines, lysp_refine_free);
+    FREE_ARRAY(UTEST_LYCTX, refines, lysp_refine_free);
     refines = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_uses_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {NULL, &siblings};
@@ -2787,39 +2395,29 @@
             EXT_SUBELEM
             "</uses>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_uses *)&siblings[0];
-    assert_string_equal(parsed->name, "uses-name");
-    assert_string_equal(parsed->dsc, "desc");
-    assert_true(parsed->flags & LYS_STATUS_OBSLT);
+    CHECK_LYSP_NODE(parsed, "desc", 1, LYS_STATUS_OBSLT, 1,
+            "uses-name", 0, LYS_USES, 0, "ref", 1);
+    CHECK_LYSP_WHEN(parsed->when, "cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "feature");
-    assert_null(parsed->next);
-    assert_int_equal(parsed->nodetype, LYS_USES);
-    assert_null(parsed->parent);
-    assert_string_equal(parsed->ref, "ref");
     assert_string_equal(parsed->refines->nodeid, "target");
-    assert_string_equal(parsed->when->cond, "cond");
     assert_string_equal(parsed->augments->nodeid, "target");
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<uses name=\"uses-name\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(siblings[0].name, "uses-name");
-    lysp_node_free(st->ctx, siblings);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_revision_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_revision *revs = NULL;
 
@@ -2831,43 +2429,38 @@
             EXT_SUBELEM
             "</revision>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_SUCCESS);
     assert_string_equal(revs->date, "2018-12-25");
     assert_string_equal(revs->dsc, "desc");
     assert_string_equal(revs->ref, "ref");
-    assert_string_equal(revs->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(revs->exts[0].insubstmt_index, 0);
-    assert_int_equal(revs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, revs, lysp_revision_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(revs->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
     revs = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<revision date=\"2005-05-05\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_SUCCESS);
     assert_string_equal(revs->date, "2005-05-05");
-    FREE_ARRAY(st->ctx, revs, lysp_revision_free);
+    FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
     revs = NULL;
 
     /* invalid value */
     data = ELEMENT_WRAPPER_START "<revision date=\"05-05-2005\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &revs, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"05-05-2005\" of \"revision\". Line number 1.");
-    FREE_ARRAY(st->ctx, revs, lysp_revision_free);
+    assert_int_equal(test_element_helper(state, data, &revs, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"05-05-2005\" of \"revision\".", "Line number 1.");
+    FREE_ARRAY(UTEST_LYCTX, revs, lysp_revision_free);
     revs = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_include_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_include *includes = NULL;
     struct include_meta inc_meta = {"module-name", &includes};
 
     /* max subelems */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<include module=\"mod\">\n"
             "    <description><text>desc</text></description>\n"
@@ -2876,56 +2469,53 @@
             EXT_SUBELEM
             "</include>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(includes->name, "mod");
     assert_string_equal(includes->dsc, "desc");
     assert_string_equal(includes->ref, "ref");
     assert_string_equal(includes->rev, "1999-09-09");
-    assert_string_equal(includes->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(includes->exts[0].insubstmt_index, 0);
-    assert_int_equal(includes->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, includes, lysp_include_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(includes->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
     includes = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<include module=\"mod\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(includes->name, "mod");
-    FREE_ARRAY(st->ctx, includes, lysp_include_free);
+    FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
     includes = NULL;
 
     /* invalid combinations */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_0;
+    YCTX->parsed_mod->version = LYS_VERSION_1_0;
     data = ELEMENT_WRAPPER_START
             "<include module=\"mod\">\n"
             "    <description><text>desc</text></description>\n"
             "    <revision-date date=\"1999-09-09\"/>\n"
             "</include>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid sub-elemnt \"description\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 2.");
-    FREE_ARRAY(st->ctx, includes, lysp_include_free);
+    assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid sub-elemnt \"description\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer.",
+            "Line number 2.");
+    FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
     includes = NULL;
 
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_0;
+    YCTX->parsed_mod->version = LYS_VERSION_1_0;
     data = ELEMENT_WRAPPER_START
             "<include module=\"mod\">\n"
             "    <reference><text>ref</text></reference>\n"
             "    <revision-date date=\"1999-09-09\"/>\n"
             "</include>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inc_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid sub-elemnt \"reference\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 2.");
-    FREE_ARRAY(st->ctx, includes, lysp_include_free);
+    assert_int_equal(test_element_helper(state, data, &inc_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid sub-elemnt \"reference\" of \"include\" element - this sub-element is allowed only in modules with version 1.1 or newer.",
+            "Line number 2.");
+    FREE_ARRAY(UTEST_LYCTX, includes, lysp_include_free);
     includes = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_list_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {NULL, &siblings};
@@ -2960,9 +2550,8 @@
             EXT_SUBELEM
             "</list>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_list *)&siblings[0];
-    assert_string_equal(parsed->dsc, "desc");
     assert_string_equal(parsed->child->name, "anyd");
     assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
     assert_string_equal(parsed->child->next->name, "anyx");
@@ -2980,53 +2569,45 @@
     assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "uses-name");
     assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_USES);
     assert_null(parsed->child->next->next->next->next->next->next->next->next);
+    uint16_t flags = LYS_ORDBY_USER | LYS_STATUS_DEPRC | LYS_CONFIG_W | LYS_SET_MIN;
+
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "list-name", 0, LYS_LIST, 0, "ref", 1);
+    CHECK_LYSP_RESTR(parsed->musts, "must-cond", NULL, NULL, NULL, 0, NULL);
+    CHECK_LYSP_WHEN(parsed->when, "when", NULL, 0, NULL);
     assert_string_equal(parsed->groupings->name, "grp");
     assert_string_equal(parsed->actions->name, "action");
     assert_int_equal(parsed->groupings->nodetype, LYS_GROUPING);
     assert_string_equal(parsed->notifs->name, "notf");
-    assert_true(parsed->flags & LYS_ORDBY_USER);
-    assert_true(parsed->flags & LYS_STATUS_DEPRC);
-    assert_true(parsed->flags & LYS_CONFIG_W);
     assert_string_equal(parsed->iffeatures[0].str, "iff");
     assert_string_equal(parsed->key, "key");
     assert_int_equal(parsed->min, 10);
-    assert_string_equal(parsed->musts->arg.str, "must-cond");
-    assert_string_equal(parsed->name, "list-name");
-    assert_null(parsed->next);
-    assert_int_equal(parsed->nodetype, LYS_LIST);
-    assert_null(parsed->parent);
-    assert_string_equal(parsed->ref, "ref");
     assert_string_equal(parsed->typedefs->name, "tpdf");
     assert_string_equal(parsed->uniques->str, "utag");
-    assert_string_equal(parsed->when->cond, "when");
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
-    ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
+    ly_set_erase(&YCTX->tpdfs_nodes, NULL);
     siblings = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<list name=\"list-name\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_list *)&siblings[0];
-    assert_string_equal(parsed->name, "list-name");
-    lysp_node_free(st->ctx, siblings);
+    CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
+            "list-name", 0, LYS_LIST, 0, NULL, 0);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_notification_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_notif *notifs = NULL;
     struct tree_node_meta notif_meta = {NULL, (struct lysp_node **)&notifs};
 
     /* max subelems */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<notification name=\"notif-name\">\n"
             "    <anydata name=\"anyd\"/>\n"
@@ -3047,7 +2628,7 @@
             EXT_SUBELEM
             "</notification>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &notif_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &notif_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(notifs->name, "notif-name");
     assert_string_equal(notifs->data->name, "anyd");
     assert_int_equal(notifs->data->nodetype, LYS_ANYDATA);
@@ -3075,26 +2656,21 @@
     assert_null(notifs->parent);
     assert_string_equal(notifs->ref, "ref");
     assert_string_equal(notifs->typedefs->name, "tpdf");
-    assert_string_equal(notifs->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(notifs->exts[0].insubstmt_index, 0);
-    assert_int_equal(notifs->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(notifs->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, notifs, lysp_notif_free);
     notifs = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<notification name=\"notif-name\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &notif_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &notif_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(notifs->name, "notif-name");
-    FREE_ARRAY(st->ctx, notifs, lysp_notif_free);
+    FREE_ARRAY(UTEST_LYCTX, notifs, lysp_notif_free);
     notifs = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_grouping_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_grp *grps = NULL;
     struct tree_node_meta grp_meta = {NULL, (struct lysp_node **)&grps};
@@ -3120,7 +2696,7 @@
             EXT_SUBELEM
             "</grouping>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(grps->name, "grp-name");
     assert_string_equal(grps->data->name, "anyd");
     assert_string_equal(grps->data->next->name, "anyx");
@@ -3142,33 +2718,28 @@
     assert_int_equal(grps->data->next->next->next->next->next->next->nodetype, LYS_CONTAINER);
     assert_string_equal(grps->data->next->next->next->next->next->next->next->name, "choice");
     assert_int_equal(grps->data->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
-    assert_string_equal(grps->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(grps->exts[0].insubstmt_index, 0);
-    assert_int_equal(grps->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, grps, lysp_grp_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(grps->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, grps, lysp_grp_free);
     grps = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<grouping name=\"grp-name\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &grp_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &grp_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(grps->name, "grp-name");
-    FREE_ARRAY(st->ctx, grps, lysp_grp_free);
+    FREE_ARRAY(UTEST_LYCTX, grps, lysp_grp_free);
     grps = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_container_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {NULL, &siblings};
     struct lysp_node_container *parsed = NULL;
 
     /* max subelems */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<container name=\"cont-name\">\n"
             "    <anydata name=\"anyd\"/>\n"
@@ -3194,19 +2765,16 @@
             EXT_SUBELEM
             "</container>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_container *)siblings;
-    assert_string_equal(parsed->name, "cont-name");
-    assert_null(parsed->parent);
-    assert_int_equal(parsed->nodetype, LYS_CONTAINER);
-    assert_true(parsed->flags & LYS_CONFIG_W);
-    assert_true(parsed->flags & LYS_STATUS_CURR);
-    assert_null(parsed->next);
-    assert_string_equal(parsed->dsc, "desc");
-    assert_string_equal(parsed->ref, "ref");
-    assert_string_equal(parsed->when->cond, "when-cond");
+    uint16_t flags = LYS_CONFIG_W | LYS_STATUS_CURR;
+
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "cont-name", 0, LYS_CONTAINER, 0, "ref", 1);
+    CHECK_LYSP_RESTR(parsed->musts, "cond", NULL, NULL, NULL, 0, NULL);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
+
     assert_string_equal(parsed->iffeatures[0].str, "iff");
-    assert_string_equal(parsed->musts->arg.str, "cond");
     assert_string_equal(parsed->presence, "presence");
     assert_string_equal(parsed->typedefs->name, "tpdf");
     assert_string_equal(parsed->groupings->name, "sub-grp");
@@ -3229,35 +2797,31 @@
     assert_null(parsed->child->next->next->next->next->next->next->next->next);
     assert_string_equal(parsed->notifs->name, "notf");
     assert_string_equal(parsed->actions->name, "act");
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
-    ly_set_erase(&st->yin_ctx->tpdfs_nodes, NULL);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
+    ly_set_erase(&YCTX->tpdfs_nodes, NULL);
     siblings = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<container name=\"cont-name\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_container *)siblings;
-    assert_string_equal(parsed->name, "cont-name");
-    lysp_node_free(st->ctx, siblings);
+    CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
+            "cont-name", 0, LYS_CONTAINER, 0, NULL, 0);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_case_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {NULL, &siblings};
     struct lysp_node_case *parsed = NULL;
 
     /* max subelems */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<case name=\"case-name\">\n"
             "    <anydata name=\"anyd\"/>\n"
@@ -3276,16 +2840,13 @@
             EXT_SUBELEM
             "</case>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_case *)siblings;
-    assert_string_equal(parsed->name, "case-name");
-    assert_null(parsed->parent);
-    assert_int_equal(parsed->nodetype, LYS_CASE);
-    assert_true(parsed->flags & LYS_STATUS_CURR);
-    assert_null(parsed->next);
-    assert_string_equal(parsed->dsc, "desc");
-    assert_string_equal(parsed->ref, "ref");
-    assert_string_equal(parsed->when->cond, "when-cond");
+    uint16_t flags = LYS_STATUS_CURR;
+
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "case-name", 0, LYS_CASE, 0, "ref", 1);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "iff");
     assert_string_equal(parsed->child->name, "anyd");
     assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
@@ -3304,34 +2865,30 @@
     assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "choice");
     assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_CHOICE);
     assert_null(parsed->child->next->next->next->next->next->next->next->next);
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<case name=\"case-name\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_case *)siblings;
-    assert_string_equal(parsed->name, "case-name");
-    lysp_node_free(st->ctx, siblings);
+    CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
+            "case-name", 0, LYS_CASE, 0, NULL, 0);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_choice_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_node *siblings = NULL;
     struct tree_node_meta node_meta = {NULL, &siblings};
     struct lysp_node_choice *parsed = NULL;
 
     /* max subelems */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<choice name=\"choice-name\">\n"
             "    <anydata name=\"anyd\"/>\n"
@@ -3353,16 +2910,13 @@
             EXT_SUBELEM
             "</choice>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_choice *)siblings;
-    assert_string_equal(parsed->name, "choice-name");
-    assert_null(parsed->parent);
-    assert_int_equal(parsed->nodetype, LYS_CHOICE);
-    assert_true(parsed->flags & LYS_CONFIG_W && parsed->flags & LYS_MAND_TRUE && parsed->flags & LYS_STATUS_CURR);
-    assert_null(parsed->next);
-    assert_string_equal(parsed->dsc, "desc");
-    assert_string_equal(parsed->ref, "ref");
-    assert_string_equal(parsed->when->cond, "when-cond");
+    uint16_t flags = LYS_CONFIG_W | LYS_MAND_TRUE | LYS_STATUS_CURR;
+
+    CHECK_LYSP_NODE(parsed, "desc", 1, flags, 1,
+            "choice-name", 0, LYS_CHOICE, 0, "ref", 1);
+    CHECK_LYSP_WHEN(parsed->when, "when-cond", NULL, 0, NULL);
     assert_string_equal(parsed->iffeatures[0].str, "iff");
     assert_string_equal(parsed->child->name, "anyd");
     assert_int_equal(parsed->child->nodetype, LYS_ANYDATA);
@@ -3381,33 +2935,30 @@
     assert_string_equal(parsed->child->next->next->next->next->next->next->next->name, "list");
     assert_int_equal(parsed->child->next->next->next->next->next->next->next->nodetype, LYS_LIST);
     assert_null(parsed->child->next->next->next->next->next->next->next->next);
-    assert_string_equal(parsed->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(parsed->exts[0].insubstmt_index, 0);
-    assert_int_equal(parsed->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_node_free(st->ctx, siblings);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(parsed->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<choice name=\"choice-name\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &node_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &node_meta, NULL, NULL), LY_SUCCESS);
     parsed = (struct lysp_node_choice *)siblings;
     assert_string_equal(parsed->name, "choice-name");
-    lysp_node_free(st->ctx, siblings);
+    CHECK_LYSP_NODE(parsed, NULL, 0, 0, 0,
+            "choice-name", 0, LYS_CHOICE, 0, NULL, 0);
+    lysp_node_free(UTEST_LYCTX, siblings);
     siblings = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_inout_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_action_inout inout = {};
     struct inout_meta inout_meta = {NULL, &inout};
 
     /* max subelements */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<input>\n"
             "    <anydata name=\"anyd\"/>\n"
@@ -3424,10 +2975,9 @@
             EXT_SUBELEM
             "</input>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
-    assert_null(inout.parent);
-    assert_int_equal(inout.nodetype, LYS_INPUT);
-    assert_string_equal(inout.musts->arg.str, "cond");
+    assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_INPUT, 0, 1);
+    CHECK_LYSP_RESTR(inout.musts, "cond", NULL, NULL, NULL, 0, NULL);
     assert_string_equal(inout.typedefs->name, "tpdf");
     assert_string_equal(inout.groupings->name, "sub-grp");
     assert_string_equal(inout.data->name, "anyd");
@@ -3447,14 +2997,12 @@
     assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
     assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
     assert_null(inout.data->next->next->next->next->next->next->next->next);
-    assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(inout.exts[0].insubstmt_index, 0);
-    assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_action_inout_free(st->ctx, &inout);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_action_inout_free(UTEST_LYCTX, &inout);
     memset(&inout, 0, sizeof inout);
 
     /* max subelements */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<output>\n"
             "    <anydata name=\"anyd\"/>\n"
@@ -3471,9 +3019,8 @@
             EXT_SUBELEM
             "</output>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
-    assert_null(inout.parent);
-    assert_int_equal(inout.nodetype, LYS_OUTPUT);
+    assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
+    CHECK_LYSP_ACTION_INOUT(&(inout), 1, 1, 1, 1, LYS_OUTPUT, 0, 1);
     assert_string_equal(inout.musts->arg.str, "cond");
     assert_string_equal(inout.typedefs->name, "tpdf");
     assert_string_equal(inout.groupings->name, "sub-grp");
@@ -3494,42 +3041,38 @@
     assert_string_equal(inout.data->next->next->next->next->next->next->next->name, "uses-name");
     assert_int_equal(inout.data->next->next->next->next->next->next->next->nodetype, LYS_USES);
     assert_null(inout.data->next->next->next->next->next->next->next->next);
-    assert_string_equal(inout.exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(inout.exts[0].insubstmt_index, 0);
-    assert_int_equal(inout.exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_action_inout_free(st->ctx, &inout);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(inout.exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_action_inout_free(UTEST_LYCTX, &inout);
     memset(&inout, 0, sizeof inout);
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<input><leaf name=\"l\"><type name=\"empty\"/></leaf></input>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
-    lysp_action_inout_free(st->ctx, &inout);
+    assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
+    lysp_action_inout_free(UTEST_LYCTX, &inout);
     memset(&inout, 0, sizeof inout);
 
     data = ELEMENT_WRAPPER_START "<output><leaf name=\"l\"><type name=\"empty\"/></leaf></output>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_SUCCESS);
-    lysp_action_inout_free(st->ctx, &inout);
+    assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_SUCCESS);
+    lysp_action_inout_free(UTEST_LYCTX, &inout);
     memset(&inout, 0, sizeof inout);
 
     /* invalid combinations */
     data = ELEMENT_WRAPPER_START "<input name=\"test\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &inout_meta, NULL, NULL), LY_EVALID);
-    logbuf_assert("Unexpected attribute \"name\" of \"input\" element. Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &inout_meta, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Unexpected attribute \"name\" of \"input\" element.", "Line number 1.");
     memset(&inout, 0, sizeof inout);
-
-    st->finished_correctly = true;
 }
 
 static void
 test_action_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_action *actions = NULL;
     struct tree_node_meta act_meta = {NULL, (struct lysp_node **)&actions};
+    uint16_t flags;
 
     /* max subelems */
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<action name=\"act\">\n"
             "    <description><text>desc</text></description>\n"
@@ -3545,26 +3088,27 @@
             ELEMENT_WRAPPER_END;
     /* there must be parent for action */
     act_meta.parent = (void *)1;
-    assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
     act_meta.parent = NULL;
-    assert_non_null(actions->parent);
-    assert_int_equal(actions->nodetype, LYS_ACTION);
-    assert_true(actions->flags & LYS_STATUS_DEPRC);
-    assert_string_equal(actions->name, "act");
-    assert_string_equal(actions->dsc, "desc");
-    assert_string_equal(actions->ref, "ref");
+    flags = LYS_STATUS_DEPRC;
+    CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\
+            1, 0, 0, 0,\
+            1, 0,\
+            "act", LYS_ACTION, \
+            1, 0, 0, 1,\
+            1, 0,\
+            1, "ref", 1);
+
     assert_string_equal(actions->iffeatures[0].str, "iff");
     assert_string_equal(actions->typedefs->name, "tpdf");
     assert_string_equal(actions->groupings->name, "grouping");
-    assert_string_equal(actions->input.data->name, "uses-name");
     assert_string_equal(actions->output.musts->arg.str, "cond");
-    assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(actions->exts[0].insubstmt_index, 0);
-    assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, actions, lysp_action_free)
+    assert_string_equal(actions->input.data->name, "uses-name");
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, actions, lysp_action_free)
     actions = NULL;
 
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<rpc name=\"act\">\n"
             "    <description><text>desc</text></description>\n"
@@ -3578,43 +3122,41 @@
             EXT_SUBELEM
             "</rpc>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
-    assert_null(actions->parent);
-    assert_int_equal(actions->nodetype, LYS_RPC);
-    assert_true(actions->flags & LYS_STATUS_DEPRC);
-    assert_string_equal(actions->name, "act");
-    assert_string_equal(actions->dsc, "desc");
-    assert_string_equal(actions->ref, "ref");
+    assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
+    flags = LYS_STATUS_DEPRC;
+    CHECK_LYSP_ACTION(actions, "desc", 1, flags, 1, 1,\
+            1, 0, 0, 0,\
+            1, 0,\
+            "act", LYS_RPC, \
+            1, 0, 0, 1,\
+            1, 0,\
+            0, "ref", 1);
+
     assert_string_equal(actions->iffeatures[0].str, "iff");
     assert_string_equal(actions->typedefs->name, "tpdf");
     assert_string_equal(actions->groupings->name, "grouping");
     assert_string_equal(actions->input.data->name, "uses-name");
     assert_string_equal(actions->output.musts->arg.str, "cond");
-    assert_string_equal(actions->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(actions->exts[0].insubstmt_index, 0);
-    assert_int_equal(actions->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, actions, lysp_action_free)
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(actions->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, actions, lysp_action_free)
     actions = NULL;
 
     /* min subelems */
     data = ELEMENT_WRAPPER_START "<action name=\"act\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &act_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &act_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(actions->name, "act");
-    FREE_ARRAY(st->ctx, actions, lysp_action_free)
+    FREE_ARRAY(UTEST_LYCTX, actions, lysp_action_free)
     actions = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_augment_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_augment *augments = NULL;
     struct tree_node_meta aug_meta = {NULL, (struct lysp_node **)&augments};
 
-    st->yin_ctx->parsed_mod->version = LYS_VERSION_1_1;
+    YCTX->parsed_mod->version = LYS_VERSION_1_1;
     data = ELEMENT_WRAPPER_START
             "<augment target-node=\"target\">\n"
             "    <action name=\"action\"/>\n"
@@ -3636,7 +3178,7 @@
             EXT_SUBELEM
             "</augment>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(augments->nodeid, "target");
     assert_null(augments->parent);
     assert_int_equal(augments->nodetype, LYS_AUGMENT);
@@ -3666,25 +3208,20 @@
     assert_null(augments->child->next->next->next->next->next->next->next->next->next);
     assert_string_equal(augments->actions->name, "action");
     assert_string_equal(augments->notifs->name, "notif");
-    assert_string_equal(augments->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(augments->exts[0].insubstmt_index, 0);
-    assert_int_equal(augments->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, augments, lysp_augment_free)
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(augments->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, augments, lysp_augment_free)
     augments = NULL;
 
     data = ELEMENT_WRAPPER_START "<augment target-node=\"target\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &aug_meta, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &aug_meta, NULL, NULL), LY_SUCCESS);
     assert_string_equal(augments->nodeid, "target");
-    FREE_ARRAY(st->ctx, augments, lysp_augment_free)
+    FREE_ARRAY(UTEST_LYCTX, augments, lysp_augment_free)
     augments = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_deviate_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_deviate *deviates = NULL;
     struct lysp_deviate_add *d_add;
@@ -3693,30 +3230,30 @@
 
     /* all valid arguments with min subelems */
     data = ELEMENT_WRAPPER_START "<deviate value=\"not-supported\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
-    lysp_deviate_free(st->ctx, deviates);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
     data = ELEMENT_WRAPPER_START "<deviate value=\"add\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     assert_int_equal(deviates->mod, LYS_DEV_ADD);
-    lysp_deviate_free(st->ctx, deviates);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
     data = ELEMENT_WRAPPER_START "<deviate value=\"replace\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     assert_int_equal(deviates->mod, LYS_DEV_REPLACE);
-    lysp_deviate_free(st->ctx, deviates);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
     data = ELEMENT_WRAPPER_START "<deviate value=\"delete\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     assert_int_equal(deviates->mod, LYS_DEV_DELETE);
-    lysp_deviate_free(st->ctx, deviates);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
@@ -3726,12 +3263,10 @@
             EXT_SUBELEM
             "</deviate>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     assert_int_equal(deviates->mod, LYS_DEV_NOT_SUPPORTED);
-    assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(deviates->exts[0].insubstmt_index, 0);
-    assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_deviate_free(st->ctx, deviates);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
@@ -3748,7 +3283,7 @@
             EXT_SUBELEM
             "</deviate>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     d_add = (struct lysp_deviate_add *)deviates;
     assert_int_equal(d_add->mod, LYS_DEV_ADD);
     assert_null(d_add->next);
@@ -3756,13 +3291,11 @@
     assert_string_equal(d_add->musts->arg.str, "cond");
     assert_string_equal(d_add->uniques[0].str, "utag");
     assert_string_equal(d_add->dflts[0].str, "def");
-    assert_true(d_add->flags & LYS_MAND_TRUE && d_add->flags & LYS_CONFIG_W);
+    assert_true((d_add->flags & LYS_MAND_TRUE) && (d_add->flags & LYS_CONFIG_W));
     assert_int_equal(d_add->min, 5);
     assert_int_equal(d_add->max, 15);
-    assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(deviates->exts[0].insubstmt_index, 0);
-    assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_deviate_free(st->ctx, deviates);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
@@ -3778,20 +3311,18 @@
             EXT_SUBELEM
             "</deviate>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     d_rpl = (struct lysp_deviate_rpl *)deviates;
     assert_int_equal(d_rpl->mod, LYS_DEV_REPLACE);
     assert_null(d_rpl->next);
     assert_string_equal(d_rpl->type->name, "newtype");
     assert_string_equal(d_rpl->units, "uni");
     assert_string_equal(d_rpl->dflt.str, "def");
-    assert_true(d_rpl->flags & LYS_MAND_TRUE && d_rpl->flags & LYS_CONFIG_W);
+    assert_true((d_rpl->flags & LYS_MAND_TRUE) && (d_rpl->flags & LYS_CONFIG_W));
     assert_int_equal(d_rpl->min, 5);
     assert_int_equal(d_rpl->max, 15);
-    assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(deviates->exts[0].insubstmt_index, 0);
-    assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_deviate_free(st->ctx, deviates);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
@@ -3804,7 +3335,7 @@
             EXT_SUBELEM
             "</deviate>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_SUCCESS);
     d_del = (struct lysp_deviate_del *)deviates;
     assert_int_equal(d_del->mod, LYS_DEV_DELETE);
     assert_null(d_del->next);
@@ -3812,32 +3343,34 @@
     assert_string_equal(d_del->musts->arg.str, "c");
     assert_string_equal(d_del->uniques[0].str, "tag");
     assert_string_equal(d_del->dflts[0].str, "default");
-    assert_string_equal(deviates->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(deviates->exts[0].insubstmt_index, 0);
-    assert_int_equal(deviates->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    lysp_deviate_free(st->ctx, deviates);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviates->exts[0]),  LYEXT_SUBSTMT_SELF);
+    lysp_deviate_free(UTEST_LYCTX, deviates);
     free(deviates);
     deviates = NULL;
 
     /* invalid arguments */
     data = ELEMENT_WRAPPER_START "<deviate value=\"\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"\" of \"value\" attribute in \"deviate\" element. "
+            "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
     deviates = NULL;
 
     data = ELEMENT_WRAPPER_START "<deviate value=\"invalid\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"invalid\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"invalid\" of \"value\" attribute in \"deviate\" element. "
+            "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
     deviates = NULL;
 
     data = ELEMENT_WRAPPER_START "<deviate value=\"ad\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"ad\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"ad\" of \"value\" attribute in \"deviate\" element. "
+            "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
     deviates = NULL;
 
     data = ELEMENT_WRAPPER_START "<deviate value=\"adds\" />" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
-    logbuf_assert("Invalid value \"adds\" of \"value\" attribute in \"deviate\" element. Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\". Line number 1.");
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid value \"adds\" of \"value\" attribute in \"deviate\" element. "
+            "Valid values are \"not-supported\", \"add\", \"replace\" and \"delete\".", "Line number 1.");
     deviates = NULL;
 
     data = ELEMENT_WRAPPER_START
@@ -3845,16 +3378,13 @@
             "    <must condition=\"c\"/>\n"
             "</deviate>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviates, NULL, NULL), LY_EVALID);
-    logbuf_assert("Deviate of this type doesn't allow \"must\" as it's sub-element. Line number 2.");
-
-    st->finished_correctly = true;
+    assert_int_equal(test_element_helper(state, data, &deviates, NULL, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Deviate of this type doesn't allow \"must\" as it's sub-element.", "Line number 2.");
 }
 
 static void
 test_deviation_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lysp_deviation *deviations = NULL;
 
@@ -3864,10 +3394,10 @@
             "    <deviate value=\"not-supported\"/>\n"
             "</deviation>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_SUCCESS);
     assert_string_equal(deviations->nodeid, "target");
     assert_int_equal(deviations->deviates->mod, LYS_DEV_NOT_SUPPORTED);
-    FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
+    FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
     deviations = NULL;
 
     /* max subelems */
@@ -3879,26 +3409,22 @@
             EXT_SUBELEM
             "</deviation>"
             ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_SUCCESS);
+    assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_SUCCESS);
     assert_string_equal(deviations->nodeid, "target");
     assert_int_equal(deviations->deviates->mod, LYS_DEV_ADD);
     assert_string_equal(deviations->ref, "ref");
     assert_string_equal(deviations->dsc, "desc");
-    assert_string_equal(deviations->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(deviations->exts[0].insubstmt_index, 0);
-    assert_int_equal(deviations->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
-    FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(deviations->exts[0]),  LYEXT_SUBSTMT_SELF);
+    FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
     deviations = NULL;
 
     /* invalid */
     data = ELEMENT_WRAPPER_START "<deviation target-node=\"target\"/>" ELEMENT_WRAPPER_END;
-    assert_int_equal(test_element_helper(st, data, &deviations, NULL, NULL), LY_EVALID);
-    FREE_ARRAY(st->ctx, deviations, lysp_deviation_free);
+    assert_int_equal(test_element_helper(state, data, &deviations, NULL, NULL), LY_EVALID);
+    FREE_ARRAY(UTEST_LYCTX, deviations, lysp_deviation_free);
     deviations = NULL;
-    logbuf_assert("Missing mandatory sub-element \"deviate\" of \"deviation\" element. Line number 1.");
-    /* TODO */
-    st->finished_correctly = true;
-}
+    CHECK_LOG_CTX("Missing mandatory sub-element \"deviate\" of \"deviation\" element.", "Line number 1.");
+    /* TODO */}
 
 static struct lysp_module *
 mod_renew(struct lys_yin_parser_ctx *ctx)
@@ -3917,9 +3443,8 @@
 static void
 test_module_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
-    struct lysp_module *lysp_mod = mod_renew(st->yin_ctx);
+    struct lysp_module *lysp_mod = mod_renew(YCTX);
 
     /* max subelems */
     data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
@@ -3954,10 +3479,10 @@
             "    <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
             EXT_SUBELEM "\n"
             "</module>\n";
-    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
-    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
 
-    assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS);
+    assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS);
     assert_string_equal(lysp_mod->mod->name, "mod");
     assert_string_equal(lysp_mod->revs, "2019-02-02");
     assert_string_equal(lysp_mod->mod->ns, "ns");
@@ -3968,7 +3493,8 @@
     assert_string_equal(lysp_mod->mod->dsc, "desc");
     assert_string_equal(lysp_mod->mod->ref, "ref");
     assert_int_equal(lysp_mod->version, LYS_VERSION_1_1);
-    assert_string_equal(lysp_mod->imports->name, "a-mod");
+    CHECK_LYSP_IMPORT(lysp_mod->imports, NULL, 0, "a-mod",
+            "imp-pref", NULL, "");
     assert_string_equal(lysp_mod->includes->name, "b-mod");
     assert_string_equal(lysp_mod->extensions->name, "ext");
     assert_string_equal(lysp_mod->features->name, "feature");
@@ -3996,40 +3522,36 @@
     assert_string_equal(lysp_mod->rpcs->name, "rpc-name");
     assert_string_equal(lysp_mod->notifs->name, "notf");
     assert_string_equal(lysp_mod->deviations->nodeid, "target");
-    assert_string_equal(lysp_mod->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(lysp_mod->exts[0].insubstmt_index, 0);
-    assert_int_equal(lysp_mod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_mod->exts[0]), LYEXT_SUBSTMT_SELF);
 
     /* min subelems */
-    ly_in_free(st->in, 0);
-    lyxml_ctx_free(st->yin_ctx->xmlctx);
-    lysp_mod = mod_renew(st->yin_ctx);
+    ly_in_free(UTEST_IN, 0);
+    lyxml_ctx_free(YCTX->xmlctx);
+    lysp_mod = mod_renew(YCTX);
     data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
             "    <namespace uri=\"ns\"/>\n"
             "    <prefix value=\"pref\"/>\n"
             "    <yang-version value=\"1.1\"/>\n"
             "</module>";
-    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
-    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
-    assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
+    assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_SUCCESS);
     assert_string_equal(lysp_mod->mod->name, "mod");
 
     /* incorrect subelem order */
-    ly_in_free(st->in, 0);
-    lyxml_ctx_free(st->yin_ctx->xmlctx);
-    lysp_mod = mod_renew(st->yin_ctx);
+    ly_in_free(UTEST_IN, 0);
+    lyxml_ctx_free(YCTX->xmlctx);
+    lysp_mod = mod_renew(YCTX);
     data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
             "    <feature name=\"feature\"/>\n"
             "    <namespace uri=\"ns\"/>\n"
             "    <prefix value=\"pref\"/>\n"
             "    <yang-version value=\"1.1\"/>\n"
             "</module>";
-    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
-    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
-    assert_int_equal(yin_parse_mod(st->yin_ctx, lysp_mod), LY_EVALID);
-    logbuf_assert("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\". Line number 3.");
-
-    st->finished_correctly = true;
+    assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
+    assert_int_equal(yin_parse_mod(YCTX, lysp_mod), LY_EVALID);
+    CHECK_LOG_CTX("Invalid order of module\'s sub-elements \"namespace\" can\'t appear after \"feature\".", "Line number 3.");
 }
 
 static struct lysp_submodule *
@@ -4050,9 +3572,8 @@
 static void
 test_submodule_elem(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
-    struct lysp_submodule *lysp_submod = submod_renew(st->yin_ctx, "module-name");
+    struct lysp_submodule *lysp_submod = submod_renew(YCTX, "module-name");
 
     /* max subelements */
     data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"mod\">\n"
@@ -4088,10 +3609,10 @@
             "    <typedef name=\"tpdf\"> <type name=\"type\"/> </typedef>\n"
             EXT_SUBELEM "\n"
             "</submodule>\n";
-    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
-    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
 
-    assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS);
+    assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS);
     assert_string_equal(lysp_submod->name, "mod");
     assert_string_equal(lysp_submod->revs, "2019-02-02");
     assert_string_equal(lysp_submod->prefix, "pref");
@@ -4101,7 +3622,8 @@
     assert_string_equal(lysp_submod->dsc, "desc");
     assert_string_equal(lysp_submod->ref, "ref");
     assert_int_equal(lysp_submod->version, LYS_VERSION_1_1);
-    assert_string_equal(lysp_submod->imports->name, "a-mod");
+    CHECK_LYSP_IMPORT(lysp_submod->imports, NULL, 0, "a-mod",
+            "imp-pref", NULL, "");
     assert_string_equal(lysp_submod->includes->name, "b-mod");
     assert_string_equal(lysp_submod->extensions->name, "ext");
     assert_string_equal(lysp_submod->features->name, "feature");
@@ -4129,45 +3651,40 @@
     assert_string_equal(lysp_submod->rpcs->name, "rpc-name");
     assert_string_equal(lysp_submod->notifs->name, "notf");
     assert_string_equal(lysp_submod->deviations->nodeid, "target");
-    assert_string_equal(lysp_submod->exts[0].name, "urn:example:extensions:c-define");
-    assert_int_equal(lysp_submod->exts[0].insubstmt_index, 0);
-    assert_int_equal(lysp_submod->exts[0].insubstmt, LYEXT_SUBSTMT_SELF);
+    TEST_1_CHECK_LYSP_EXT_INSTANCE(&(lysp_submod->exts[0]), LYEXT_SUBSTMT_SELF);
 
     /* min subelemnts */
-    ly_in_free(st->in, 0);
-    lyxml_ctx_free(st->yin_ctx->xmlctx);
-    lysp_submod = submod_renew(st->yin_ctx, "module-name");
+    ly_in_free(UTEST_IN, 0);
+    lyxml_ctx_free(YCTX->xmlctx);
+    lysp_submod = submod_renew(YCTX, "module-name");
     data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n"
             "    <yang-version value=\"1\"/>\n"
             "    <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n"
             "</submodule>";
-    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
-    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
-    assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_SUCCESS);
+    assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
+    assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_SUCCESS);
     assert_string_equal(lysp_submod->prefix, "pref");
     assert_int_equal(lysp_submod->version, LYS_VERSION_1_0);
 
     /* incorrect subelem order */
-    ly_in_free(st->in, 0);
-    lyxml_ctx_free(st->yin_ctx->xmlctx);
-    lysp_submod = submod_renew(st->yin_ctx, "module-name");
+    ly_in_free(UTEST_IN, 0);
+    lyxml_ctx_free(YCTX->xmlctx);
+    lysp_submod = submod_renew(YCTX, "module-name");
     data = "<submodule xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\"submod\">\n"
             "    <yang-version value=\"1\"/>\n"
             "    <reference><text>ref</text></reference>\n"
             "    <belongs-to module=\"module-name\"><prefix value=\"pref\"/></belongs-to>\n"
             "</submodule>";
-    assert_int_equal(ly_in_new_memory(data, &st->in), LY_SUCCESS);
-    assert_int_equal(lyxml_ctx_new(st->ctx, st->in, &st->yin_ctx->xmlctx), LY_SUCCESS);
-    assert_int_equal(yin_parse_submod(st->yin_ctx, lysp_submod), LY_EVALID);
-    logbuf_assert("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\". Line number 4.");
-
-    st->finished_correctly = true;
+    assert_int_equal(ly_in_new_memory(data, &UTEST_IN), LY_SUCCESS);
+    assert_int_equal(lyxml_ctx_new(UTEST_LYCTX, UTEST_IN, &YCTX->xmlctx), LY_SUCCESS);
+    assert_int_equal(yin_parse_submod(YCTX, lysp_submod), LY_EVALID);
+    CHECK_LOG_CTX("Invalid order of submodule's sub-elements \"belongs-to\" can't appear after \"reference\".", "Line number 4.");
 }
 
 static void
 test_yin_parse_module(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lys_module *mod;
     struct lys_yin_parser_ctx *yin_ctx = NULL;
@@ -4175,7 +3692,7 @@
     struct lys_glob_unres unres = {0};
 
     mod = calloc(1, sizeof *mod);
-    mod->ctx = st->ctx;
+    mod->ctx = UTEST_LYCTX;
     data = "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:md=\"urn:ietf:params:xml:ns:yang:ietf-yang-metadata\" name=\"a\"> \n"
             "    <yang-version value=\"1.1\"/>\n"
             "    <namespace uri=\"urn:tests:extensions:metadata:a\"/>\n"
@@ -4201,7 +3718,7 @@
     assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
     assert_null(mod->parsed->exts->child->next->child);
     assert_string_equal(mod->parsed->exts->child->next->arg, "test");
-    lys_compile_unres_glob_erase(st->ctx, &unres);
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
@@ -4209,7 +3726,7 @@
     yin_ctx = NULL;
 
     mod = calloc(1, sizeof *mod);
-    mod->ctx = st->ctx;
+    mod->ctx = UTEST_LYCTX;
     data = "<module name=\"example-foo\""
             "    xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\""
             "    xmlns:foo=\"urn:example:foo\""
@@ -4240,7 +3757,7 @@
             "</module>\n";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
     assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
-    lys_compile_unres_glob_erase(st->ctx, &unres);
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
@@ -4248,7 +3765,7 @@
     yin_ctx = NULL;
 
     mod = calloc(1, sizeof *mod);
-    mod->ctx = st->ctx;
+    mod->ctx = UTEST_LYCTX;
     data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
             "    <yang-version value=\"1\"/>\n"
             "    <namespace uri=\"urn:example:foo\"/>\n"
@@ -4256,7 +3773,7 @@
             "</module>\n";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
     assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_SUCCESS);
-    lys_compile_unres_glob_erase(st->ctx, &unres);
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
@@ -4264,18 +3781,18 @@
     yin_ctx = NULL;
 
     mod = calloc(1, sizeof *mod);
-    mod->ctx = st->ctx;
+    mod->ctx = UTEST_LYCTX;
     data = "<submodule name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
             "</submodule>\n";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
     assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_EINVAL);
-    logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
+    CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL);
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
 
     mod = calloc(1, sizeof *mod);
-    mod->ctx = st->ctx;
+    mod->ctx = UTEST_LYCTX;
     data = "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">\n"
             "    <yang-version value=\"1\"/>\n"
             "    <namespace uri=\"urn:example:foo\"/>\n"
@@ -4284,26 +3801,23 @@
             "<module>";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
     assert_int_equal(yin_parse_module(&yin_ctx, in, mod, &unres), LY_EVALID);
-    logbuf_assert("Trailing garbage \"<module>\" after module, expected end-of-input. Line number 6.");
+    CHECK_LOG_CTX("Trailing garbage \"<module>\" after module, expected end-of-input.", "Line number 6.");
     lys_module_free(mod, NULL);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
     mod = NULL;
     yin_ctx = NULL;
-
-    st->finished_correctly = true;
 }
 
 static void
 test_yin_parse_submodule(void **state)
 {
-    struct test_parser_yin_state *st = *state;
     const char *data;
     struct lys_yin_parser_ctx *yin_ctx = NULL;
     struct lysp_submodule *submod = NULL;
     struct ly_in *in;
 
-    lydict_insert(st->ctx, "a", 0, &st->yin_ctx->parsed_mod->mod->name);
+    lydict_insert(UTEST_LYCTX, "a", 0, &YCTX->parsed_mod->mod->name);
 
     data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
             "<submodule name=\"asub\""
@@ -4330,7 +3844,7 @@
             "    </augment>\n"
             "</submodule>";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
-    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, (struct lys_parser_ctx *)st->yin_ctx, in, &submod), LY_SUCCESS);
+    assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_SUCCESS);
     lysp_module_free((struct lysp_module *)submod);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
@@ -4345,7 +3859,7 @@
             "    </belongs-to>\n"
             "</submodule>";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
-    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, (struct lys_parser_ctx *)st->yin_ctx, in, &submod), LY_SUCCESS);
+    assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_SUCCESS);
     lysp_module_free((struct lysp_module *)submod);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
@@ -4356,8 +3870,8 @@
             "<module name=\"inval\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\">"
             "</module>";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
-    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, (struct lys_parser_ctx *)st->yin_ctx, in, &submod), LY_EINVAL);
-    logbuf_assert("Input data contains module in situation when a submodule is expected.");
+    assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EINVAL);
+    CHECK_LOG_CTX("Input data contains module in situation when a submodule is expected.", NULL);
     lysp_module_free((struct lysp_module *)submod);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
@@ -4378,15 +3892,13 @@
             "    </belongs-to>\n"
             "</submodule>";
     assert_int_equal(ly_in_new_memory(data, &in), LY_SUCCESS);
-    assert_int_equal(yin_parse_submodule(&yin_ctx, st->ctx, (struct lys_parser_ctx *)st->yin_ctx, in, &submod), LY_EVALID);
-    logbuf_assert("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input. Line number 8.");
+    assert_int_equal(yin_parse_submodule(&yin_ctx, UTEST_LYCTX, (struct lys_parser_ctx *)YCTX, in, &submod), LY_EVALID);
+    CHECK_LOG_CTX("Trailing garbage \"<submodule name...\" after submodule, expected end-of-input.", "Line number 8.");
     lysp_module_free((struct lysp_module *)submod);
     yin_parser_ctx_free(yin_ctx);
     ly_in_free(in, 0);
     yin_ctx = NULL;
     submod = NULL;
-
-    st->finished_correctly = true;
 }
 
 int
@@ -4394,75 +3906,75 @@
 {
 
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_yin_match_keyword, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_yin_parse_element_generic, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_yin_parse_extension_instance, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_yin_parse_content, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_validate_value, setup_f, teardown_f),
+        UTEST(test_yin_match_keyword, setup, teardown),
+        UTEST(test_yin_parse_element_generic, setup, teardown),
+        UTEST(test_yin_parse_extension_instance, setup, teardown),
+        UTEST(test_yin_parse_content, setup, teardown),
+        UTEST(test_validate_value, setup, teardown),
 
-        cmocka_unit_test(test_yin_match_argument_name),
-        cmocka_unit_test_setup_teardown(test_enum_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_bit_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_meta_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_import_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_status_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_ext_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_yin_element_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_yangversion_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_mandatory_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_argument_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_base_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_belongsto_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_config_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_default_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_err_msg_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_iffeature_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_length_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_modifier_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_namespace_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_pattern_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_value_position_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_prefix_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_range_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_revision_date_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_unique_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_units_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_when_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_type_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_max_elems_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_min_elems_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_ordby_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_any_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_leaf_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_presence_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_key_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_typedef_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_refine_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_uses_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_revision_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_include_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_list_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_notification_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_grouping_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_container_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_case_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_choice_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_inout_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_action_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_augment_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_deviate_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_deviation_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_module_elem, setup_element_test, teardown_f),
-        cmocka_unit_test_setup_teardown(test_submodule_elem, setup_element_test, teardown_f),
+        UTEST(test_yin_match_argument_name),
+        cmocka_unit_test_setup_teardown(test_enum_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_bit_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_meta_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_import_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_status_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_ext_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_yin_element_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_yangversion_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_mandatory_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_argument_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_base_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_belongsto_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_config_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_default_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_err_app_tag_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_err_msg_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_fracdigits_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_iffeature_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_length_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_modifier_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_namespace_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_pattern_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_value_position_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_prefix_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_range_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_reqinstance_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_revision_date_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_unique_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_units_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_when_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_yin_text_value_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_type_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_max_elems_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_min_elems_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_ordby_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_any_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_leaf_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_leaf_list_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_presence_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_key_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_typedef_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_refine_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_uses_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_revision_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_include_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_list_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_notification_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_grouping_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_container_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_case_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_choice_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_inout_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_action_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_augment_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_deviate_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_deviation_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_module_elem, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_submodule_elem, setup, teardown),
 
-        cmocka_unit_test_setup_teardown(test_yin_parse_module, setup_f, teardown_f),
-        cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup_f, teardown_f),
+        cmocka_unit_test_setup_teardown(test_yin_parse_module, setup, teardown),
+        cmocka_unit_test_setup_teardown(test_yin_parse_submodule, setup, teardown),
     };
 
-    return cmocka_run_group_tests(tests, setup_ly_ctx, destroy_ly_ctx);
+    return cmocka_run_group_tests(tests, NULL, NULL);
 }
diff --git a/tests/utests/schema/test_printer_yang.c b/tests/utests/schema/test_printer_yang.c
index 4296c05..124bb28 100644
--- a/tests/utests/schema/test_printer_yang.c
+++ b/tests/utests/schema/test_printer_yang.c
@@ -3,7 +3,7 @@
  * @author: Radek Krejci <rkrejci@cesnet.cz>
  * @brief unit tests for functions from printer_yang.c
  *
- * Copyright (c) 2019 CESNET, z.s.p.o.
+ * Copyright (c) 2019-2020 CESNET, z.s.p.o.
  *
  * This source code is licensed under BSD 3-Clause License (the "License").
  * You may not use this file except in compliance with the License.
@@ -11,80 +11,18 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include "common.h"
 #include "context.h"
 #include "out.h"
 #include "printer_schema.h"
 #include "tree_schema.h"
-#include "utests.h"
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-static int
-logger_setup(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-    return 0;
-}
-
-static int
-logger_teardown(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
 
 static void
 test_module(void **state)
 {
-    *state = test_module;
-
-    struct ly_ctx *ctx = {0};
     const struct lys_module *mod;
     const char *orig = "module a {\n"
             "  yang-version 1.1;\n"
@@ -125,9 +63,8 @@
     struct ly_out *out;
 
     assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, orig, LYS_IN_YANG, &mod));
+    UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
     assert_int_equal(LY_SUCCESS, lys_print_module(out, mod, LYS_OUT_YANG, 0, 0));
     assert_int_equal(strlen(orig), ly_out_printed(out));
     assert_string_equal(printed, orig);
@@ -167,7 +104,7 @@
             "  prefix b;\n\n"
             "  revision 2019-04-16;\n"
             "}\n";
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, orig, LYS_IN_YANG, &mod));
+    UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
     assert_int_equal(LY_SUCCESS, lys_print_module(out, mod, LYS_OUT_YANG, 0, 0));
     assert_int_equal(strlen(orig), ly_out_printed(out));
     assert_string_equal(printed, orig);
@@ -198,7 +135,7 @@
             "  namespace \"urn:test:c\";\n"
             "  prefix c;\n"
             "}\n";
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, orig, LYS_IN_YANG, &mod));
+    UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
     assert_int_equal(LY_SUCCESS, lys_print_module(out, mod, LYS_OUT_YANG, 0, 0));
     assert_int_equal(strlen(orig), ly_out_printed(out));
     assert_string_equal(printed, orig);
@@ -207,9 +144,7 @@
     assert_int_equal(strlen(compiled), ly_out_printed(out));
     assert_string_equal(printed, compiled);
 
-    *state = NULL;
     ly_out_free(out, NULL, 1);
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static LY_ERR
@@ -226,9 +161,6 @@
 static void
 test_submodule(void **state)
 {
-    *state = test_submodule;
-
-    struct ly_ctx *ctx = {0};
     const struct lys_module *mod;
     const char *mod_yang = "module a {\n"
             "  yang-version 1.1;\n"
@@ -259,25 +191,23 @@
     struct ly_out *out;
 
     assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, submod_yang);
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, mod_yang, LYS_IN_YANG, &mod));
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod_yang);
+    UTEST_ADD_MODULE(mod_yang, LYS_IN_YANG, NULL, &mod);
     assert_int_equal(LY_SUCCESS, lys_print_submodule(out, mod, mod->parsed->includes[0].submodule, LYS_OUT_YANG, 0, 0));
     assert_int_equal(strlen(submod_yang), ly_out_printed(out));
     assert_string_equal(printed, submod_yang);
 
     *state = NULL;
     ly_out_free(out, NULL, 1);
-    ly_ctx_destroy(ctx, NULL);
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_module, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_submodule, logger_setup, logger_teardown),
+        UTEST(test_module),
+        UTEST(test_submodule),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/schema/test_printer_yin.c b/tests/utests/schema/test_printer_yin.c
index 3688faa..d1d42e8 100644
--- a/tests/utests/schema/test_printer_yin.c
+++ b/tests/utests/schema/test_printer_yin.c
@@ -3,7 +3,7 @@
  * @author: Fred Gan <ganshaolong@vip.qq.com>
  * @brief unit tests for functions from printer_yin.c
  *
- * Copyright (c) 2019 CESNET, z.s.p.o.
+ * Copyright (c) 2019-2020 CESNET, z.s.p.o.
  *
  * This source code is licensed under BSD 3-Clause License (the "License").
  * You may not use this file except in compliance with the License.
@@ -11,80 +11,18 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include "common.h"
 #include "context.h"
 #include "out.h"
 #include "printer_schema.h"
 #include "tree_schema.h"
-#include "utests.h"
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-static int
-logger_setup(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
-    return 0;
-}
-
-static int
-logger_teardown(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
 
 static void
 test_module(void **state)
 {
-    *state = test_module;
-
-    struct ly_ctx *ctx = {0};
     const struct lys_module *mod;
 
     const char *orig =
@@ -577,16 +515,13 @@
     struct ly_out *out;
 
     assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, orig, LYS_IN_YANG, &mod));
+    UTEST_ADD_MODULE(orig, LYS_IN_YANG, NULL, &mod);
     assert_int_equal(LY_SUCCESS, lys_print_module(out, mod, LYS_OUT_YIN, 0, 0));
     assert_int_equal(strlen(ori_res), ly_out_printed(out));
     assert_string_equal(printed, ori_res);
 
-    *state = NULL;
     ly_out_free(out, NULL, 1);
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static LY_ERR
@@ -603,9 +538,6 @@
 static void
 test_submodule(void **state)
 {
-    *state = test_module;
-
-    struct ly_ctx *ctx = {0};
     const struct lys_module *mod;
 
     const char *mod_yin =
@@ -645,25 +577,23 @@
     struct ly_out *out;
 
     assert_int_equal(LY_SUCCESS, ly_out_new_memory(&printed, 0, &out));
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, submod_yin);
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, mod_yin, LYS_IN_YIN, &mod));
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, submod_yin);
+
+    UTEST_ADD_MODULE(mod_yin, LYS_IN_YIN, NULL, &mod);
     assert_int_equal(LY_SUCCESS, lys_print_submodule(out, mod, mod->parsed->includes[0].submodule, LYS_OUT_YIN, 0, 0));
     assert_int_equal(strlen(submod_yin), ly_out_printed(out));
     assert_string_equal(printed, submod_yin);
 
-    *state = NULL;
     ly_out_free(out, NULL, 1);
-    ly_ctx_destroy(ctx, NULL);
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_module, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_submodule, logger_setup, logger_teardown),
+        UTEST(test_module),
+        UTEST(test_submodule),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/schema/test_schema.c b/tests/utests/schema/test_schema.c
index ebe8af3..7e7a351 100644
--- a/tests/utests/schema/test_schema.c
+++ b/tests/utests/schema/test_schema.c
@@ -11,73 +11,14 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
-
+#define _UTEST_MAIN_
 #include "test_schema.h"
 
 #include <string.h>
 
 #include "log.h"
 #include "parser_schema.h"
-#include "tests/config.h"
 #include "tree_schema.h"
-#include "utests.h"
-
-#if ENABLE_LOGGER_CHECKING
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-int store = -1; /* negative for infinite logging, positive for limited logging */
-
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-    if (store) {
-        if (path && path[0]) {
-            snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-        } else {
-            strncpy(logbuf, msg, BUFSIZE - 1);
-        }
-        if (store > 0) {
-            --store;
-        }
-    }
-}
-
-#endif
-
-static int
-logger_setup(void **state)
-{
-    (void) state; /* unused */
-
-#if ENABLE_LOGGER_CHECKING
-    /* setup logger */
-    ly_set_log_clb(logger, 1);
-#endif
-
-    return 0;
-}
-
-static int
-logger_teardown(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-#if ENABLE_LOGGER_CHECKING
-    logbuf[0] = '\0';
-#endif
-}
 
 LY_ERR
 test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
@@ -109,15 +50,15 @@
 {
     const struct CMUnitTest tests[] = {
         /** test_schema_common.c */
-        cmocka_unit_test_setup_teardown(test_getnext, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_date, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_revisions, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_typedef, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_accessible_tree, logger_setup, logger_teardown),
+        UTEST(test_getnext),
+        UTEST(test_date),
+        UTEST(test_revisions),
+        UTEST(test_typedef),
+        UTEST(test_accessible_tree),
 
         /** test_schema_stmts.c */
-        cmocka_unit_test_setup_teardown(test_identity, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_feature, logger_setup, logger_teardown),
+        UTEST(test_identity),
+        UTEST(test_feature),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);
diff --git a/tests/utests/schema/test_schema.h b/tests/utests/schema/test_schema.h
index 2599db3..d3cacb7 100644
--- a/tests/utests/schema/test_schema.h
+++ b/tests/utests/schema/test_schema.h
@@ -15,22 +15,12 @@
 #ifndef TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_
 #define TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_
 
+#include "utests.h"
+
 #include "log.h"
 #include "parser_schema.h"
 #include "tests/config.h"
 
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-extern char logbuf[];
-#   define logbuf_assert(str) assert_string_equal(logbuf, str)
-#else
-#   define logbuf_assert(str)
-#endif
-
-void logbuf_clean(void);
-
 LY_ERR test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
         const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT * format,
         const char **module_data, void (**free_module_data)(void *model_data, void *user_data));
@@ -49,7 +39,7 @@
     "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\""MOD_NAME"\"><yang-version value=\"1.1\"/>" \
     "<namespace uri=\""MOD_NS"\"/><prefix value=\""MOD_PREFIX"\"/>"CONTENT"</module>"
 
-#define TEST_SCHEMA_STR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, STR) \
+#define TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, STR) \
     if (YIN) { \
         if (RFC7950) { \
             STR = TEST_YIN_MODULE_11(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
@@ -64,30 +54,31 @@
         } \
     }
 
-#define TEST_SCHEMA_OK(CTX, RFC7950, YIN, MOD_NAME, CONTENT, RESULT) \
+#define TEST_SCHEMA_OK(RFC7950, YIN, MOD_NAME, CONTENT, RESULT) \
     { \
     const char *test_str__; \
-    TEST_SCHEMA_STR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(CTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, &(RESULT))); \
+    TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, &(RESULT))); \
     }
 
-#define TEST_SCHEMA_ERR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, ERRMSG) \
+#define TEST_SCHEMA_ERR(RFC7950, YIN, MOD_NAME, CONTENT, ERRMSG, ERRPATH) \
     { \
     const char *test_str__; \
-    TEST_SCHEMA_STR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
-    assert_int_not_equal(lys_parse_mem(CTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, NULL), LY_SUCCESS); \
-    logbuf_assert(ERRMSG); \
+    TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
+    assert_int_not_equal(lys_parse_mem(UTEST_LYCTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, NULL), LY_SUCCESS); \
+    CHECK_LOG_CTX(ERRMSG, ERRPATH); \
     }
 
-#define TEST_STMT_DUP(CTX, RFC7950, YIN, STMT, MEMBER, VALUE1, VALUE2, LINE) \
+#define TEST_STMT_DUP(RFC7950, YIN, STMT, MEMBER, VALUE1, VALUE2, LINE) \
     if (YIN) { \
-        TEST_SCHEMA_ERR(CTX, RFC7950, YIN, "dup", "", "Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
+        TEST_SCHEMA_ERR(RFC7950, YIN, "dup", "", "Duplicate keyword \""MEMBER"\".", "Line number "LINE"."); \
     } else { \
-        TEST_SCHEMA_ERR(CTX, RFC7950, YIN, "dup", STMT"{"MEMBER" "VALUE1";"MEMBER" "VALUE2";}", \
-                        "Duplicate keyword \""MEMBER"\". Line number "LINE"."); \
+        TEST_SCHEMA_ERR(RFC7950, YIN, "dup", STMT"{"MEMBER" "VALUE1";"MEMBER" "VALUE2";}", \
+                        "Duplicate keyword \""MEMBER"\".", "Line number "LINE"."); \
     }
 
-#define TEST_STMT_SUBSTM_ERR(CTX, RFC7950, STMT, SUBSTMT, VALUE) ;\
-        TEST_SCHEMA_ERR(CTX, RFC7950, 0, "inv", STMT" test {"SUBSTMT" "VALUE";}", "Invalid keyword \""SUBSTMT"\" as a child of \""STMT"\". Line number 1.");
+#define TEST_STMT_SUBSTM_ERR(RFC7950, STMT, SUBSTMT, VALUE) ;\
+        TEST_SCHEMA_ERR(RFC7950, 0, "inv", STMT" test {"SUBSTMT" "VALUE";}", \
+                        "Invalid keyword \""SUBSTMT"\" as a child of \""STMT"\".", "Line number 1.");
 
 #endif /* TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_ */
diff --git a/tests/utests/schema/test_schema_common.c b/tests/utests/schema/test_schema_common.c
index 8e3bc5d..ab4b3b2 100644
--- a/tests/utests/schema/test_schema_common.c
+++ b/tests/utests/schema/test_schema_common.c
@@ -11,6 +11,7 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#include "test_schema.h"
 
 #include <string.h>
 
@@ -18,24 +19,16 @@
 #include "log.h"
 #include "tree_schema.h"
 #include "tree_schema_internal.h"
-#include "utests.h"
-
-#include "test_schema.h"
 
 void
 test_getnext(void **state)
 {
-    *state = test_getnext;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     const struct lysc_node *node = NULL, *four;
     const struct lysc_node_container *cont;
     const struct lysc_action *rpc;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1; namespace urn:a;prefix a;"
             "container a { container one {presence test;} leaf two {type string;} leaf-list three {type string;}"
             "  list four {config false;} choice x { leaf five {type string;} case y {leaf six {type string;}}}"
             "  anyxml seven; action eight {input {leaf eight-input {type string;}} output {leaf eight-output {type string;}}}"
@@ -119,68 +112,58 @@
     assert_string_equal("h-output", node->name);
     assert_null(node = lys_getnext(node, (const struct lysc_node *)rpc, mod->compiled, LYS_GETNEXT_OUTPUT));
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c; rpc c;}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c; rpc c;}", LYS_IN_YANG, &mod));
     assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0));
     assert_string_equal("c", node->name);
     assert_null(node = lys_getnext(node, NULL, mod->compiled, 0));
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; notification d;}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; notification d;}", LYS_IN_YANG, &mod));
     assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0));
     assert_string_equal("d", node->name);
     assert_null(node = lys_getnext(node, NULL, mod->compiled, 0));
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {namespace urn:e;prefix e; container c {container cc;} leaf a {type string;}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e; container c {container cc;} leaf a {type string;}}", LYS_IN_YANG, &mod));
     assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, 0));
     assert_string_equal("c", node->name);
     assert_non_null(node = lys_getnext(NULL, NULL, mod->compiled, LYS_GETNEXT_INTONPCONT));
     assert_string_equal("a", node->name);
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
 
 void
 test_date(void **state)
 {
-    *state = test_date;
-
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, NULL, 0, "date"));
-    logbuf_assert("Invalid argument date (lysp_check_date()).");
+    CHECK_LOG("Invalid argument date (lysp_check_date()).", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "x", 1, "date"));
-    logbuf_assert("Invalid argument date_len (lysp_check_date()).");
+    CHECK_LOG("Invalid argument date_len (lysp_check_date()).", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "nonsencexx", 10, "date"));
-    logbuf_assert("Invalid value \"nonsencexx\" of \"date\".");
+    CHECK_LOG("Invalid value \"nonsencexx\" of \"date\".", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "123x-11-11", 10, "date"));
-    logbuf_assert("Invalid value \"123x-11-11\" of \"date\".");
+    CHECK_LOG("Invalid value \"123x-11-11\" of \"date\".", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-13-11", 10, "date"));
-    logbuf_assert("Invalid value \"2018-13-11\" of \"date\".");
+    CHECK_LOG("Invalid value \"2018-13-11\" of \"date\".", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-11-41", 10, "date"));
-    logbuf_assert("Invalid value \"2018-11-41\" of \"date\".");
+    CHECK_LOG("Invalid value \"2018-11-41\" of \"date\".", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-02-29", 10, "date"));
-    logbuf_assert("Invalid value \"2018-02-29\" of \"date\".");
+    CHECK_LOG("Invalid value \"2018-02-29\" of \"date\".", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018.02-28", 10, "date"));
-    logbuf_assert("Invalid value \"2018.02-28\" of \"date\".");
+    CHECK_LOG("Invalid value \"2018.02-28\" of \"date\".", NULL);
     assert_int_equal(LY_EINVAL, lysp_check_date(NULL, "2018-02.28", 10, "date"));
-    logbuf_assert("Invalid value \"2018-02.28\" of \"date\".");
+    CHECK_LOG("Invalid value \"2018-02.28\" of \"date\".", NULL);
 
     assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2018-11-11", 10, "date"));
     assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2018-02-28", 10, "date"));
     assert_int_equal(LY_SUCCESS, lysp_check_date(NULL, "2016-02-29", 10, "date"));
-
-    *state = NULL;
 }
 
 void
 test_revisions(void **state)
 {
-    (void) state; /* unused */
-
     struct lysp_revision *revs = NULL, *rev;
 
-    logbuf_clean();
     /* no error, it just does nothing */
     lysp_sort_revisions(NULL);
-    logbuf_assert("");
+    CHECK_LOG(NULL, NULL);
 
     /* revisions are stored in wrong order - the newest is the last */
     LY_ARRAY_NEW_RET(NULL, revs, rev, );
@@ -202,127 +185,112 @@
 void
 test_typedef(void **state)
 {
-    *state = test_typedef;
-
-    struct ly_ctx *ctx = NULL;
     const char *str;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
     str = "module a {namespace urn:a; prefix a; typedef binary {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"binary\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"binary\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef bits {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"bits\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"bits\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef boolean {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"boolean\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"boolean\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef decimal64 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"decimal64\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"decimal64\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef empty {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"empty\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"empty\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef enumeration {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"enumeration\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"enumeration\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef int8 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"int8\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"int8\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef int16 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"int16\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"int16\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef int32 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"int32\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"int32\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef int64 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"int64\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"int64\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef instance-identifier {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"instance-identifier\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"instance-identifier\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef identityref {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"identityref\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"identityref\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef leafref {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"leafref\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"leafref\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef string {type int8;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"string\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"string\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef union {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"union\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"union\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef uint8 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"uint8\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"uint8\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef uint16 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"uint16\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"uint16\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef uint32 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"uint32\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"uint32\" of typedef - name collision with a built-in type.", "Line number 1.");
     str = "module a {namespace urn:a; prefix a; typedef uint64 {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"uint64\" of typedef - name collision with a built-in type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"uint64\" of typedef - name collision with a built-in type.", "Line number 1.");
 
     str = "module mytypes {namespace urn:types; prefix t; typedef binary_ {type string;} typedef bits_ {type string;} typedef boolean_ {type string;} "
             "typedef decimal64_ {type string;} typedef empty_ {type string;} typedef enumeration_ {type string;} typedef int8_ {type string;} typedef int16_ {type string;}"
             "typedef int32_ {type string;} typedef int64_ {type string;} typedef instance-identifier_ {type string;} typedef identityref_ {type string;}"
             "typedef leafref_ {type string;} typedef string_ {type int8;} typedef union_ {type string;} typedef uint8_ {type string;} typedef uint16_ {type string;}"
             "typedef uint32_ {type string;} typedef uint64_ {type string;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
 
     str = "module a {namespace urn:a; prefix a; typedef test {type string;} typedef test {type int8;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"test\" of typedef - name collision with another top-level type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"test\" of typedef - name collision with another top-level type.", "Line number 1.");
 
     str = "module a {namespace urn:a; prefix a; typedef x {type string;} container c {typedef x {type int8;}}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"x\" of typedef - scoped type collide with a top-level type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"x\" of typedef - scoped type collide with a top-level type.", "Line number 1.");
 
     str = "module a {namespace urn:a; prefix a; container c {container d {typedef y {type int8;}} typedef y {type string;}}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"y\" of typedef - name collision with another scoped type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"y\" of typedef - name collision with another scoped type.", "Line number 1.");
 
     str = "module a {namespace urn:a; prefix a; container c {typedef y {type int8;} typedef y {type string;}}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"y\" of typedef - name collision with sibling type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"y\" of typedef - name collision with sibling type.", "Line number 1.");
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type string;}}");
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type string;}}");
     str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"x\" of typedef - name collision with another top-level type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"x\" of typedef - name collision with another top-level type.", "Line number 1.");
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule b {belongs-to a {prefix a;} container c {typedef x {type string;}}}");
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} container c {typedef x {type string;}}}");
     str = "module a {namespace urn:a; prefix a; include b; typedef x {type int8;}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"x\" of typedef - scoped type collide with a top-level type. Line number 1.");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"x\" of typedef - scoped type collide with a top-level type.", "Line number 1.");
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type int8;}}");
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule b {belongs-to a {prefix a;} typedef x {type int8;}}");
     str = "module a {namespace urn:a; prefix a; include b; container c {typedef x {type string;}}}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EEXIST);
-    logbuf_assert("Invalid name \"x\" of typedef - scoped type collide with a top-level type. Line number 1.");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EEXIST);
+    CHECK_LOG("Invalid name \"x\" of typedef - scoped type collide with a top-level type.", "Line number 1.");
 }
 
 void
 test_accessible_tree(void **state)
 {
-    *state = test_accessible_tree;
-
-    struct ly_ctx *ctx = NULL;
     const char *str;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-    logbuf_clean();
-
     /* config -> config */
-    str =
-            "module a {\n"
+    str = "module a {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    container cont {\n"
@@ -339,12 +307,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* config -> state leafref */
-    str =
-            "module b {\n"
+    str = "module b {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    container cont {\n"
@@ -361,14 +328,12 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
-    logbuf_assert("Invalid leafref path \"/cont/l\" - target is supposed to represent configuration data"
-            " (as the leafref does), but it does not. /b:cont2/l2");
-    logbuf_clean();
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Invalid leafref path \"/cont/l\" - target is supposed to represent configuration data"
+            " (as the leafref does), but it does not.", "/b:cont2/l2");
 
     /* config -> state must */
-    str =
-            "module b {\n"
+    str = "module b {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    container cont {\n"
@@ -384,13 +349,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("Schema node \"l\" not found (\"../../cont/l\") with context node \"/b:cont2/l2\".");
-    logbuf_clean();
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX("Schema node \"l\" not found (\"../../cont/l\") with context node \"/b:cont2/l2\".", NULL);
 
     /* state -> config */
-    str =
-            "module c {\n"
+    str = "module c {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    container cont {\n"
@@ -408,12 +371,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* notif -> state */
-    str =
-            "module d {\n"
+    str = "module d {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    container cont {\n"
@@ -431,12 +393,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* notif -> notif */
-    str =
-            "module e {\n"
+    str = "module e {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    notification notif {\n"
@@ -451,12 +412,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* rpc input -> state */
-    str =
-            "module f {\n"
+    str = "module f {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    container cont {\n"
@@ -476,12 +436,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* rpc input -> rpc input */
-    str =
-            "module g {\n"
+    str = "module g {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    rpc rp {\n"
@@ -498,12 +457,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* rpc input -> rpc output leafref */
-    str =
-            "module h {\n"
+    str = "module h {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    rpc rp {\n"
@@ -521,13 +479,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
-    logbuf_assert("Not found node \"l\" in path. /h:rp/l2");
-    logbuf_clean();
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Not found node \"l\" in path.", "/h:rp/l2");
 
     /* rpc input -> rpc output must */
-    str =
-            "module h {\n"
+    str = "module h {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    rpc rp {\n"
@@ -544,13 +500,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("Schema node \"l\" not found (\"../l\") with context node \"/h:rp/l2\".");
-    logbuf_clean();
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX("Schema node \"l\" not found (\"../l\") with context node \"/h:rp/l2\".", NULL);
 
     /* rpc input -> notif leafref */
-    str =
-            "module i {\n"
+    str = "module i {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    rpc rp {\n"
@@ -568,13 +522,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
-    logbuf_assert("Not found node \"notif\" in path. /i:rp/l2");
-    logbuf_clean();
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Not found node \"notif\" in path.", "/i:rp/l2");
 
     /* rpc input -> notif must */
-    str =
-            "module i {\n"
+    str = "module i {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
             "    rpc rp {\n"
@@ -591,13 +543,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("Schema node \"l\" not found (\"/notif/l\") with context node \"/i:rp/l2\".");
-    logbuf_clean();
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX("Schema node \"l\" not found (\"/notif/l\") with context node \"/i:rp/l2\".", NULL);
 
     /* action output -> state */
-    str =
-            "module j {\n"
+    str = "module j {\n"
             "    yang-version 1.1;\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -624,12 +574,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("");
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* action output -> action input leafref */
-    str =
-            "module k {\n"
+    str = "module k {\n"
             "    yang-version 1.1;\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -656,13 +605,11 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_EVALID);
-    logbuf_assert("Not found node \"l\" in path. /k:cont/ll/act/l2");
-    logbuf_clean();
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_EVALID);
+    CHECK_LOG_CTX("Not found node \"l\" in path.", "/k:cont/ll/act/l2");
 
     /* action output -> action input must */
-    str =
-            "module k {\n"
+    str = "module k {\n"
             "    yang-version 1.1;\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -688,10 +635,6 @@
             "        }\n"
             "    }\n"
             "}";
-    assert_int_equal(lys_parse_mem(ctx, str, LYS_IN_YANG, NULL), LY_SUCCESS);
-    logbuf_assert("Schema node \"l\" not found (\"/cont/ll/act/l\") with context node \"/k:cont/ll/act/l2\".");
-    logbuf_clean();
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    assert_int_equal(lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, NULL), LY_SUCCESS);
+    CHECK_LOG_CTX("Schema node \"l\" not found (\"/cont/ll/act/l\") with context node \"/k:cont/ll/act/l2\".", NULL);
 }
diff --git a/tests/utests/schema/test_schema_stmts.c b/tests/utests/schema/test_schema_stmts.c
index 24417c4..1cd8ced 100644
--- a/tests/utests/schema/test_schema_stmts.c
+++ b/tests/utests/schema/test_schema_stmts.c
@@ -11,49 +11,41 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#include "test_schema.h"
 
 #include <string.h>
 
 #include "context.h"
 #include "log.h"
-#include "test_schema.h"
 #include "tree_schema.h"
-#include "utests.h"
-
-#include "test_schema.h"
 
 void
 test_identity(void **state)
 {
-    *state = test_identity;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod, *mod_imp;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
-
     /*
      * parsing YANG
      */
-    TEST_STMT_DUP(ctx, 1, 0, "identity id", "description", "a", "b", "1");
-    TEST_STMT_DUP(ctx, 1, 0, "identity id", "reference", "a", "b", "1");
-    TEST_STMT_DUP(ctx, 1, 0, "identity id", "status", "current", "obsolete", "1");
+    TEST_STMT_DUP(1, 0, "identity id", "description", "a", "b", "1");
+    TEST_STMT_DUP(1, 0, "identity id", "reference", "a", "b", "1");
+    TEST_STMT_DUP(1, 0, "identity id", "status", "current", "obsolete", "1");
 
     /* full content */
-    TEST_SCHEMA_OK(ctx, 1, 0, "identityone",
+    TEST_SCHEMA_OK(1, 0, "identityone",
             "identity test {base \"a\";base b; description text;reference \'another text\';status current; if-feature x;if-feature y; identityone:ext;}"
             "identity a; identity b; extension ext; feature x; feature y;", mod);
     assert_non_null(mod->parsed->identities);
     assert_int_equal(3, LY_ARRAY_COUNT(mod->parsed->identities));
 
     /* invalid substatement */
-    TEST_STMT_SUBSTM_ERR(ctx, 0, "identity", "organization", "XXX");
+    TEST_STMT_SUBSTM_ERR(0, "identity", "organization", "XXX");
 
     /*
      * parsing YIN
      */
     /* max subelems */
-    TEST_SCHEMA_OK(ctx, 1, 1, "identityone-yin", "<identity name=\"ident-name\">"
+    TEST_SCHEMA_OK(1, 1, "identityone-yin", "<identity name=\"ident-name\">"
             "<if-feature name=\"iff\"/>"
             "<base name=\"base-name\"/>"
             "<status value=\"deprecated\"/>"
@@ -75,19 +67,20 @@
     assert_int_equal(mod->parsed->identities[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);*/
 
     /* min subelems */
-    TEST_SCHEMA_OK(ctx, 1, 1, "identitytwo-yin", "<identity name=\"ident-name\" />", mod);
+    TEST_SCHEMA_OK(1, 1, "identitytwo-yin", "<identity name=\"ident-name\" />", mod);
     assert_int_equal(1, LY_ARRAY_COUNT(mod->parsed->identities));
     assert_string_equal(mod->parsed->identities[0].name, "ident-name");
 
     /* invalid substatement */
-    TEST_SCHEMA_ERR(ctx, 0, 1, "inv", "<identity name=\"ident-name\"><if-feature name=\"iff\"/></identity>",
-            "Invalid sub-elemnt \"if-feature\" of \"identity\" element - this sub-element is allowed only in modules with version 1.1 or newer. Line number 1.");
+    TEST_SCHEMA_ERR(0, 1, "inv", "<identity name=\"ident-name\"><if-feature name=\"iff\"/></identity>",
+            "Invalid sub-elemnt \"if-feature\" of \"identity\" element - "
+            "this sub-element is allowed only in modules with version 1.1 or newer.", "Line number 1.");
 
     /*
      * compiling
      */
-    TEST_SCHEMA_OK(ctx, 0, 0, "a", "identity a1;", mod_imp);
-    TEST_SCHEMA_OK(ctx, 1, 0, "b", "import a {prefix a;}"
+    TEST_SCHEMA_OK(0, 0, "a", "identity a1;", mod_imp);
+    TEST_SCHEMA_OK(1, 0, "b", "import a {prefix a;}"
             "identity b1; identity b2; identity b3 {base b1; base b:b2; base a:a1;}"
             "identity b4 {base b:b1; base b3;}", mod);
     assert_non_null(mod_imp->compiled);
@@ -107,34 +100,34 @@
     assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[2].derived));
     assert_ptr_equal(mod->identities[2].derived[0], &mod->identities[3]);
 
-    TEST_SCHEMA_OK(ctx, 1, 0, "c", "identity c2 {base c1;} identity c1;", mod);
+    TEST_SCHEMA_OK(1, 0, "c", "identity c2 {base c1;} identity c1;", mod);
     assert_int_equal(1, LY_ARRAY_COUNT(mod->identities[1].derived));
     assert_ptr_equal(mod->identities[1].derived[0], &mod->identities[0]);
 
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "identity i1;identity i1;", "Duplicate identifier \"i1\" of identity statement. Line number 1.");
+    TEST_SCHEMA_ERR(0, 0, "inv", "identity i1;identity i1;", "Duplicate identifier \"i1\" of identity statement.", "Line number 1.");
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} identity i1;}");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "include inv_sub;identity i1;",
-            "Duplicate identifier \"i1\" of identity statement. Line number 1.");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "identity i1 {base i2;}", "Unable to find base (i2) of identity \"i1\". /inv:{identity='i1'}");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "identity i1 {base i1;}", "Identity \"i1\" is derived from itself. /inv:{identity='i1'}");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "identity i1 {base i2;}identity i2 {base i3;}identity i3 {base i1;}",
-            "Identity \"i1\" is indirectly derived from itself. /inv:{identity='i3'}");
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} identity i1;}");
+    TEST_SCHEMA_ERR(0, 0, "inv", "include inv_sub;identity i1;",
+            "Duplicate identifier \"i1\" of identity statement.", "Line number 1.");
+    TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i2;}", "Unable to find base (i2) of identity \"i1\".", "/inv:{identity='i1'}");
+    TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i1;}", "Identity \"i1\" is derived from itself.", "/inv:{identity='i1'}");
+    TEST_SCHEMA_ERR(0, 0, "inv", "identity i1 {base i2;}identity i2 {base i3;}identity i3 {base i1;}",
+            "Identity \"i1\" is indirectly derived from itself.", "/inv:{identity='i3'}");
 
     /* base in non-implemented module */
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb,
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb,
             "module base {namespace \"urn\"; prefix b; identity i1; identity i2 {base i1;}}");
-    TEST_SCHEMA_OK(ctx, 0, 0, "ident", "import base {prefix b;} identity ii {base b:i1;}", mod);
+    TEST_SCHEMA_OK(0, 0, "ident", "import base {prefix b;} identity ii {base b:i1;}", mod);
 
     /* default value from non-implemented module */
-    TEST_SCHEMA_ERR(ctx, 0, 0, "ident2", "import base {prefix b;} leaf l {type identityref {base b:i1;} default b:i2;}",
+    TEST_SCHEMA_ERR(0, 0, "ident2", "import base {prefix b;} leaf l {type identityref {base b:i1;} default b:i2;}",
             "Invalid default - value does not fit the type (Invalid identityref \"b:i2\" value"
-            " - identity found in non-implemented module \"base\".). /ident2:l");
+            " - identity found in non-implemented module \"base\".).", "/ident2:l");
 
     /* default value in typedef from non-implemented module */
-    TEST_SCHEMA_ERR(ctx, 0, 0, "ident2", "import base {prefix b;} typedef t1 {type identityref {base b:i1;} default b:i2;}"
+    TEST_SCHEMA_ERR(0, 0, "ident2", "import base {prefix b;} typedef t1 {type identityref {base b:i1;} default b:i2;}"
             "leaf l {type t1;}", "Invalid default - value does not fit the type (Invalid"
-            " identityref \"b:i2\" value - identity found in non-implemented module \"base\".). /ident2:l");
+            " identityref \"b:i2\" value - identity found in non-implemented module \"base\".).", "/ident2:l");
 
     /*
      * printing
@@ -143,45 +136,37 @@
     /*
      * cleanup
      */
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
 
 void
 test_feature(void **state)
 {
-    *state = test_feature;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     const struct lysp_feature *f;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
-
     /*
      * parsing YANG
      */
 
-    TEST_STMT_DUP(ctx, 1, 0, "feature f", "description", "a", "b", "1");
-    TEST_STMT_DUP(ctx, 1, 0, "feature f", "reference", "a", "b", "1");
-    TEST_STMT_DUP(ctx, 1, 0, "feature f", "status", "current", "obsolete", "1");
+    TEST_STMT_DUP(1, 0, "feature f", "description", "a", "b", "1");
+    TEST_STMT_DUP(1, 0, "feature f", "reference", "a", "b", "1");
+    TEST_STMT_DUP(1, 0, "feature f", "status", "current", "obsolete", "1");
 
     /* full content */
-    TEST_SCHEMA_OK(ctx, 1, 0, "featureone",
+    TEST_SCHEMA_OK(1, 0, "featureone",
             "feature test {description text;reference \'another text\';status current; if-feature x; if-feature y; featureone:ext;}"
             "extension ext; feature x; feature y;", mod);
     assert_non_null(mod->parsed->features);
     assert_int_equal(3, LY_ARRAY_COUNT(mod->parsed->features));
 
     /* invalid substatement */
-    TEST_STMT_SUBSTM_ERR(ctx, 0, "feature", "organization", "XXX");
+    TEST_STMT_SUBSTM_ERR(0, "feature", "organization", "XXX");
 
     /*
      * parsing YIN
      */
     /* max subelems */
-    TEST_SCHEMA_OK(ctx, 0, 1, "featureone-yin", "<feature name=\"feature-name\">"
+    TEST_SCHEMA_OK(0, 1, "featureone-yin", "<feature name=\"feature-name\">"
             "<if-feature name=\"iff\"/>"
             "<status value=\"deprecated\"/>"
             "<description><text>desc</text></description>"
@@ -199,19 +184,19 @@
     assert_int_equal(mod->parsed->features[0].exts[0].insubstmt, LYEXT_SUBSTMT_SELF);*/
 
     /* min subelems */
-    TEST_SCHEMA_OK(ctx, 0, 1, "featuretwo-yin", "<feature name=\"feature-name\"/>", mod)
+    TEST_SCHEMA_OK(0, 1, "featuretwo-yin", "<feature name=\"feature-name\"/>", mod)
     assert_int_equal(1, LY_ARRAY_COUNT(mod->parsed->features));
     assert_string_equal(mod->parsed->features[0].name, "feature-name");
 
     /* invalid substatement */
-    TEST_SCHEMA_ERR(ctx, 0, 1, "inv", "<feature name=\"feature-name\"><organization><text>org</text></organization></feature>",
-            "Unexpected sub-element \"organization\" of \"feature\" element. Line number 1.");
+    TEST_SCHEMA_ERR(0, 1, "inv", "<feature name=\"feature-name\"><organization><text>org</text></organization></feature>",
+            "Unexpected sub-element \"organization\" of \"feature\" element.", "Line number 1.");
 
     /*
      * compiling
      */
 
-    TEST_SCHEMA_OK(ctx, 1, 0, "a", "feature f1 {description test1;reference test2;status current;} feature f2; feature f3;\n"
+    TEST_SCHEMA_OK(1, 0, "a", "feature f1 {description test1;reference test2;status current;} feature f2; feature f3;\n"
             "feature orfeature {if-feature \"f1 or f2\";}\n"
             "feature andfeature {if-feature \"f1 and f2\";}\n"
             "feature f6 {if-feature \"not f1\";}\n"
@@ -227,42 +212,42 @@
     }
 
     /* some invalid expressions */
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f{if-feature f1;}",
-            "Invalid value \"f1\" of if-feature - unable to find feature \"f1\".");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature 'f and';}",
-            "Invalid value \"f and\" of if-feature - unexpected end of expression.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f{if-feature 'or';}",
-            "Invalid value \"or\" of if-feature - unexpected end of expression.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature '(f1';}",
-            "Invalid value \"(f1\" of if-feature - non-matching opening and closing parentheses.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature 'f1)';}",
-            "Invalid value \"f1)\" of if-feature - non-matching opening and closing parentheses.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2{if-feature ---;}",
-            "Invalid value \"---\" of if-feature - unable to find feature \"---\".");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1; feature f2{if-feature 'not f1';}",
-            "Invalid value \"not f1\" of if-feature - YANG 1.1 expression in YANG 1.0 module.");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1; feature f1;",
-            "Duplicate identifier \"f1\" of feature statement. Line number 1.");
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f{if-feature f1;}",
+            "Invalid value \"f1\" of if-feature - unable to find feature \"f1\".", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2{if-feature 'f and';}",
+            "Invalid value \"f and\" of if-feature - unexpected end of expression.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f{if-feature 'or';}",
+            "Invalid value \"or\" of if-feature - unexpected end of expression.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2{if-feature '(f1';}",
+            "Invalid value \"(f1\" of if-feature - non-matching opening and closing parentheses.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2{if-feature 'f1)';}",
+            "Invalid value \"f1)\" of if-feature - non-matching opening and closing parentheses.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2{if-feature ---;}",
+            "Invalid value \"---\" of if-feature - unable to find feature \"---\".", NULL);
+    TEST_SCHEMA_ERR(0, 0, "inv", "feature f1; feature f2{if-feature 'not f1';}",
+            "Invalid value \"not f1\" of if-feature - YANG 1.1 expression in YANG 1.0 module.", NULL);
+    TEST_SCHEMA_ERR(0, 0, "inv", "feature f1; feature f1;",
+            "Duplicate identifier \"f1\" of feature statement.", "Line number 1.");
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} feature f1;}");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "include inv_sub;feature f1;",
-            "Duplicate identifier \"f1\" of feature statement. Line number 1.");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1 {if-feature f2;} feature f2 {if-feature f1;}",
-            "Feature \"f1\" is indirectly referenced from itself.");
-    TEST_SCHEMA_ERR(ctx, 0, 0, "inv", "feature f1 {if-feature f1;}",
-            "Feature \"f1\" is referenced from itself.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f {if-feature ();}",
-            "Invalid value \"()\" of if-feature - number of features in expression does not match the required number of operands for the operations.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1(';}",
-            "Invalid value \"f1(\" of if-feature - non-matching opening and closing parentheses.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'and f1';}",
-            "Invalid value \"and f1\" of if-feature - missing feature/expression before \"and\" operation.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1 not ';}",
-            "Invalid value \"f1 not \" of if-feature - unexpected end of expression.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f {if-feature 'f1 not not ';}",
-            "Invalid value \"f1 not not \" of if-feature - unexpected end of expression.");
-    TEST_SCHEMA_ERR(ctx, 1, 0, "inv", "feature f1; feature f2; feature f {if-feature 'or f1 f2';}",
-            "Invalid value \"or f1 f2\" of if-feature - missing feature/expression before \"or\" operation.");
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule inv_sub {belongs-to inv {prefix inv;} feature f1;}");
+    TEST_SCHEMA_ERR(0, 0, "inv", "include inv_sub;feature f1;",
+            "Duplicate identifier \"f1\" of feature statement.", "Line number 1.");
+    TEST_SCHEMA_ERR(0, 0, "inv", "feature f1 {if-feature f2;} feature f2 {if-feature f1;}",
+            "Feature \"f1\" is indirectly referenced from itself.", NULL);
+    TEST_SCHEMA_ERR(0, 0, "inv", "feature f1 {if-feature f1;}",
+            "Feature \"f1\" is referenced from itself.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f {if-feature ();}",
+            "Invalid value \"()\" of if-feature - number of features in expression does not match the required number of operands for the operations.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1(';}",
+            "Invalid value \"f1(\" of if-feature - non-matching opening and closing parentheses.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'and f1';}",
+            "Invalid value \"and f1\" of if-feature - missing feature/expression before \"and\" operation.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1 not ';}",
+            "Invalid value \"f1 not \" of if-feature - unexpected end of expression.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f {if-feature 'f1 not not ';}",
+            "Invalid value \"f1 not not \" of if-feature - unexpected end of expression.", NULL);
+    TEST_SCHEMA_ERR(1, 0, "inv", "feature f1; feature f2; feature f {if-feature 'or f1 f2';}",
+            "Invalid value \"or f1 f2\" of if-feature - missing feature/expression before \"or\" operation.", NULL);
 
     /*
      * printing
@@ -271,7 +256,4 @@
     /*
      * cleanup
      */
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index 7f0e4da..6f5977c 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -11,6 +11,8 @@
  *
  *     https://opensource.org/licenses/BSD-3-Clause
  */
+#define _UTEST_MAIN_
+#include "utests.h"
 
 #include "common.h"
 #include "in.h"
@@ -18,66 +20,18 @@
 #include "path.h"
 #include "plugins_types.h"
 #include "schema_compile.h"
-#include "utests.h"
 #include "xpath.h"
 
-void yang_parser_ctx_free(struct lys_yang_parser_ctx *ctx);
-
-#define BUFSIZE 1024
-char logbuf[BUFSIZE] = {0};
-
-/* set to 0 to printing error messages to stderr instead of checking them in code */
-#define ENABLE_LOGGER_CHECKING 1
-
-#if ENABLE_LOGGER_CHECKING
-static void
-logger(LY_LOG_LEVEL level, const char *msg, const char *path)
-{
-    (void) level; /* unused */
-
-    if (path && path[0]) {
-        snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path);
-    } else {
-        strncpy(logbuf, msg, BUFSIZE - 1);
-    }
-}
-
-#endif
-
 static int
-logger_setup(void **state)
+setup(void **state)
 {
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    ly_set_log_clb(logger, 1);
-#endif
+    UTEST_SETUP;
+
+    assert_int_equal(LY_SUCCESS, ly_ctx_set_options(UTEST_LYCTX, LY_CTX_DISABLE_SEARCHDIRS));
+
     return 0;
 }
 
-static int
-logger_teardown(void **state)
-{
-    (void) state; /* unused */
-#if ENABLE_LOGGER_CHECKING
-    if (*state) {
-        fprintf(stderr, "%s\n", logbuf);
-    }
-#endif
-    return 0;
-}
-
-void
-logbuf_clean(void)
-{
-    logbuf[0] = '\0';
-}
-
-#if ENABLE_LOGGER_CHECKING
-#   define logbuf_assert(str) assert_string_equal(logbuf, str);logbuf_clean()
-#else
-#   define logbuf_assert(str)
-#endif
-
 static LY_ERR
 test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
         const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
@@ -92,11 +46,8 @@
 static void
 test_module(void **state)
 {
-    *state = test_module;
-
     const char *str;
     struct ly_in *in;
-    struct ly_ctx *ctx = NULL;
     struct lys_module *mod = NULL;
     struct lysp_feature *f;
     struct lysc_iffeature *iff;
@@ -104,24 +55,22 @@
 
     str = "module test {namespace urn:test; prefix t;"
             "feature f1;feature f2 {if-feature f1;}}";
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx));
-
     assert_int_equal(LY_EINVAL, lys_compile(NULL, 0, NULL));
-    logbuf_assert("Invalid argument mod (lys_compile()).");
+    CHECK_LOG("Invalid argument mod (lys_compile()).", NULL);
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_SUCCESS, lys_create_module(ctx, in, LYS_IN_YANG, 0, NULL, NULL, NULL, &unres, &mod));
-    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(ctx, &unres));
-    lys_compile_unres_glob_erase(ctx, &unres);
+    assert_int_equal(LY_SUCCESS, lys_create_module(UTEST_LYCTX, in, LYS_IN_YANG, 0, NULL, NULL, NULL, &unres, &mod));
+    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     ly_in_free(in, 0);
     assert_int_equal(0, mod->implemented);
     assert_int_equal(LY_SUCCESS, lys_compile(mod, 0, &unres));
-    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(ctx, &unres));
-    lys_compile_unres_glob_erase(ctx, &unres);
+    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     assert_null(mod->compiled);
     mod->implemented = 1;
     assert_int_equal(LY_SUCCESS, lys_compile(mod, 0, &unres));
-    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(ctx, &unres));
-    lys_compile_unres_glob_erase(ctx, &unres);
+    assert_int_equal(LY_SUCCESS, lys_compile_unres_glob(UTEST_LYCTX, &unres));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     assert_non_null(mod->compiled);
     assert_string_equal("test", mod->name);
     assert_string_equal("urn:test", mod->ns);
@@ -141,60 +90,52 @@
     /* submodules cannot be compiled directly */
     str = "submodule test {belongs-to xxx {prefix x;}}";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_EINVAL, lys_create_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, NULL));
-    lys_compile_unres_glob_erase(ctx, &unres);
+    assert_int_equal(LY_EINVAL, lys_create_module(UTEST_LYCTX, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, NULL));
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     ly_in_free(in, 0);
-    logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module.");
+    CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL);
 
     /* data definition name collision in top level */
     str = "module aa {namespace urn:aa;prefix aa; leaf a {type string;} container a{presence x;}}";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
-    assert_int_equal(LY_EEXIST, lys_create_module(ctx, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod));
-    logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /aa:a");
-    lys_compile_unres_glob_erase(ctx, &unres);
+    assert_int_equal(LY_EEXIST, lys_create_module(UTEST_LYCTX, in, LYS_IN_YANG, 1, NULL, NULL, NULL, &unres, &mod));
+    CHECK_LOG_CTX("Duplicate identifier \"a\" of data definition/RPC/action/notification statement.", "/aa:a");
+    lys_compile_unres_glob_erase(UTEST_LYCTX, &unres);
     ly_in_free(in, 0);
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static void
 test_name_collisions(void **state)
 {
-    (void) state; /* unused */
-
-    struct ly_ctx *ctx;
     const char *yang_data;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
     /* top-level */
     yang_data = "module a {namespace urn:a;prefix a;"
             "  container c;"
             "  leaf a {type empty;}"
             "  leaf c {type empty;}"
             "}";
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, yang_data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"c\" of data definition/RPC/action/notification statement. /a:c");
-    logbuf_clean();
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"c\" of data definition/RPC/action/notification statement.", "/a:c");
+    UTEST_LOG_CLEAN;
 
     yang_data = "module a {namespace urn:a;prefix a;"
             "  container c;"
             "  leaf a {type empty;}"
             "  notification c;"
             "}";
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, yang_data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"c\" of data definition/RPC/action/notification statement. /a:c");
-    logbuf_clean();
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"c\" of data definition/RPC/action/notification statement.", "/a:c");
+    UTEST_LOG_CLEAN;
 
     yang_data = "module a {namespace urn:a;prefix a;"
             "  container c;"
             "  leaf a {type empty;}"
             "  rpc c;"
             "}";
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, yang_data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"c\" of data definition/RPC/action/notification statement. /a:c");
-    logbuf_clean();
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"c\" of data definition/RPC/action/notification statement.", "/a:c");
+    UTEST_LOG_CLEAN;
 
     yang_data = "module a {namespace urn:a;prefix a;"
             "  container c;"
@@ -206,51 +147,45 @@
             "    }"
             "  }"
             "}";
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, yang_data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"c\" of data definition/RPC/action/notification statement. /a:ch/c/c");
-    logbuf_clean();
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"c\" of data definition/RPC/action/notification statement.", "/a:ch/c/c");
+    UTEST_LOG_CLEAN;
 
     /* nested */
     yang_data = "module a {namespace urn:a;prefix a;container c { list l {key \"k\"; leaf k {type string;}"
             "leaf-list a {type string;}"
             "container a;"
             "}}}";
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, yang_data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /a:c/l/a");
-    logbuf_clean();
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"a\" of data definition/RPC/action/notification statement.", "/a:c/l/a");
+    UTEST_LOG_CLEAN;
 
     yang_data = "module a {yang-version 1.1;namespace urn:a;prefix a;container c { list l {key \"k\"; leaf k {type string;}"
             "leaf-list a {type string;}"
             "notification a;"
             "}}}";
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, yang_data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /a:c/l/a");
-    logbuf_clean();
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"a\" of data definition/RPC/action/notification statement.", "/a:c/l/a");
+    UTEST_LOG_CLEAN;
 
     yang_data = "module a {yang-version 1.1;namespace urn:a;prefix a;container c { list l {key \"k\"; leaf k {type string;}"
             "leaf-list a {type string;}"
             "action a;"
             "}}}";
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, yang_data, LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /a:c/l/a");
-    logbuf_clean();
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"a\" of data definition/RPC/action/notification statement.", "/a:c/l/a");
+    UTEST_LOG_CLEAN;
 
     /* grouping */
-
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static void
 test_node_container(void **state)
 {
-    (void) state; /* unused */
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_node_container *cont;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;container c;}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;container c;}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled);
     assert_non_null((cont = (struct lysc_node_container *)mod->compiled->data));
     assert_int_equal(LYS_CONTAINER, cont->nodetype);
@@ -258,8 +193,8 @@
     assert_true(cont->flags & LYS_CONFIG_W);
     assert_true(cont->flags & LYS_STATUS_CURR);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;container c {config false; status deprecated; container child;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing explicit \"deprecated\" status that was already specified in parent, inheriting.");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;container c {config false; status deprecated; container child;}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Missing explicit \"deprecated\" status that was already specified in parent, inheriting.", NULL);
     assert_non_null(mod->compiled);
     assert_non_null((cont = (struct lysc_node_container *)mod->compiled->data));
     assert_true(cont->flags & LYS_CONFIG_R);
@@ -269,16 +204,11 @@
     assert_true(cont->flags & LYS_CONFIG_R);
     assert_true(cont->flags & LYS_STATUS_DEPRC);
     assert_string_equal("child", cont->name);
-
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static void
 test_node_leaflist(void **state)
 {
-    *state = test_node_leaflist;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
     struct lysc_node_leaflist *ll;
@@ -286,9 +216,7 @@
     const char *dflt;
     uint8_t dynamic;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;"
             "typedef mytype {type union {type leafref {path ../target;} type string;}}"
             "leaf-list ll1 {type union {type decimal64 {fraction-digits 2;} type mytype;}}"
             "leaf-list ll2 {type leafref {path ../target;}}"
@@ -312,13 +240,13 @@
     assert_non_null(((struct lysc_type_leafref *)type)->realtype);
     assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref *)type)->realtype->basetype);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf-list ll {type string;}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;leaf-list ll {type string;}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled);
     assert_non_null((ll = (struct lysc_node_leaflist *)mod->compiled->data));
     assert_int_equal(0, ll->min);
     assert_int_equal((uint32_t)-1, ll->max);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c;typedef mytype {type int8;default 10;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1;namespace urn:c;prefix c;typedef mytype {type int8;default 10;}"
             "leaf-list ll1 {type mytype;default 1; default 1; config false;}"
             "leaf-list ll2 {type mytype; ordered-by user;}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled);
@@ -340,26 +268,26 @@
     assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_USER, ll->flags);
 
     /* ordered-by is ignored for state data, RPC/action output parameters and notification content */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {yang-version 1.1;namespace urn:d;prefix d;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {yang-version 1.1;namespace urn:d;prefix d;"
             "leaf-list ll {config false; type string; ordered-by user;}}", LYS_IN_YANG, &mod));
     /* but warning is present: */
-    logbuf_assert("The ordered-by statement is ignored in lists representing state data (/d:ll).");
+    CHECK_LOG_CTX("The ordered-by statement is ignored in lists representing state data (/d:ll).", NULL);
     assert_non_null(mod->compiled);
     assert_non_null((ll = (struct lysc_node_leaflist *)mod->compiled->data));
     assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_CONFIG, ll->flags);
-    logbuf_clean();
+    UTEST_LOG_CLEAN;
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {yang-version 1.1;namespace urn:e;prefix e;"
             "rpc oper {output {leaf-list ll {type string; ordered-by user;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("The ordered-by statement is ignored in lists representing RPC/action output parameters (/e:oper/output/ll).");
-    logbuf_clean();
+    CHECK_LOG_CTX("The ordered-by statement is ignored in lists representing RPC/action output parameters (/e:oper/output/ll).", NULL);
+    UTEST_LOG_CLEAN;
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {yang-version 1.1;namespace urn:f;prefix f;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {yang-version 1.1;namespace urn:f;prefix f;"
             "notification event {leaf-list ll {type string; ordered-by user;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("The ordered-by statement is ignored in lists representing notification content (/f:event/ll).");
+    CHECK_LOG_CTX("The ordered-by statement is ignored in lists representing notification content (/f:event/ll).", NULL);
 
     /* forward reference in default */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {yang-version 1.1; namespace urn:g;prefix g;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {yang-version 1.1; namespace urn:g;prefix g;"
             "leaf ref {type instance-identifier {require-instance true;} default \"/g:g[.='val']\";}"
             "leaf-list g {type string;}}", LYS_IN_YANG, &mod));
     assert_non_null(l = (struct lysc_node_leaf *)mod->compiled->data);
@@ -367,38 +295,32 @@
     assert_non_null(l->dflt);
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;leaf-list ll {type empty;}}",
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;leaf-list ll {type empty;}}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules. /aa:ll");
+    CHECK_LOG_CTX("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules.", "/aa:ll");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {yang-version 1.1;namespace urn:bb;prefix bb;leaf-list ll {type empty; default x;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid default - value does not fit the type (Invalid empty value \"x\".). /bb:ll");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {yang-version 1.1;namespace urn:bb;prefix bb;leaf-list ll {type empty; default x;}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid empty value \"x\".).", "/bb:ll");
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;"
             "leaf-list ll {config false;type string; default one;default two;default one;}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled);
     assert_non_null((ll = (struct lysc_node_leaflist *)mod->compiled->data));
     assert_non_null(ll->dflts);
     assert_int_equal(3, LY_ARRAY_COUNT(ll->dflts));
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;"
             "leaf-list ll {type string; default one;default two;default one;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Configuration leaf-list has multiple defaults of the same value \"one\". /dd:ll");
+    CHECK_LOG_CTX("Configuration leaf-list has multiple defaults of the same value \"one\".", "/dd:ll");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;"
             "leaf ref {type instance-identifier {require-instance true;} default \"/ee:g\";}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid default - value does not fit the type "
-            "(Invalid instance-identifier \"/ee:g\" value - semantic error.). /ee:ref");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Invalid default - value does not fit the type "
+            "(Invalid instance-identifier \"/ee:g\" value - semantic error.).", "/ee:ref");
 }
 
 static void
 test_node_list(void **state)
 {
-    *state = test_node_list;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_node_list *list;
     struct lysc_node *child;
@@ -409,10 +331,8 @@
             "list l2 {config false;leaf value {type string;}}}";
     const char *feats[] = {"f", NULL};
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lys_parse(ctx, in, LYS_IN_YANG, feats, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse(UTEST_LYCTX, in, LYS_IN_YANG, feats, &mod));
     ly_in_free(in, 0);
     list = (struct lysc_node_list *)mod->compiled->data;
     assert_non_null(list);
@@ -431,7 +351,7 @@
     assert_false(list->child->flags & LYS_KEY);
     assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_SYSTEM | LYS_SET_CONFIG | LYS_KEYLESS, list->flags);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;"
             "list l {key a; unique \"a c/b:b\"; unique \"c/e d\";"
             "leaf a {type string; default x;} leaf d {type string;config false;}"
             "container c {leaf b {type string;}leaf e{type string;config false;}}}}",
@@ -455,7 +375,7 @@
     assert_string_equal("d", list->uniques[1][1]->name);
     assert_true(list->uniques[1][1]->flags & LYS_UNIQUE);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1;namespace urn:c;prefix c;"
             "list l {key a;leaf a {type empty;}}}", LYS_IN_YANG, &mod));
     list = (struct lysc_node_list *)mod->compiled->data;
     assert_non_null(list);
@@ -465,7 +385,7 @@
     assert_int_equal(LY_TYPE_EMPTY, ((struct lysc_node_leaf *)list->child)->type->basetype);
 
     /* keys order */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {yang-version 1.1;namespace urn:d;prefix d;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {yang-version 1.1;namespace urn:d;prefix d;"
             "list l {key \"d b c\";leaf a {type string;} leaf b {type string;} leaf c {type string;} leaf d {type string;}}}", LYS_IN_YANG, &mod));
     list = (struct lysc_node_list *)mod->compiled->data;
     assert_non_null(list);
@@ -484,74 +404,66 @@
     assert_false(child->flags & LYS_KEY);
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;list l;}", LYS_IN_YANG, NULL));
-    logbuf_assert("Missing key in list representing configuration data. /aa:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;list l;}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Missing key in list representing configuration data.", "/aa:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {yang-version 1.1; namespace urn:bb;prefix bb;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {yang-version 1.1; namespace urn:bb;prefix bb;"
             "list l {key x; leaf x {type string; when 1;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("List's key must not have any \"when\" statement. /bb:l/x");
+    CHECK_LOG_CTX("List's key must not have any \"when\" statement.", "/bb:l/x");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;feature f;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;feature f;"
             "list l {key x; leaf x {type string; if-feature f;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Key \"x\" is disabled by its if-features. /cc:l/x");
+    CHECK_LOG_CTX("Key \"x\" is disabled by its if-features.", "/cc:l/x");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;"
             "list l {key x; leaf x {type string; config false;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Key of the configuration list must not be status leaf. /dd:l/x");
+    CHECK_LOG_CTX("Key of the configuration list must not be status leaf.", "/dd:l/x");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;"
             "list l {config false;key x; leaf x {type string; config true;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Configuration node cannot be child of any state data node. /ee:l/x");
+    CHECK_LOG_CTX("Configuration node cannot be child of any state data node.", "/ee:l/x");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;"
             "list l {key x; leaf-list x {type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("The list's key \"x\" not found. /ff:l");
+    CHECK_LOG_CTX("The list's key \"x\" not found.", "/ff:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;"
             "list l {key x; unique y;leaf x {type string;} leaf-list y {type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Unique's descendant-schema-nodeid \"y\" refers to leaf-list node instead of a leaf. /gg:l");
+    CHECK_LOG_CTX("Unique's descendant-schema-nodeid \"y\" refers to leaf-list node instead of a leaf.", "/gg:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh;"
             "list l {key x; unique \"x y\";leaf x {type string;} leaf y {config false; type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Unique statement \"x y\" refers to leaves with different config type. /hh:l");
+    CHECK_LOG_CTX("Unique statement \"x y\" refers to leaves with different config type.", "/hh:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii {namespace urn:ii;prefix ii;"
             "list l {key x; unique a:x;leaf x {type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid descendant-schema-nodeid value \"a:x\" - prefix \"a\" not defined in module \"ii\". /ii:l");
+    CHECK_LOG_CTX("Invalid descendant-schema-nodeid value \"a:x\" - prefix \"a\" not defined in module \"ii\".", "/ii:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj {namespace urn:jj;prefix jj;"
             "list l {key x; unique c/x;leaf x {type string;}container c {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid descendant-schema-nodeid value \"c/x\" - target node not found. /jj:l");
+    CHECK_LOG_CTX("Invalid descendant-schema-nodeid value \"c/x\" - target node not found.", "/jj:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk {namespace urn:kk;prefix kk;"
             "list l {key x; unique c^y;leaf x {type string;}container c {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid descendant-schema-nodeid value \"c^\" - missing \"/\" as node-identifier separator. /kk:l");
+    CHECK_LOG_CTX("Invalid descendant-schema-nodeid value \"c^\" - missing \"/\" as node-identifier separator.", "/kk:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll {namespace urn:ll;prefix ll;"
             "list l {key \"x y x\";leaf x {type string;}leaf y {type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicated key identifier \"x\". /ll:l");
+    CHECK_LOG_CTX("Duplicated key identifier \"x\".", "/ll:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm {namespace urn:mm;prefix mm;"
             "list l {key x;leaf x {type empty;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("List's key cannot be of \"empty\" type until it is in YANG 1.1 module. /mm:l/x");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("List's key cannot be of \"empty\" type until it is in YANG 1.1 module.", "/mm:l/x");
 }
 
 static void
 test_node_choice(void **state)
 {
-    *state = test_node_choice;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_node_choice *ch;
     struct lysc_node_case *cs;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;feature f;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;feature f;"
             "choice ch {default a:b; when \"true()\"; case a {leaf a1 {type string;}leaf a2 {type string;}}"
             "leaf b {type string;}}}", LYS_IN_YANG, &mod));
     ch = (struct lysc_node_choice *)mod->compiled->data;
@@ -578,81 +490,65 @@
     assert_ptr_equal(cs, cs->child->parent);
     assert_ptr_equal(ch->dflt, cs);
 
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
             "choice ch {case a {leaf x {type string;}}leaf x {type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"x\" of data definition/RPC/action/notification statement. /aa:ch/x/x");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module aa2 {namespace urn:aa2;prefix aa;"
+    CHECK_LOG_CTX("Duplicate identifier \"x\" of data definition/RPC/action/notification statement.", "/aa:ch/x/x");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module aa2 {namespace urn:aa2;prefix aa;"
             "choice ch {case a {leaf y {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"y\" of data definition/RPC/action/notification statement. /aa2:ch/b/y");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;"
+    CHECK_LOG_CTX("Duplicate identifier \"y\" of data definition/RPC/action/notification statement.", "/aa2:ch/b/y");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;"
             "choice ch {case a {leaf x {type string;}}leaf a {type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"a\" of case statement. /bb:ch/a");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module bb2 {namespace urn:bb2;prefix bb;"
+    CHECK_LOG_CTX("Duplicate identifier \"a\" of case statement.", "/bb:ch/a");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb2 {namespace urn:bb2;prefix bb;"
             "choice ch {case b {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"b\" of case statement. /bb2:ch/b");
+    CHECK_LOG_CTX("Duplicate identifier \"b\" of case statement.", "/bb2:ch/b");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ca {namespace urn:ca;prefix ca;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ca {namespace urn:ca;prefix ca;"
             "choice ch {default c;case a {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Default case \"c\" not found. /ca:ch");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cb {namespace urn:cb;prefix cb; import a {prefix a;}"
+    CHECK_LOG_CTX("Default case \"c\" not found.", "/ca:ch");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cb {namespace urn:cb;prefix cb; import a {prefix a;}"
             "choice ch {default a:a;case a {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Default case \"a:a\" not found. /cb:ch");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;"
+    CHECK_LOG_CTX("Default case \"a:a\" not found.", "/cb:ch");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;"
             "choice ch {default a;case a {leaf x {mandatory true;type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Mandatory node \"x\" under the default case \"a\". /cc:ch");
+    CHECK_LOG_CTX("Mandatory node \"x\" under the default case \"a\".", "/cc:ch");
     /* TODO check with mandatory nodes from augment placed into the case */
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static void
 test_node_anydata(void **state)
 {
-    *state = test_node_anydata;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_node_anydata *any;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1;namespace urn:a;prefix a;"
             "anydata any {config false;mandatory true;}}", LYS_IN_YANG, &mod));
     any = (struct lysc_node_anydata *)mod->compiled->data;
     assert_non_null(any);
     assert_int_equal(LYS_ANYDATA, any->nodetype);
     assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE | LYS_SET_CONFIG, any->flags);
 
-    logbuf_clean();
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;"
+    UTEST_LOG_CLEAN;
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;"
             "anyxml any;}", LYS_IN_YANG, &mod));
     any = (struct lysc_node_anydata *)mod->compiled->data;
     assert_non_null(any);
     assert_int_equal(LYS_ANYXML, any->nodetype);
     assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR, any->flags);
-    logbuf_assert("Use of anyxml to define configuration data is not recommended. /b:any"); /* warning */
+    CHECK_LOG_CTX("Use of anyxml to define configuration data is not recommended. /b:any", NULL);     /* warning */
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;anydata any;}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid keyword \"anydata\" as a child of \"module\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;anydata any;}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid keyword \"anydata\" as a child of \"module\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
 }
 
 static void
 test_action(void **state)
 {
-    *state = test_action;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     const struct lysc_action *rpc;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;"
             "rpc a {input {leaf x {type int8;} leaf y {type int8;}} output {leaf result {type int16;}}}}", LYS_IN_YANG, &mod));
     rpc = mod->compiled->rpcs;
     assert_non_null(rpc);
@@ -661,7 +557,7 @@
     assert_int_equal(LYS_STATUS_CURR, rpc->flags);
     assert_string_equal("a", rpc->name);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {"
             "action b {input {leaf x {type int8;} leaf y {type int8;}}"
             "output {must \"result > 25\"; must \"/top\"; leaf result {type int16;}}}}"
             "augment /top/b/output {leaf result2 {type string;}}}", LYS_IN_YANG, &mod));
@@ -675,49 +571,41 @@
     assert_int_equal(2, LY_ARRAY_COUNT(rpc->output.musts));
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container top {action x;}}",
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;container top {action x;}}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid keyword \"action\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
+    CHECK_LOG_CTX("Invalid keyword \"action\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
 
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} rpc x;}",
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} rpc x;}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"x\" of data definition/RPC/action/notification statement. /bb:x");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} action y;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"y\" of data definition/RPC/action/notification statement. /cc:c/y");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {action z; action z;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"z\" of data definition/RPC/action/notification statement. /dd:c/z");
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule eesub {belongs-to ee {prefix ee;} notification w;}");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; rpc w;}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"w\" of data definition/RPC/action/notification statement. /ee:w");
+    CHECK_LOG_CTX("Duplicate identifier \"x\" of data definition/RPC/action/notification statement.", "/bb:x");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} action y;}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"y\" of data definition/RPC/action/notification statement.", "/cc:c/y");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {action z; action z;}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"z\" of data definition/RPC/action/notification statement.", "/dd:c/z");
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule eesub {belongs-to ee {prefix ee;} notification w;}");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; rpc w;}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"w\" of data definition/RPC/action/notification statement.", "/ee:w");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}"
             "augment /test/input/a {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Action \"invalid\" is placed inside another RPC/action. /ff:{augment='/test/input/a'}/invalid");
+    CHECK_LOG_CTX("Action \"invalid\" is placed inside another RPC/action.", "/ff:{augment='/test/input/a'}/invalid");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}"
             "augment /test/a {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Action \"invalid\" is placed inside notification. /gg:{augment='/test/a'}/invalid");
+    CHECK_LOG_CTX("Action \"invalid\" is placed inside notification.", "/gg:{augment='/test/a'}/invalid");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; notification test {container a {uses grp;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; notification test {container a {uses grp;}}"
             "grouping grp {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Action \"invalid\" is placed inside notification. /hh:test/a/{uses='grp'}/invalid");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Action \"invalid\" is placed inside notification.", "/hh:test/a/{uses='grp'}/invalid");
 }
 
 static void
 test_notification(void **state)
 {
-    *state = test_notification;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     const struct lysc_notif *notif;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;"
             "notification a1 {leaf x {type int8;}} notification a2;}", LYS_IN_YANG, &mod));
     notif = mod->compiled->notifs;
     assert_non_null(notif);
@@ -732,7 +620,7 @@
     assert_string_equal("a2", notif[1].name);
     assert_null(notif[1].data);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {"
             "notification b1 {leaf x {type int8;}} notification b2 {must \"/top\";}}}", LYS_IN_YANG, &mod));
     notif = lysc_node_notifs(mod->compiled->data);
     assert_non_null(notif);
@@ -749,34 +637,31 @@
     assert_int_equal(1, LY_ARRAY_COUNT(notif[1].musts));
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container top {notification x;}}",
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;container top {notification x;}}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid keyword \"notification\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
+    CHECK_LOG_CTX("Invalid keyword \"notification\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
 
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} notification x;}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"x\" of data definition/RPC/action/notification statement. /bb:x");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} notification y;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"y\" of data definition/RPC/action/notification statement. /cc:c/y");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {notification z; notification z;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"z\" of data definition/RPC/action/notification statement. /dd:c/z");
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule eesub {belongs-to ee {prefix ee;} rpc w;}");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; notification w;}", LYS_IN_YANG, NULL));
-    logbuf_assert("Duplicate identifier \"w\" of data definition/RPC/action/notification statement. /ee:w");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} notification x;}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"x\" of data definition/RPC/action/notification statement.", "/bb:x");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} notification y;}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"y\" of data definition/RPC/action/notification statement.", "/cc:c/y");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {notification z; notification z;}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"z\" of data definition/RPC/action/notification statement.", "/dd:c/z");
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule eesub {belongs-to ee {prefix ee;} rpc w;}");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; notification w;}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Duplicate identifier \"w\" of data definition/RPC/action/notification statement.", "/ee:w");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}"
             "augment /test/input/a {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Notification \"invalid\" is placed inside RPC/action. /ff:{augment='/test/input/a'}/invalid");
+    CHECK_LOG_CTX("Notification \"invalid\" is placed inside RPC/action.", "/ff:{augment='/test/input/a'}/invalid");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}"
             "augment /test/a {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Notification \"invalid\" is placed inside another notification. /gg:{augment='/test/a'}/invalid");
+    CHECK_LOG_CTX("Notification \"invalid\" is placed inside another notification.", "/gg:{augment='/test/a'}/invalid");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; rpc test {input {container a {uses grp;}}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; rpc test {input {container a {uses grp;}}}"
             "grouping grp {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Notification \"invalid\" is placed inside RPC/action. /hh:test/input/a/{uses='grp'}/invalid");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Notification \"invalid\" is placed inside RPC/action.", "/hh:test/input/a/{uses='grp'}/invalid");
 }
 
 /**
@@ -786,15 +671,10 @@
 static void
 test_type_range(void **state)
 {
-    *state = test_type_range;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type int8 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;leaf l {type int8 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_INT8, type->basetype);
@@ -806,7 +686,7 @@
     assert_int_equal(127, ((struct lysc_type_num *)type)->range->parts[1].min_64);
     assert_int_equal(127, ((struct lysc_type_num *)type)->range->parts[1].max_64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf l {type int16 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;leaf l {type int16 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_INT16, type->basetype);
@@ -818,7 +698,7 @@
     assert_int_equal(32767, ((struct lysc_type_num *)type)->range->parts[1].min_64);
     assert_int_equal(32767, ((struct lysc_type_num *)type)->range->parts[1].max_64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;leaf l {type int32 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;leaf l {type int32 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_INT32, type->basetype);
@@ -830,7 +710,7 @@
     assert_int_equal(INT64_C(2147483647), ((struct lysc_type_num *)type)->range->parts[1].min_64);
     assert_int_equal(INT64_C(2147483647), ((struct lysc_type_num *)type)->range->parts[1].max_64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type int64 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d;leaf l {type int64 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_INT64, type->basetype);
@@ -842,7 +722,7 @@
     assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_num *)type)->range->parts[1].min_64);
     assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_num *)type)->range->parts[1].max_64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;leaf l {type uint8 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e;leaf l {type uint8 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_UINT8, type->basetype);
@@ -854,7 +734,7 @@
     assert_int_equal(255, ((struct lysc_type_num *)type)->range->parts[1].min_u64);
     assert_int_equal(255, ((struct lysc_type_num *)type)->range->parts[1].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;leaf l {type uint16 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;leaf l {type uint16 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_UINT16, type->basetype);
@@ -866,7 +746,7 @@
     assert_int_equal(65535, ((struct lysc_type_num *)type)->range->parts[1].min_u64);
     assert_int_equal(65535, ((struct lysc_type_num *)type)->range->parts[1].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;leaf l {type uint32 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g;leaf l {type uint32 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_UINT32, type->basetype);
@@ -878,7 +758,7 @@
     assert_int_equal(UINT64_C(4294967295), ((struct lysc_type_num *)type)->range->parts[1].min_u64);
     assert_int_equal(UINT64_C(4294967295), ((struct lysc_type_num *)type)->range->parts[1].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;leaf l {type uint64 {range min..10|max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {namespace urn:h;prefix h;leaf l {type uint64 {range min..10|max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_UINT64, type->basetype);
@@ -890,7 +770,7 @@
     assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_num *)type)->range->parts[1].min_u64);
     assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_num *)type)->range->parts[1].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;typedef mytype {type uint8 {range 10..100;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i;typedef mytype {type uint8 {range 10..100;}}"
             "typedef mytype2 {type mytype;} leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -900,7 +780,7 @@
     assert_non_null(((struct lysc_type_num *)type)->range->parts);
     assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_num *)type)->range->parts));
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module j {namespace urn:j;prefix j;"
             "typedef mytype {type uint8 {range 1..100{description \"one to hundred\";reference A;}}}"
             "leaf l {type mytype {range 1..10 {description \"one to ten\";reference B;}}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -914,23 +794,15 @@
     assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_num *)type)->range->parts));
     assert_int_equal(1, ((struct lysc_type_num *)type)->range->parts[0].min_u64);
     assert_int_equal(10, ((struct lysc_type_num *)type)->range->parts[0].max_u64);
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static void
 test_type_length(void **state)
 {
-    *state = test_type_length;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type binary {length min {error-app-tag errortag;error-message error;}}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;leaf l {type binary {length min {error-app-tag errortag;error-message error;}}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_non_null(((struct lysc_type_bin *)type)->length);
@@ -941,7 +813,7 @@
     assert_int_equal(0, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(0, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;leaf l {type binary {length max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;leaf l {type binary {length max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_non_null(((struct lysc_type_bin *)type)->length);
@@ -950,7 +822,7 @@
     assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;leaf l {type binary {length min..max;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;leaf l {type binary {length min..max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_non_null(((struct lysc_type_bin *)type)->length);
@@ -959,7 +831,7 @@
     assert_int_equal(0, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type binary {length 5;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d;leaf l {type binary {length 5;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_non_null(((struct lysc_type_bin *)type)->length);
@@ -968,7 +840,7 @@
     assert_int_equal(5, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(5, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;leaf l {type binary {length 1..10;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e;leaf l {type binary {length 1..10;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_non_null(((struct lysc_type_bin *)type)->length);
@@ -977,7 +849,7 @@
     assert_int_equal(1, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;leaf l {type binary {length 1..10|20..30;}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;leaf l {type binary {length 1..10|20..30;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_non_null(((struct lysc_type_bin *)type)->length);
@@ -988,7 +860,7 @@
     assert_int_equal(20, ((struct lysc_type_bin *)type)->length->parts[1].min_u64);
     assert_int_equal(30, ((struct lysc_type_bin *)type)->length->parts[1].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;leaf l {type binary {length \"16 | 32\";}}}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g;leaf l {type binary {length \"16 | 32\";}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_non_null(((struct lysc_type_bin *)type)->length);
@@ -999,7 +871,7 @@
     assert_int_equal(32, ((struct lysc_type_bin *)type)->length->parts[1].min_u64);
     assert_int_equal(32, ((struct lysc_type_bin *)type)->length->parts[1].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;typedef mytype {type binary {length 10;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {namespace urn:h;prefix h;typedef mytype {type binary {length 10;}}"
             "leaf l {type mytype {length \"10\";}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1009,7 +881,7 @@
     assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;typedef mytype {type binary {length 10..100;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i;typedef mytype {type binary {length 10..100;}}"
             "leaf l {type mytype {length \"50\";}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1019,7 +891,7 @@
     assert_int_equal(50, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(50, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;typedef mytype {type binary {length 10..100;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module j {namespace urn:j;prefix j;typedef mytype {type binary {length 10..100;}}"
             "leaf l {type mytype {length \"10..30|60..100\";}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1031,7 +903,7 @@
     assert_int_equal(60, ((struct lysc_type_bin *)type)->length->parts[1].min_u64);
     assert_int_equal(100, ((struct lysc_type_bin *)type)->length->parts[1].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module k {namespace urn:k;prefix k;typedef mytype {type binary {length 10..100;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module k {namespace urn:k;prefix k;typedef mytype {type binary {length 10..100;}}"
             "leaf l {type mytype {length \"10..80\";}}leaf ll {type mytype;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1050,7 +922,7 @@
     assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
     assert_int_equal(100, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module l {namespace urn:l;prefix l;typedef mytype {type string {length 10..100;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module l {namespace urn:l;prefix l;typedef mytype {type string {length 10..100;}}"
             "typedef mytype2 {type mytype {pattern '[0-9]*';}} leaf l {type mytype2 {pattern '[0-4]*';}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1062,7 +934,7 @@
     assert_int_equal(10, ((struct lysc_type_str *)type)->length->parts[0].min_u64);
     assert_int_equal(100, ((struct lysc_type_str *)type)->length->parts[0].max_u64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module m {namespace urn:m;prefix m;typedef mytype {type string {length 10;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module m {namespace urn:m;prefix m;typedef mytype {type string {length 10;}}"
             "leaf l {type mytype {length min..max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1075,72 +947,64 @@
     assert_int_equal(10, ((struct lysc_type_str *)type)->length->parts[0].max_u64);
 
     /* invalid values */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;leaf l {type binary {length -10;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - value \"-10\" does not fit the type limitations. /aa:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf l {type binary {length 18446744073709551616;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - invalid value \"18446744073709551616\". /bb:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;leaf l {type binary {length \"max .. 10\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - unexpected data after max keyword (.. 10). /cc:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;leaf l {type binary {length 50..10;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - values are not in ascending order (10). /dd:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type binary {length \"50 | 10\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - values are not in ascending order (10). /ee:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type binary {length \"x\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - unexpected data (x). /ff:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;leaf l {type binary {length \"50 | min\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - unexpected data before min keyword (50 | ). /gg:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;leaf l {type binary {length \"| 50\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - unexpected beginning of the expression (| 50). /hh:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;leaf l {type binary {length \"10 ..\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - unexpected end of the expression after \"..\" (10 ..). /ii:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;leaf l {type binary {length \".. 10\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - unexpected \"..\" without a lower bound. /jj:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;leaf l {type binary {length \"10 |\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - unexpected end of the expression (10 |). /kk:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kl {namespace urn:kl;prefix kl;leaf l {type binary {length \"10..20 | 15..30\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - values are not in ascending order (15). /kl:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;leaf l {type binary {length -10;}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - value \"-10\" does not fit the type limitations.", "/aa:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;leaf l {type binary {length 18446744073709551616;}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - invalid value \"18446744073709551616\".", "/bb:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;leaf l {type binary {length \"max .. 10\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - unexpected data after max keyword (.. 10).", "/cc:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;leaf l {type binary {length 50..10;}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - values are not in ascending order (10).", "/dd:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;leaf l {type binary {length \"50 | 10\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - values are not in ascending order (10).", "/ee:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;leaf l {type binary {length \"x\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - unexpected data (x).", "/ff:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;leaf l {type binary {length \"50 | min\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - unexpected data before min keyword (50 | ).", "/gg:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh;leaf l {type binary {length \"| 50\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - unexpected beginning of the expression (| 50).", "/hh:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii {namespace urn:ii;prefix ii;leaf l {type binary {length \"10 ..\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - unexpected end of the expression after \"..\" (10 ..).", "/ii:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj {namespace urn:jj;prefix jj;leaf l {type binary {length \".. 10\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - unexpected \"..\" without a lower bound.", "/jj:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk {namespace urn:kk;prefix kk;leaf l {type binary {length \"10 |\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - unexpected end of the expression (10 |).", "/kk:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kl {namespace urn:kl;prefix kl;leaf l {type binary {length \"10..20 | 15..30\";}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid length restriction - values are not in ascending order (15).", "/kl:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;typedef mytype {type binary {length 10;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll {namespace urn:ll;prefix ll;typedef mytype {type binary {length 10;}}"
             "leaf l {type mytype {length 11;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - the derived restriction (11) is not equally or more limiting. /ll:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;typedef mytype {type binary {length 10..100;}}"
+    CHECK_LOG_CTX("Invalid length restriction - the derived restriction (11) is not equally or more limiting.", "/ll:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm {namespace urn:mm;prefix mm;typedef mytype {type binary {length 10..100;}}"
             "leaf l {type mytype {length 1..11;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - the derived restriction (1..11) is not equally or more limiting. /mm:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module nn {namespace urn:nn;prefix nn;typedef mytype {type binary {length 10..100;}}"
+    CHECK_LOG_CTX("Invalid length restriction - the derived restriction (1..11) is not equally or more limiting.", "/mm:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module nn {namespace urn:nn;prefix nn;typedef mytype {type binary {length 10..100;}}"
             "leaf l {type mytype {length 20..110;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - the derived restriction (20..110) is not equally or more limiting. /nn:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo {namespace urn:oo;prefix oo;typedef mytype {type binary {length 10..100;}}"
+    CHECK_LOG_CTX("Invalid length restriction - the derived restriction (20..110) is not equally or more limiting.", "/nn:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo {namespace urn:oo;prefix oo;typedef mytype {type binary {length 10..100;}}"
             "leaf l {type mytype {length 20..30|110..120;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - the derived restriction (20..30|110..120) is not equally or more limiting. /oo:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module pp {namespace urn:pp;prefix pp;typedef mytype {type binary {length 10..11;}}"
+    CHECK_LOG_CTX("Invalid length restriction - the derived restriction (20..30|110..120) is not equally or more limiting.", "/oo:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module pp {namespace urn:pp;prefix pp;typedef mytype {type binary {length 10..11;}}"
             "leaf l {type mytype {length 15;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - the derived restriction (15) is not equally or more limiting. /pp:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module qq {namespace urn:qq;prefix qq;typedef mytype {type binary {length 10..20|30..40;}}"
+    CHECK_LOG_CTX("Invalid length restriction - the derived restriction (15) is not equally or more limiting.", "/pp:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module qq {namespace urn:qq;prefix qq;typedef mytype {type binary {length 10..20|30..40;}}"
             "leaf l {type mytype {length 15..35;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - the derived restriction (15..35) is not equally or more limiting. /qq:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module rr {namespace urn:rr;prefix rr;typedef mytype {type binary {length 10;}}"
+    CHECK_LOG_CTX("Invalid length restriction - the derived restriction (15..35) is not equally or more limiting.", "/qq:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module rr {namespace urn:rr;prefix rr;typedef mytype {type binary {length 10;}}"
             "leaf l {type mytype {length 10..35;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid length restriction - the derived restriction (10..35) is not equally or more limiting. /rr:l");
+    CHECK_LOG_CTX("Invalid length restriction - the derived restriction (10..35) is not equally or more limiting.", "/rr:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ss {namespace urn:ss;prefix ss;leaf l {type binary {pattern '[0-9]*';}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid type restrictions for binary type. /ss:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ss {namespace urn:ss;prefix ss;leaf l {type binary {pattern '[0-9]*';}}}", LYS_IN_YANG, NULL));
+    CHECK_LOG_CTX("Invalid type restrictions for binary type.", "/ss:l");
 }
 
 static void
 test_type_pattern(void **state)
 {
-    *state = test_type_pattern;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;leaf l {type string {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1; namespace urn:a;prefix a;leaf l {type string {"
             "pattern .* {error-app-tag errortag;error-message error;}"
             "pattern [0-9].*[0-9] {modifier invert-match;}}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1156,7 +1020,7 @@
     assert_string_equal("[0-9].*[0-9]", ((struct lysc_type_str *)type)->patterns[1]->expr);
     assert_int_equal(1, ((struct lysc_type_str *)type)->patterns[1]->inverted);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;typedef mytype {type string {pattern '[0-9]*';}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;typedef mytype {type string {pattern '[0-9]*';}}"
             "typedef mytype2 {type mytype {length 10;}} leaf l {type mytype2 {pattern '[0-4]*';}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1169,7 +1033,7 @@
     assert_string_equal("[0-4]*", ((struct lysc_type_str *)type)->patterns[1]->expr);
     assert_int_equal(1, ((struct lysc_type_str *)type)->patterns[1]->refcount);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;typedef mytype {type string {pattern '[0-9]*';}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;typedef mytype {type string {pattern '[0-9]*';}}"
             "leaf l {type mytype {length 10;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1181,7 +1045,7 @@
     assert_int_equal(2, ((struct lysc_type_str *)type)->patterns[0]->refcount);
 
     /* test substitutions */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;leaf l {type string {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d;leaf l {type string {"
             "pattern '^\\p{IsLatinExtended-A}$';}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1189,23 +1053,15 @@
     assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_str *)type)->patterns));
     assert_string_equal("^\\p{IsLatinExtended-A}$", ((struct lysc_type_str *)type)->patterns[0]->expr);
     /* TODO check some data "^ř$" */
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static void
 test_type_enum(void **state)
 {
-    *state = test_type_enum;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type enumeration {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type enumeration {"
             "enum automin; enum min {value -2147483648;}enum one {if-feature f; value 1;}"
             "enum two; enum seven {value 7;}enum eight;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1224,139 +1080,132 @@
     assert_string_equal("eight", ((struct lysc_type_enum *)type)->enums[4].name);
     assert_int_equal(8, ((struct lysc_type_enum *)type)->enums[4].value);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1; namespace urn:b;prefix b;feature f; typedef mytype {type enumeration {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1; namespace urn:b;prefix b;feature f; typedef mytype {type enumeration {"
             "enum 11; enum min {value -2147483648;}enum x$&;"
             "enum two; enum seven {value 7;}enum eight;}} leaf l { type mytype {enum seven;enum eight;}}}",
             LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_ENUM, type->basetype);
-    assert_non_null(((struct lysc_type_enum*)type)->enums);
-    assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_enum*)type)->enums));
-    assert_string_equal("seven", ((struct lysc_type_enum*)type)->enums[0].name);
-    assert_int_equal(7, ((struct lysc_type_enum*)type)->enums[0].value);
-    assert_string_equal("eight", ((struct lysc_type_enum*)type)->enums[1].name);
-    assert_int_equal(8, ((struct lysc_type_enum*)type)->enums[1].value);
+    assert_non_null(((struct lysc_type_enum *)type)->enums);
+    assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_enum *)type)->enums));
+    assert_string_equal("seven", ((struct lysc_type_enum *)type)->enums[0].name);
+    assert_int_equal(7, ((struct lysc_type_enum *)type)->enums[0].value);
+    assert_string_equal("eight", ((struct lysc_type_enum *)type)->enums[1].name);
+    assert_int_equal(8, ((struct lysc_type_enum *)type)->enums[1].value);
 
     const char *new_module = "module moc_c {yang-version 1.1; namespace urn:moc_c;prefix moc_c;feature f; typedef mytype {type enumeration {"
-                                        "enum first{value -270;} enum second; enum third {value -400;} enum fourth;}} leaf l { type mytype;}}";
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, new_module, LYS_IN_YANG, &mod));
+            "enum first{value -270;} enum second; enum third {value -400;} enum fourth;}} leaf l { type mytype;}}";
 
-    type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, new_module, LYS_IN_YANG, &mod));
+
+    type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_ENUM, type->basetype);
-    assert_non_null(((struct lysc_type_enum*)type)->enums);
-    assert_int_equal(4, LY_ARRAY_COUNT(((struct lysc_type_enum*)type)->enums));
-    assert_string_equal("first", ((struct lysc_type_enum*)type)->enums[0].name);
-    assert_int_equal(-270, ((struct lysc_type_enum*)type)->enums[0].value);
-    assert_string_equal("second", ((struct lysc_type_enum*)type)->enums[1].name);
-    assert_int_equal(-269, ((struct lysc_type_enum*)type)->enums[1].value);
-    assert_string_equal("third", ((struct lysc_type_enum*)type)->enums[2].name);
-    assert_int_equal(-400, ((struct lysc_type_enum*)type)->enums[2].value);
-    assert_string_equal("fourth", ((struct lysc_type_enum*)type)->enums[3].name);
-    assert_int_equal(-268, ((struct lysc_type_enum*)type)->enums[3].value);
+    assert_non_null(((struct lysc_type_enum *)type)->enums);
+    assert_int_equal(4, LY_ARRAY_COUNT(((struct lysc_type_enum *)type)->enums));
+    assert_string_equal("first", ((struct lysc_type_enum *)type)->enums[0].name);
+    assert_int_equal(-270, ((struct lysc_type_enum *)type)->enums[0].value);
+    assert_string_equal("second", ((struct lysc_type_enum *)type)->enums[1].name);
+    assert_int_equal(-269, ((struct lysc_type_enum *)type)->enums[1].value);
+    assert_string_equal("third", ((struct lysc_type_enum *)type)->enums[2].name);
+    assert_int_equal(-400, ((struct lysc_type_enum *)type)->enums[2].value);
+    assert_string_equal("fourth", ((struct lysc_type_enum *)type)->enums[3].name);
+    assert_int_equal(-268, ((struct lysc_type_enum *)type)->enums[3].value);
 
     new_module = "module moc_d {yang-version 1.1; namespace urn:moc_d;prefix moc_d;feature f; typedef mytype {type enumeration {"
-                 "enum first; enum second;}} leaf l { type mytype;}}";
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, new_module, LYS_IN_YANG, &mod));
+            "enum first; enum second;}} leaf l { type mytype;}}";
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, new_module, LYS_IN_YANG, &mod));
 
-    type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
+    type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_ENUM, type->basetype);
-    assert_non_null(((struct lysc_type_enum*)type)->enums);
-    assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_enum*)type)->enums));
-    assert_string_equal("first", ((struct lysc_type_enum*)type)->enums[0].name);
-    assert_int_equal(0, ((struct lysc_type_enum*)type)->enums[0].value);
-    assert_string_equal("second", ((struct lysc_type_enum*)type)->enums[1].name);
-    assert_int_equal(1, ((struct lysc_type_enum*)type)->enums[1].value);
+    assert_non_null(((struct lysc_type_enum *)type)->enums);
+    assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_enum *)type)->enums));
+    assert_string_equal("first", ((struct lysc_type_enum *)type)->enums[0].name);
+    assert_int_equal(0, ((struct lysc_type_enum *)type)->enums[0].value);
+    assert_string_equal("second", ((struct lysc_type_enum *)type)->enums[1].name);
+    assert_int_equal(1, ((struct lysc_type_enum *)type)->enums[1].value);
 
     /* invalid cases */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type enumeration {"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type enumeration {"
             "enum one {if-feature f;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid keyword \"if-feature\" as a child of \"enum\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+    CHECK_LOG_CTX("Invalid keyword \"if-feature\" as a child of \"enum\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
             "enum one {value -2147483649;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid value \"-2147483649\" of \"value\". Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+    CHECK_LOG_CTX("Invalid value \"-2147483649\" of \"value\".", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
             "enum one {value 2147483648;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid value \"2147483648\" of \"value\". Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+    CHECK_LOG_CTX("Invalid value \"2147483648\" of \"value\".", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
             "enum one; enum one;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Duplicate identifier \"one\" of enum statement. Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+    CHECK_LOG_CTX("Duplicate identifier \"one\" of enum statement.", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
             "enum '';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Enum name must not be zero-length. Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+    CHECK_LOG_CTX("Enum name must not be zero-length.", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
             "enum ' x';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Enum name must not have any leading or trailing whitespaces (\" x\"). Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+    CHECK_LOG_CTX("Enum name must not have any leading or trailing whitespaces (\" x\").", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
             "enum 'x ';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Enum name must not have any leading or trailing whitespaces (\"x \"). Line number 1.");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
+    CHECK_LOG_CTX("Enum name must not have any leading or trailing whitespaces (\"x \").", "Line number 1.");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
             "enum 'inva\nlid';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Control characters in enum name should be avoided (\"inva\nlid\", character number 5).");
+    CHECK_LOG_CTX("Control characters in enum name should be avoided (\"inva\nlid\", character number 5).", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type enumeration;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing enum substatement for enumeration type. /bb:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb; leaf l {type enumeration;}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Missing enum substatement for enumeration type.", "/bb:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type enumeration {enum one;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type enumeration {enum one;}}"
             "leaf l {type mytype {enum two;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid enumeration - derived type adds new item \"two\". /cc:l");
+    CHECK_LOG_CTX("Invalid enumeration - derived type adds new item \"two\".", "/cc:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type enumeration {enum one;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type enumeration {enum one;}}"
             "leaf l {type mytype {enum one {value 1;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid enumeration - value of the item \"one\" has changed from 0 to 1 in the derived type. /dd:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type enumeration {enum x {value 2147483647;}enum y;}}}",
+    CHECK_LOG_CTX("Invalid enumeration - value of the item \"one\" has changed from 0 to 1 in the derived type.", "/dd:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;leaf l {type enumeration {enum x {value 2147483647;}enum y;}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid enumeration - it is not possible to auto-assign enum value for \"y\" since the highest value is already 2147483647. /ee:l");
+    CHECK_LOG_CTX("Invalid enumeration - it is not possible to auto-assign enum value for \"y\" since the highest value is already 2147483647.", "/ee:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type enumeration {enum x {value 1;}enum y {value 1;}}}}",
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;leaf l {type enumeration {enum x {value 1;}enum y {value 1;}}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid enumeration - value 1 collide in items \"y\" and \"x\". /ff:l");
+    CHECK_LOG_CTX("Invalid enumeration - value 1 collide in items \"y\" and \"x\".", "/ff:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;typedef mytype {type enumeration;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;typedef mytype {type enumeration;}"
             "leaf l {type mytype {enum one;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing enum substatement for enumeration type mytype. /gg:l");
+    CHECK_LOG_CTX("Missing enum substatement for enumeration type mytype.", "/gg:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh; typedef mytype {type enumeration {enum one;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh; typedef mytype {type enumeration {enum one;}}"
             "leaf l {type mytype {enum one;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Enumeration type can be subtyped only in YANG 1.1 modules. /hh:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Enumeration type can be subtyped only in YANG 1.1 modules.", "/hh:l");
 }
 
 static void
 test_type_bits(void **state)
 {
-    *state = test_type_bits;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type bits {"
-                                        "bit automin; bit one {if-feature f; position 1;}"
-                                        "bit two; bit seven {position 7;} bit five {position 5;} bit eight;}}}", LYS_IN_YANG, &mod));
-    type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type bits {"
+            "bit automin; bit one {if-feature f; position 1;}"
+            "bit two; bit seven {position 7;} bit five {position 5;} bit eight;}}}", LYS_IN_YANG, &mod));
+    type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_BITS, type->basetype);
-    assert_non_null(((struct lysc_type_bits*)type)->bits);
-    assert_int_equal(5, LY_ARRAY_COUNT(((struct lysc_type_bits*)type)->bits));
-    assert_string_equal("automin", ((struct lysc_type_bits*)type)->bits[0].name);
-    assert_int_equal(0, ((struct lysc_type_bits*)type)->bits[0].position);
-    assert_string_equal("two", ((struct lysc_type_bits*)type)->bits[1].name);
-    assert_int_equal(2, ((struct lysc_type_bits*)type)->bits[1].position);
-    assert_string_equal("seven", ((struct lysc_type_bits*)type)->bits[2].name);
-    assert_int_equal(7, ((struct lysc_type_bits*)type)->bits[2].position);
-    assert_string_equal("five", ((struct lysc_type_bits*)type)->bits[3].name);
-    assert_int_equal(5, ((struct lysc_type_bits*)type)->bits[3].position);
-    assert_string_equal("eight", ((struct lysc_type_bits*)type)->bits[4].name);
-    assert_int_equal(8, ((struct lysc_type_bits*)type)->bits[4].position);
+    assert_non_null(((struct lysc_type_bits *)type)->bits);
+    assert_int_equal(5, LY_ARRAY_COUNT(((struct lysc_type_bits *)type)->bits));
+    assert_string_equal("automin", ((struct lysc_type_bits *)type)->bits[0].name);
+    assert_int_equal(0, ((struct lysc_type_bits *)type)->bits[0].position);
+    assert_string_equal("two", ((struct lysc_type_bits *)type)->bits[1].name);
+    assert_int_equal(2, ((struct lysc_type_bits *)type)->bits[1].position);
+    assert_string_equal("seven", ((struct lysc_type_bits *)type)->bits[2].name);
+    assert_int_equal(7, ((struct lysc_type_bits *)type)->bits[2].position);
+    assert_string_equal("five", ((struct lysc_type_bits *)type)->bits[3].name);
+    assert_int_equal(5, ((struct lysc_type_bits *)type)->bits[3].position);
+    assert_string_equal("eight", ((struct lysc_type_bits *)type)->bits[4].name);
+    assert_int_equal(8, ((struct lysc_type_bits *)type)->bits[4].position);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;feature f; typedef mytype {type bits {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1;namespace urn:b;prefix b;feature f; typedef mytype {type bits {"
             "bit automin; bit one;bit two; bit seven {position 7;}bit eight;}} leaf l { type mytype {bit eight;bit seven;bit automin;}}}",
             LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1372,65 +1221,57 @@
     assert_int_equal(8, ((struct lysc_type_bits *)type)->bits[2].position);
 
     /* invalid cases */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type bits {"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type bits {"
             "bit one {if-feature f;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid keyword \"if-feature\" as a child of \"bit\" - the statement is allowed only in YANG 1.1 modules. Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+    CHECK_LOG_CTX("Invalid keyword \"if-feature\" as a child of \"bit\" - the statement is allowed only in YANG 1.1 modules.", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
             "bit one {position -1;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid value \"-1\" of \"position\". Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+    CHECK_LOG_CTX("Invalid value \"-1\" of \"position\".", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
             "bit one {position 4294967296;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid value \"4294967296\" of \"position\". Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+    CHECK_LOG_CTX("Invalid value \"4294967296\" of \"position\".", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
             "bit one; bit one;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Duplicate identifier \"one\" of bit statement. Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+    CHECK_LOG_CTX("Duplicate identifier \"one\" of bit statement.", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
             "bit '11';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid identifier first character '1' (0x0031). Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
+    CHECK_LOG_CTX("Invalid identifier first character '1' (0x0031).", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
             "bit 'x1$1';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid identifier character '$' (0x0024). Line number 1.");
+    CHECK_LOG_CTX("Invalid identifier character '$' (0x0024).", "Line number 1.");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type bits;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing bit substatement for bits type. /bb:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb; leaf l {type bits;}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Missing bit substatement for bits type.", "/bb:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type bits {bit one;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type bits {bit one;}}"
             "leaf l {type mytype {bit two;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid bits - derived type adds new item \"two\". /cc:l");
+    CHECK_LOG_CTX("Invalid bits - derived type adds new item \"two\".", "/cc:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type bits {bit one;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type bits {bit one;}}"
             "leaf l {type mytype {bit one {position 1;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid bits - position of the item \"one\" has changed from 0 to 1 in the derived type. /dd:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;leaf l {type bits {bit x {position 4294967295;}bit y;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid bits - it is not possible to auto-assign bit position for \"y\" since the highest value is already 4294967295. /ee:l");
+    CHECK_LOG_CTX("Invalid bits - position of the item \"one\" has changed from 0 to 1 in the derived type.", "/dd:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;leaf l {type bits {bit x {position 4294967295;}bit y;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid bits - it is not possible to auto-assign bit position for \"y\" since the highest value is already 4294967295.", "/ee:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;leaf l {type bits {bit x {position 1;}bit y {position 1;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid bits - position 1 collide in items \"y\" and \"x\". /ff:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;leaf l {type bits {bit x {position 1;}bit y {position 1;}}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid bits - position 1 collide in items \"y\" and \"x\".", "/ff:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;typedef mytype {type bits;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;typedef mytype {type bits;}"
             "leaf l {type mytype {bit one;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing bit substatement for bits type mytype. /gg:l");
+    CHECK_LOG_CTX("Missing bit substatement for bits type mytype.", "/gg:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh; typedef mytype {type bits {bit one;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh; typedef mytype {type bits {bit one;}}"
             "leaf l {type mytype {bit one;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Bits type can be subtyped only in YANG 1.1 modules. /hh:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Bits type can be subtyped only in YANG 1.1 modules.", "/hh:l");
 }
 
 static void
 test_type_dec64(void **state)
 {
-    *state = test_type_dec64;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;leaf l {type decimal64 {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;leaf l {type decimal64 {"
             "fraction-digits 2;range min..max;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1442,7 +1283,7 @@
     assert_int_equal(INT64_C(-9223372036854775807) - INT64_C(1), ((struct lysc_type_dec *)type)->range->parts[0].min_64);
     assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_dec *)type)->range->parts[0].max_64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;typedef mytype {type decimal64 {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;typedef mytype {type decimal64 {"
             "fraction-digits 2;range '3.14 | 5.1 | 10';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1458,7 +1299,7 @@
     assert_int_equal(1000, ((struct lysc_type_dec *)type)->range->parts[2].min_64);
     assert_int_equal(1000, ((struct lysc_type_dec *)type)->range->parts[2].max_64);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
             "fraction-digits 2;range '1 .. 65535';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_int_equal(LY_TYPE_DEC64, type->basetype);
@@ -1470,58 +1311,50 @@
     assert_int_equal(6553500, ((struct lysc_type_dec *)type)->range->parts[0].max_64);
 
     /* invalid cases */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 0;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid value \"0\" of \"fraction-digits\". Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits -1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid value \"-1\" of \"fraction-digits\". Line number 1.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 19;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Value \"19\" is out of \"fraction-digits\" bounds. Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 0;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid value \"0\" of \"fraction-digits\".", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits -1;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid value \"-1\" of \"fraction-digits\".", "Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 19;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Value \"19\" is out of \"fraction-digits\" bounds.", "Line number 1.");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing fraction-digits substatement for decimal64 type. /aa:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64;}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Missing fraction-digits substatement for decimal64 type.", "/aa:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ab {namespace urn:ab;prefix ab; typedef mytype {type decimal64;}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing fraction-digits substatement for decimal64 type mytype. /ab:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ab {namespace urn:ab;prefix ab; typedef mytype {type decimal64;}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Missing fraction-digits substatement for decimal64 type mytype.", "/ab:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type decimal64 {fraction-digits 2;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb; leaf l {type decimal64 {fraction-digits 2;"
             "range '3.142';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Range boundary \"3.142\" of decimal64 type exceeds defined number (2) of fraction digits. /bb:l");
+    CHECK_LOG_CTX("Range boundary \"3.142\" of decimal64 type exceeds defined number (2) of fraction digits.", "/bb:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; leaf l {type decimal64 {fraction-digits 2;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc; leaf l {type decimal64 {fraction-digits 2;"
             "range '4 | 3.14';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid range restriction - values are not in ascending order (3.14). /cc:l");
+    CHECK_LOG_CTX("Invalid range restriction - values are not in ascending order (3.14).", "/cc:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; typedef mytype {type decimal64 {fraction-digits 2;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd; typedef mytype {type decimal64 {fraction-digits 2;}}"
             "leaf l {type mytype {fraction-digits 3;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid fraction-digits substatement for type not directly derived from decimal64 built-in type. /dd:l");
+    CHECK_LOG_CTX("Invalid fraction-digits substatement for type not directly derived from decimal64 built-in type.", "/dd:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module de {namespace urn:de;prefix de; typedef mytype {type decimal64 {fraction-digits 2;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module de {namespace urn:de;prefix de; typedef mytype {type decimal64 {fraction-digits 2;}}"
             "typedef mytype2 {type mytype {fraction-digits 3;}}leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid fraction-digits substatement for type \"mytype2\" not directly derived from decimal64 built-in type. /de:l");
+    CHECK_LOG_CTX("Invalid fraction-digits substatement for type \"mytype2\" not directly derived from decimal64 built-in type.", "/de:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
             "fraction-digits 18;range '-10 .. 0';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid range restriction - invalid value \"-10000000000000000000\". /ee:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
+    CHECK_LOG_CTX("Invalid range restriction - invalid value \"-10000000000000000000\".", "/ee:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
             "fraction-digits 18;range '0 .. 10';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid range restriction - invalid value \"10000000000000000000\". /ee:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Invalid range restriction - invalid value \"10000000000000000000\".", "/ee:l");
 }
 
 static void
 test_type_instanceid(void **state)
 {
-    *state = test_type_instanceid;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;typedef mytype {type instance-identifier {require-instance false;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;typedef mytype {type instance-identifier {require-instance false;}}"
             "leaf l1 {type instance-identifier {require-instance true;}}"
             "leaf l2 {type mytype;} leaf l3 {type instance-identifier;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1540,28 +1373,20 @@
     assert_int_equal(1, ((struct lysc_type_instanceid *)type)->require_instance);
 
     /* invalid cases */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {require-instance yes;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid value \"yes\" of \"require-instance\". Line number 1.");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {require-instance yes;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid value \"yes\" of \"require-instance\".", "Line number 1.");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {fraction-digits 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid type restrictions for instance-identifier type. /aa:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {fraction-digits 1;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid type restrictions for instance-identifier type.", "/aa:l");
 }
 
 static void
 test_type_identityref(void **state)
 {
-    *state = test_type_identityref;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;identity i; identity j; identity k {base i;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1;namespace urn:a;prefix a;identity i; identity j; identity k {base i;}"
             "typedef mytype {type identityref {base i;}}"
             "leaf l1 {type mytype;} leaf l2 {type identityref {base a:k; base j;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1579,7 +1404,7 @@
     assert_string_equal("k", ((struct lysc_type_identityref *)type)->bases[0]->name);
     assert_string_equal("j", ((struct lysc_type_identityref *)type)->bases[1]->name);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;import a {prefix a;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1;namespace urn:b;prefix b;import a {prefix a;}"
             "leaf l {type identityref {base a:k; base a:j;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1590,89 +1415,81 @@
     assert_string_equal("j", ((struct lysc_type_identityref *)type)->bases[1]->name);
 
     /* invalid cases */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type identityref;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing base substatement for identityref type. /aa:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type identityref;}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Missing base substatement for identityref type.", "/aa:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; typedef mytype {type identityref;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb; typedef mytype {type identityref;}"
             "leaf l {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing base substatement for identityref type mytype. /bb:l");
+    CHECK_LOG_CTX("Missing base substatement for identityref type mytype.", "/bb:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; identity i; typedef mytype {type identityref {base i;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc; identity i; typedef mytype {type identityref {base i;}}"
             "leaf l {type mytype {base i;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid base substatement for the type not directly derived from identityref built-in type. /cc:l");
+    CHECK_LOG_CTX("Invalid base substatement for the type not directly derived from identityref built-in type.", "/cc:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; identity i; typedef mytype {type identityref {base i;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd; identity i; typedef mytype {type identityref {base i;}}"
             "typedef mytype2 {type mytype {base i;}}leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid base substatement for the type \"mytype2\" not directly derived from identityref built-in type. /dd:l");
+    CHECK_LOG_CTX("Invalid base substatement for the type \"mytype2\" not directly derived from identityref built-in type.", "/dd:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee; identity i; identity j;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee; identity i; identity j;"
             "leaf l {type identityref {base i;base j;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Multiple bases in identityref type are allowed only in YANG 1.1 modules. /ee:l");
+    CHECK_LOG_CTX("Multiple bases in identityref type are allowed only in YANG 1.1 modules.", "/ee:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff; identity i;leaf l {type identityref {base j;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Unable to find base (j) of identityref. /ff:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff; identity i;leaf l {type identityref {base j;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Unable to find base (j) of identityref.", "/ff:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;leaf l {type identityref {base x:j;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid prefix used for base (x:j) of identityref. /gg:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;leaf l {type identityref {base x:j;}}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid prefix used for base (x:j) of identityref.", "/gg:l");
 }
 
 static void
 test_type_leafref(void **state)
 {
-    *state = test_type_leafref;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
     const char *path;
     struct lyxp_expr *expr;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
     /* lys_path_parse() */
     path = "invalid_path";
-    assert_int_equal(LY_EVALID, ly_path_parse(ctx, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+    assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
     path = "..";
-    assert_int_equal(LY_EVALID, ly_path_parse(ctx, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+    assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
     path = "..[";
-    assert_int_equal(LY_EVALID, ly_path_parse(ctx, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+    assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
     path = "../";
-    assert_int_equal(LY_EVALID, ly_path_parse(ctx, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+    assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
     path = "/";
-    assert_int_equal(LY_EVALID, ly_path_parse(ctx, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+    assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
 
     path = "../../pref:id/xxx[predicate]/invalid!!!";
-    assert_int_equal(LY_EVALID, ly_path_parse(ctx, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+    assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
-    logbuf_assert("Invalid character 0x21 ('!'), perhaps \"invalid\" is supposed to be a function call.");
+    CHECK_LOG_CTX("Invalid character 0x21 ('!'), perhaps \"invalid\" is supposed to be a function call.", NULL);
 
     path = "/absolute/prefix:path";
-    assert_int_equal(LY_SUCCESS, ly_path_parse(ctx, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
+    assert_int_equal(LY_SUCCESS, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
             LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
     assert_int_equal(4, expr->used);
     assert_int_equal(LYXP_TOKEN_OPER_PATH, expr->tokens[0]);
     assert_int_equal(LYXP_TOKEN_NAMETEST, expr->tokens[1]);
     assert_int_equal(LYXP_TOKEN_OPER_PATH, expr->tokens[2]);
     assert_int_equal(LYXP_TOKEN_NAMETEST, expr->tokens[3]);
-    lyxp_expr_free(ctx, expr);
+    lyxp_expr_free(UTEST_LYCTX, expr);
 
     /* complete leafref paths */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1;namespace urn:a;prefix a;"
             "leaf ref1 {type leafref {path /a:target1;}} leaf ref2 {type leafref {path /a/target2; require-instance false;}}"
             "leaf target1 {type string;}container a {leaf target2 {type uint8;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
     assert_string_equal("/a:target1", ((struct lysc_type_leafref *)type)->path->expr);
-    assert_ptr_equal(mod, ly_resolve_prefix(ctx, "a", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
+    assert_ptr_equal(mod, ly_resolve_prefix(UTEST_LYCTX, "a", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
     assert_non_null(((struct lysc_type_leafref *)type)->realtype);
     assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
     assert_int_equal(1, ((struct lysc_type_leafref *)type)->require_instance);
@@ -1685,7 +1502,7 @@
     assert_int_equal(LY_TYPE_UINT8, ((struct lysc_type_leafref *)type)->realtype->basetype);
     assert_int_equal(0, ((struct lysc_type_leafref *)type)->require_instance);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; typedef mytype {type leafref {path /b:target;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b; typedef mytype {type leafref {path /b:target;}}"
             "typedef mytype2 {type mytype;} typedef mytype3 {type leafref {path /target;}} leaf ref {type mytype2;}"
             "leaf target {type leafref {path ../realtarget;}} leaf realtarget {type string;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1693,13 +1510,13 @@
     assert_int_equal(1, type->refcount);
     assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
     assert_string_equal("/b:target", ((struct lysc_type_leafref *)type)->path->expr);
-    assert_ptr_equal(mod, ly_resolve_prefix(ctx, "b", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
+    assert_ptr_equal(mod, ly_resolve_prefix(UTEST_LYCTX, "b", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
     assert_non_null(((struct lysc_type_leafref *)type)->realtype);
     assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
     assert_int_equal(1, ((struct lysc_type_leafref *)type)->require_instance);
 
     /* prefixes are reversed to check using correct context of the path! */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix b; import b {prefix c;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1;namespace urn:c;prefix b; import b {prefix c;}"
             "typedef mytype3 {type c:mytype {require-instance false;}}"
             "leaf ref1 {type b:mytype3;}leaf ref2 {type c:mytype2;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1707,7 +1524,7 @@
     assert_int_equal(1, type->refcount);
     assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
     assert_string_equal("/b:target", ((struct lysc_type_leafref *)type)->path->expr);
-    assert_ptr_not_equal(mod, ly_resolve_prefix(ctx, "b", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
+    assert_ptr_not_equal(mod, ly_resolve_prefix(UTEST_LYCTX, "b", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
     assert_non_null(((struct lysc_type_leafref *)type)->realtype);
     assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
     assert_int_equal(0, ((struct lysc_type_leafref *)type)->require_instance);
@@ -1716,11 +1533,11 @@
     assert_int_equal(1, type->refcount);
     assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
     assert_string_equal("/b:target", ((struct lysc_type_leafref *)type)->path->expr);
-    assert_ptr_not_equal(mod, ly_resolve_prefix(ctx, "b", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
+    assert_ptr_not_equal(mod, ly_resolve_prefix(UTEST_LYCTX, "b", 1, LY_PREF_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
     assert_int_equal(1, ((struct lysc_type_leafref *)type)->require_instance);
 
     /* non-prefixed nodes in path are supposed to be from the module where the leafref type is instantiated */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; import b {prefix b;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; import b {prefix b;}"
             "leaf ref {type b:mytype3;}leaf target {type int8;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -1733,7 +1550,7 @@
     assert_int_equal(1, ((struct lysc_type_leafref *)type)->require_instance);
 
     /* conditional leafrefs */
-    /*assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e;feature f1; feature f2;"
+    /*assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {yang-version 1.1;namespace urn:e;prefix e;feature f1; feature f2;"
                                         "leaf ref1 {if-feature 'f1 and f2';type leafref {path /target;}}"
                                         "leaf target {if-feature f1; type boolean;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf*)mod->compiled->data)->type;
@@ -1745,7 +1562,7 @@
     assert_non_null(((struct lysc_type_leafref*)type)->realtype);
     assert_int_equal(LY_TYPE_BOOL, ((struct lysc_type_leafref*)type)->realtype->basetype);*/
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;"
             "list interface{key name;leaf name{type string;}list address {key ip;leaf ip {type string;}}}"
             "container default-address{leaf ifname{type leafref{ path \"../../interface/name\";}}"
             "leaf address {type leafref{ path \"../../interface[  name = current()/../ifname ]/address/ip\";}}}}",
@@ -1760,7 +1577,7 @@
     assert_non_null(((struct lysc_type_leafref *)type)->realtype);
     assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g;"
             "leaf source {type leafref {path \"/endpoint-parent[id=current()/../field]/endpoint/name\";}}"
             "leaf field {type int32;}list endpoint-parent {key id;leaf id {type int32;}"
             "list endpoint {key name;leaf name {type string;}}}}", LYS_IN_YANG, &mod));
@@ -1774,21 +1591,21 @@
     assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
 
     /* leafref to imported (not yet implemented) module */
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module h {namespace urn:h;prefix h; leaf h  {type uint16;}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;import h {prefix h;}"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module h {namespace urn:h;prefix h; leaf h  {type uint16;}}");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i;import h {prefix h;}"
             "leaf i {type leafref {path /h:h;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
     assert_non_null(((struct lysc_type_leafref *)type)->realtype);
     assert_int_equal(LY_TYPE_UINT16, ((struct lysc_type_leafref *)type)->realtype->basetype);
-    assert_non_null(mod = ly_ctx_get_module_implemented(ctx, "h"));
+    assert_non_null(mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "h"));
     assert_int_equal(1, mod->implemented);
     assert_non_null(mod->compiled->data);
     assert_string_equal("h", mod->compiled->data->name);
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module j {namespace urn:j;prefix j; leaf j  {type string;}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module k {namespace urn:k;prefix k;import j {prefix j;}"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module j {namespace urn:j;prefix j; leaf j  {type string;}}");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module k {namespace urn:k;prefix k;import j {prefix j;}"
             "leaf i {type leafref {path \"/ilist[name = current()/../j:j]/value\";}}"
             "list ilist {key name; leaf name {type string;} leaf value {type uint16;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1796,13 +1613,13 @@
     assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
     assert_non_null(((struct lysc_type_leafref *)type)->realtype);
     assert_int_equal(LY_TYPE_UINT16, ((struct lysc_type_leafref *)type)->realtype->basetype);
-    assert_non_null(mod = ly_ctx_get_module_implemented(ctx, "j"));
+    assert_non_null(mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "j"));
     assert_int_equal(1, mod->implemented);
     assert_non_null(mod->compiled->data);
     assert_string_equal("j", mod->compiled->data->name);
 
     /* leafref with a default value */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module l {namespace urn:l;prefix l;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module l {namespace urn:l;prefix l;"
             "leaf source {type leafref {path \"../target\";}default true;}"
             "leaf target {type boolean;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -1817,208 +1634,192 @@
     assert_int_equal(1, ((struct lysc_node_leaf *)mod->compiled->data)->dflt->boolean);
 
     /* invalid paths */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;container a {leaf target2 {type uint8;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;container a {leaf target2 {type uint8;}}"
             "leaf ref1 {type leafref {path ../a/invalid;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Not found node \"invalid\" in path. /aa:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;container a {leaf target2 {type uint8;}}"
+    CHECK_LOG_CTX("Not found node \"invalid\" in path.", "/aa:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;container a {leaf target2 {type uint8;}}"
             "leaf ref1 {type leafref {path ../../toohigh;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Too many parent references in path. /bb:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;container a {leaf target2 {type uint8;}}"
+    CHECK_LOG_CTX("Too many parent references in path.", "/bb:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;container a {leaf target2 {type uint8;}}"
             "leaf ref1 {type leafref {path /a:invalid;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("No module connected with the prefix \"a\" found (prefix format schema stored mapping). /cc:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;leaf target1 {type string;}"
+    CHECK_LOG_CTX("No module connected with the prefix \"a\" found (prefix format schema stored mapping).", "/cc:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;leaf target1 {type string;}"
             "container a {leaf target2 {type uint8;}} leaf ref1 {type leafref {"
             "path '/a[target2 = current()/../target1]/target2';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("List predicate defined for container \"a\" in path. /dd:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;container a {leaf target2 {type uint8;}}"
+    CHECK_LOG_CTX("List predicate defined for container \"a\" in path.", "/dd:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;container a {leaf target2 {type uint8;}}"
             "leaf ref1 {type leafref {path /a!invalid;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid character 0x21 ('!'), perhaps \"a\" is supposed to be a function call.");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;container a {leaf target2 {type uint8;}}"
+    CHECK_LOG_CTX("Invalid character 0x21 ('!'), perhaps \"a\" is supposed to be a function call.", NULL);
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;container a {leaf target2 {type uint8;}}"
             "leaf ref1 {type leafref {path /a;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid leafref path \"/a\" - target node is container instead of leaf or leaf-list. /ff:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;container a {leaf target2 {type uint8;"
+    CHECK_LOG_CTX("Invalid leafref path \"/a\" - target node is container instead of leaf or leaf-list.", "/ff:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;container a {leaf target2 {type uint8;"
             "status deprecated;}} leaf ref1 {type leafref {path /a/target2;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("A current definition \"ref1\" is not allowed to reference deprecated definition \"target2\". /gg:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;"
+    CHECK_LOG_CTX("A current definition \"ref1\" is not allowed to reference deprecated definition \"target2\".", "/gg:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh;"
             "leaf ref1 {type leafref;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing path substatement for leafref type. /hh:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;typedef mytype {type leafref;}"
+    CHECK_LOG_CTX("Missing path substatement for leafref type.", "/hh:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii {namespace urn:ii;prefix ii;typedef mytype {type leafref;}"
             "leaf ref1 {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing path substatement for leafref type mytype. /ii:ref1");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;feature f;"
+    CHECK_LOG_CTX("Missing path substatement for leafref type mytype.", "/ii:ref1");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj {namespace urn:jj;prefix jj;feature f;"
             "leaf ref {type leafref {path /target;}}leaf target {if-feature f;type string;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Not found node \"target\" in path. /jj:ref");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;"
+    CHECK_LOG_CTX("Not found node \"target\" in path.", "/jj:ref");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk {namespace urn:kk;prefix kk;"
             "leaf ref {type leafref {path /target;}}leaf target {type string;config false;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid leafref path \"/target\" - target is supposed to represent configuration data (as the leafref does), but it does not. /kk:ref");
+    CHECK_LOG_CTX("Invalid leafref path \"/target\" - target is supposed to represent configuration data (as the leafref does), but it does not.", "/kk:ref");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll {namespace urn:ll;prefix ll;"
             "leaf ref {type leafref {path /target; require-instance true;}}leaf target {type string;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Leafref type can be restricted by require-instance statement only in YANG 1.1 modules. /ll:ref");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;typedef mytype {type leafref {path /target;require-instance false;}}"
+    CHECK_LOG_CTX("Leafref type can be restricted by require-instance statement only in YANG 1.1 modules.", "/ll:ref");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm {namespace urn:mm;prefix mm;typedef mytype {type leafref {path /target;require-instance false;}}"
             "leaf ref {type mytype;}leaf target {type string;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Leafref type \"mytype\" can be restricted by require-instance statement only in YANG 1.1 modules. /mm:ref");
+    CHECK_LOG_CTX("Leafref type \"mytype\" can be restricted by require-instance statement only in YANG 1.1 modules.", "/mm:ref");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module nn {namespace urn:nn;prefix nn;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module nn {namespace urn:nn;prefix nn;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}"
             "leaf address {type leafref{ path \"/interface[name is current()/../ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid character 0x69 ('i'), perhaps \"name\" is supposed to be a function call.");
+    CHECK_LOG_CTX("Invalid character 0x69 ('i'), perhaps \"name\" is supposed to be a function call.", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo {namespace urn:oo;prefix oo;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo {namespace urn:oo;prefix oo;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}"
             "leaf address {type leafref{ path \"/interface[name=current()/../ifname/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Unexpected XPath expression end.");
+    CHECK_LOG_CTX("Unexpected XPath expression end.", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module pp {namespace urn:pp;prefix pp;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module pp {namespace urn:pp;prefix pp;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}"
             "leaf address {type leafref{ path \"/interface[x:name=current()/../ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("No module connected with the prefix \"x\" found (prefix format schema stored mapping). /pp:address");
+    CHECK_LOG_CTX("No module connected with the prefix \"x\" found (prefix format schema stored mapping).", "/pp:address");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module qq {namespace urn:qq;prefix qq;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module qq {namespace urn:qq;prefix qq;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}"
             "leaf address {type leafref{ path \"/interface[id=current()/../ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Not found node \"id\" in path. /qq:address");
+    CHECK_LOG_CTX("Not found node \"id\" in path.", "/qq:address");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module rr {namespace urn:rr;prefix rr;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module rr {namespace urn:rr;prefix rr;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
             "leaf address {type leafref{ path \"/interface[name=current() /  .. / ifname][name=current()/../test]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Duplicate predicate key \"name\" in path.");
+    CHECK_LOG_CTX("Duplicate predicate key \"name\" in path.", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ss {namespace urn:ss;prefix ss;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ss {namespace urn:ss;prefix ss;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
             "leaf address {type leafref{ path \"/interface[name = ../ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Unexpected XPath token \"..\" (\"../ifname]/ip\"), expected \"FunctionName\".");
+    CHECK_LOG_CTX("Unexpected XPath token \"..\" (\"../ifname]/ip\"), expected \"FunctionName\".", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module tt {namespace urn:tt;prefix tt;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module tt {namespace urn:tt;prefix tt;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
             "leaf address {type leafref{ path \"/interface[name = current()../ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Unexpected XPath token \"..\" (\"../ifname]/ip\"), expected \"]\".");
+    CHECK_LOG_CTX("Unexpected XPath token \"..\" (\"../ifname]/ip\"), expected \"]\".", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module uu {namespace urn:uu;prefix uu;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module uu {namespace urn:uu;prefix uu;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
             "leaf address {type leafref{ path \"/interface[name = current()/..ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid character number 31 of expression '/interface[name = current()/..ifname]/ip'.");
+    CHECK_LOG_CTX("Invalid character number 31 of expression '/interface[name = current()/..ifname]/ip'.", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module vv {namespace urn:vv;prefix vv;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module vv {namespace urn:vv;prefix vv;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
             "leaf address {type leafref{ path \"/interface[name = current()/ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Unexpected XPath token \"NameTest\" (\"ifname]/ip\"), expected \"..\".");
+    CHECK_LOG_CTX("Unexpected XPath token \"NameTest\" (\"ifname]/ip\"), expected \"..\".", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ww {namespace urn:ww;prefix ww;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ww {namespace urn:ww;prefix ww;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
             "leaf address {type leafref{ path \"/interface[name = current()/../]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Unexpected XPath token \"]\" (\"]/ip\").");
+    CHECK_LOG_CTX("Unexpected XPath token \"]\" (\"]/ip\").", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module xx {namespace urn:xx;prefix xx;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module xx {namespace urn:xx;prefix xx;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}"
             "leaf address {type leafref{ path \"/interface[name = current()/../$node]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid character 0x24 ('$'), perhaps \"\" is supposed to be a function call.");
+    CHECK_LOG_CTX("Invalid character 0x24 ('$'), perhaps \"\" is supposed to be a function call.", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module yy {namespace urn:yy;prefix yy;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module yy {namespace urn:yy;prefix yy;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}"
             "leaf address {type leafref{ path \"/interface[name=current()/../x:ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("No module connected with the prefix \"x\" found (prefix format schema stored mapping). /yy:address");
+    CHECK_LOG_CTX("No module connected with the prefix \"x\" found (prefix format schema stored mapping).", "/yy:address");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zz {namespace urn:zz;prefix zz;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zz {namespace urn:zz;prefix zz;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}"
             "leaf address {type leafref{ path \"/interface[name=current()/../xxx]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Not found node \"xxx\" in path. /zz:address");
+    CHECK_LOG_CTX("Not found node \"xxx\" in path.", "/zz:address");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zza {namespace urn:zza;prefix zza;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zza {namespace urn:zza;prefix zza;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}container c;"
             "leaf address {type leafref{ path \"/interface[name=current()/../c]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Leaf expected instead of container \"c\" in leafref predicate in path. /zza:address");
+    CHECK_LOG_CTX("Leaf expected instead of container \"c\" in leafref predicate in path.", "/zza:address");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zzb {namespace urn:zzb;prefix zzb;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zzb {namespace urn:zzb;prefix zzb;"
             "list interface{key name;leaf name{type string;}leaf ip {type string;}container c;}"
             "leaf ifname{type leafref{ path \"../interface/name\";}}"
             "leaf address {type leafref{ path \"/interface[c=current()/../ifname]/ip\";}}}",
             LYS_IN_YANG, &mod));
-    logbuf_assert("Key expected instead of container \"c\" in path. /zzb:address");
+    CHECK_LOG_CTX("Key expected instead of container \"c\" in path.", "/zzb:address");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zzc {namespace urn:zzc;prefix zzc;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zzc {namespace urn:zzc;prefix zzc;"
             "leaf source {type leafref {path \"../target\";}default true;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Not found node \"target\" in path. /zzc:source");
+    CHECK_LOG_CTX("Not found node \"target\" in path.", "/zzc:source");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module zzd {namespace urn:zzd;prefix zzd;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zzd {namespace urn:zzd;prefix zzd;"
             "leaf source {type leafref {path \"../target\";}default true;}"
             "leaf target {type uint8;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid default - value does not fit the type (Invalid uint8 value \"true\".). /zzd:source");
+    CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid uint8 value \"true\".).", "/zzd:source");
 
     /* circular chain */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aaa {namespace urn:aaa;prefix aaa;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aaa {namespace urn:aaa;prefix aaa;"
             "leaf ref1 {type leafref {path /ref2;}}"
             "leaf ref2 {type leafref {path /ref3;}}"
             "leaf ref3 {type leafref {path /ref4;}}"
             "leaf ref4 {type leafref {path /ref1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid leafref path \"/ref1\" - circular chain of leafrefs detected. /aaa:ref4");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Invalid leafref path \"/ref1\" - circular chain of leafrefs detected.", "/aaa:ref4");
 }
 
 static void
 test_type_empty(void **state)
 {
-    *state = test_type_empty;
-
-    struct ly_ctx *ctx;
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
             "leaf l {type empty; default x;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid default - value does not fit the type (Invalid empty value \"x\".). /aa:l");
+    CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid empty value \"x\".).", "/aa:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;typedef mytype {type empty; default x;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;typedef mytype {type empty; default x;}"
             "leaf l {type mytype;}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid type \"mytype\" - \"empty\" type must not have a default value (x). /bb:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Invalid type \"mytype\" - \"empty\" type must not have a default value (x).", "/bb:l");
 }
 
 static void
 test_type_union(void **state)
 {
-    *state = test_type_union;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {yang-version 1.1;namespace urn:a;prefix a; typedef mybasetype {type string;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1;namespace urn:a;prefix a; typedef mybasetype {type string;}"
             "typedef mytype {type union {type int8; type mybasetype;}}"
             "leaf l {type mytype;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -2030,7 +1831,7 @@
     assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_union *)type)->types[0]->basetype);
     assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union *)type)->types[1]->basetype);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b; typedef mybasetype {type string;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1;namespace urn:b;prefix b; typedef mybasetype {type string;}"
             "typedef mytype {type union {type int8; type mybasetype;}}"
             "leaf l {type union {type decimal64 {fraction-digits 2;} type mytype;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
@@ -2043,7 +1844,7 @@
     assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_union *)type)->types[1]->basetype);
     assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union *)type)->types[2]->basetype);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {yang-version 1.1;namespace urn:c;prefix c; typedef mybasetype {type string;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1;namespace urn:c;prefix c; typedef mybasetype {type string;}"
             "typedef mytype {type union {type leafref {path ../target;} type mybasetype;}}"
             "leaf l {type union {type decimal64 {fraction-digits 2;} type mytype;}}"
             "leaf target {type leafref {path ../realtarget;}} leaf realtarget {type int8;}}",
@@ -2061,47 +1862,39 @@
     assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref *)((struct lysc_type_union *)type)->types[1])->realtype->basetype);
 
     /* invalid unions */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;typedef mytype {type union;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;typedef mytype {type union;}"
             "leaf l {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing type substatement for union type mytype. /aa:l");
+    CHECK_LOG_CTX("Missing type substatement for union type mytype.", "/aa:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;leaf l {type union;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Missing type substatement for union type. /bb:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;leaf l {type union;}}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Missing type substatement for union type.", "/bb:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;typedef mytype {type union{type int8; type string;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;typedef mytype {type union{type int8; type string;}}"
             "leaf l {type mytype {type string;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid type substatement for the type not directly derived from union built-in type. /cc:l");
+    CHECK_LOG_CTX("Invalid type substatement for the type not directly derived from union built-in type.", "/cc:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;typedef mytype {type union{type int8; type string;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;typedef mytype {type union{type int8; type string;}}"
             "typedef mytype2 {type mytype {type string;}}leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid type substatement for the type \"mytype2\" not directly derived from union built-in type. /dd:l");
+    CHECK_LOG_CTX("Invalid type substatement for the type \"mytype2\" not directly derived from union built-in type.", "/dd:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;typedef mytype {type union{type mytype; type string;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;typedef mytype {type union{type mytype; type string;}}"
             "leaf l {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid \"mytype\" type reference - circular chain of types detected. /ee:l");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ef {namespace urn:ef;prefix ef;typedef mytype {type mytype2;}"
+    CHECK_LOG_CTX("Invalid \"mytype\" type reference - circular chain of types detected.", "/ee:l");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ef {namespace urn:ef;prefix ef;typedef mytype {type mytype2;}"
             "typedef mytype2 {type mytype;} leaf l {type mytype;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid \"mytype\" type reference - circular chain of types detected. /ef:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Invalid \"mytype\" type reference - circular chain of types detected.", "/ef:l");
 }
 
 static void
 test_type_dflt(void **state)
 {
-    *state = test_type_union;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_type *type;
     struct lysc_node_leaf *leaf;
     uint8_t dynamic;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
     /* default is not inherited from union's types */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a; typedef mybasetype {type string;default hello;units xxx;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a; typedef mybasetype {type string;default hello;units xxx;}"
             "leaf l {type union {type decimal64 {fraction-digits 2;} type mybasetype;}}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
@@ -2114,34 +1907,34 @@
     assert_null(((struct lysc_node_leaf *)mod->compiled->data)->dflt);
     assert_null(((struct lysc_node_leaf *)mod->compiled->data)->units);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; typedef mybasetype {type string;default hello;units xxx;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b; typedef mybasetype {type string;default hello;units xxx;}"
             "leaf l {type mybasetype;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
-    assert_int_equal(3, type->refcount); /* 2x type reference, 1x default value's reference (typedf's default does not reference own type)*/
+    assert_int_equal(3, type->refcount);     /* 2x type reference, 1x default value's reference (typedf's default does not reference own type)*/
     assert_int_equal(LY_TYPE_STRING, type->basetype);
     assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
     assert_string_equal("hello", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
     assert_string_equal("xxx", leaf->units);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c; typedef mybasetype {type string;default hello;units xxx;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c; typedef mybasetype {type string;default hello;units xxx;}"
             "leaf l {type mybasetype; default goodbye;units yyy;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
-    assert_int_equal(3, type->refcount); /* 2x type reference, 1x default value's reference */
+    assert_int_equal(3, type->refcount);     /* 2x type reference, 1x default value's reference */
     assert_int_equal(LY_TYPE_STRING, type->basetype);
     leaf = (struct lysc_node_leaf *)mod->compiled->data;
     assert_string_equal("goodbye", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
     assert_string_equal("yyy", leaf->units);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; typedef mybasetype {type string;default hello;units xxx;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; typedef mybasetype {type string;default hello;units xxx;}"
             "typedef mytype {type mybasetype;}leaf l1 {type mytype; default goodbye;units yyy;}"
             "leaf l2 {type mytype;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
-    assert_int_equal(6, type->refcount); /* 4x type reference, 2x default value's reference (1 shared compiled type of typedefs which default does not reference own type) */
+    assert_int_equal(6, type->refcount);     /* 4x type reference, 2x default value's reference (1 shared compiled type of typedefs which default does not reference own type) */
     assert_int_equal(LY_TYPE_STRING, type->basetype);
     leaf = (struct lysc_node_leaf *)mod->compiled->data;
     assert_string_equal("goodbye", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
@@ -2149,18 +1942,18 @@
     assert_string_equal("yyy", leaf->units);
     type = ((struct lysc_node_leaf *)mod->compiled->data->next)->type;
     assert_non_null(type);
-    assert_int_equal(6, type->refcount); /* 4x type reference, 2x default value's reference (1 shared compiled type of typedefs which default does not reference own type) */
+    assert_int_equal(6, type->refcount);     /* 4x type reference, 2x default value's reference (1 shared compiled type of typedefs which default does not reference own type) */
     assert_int_equal(LY_TYPE_STRING, type->basetype);
     leaf = (struct lysc_node_leaf *)mod->compiled->data->next;
     assert_string_equal("hello", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
     assert_string_equal("xxx", leaf->units);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {namespace urn:e;prefix e; typedef mybasetype {type string;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e; typedef mybasetype {type string;}"
             "typedef mytype {type mybasetype; default hello;units xxx;}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
-    assert_int_equal(4, type->refcount); /* 3x type reference, 1x default value's reference (typedef's default does not reference own type) */
+    assert_int_equal(4, type->refcount);     /* 3x type reference, 1x default value's reference (typedef's default does not reference own type) */
     assert_int_equal(LY_TYPE_STRING, type->basetype);
     leaf = (struct lysc_node_leaf *)mod->compiled->data;
     assert_string_equal("hello", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
@@ -2168,99 +1961,75 @@
     assert_string_equal("xxx", leaf->units);
 
     /* mandatory leaf does not takes default value from type */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;typedef mytype {type string; default hello;units xxx;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;typedef mytype {type string; default hello;units xxx;}"
             "leaf l {type mytype; mandatory true;}}", LYS_IN_YANG, &mod));
     type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
     assert_non_null(type);
     assert_int_equal(LY_TYPE_STRING, type->basetype);
     assert_null(((struct lysc_node_leaf *)mod->compiled->data)->dflt);
     assert_string_equal("xxx", ((struct lysc_node_leaf *)mod->compiled->data)->units);
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
 }
 
 static void
 test_status(void **state)
 {
-    *state = test_status;
 
-    struct ly_ctx *ctx;
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
             "container c {status deprecated; leaf l {status current; type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("A \"current\" status is in conflict with the parent's \"deprecated\" status. /aa:c/l");
+    CHECK_LOG_CTX("A \"current\" status is in conflict with the parent's \"deprecated\" status.", "/aa:c/l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;"
             "container c {status obsolete; leaf l {status current; type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("A \"current\" status is in conflict with the parent's \"obsolete\" status. /bb:c/l");
+    CHECK_LOG_CTX("A \"current\" status is in conflict with the parent's \"obsolete\" status.", "/bb:c/l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;"
             "container c {status obsolete; leaf l {status deprecated; type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status. /cc:c/l");
+    CHECK_LOG_CTX("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status.", "/cc:c/l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:dd;prefix d;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:dd;prefix d;"
             "container c {leaf l {status obsolete; type string;}}"
             "container d {leaf m {when \"../../c/l\"; type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("A current definition \"m\" is not allowed to reference obsolete definition \"l\". /cc:d/m");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("A current definition \"m\" is not allowed to reference obsolete definition \"l\".", "/cc:d/m");
 }
 
 static void
 test_grouping(void **state)
 {
-    *state = test_grouping;
-
-    struct ly_ctx *ctx;
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
 
     /* result ok, but a warning about not used locally scoped grouping printed */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a; grouping grp1 {leaf a1 {type string;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a; grouping grp1 {leaf a1 {type string;}}"
             "container a {leaf x {type string;} grouping grp2 {leaf a2 {type string;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Locally scoped grouping \"grp2\" not used.");
-    logbuf_clean();
+    CHECK_LOG_CTX("Locally scoped grouping \"grp2\" not used.", NULL);
+    UTEST_LOG_CLEAN;
 
     /* result ok - when statement or leafref target must be checked only at the place where the grouping is really instantiated */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b; grouping grp {"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b; grouping grp {"
             "leaf ref {type leafref {path \"../name\";}}"
             "leaf cond {type string; when \"../name = 'specialone'\";}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("");
+    CHECK_LOG_CTX(NULL, NULL);
 
     /* invalid - error in a non-instantiated grouping */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
             "grouping grp {leaf x {type leafref;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Missing path substatement for leafref type. /aa:{grouping='grp'}/x");
-    logbuf_clean();
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;"
+    CHECK_LOG_CTX("Missing path substatement for leafref type.", "/aa:{grouping='grp'}/x");
+    UTEST_LOG_CLEAN;
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
             "container a {grouping grp {leaf x {type leafref;}}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Missing path substatement for leafref type. /aa:a/{grouping='grp'}/x");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Missing path substatement for leafref type.", "/aa:a/{grouping='grp'}/x");
 }
 
 static void
 test_uses(void **state)
 {
-    *state = test_uses;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     const struct lysc_node *parent, *child;
     const struct lysc_node_container *cont;
     const struct lysc_node_choice *choice;
     const struct lysc_node_case *cs;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module grp {namespace urn:grp;prefix g; typedef mytype {type string;} feature f;"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module grp {namespace urn:grp;prefix g; typedef mytype {type string;} feature f;"
             "grouping grp {leaf x {type mytype;} leaf y {type string; if-feature f;}}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;import grp {prefix g;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;import grp {prefix g;}"
             "grouping grp_a_top {leaf a1 {type int8;}}"
             "container a {uses grp_a; uses grp_a_top; uses g:grp; grouping grp_a {leaf a2 {type uint8;}}}}", LYS_IN_YANG, &mod));
     assert_non_null((parent = mod->compiled->data));
@@ -2276,8 +2045,8 @@
     assert_ptr_equal(mod, child->module);
     assert_null((child = child->next));
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule bsub {belongs-to b {prefix b;} grouping grp {leaf b {when 1; type string;} leaf c {type string;}}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;include bsub;uses grp {when 2;}}", LYS_IN_YANG, &mod));
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule bsub {belongs-to b {prefix b;} grouping grp {leaf b {when 1; type string;} leaf c {type string;}}}");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;include bsub;uses grp {when 2;}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
     assert_int_equal(LYS_LEAF, mod->compiled->data->nodetype);
     assert_string_equal("b", mod->compiled->data->name);
@@ -2294,8 +2063,8 @@
     assert_int_equal(2, mod->compiled->data->next->when[0]->refcount);
     assert_null(mod->compiled->data->next->when[0]->context);
 
-    logbuf_clean();
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:ii;prefix ii;"
+    UTEST_LOG_CLEAN;
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:ii;prefix ii;"
             "grouping grp {leaf l {type string;}leaf k {type string; status obsolete;}}"
             "uses grp {status deprecated;}}", LYS_IN_YANG, &mod));
     assert_int_equal(LYS_LEAF, mod->compiled->data->nodetype);
@@ -2304,9 +2073,9 @@
     assert_int_equal(LYS_LEAF, mod->compiled->data->next->nodetype);
     assert_string_equal("k", mod->compiled->data->next->name);
     assert_true(LYS_STATUS_OBSLT & mod->compiled->data->next->flags);
-    logbuf_assert(""); /* no warning about inheriting deprecated flag from uses */
+    CHECK_LOG(NULL, NULL);     /* no warning about inheriting deprecated flag from uses */
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; grouping grp {container g;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; grouping grp {container g;}"
             "container top {uses grp {augment g {leaf x {type int8;}}}}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
     assert_non_null(child = lysc_node_children(mod->compiled->data, 0));
@@ -2314,7 +2083,7 @@
     assert_non_null(child = lysc_node_children(child, 0));
     assert_string_equal("x", child->name);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {yang-version 1.1;namespace urn:e;prefix e; grouping grp {action g { description \"super g\";}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {yang-version 1.1;namespace urn:e;prefix e; grouping grp {action g { description \"super g\";}}"
             "container top {action e; uses grp {refine g {description \"ultra g\";}}}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
     cont = (const struct lysc_node_container *)mod->compiled->data;
@@ -2324,7 +2093,7 @@
     assert_string_equal("g", cont->actions[0].name);
     assert_string_equal("ultra g", cont->actions[0].dsc);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {yang-version 1.1;namespace urn:f;prefix f; grouping grp {notification g { description \"super g\";}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {yang-version 1.1;namespace urn:f;prefix f; grouping grp {notification g { description \"super g\";}}"
             "container top {notification f; uses grp {refine g {description \"ultra g\";}}}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
     cont = (const struct lysc_node_container *)mod->compiled->data;
@@ -2335,11 +2104,11 @@
     assert_string_equal("ultra g", cont->notifs[0].dsc);
 
     /* empty grouping */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g; grouping grp; uses grp;}", LYS_IN_YANG, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g; grouping grp; uses grp;}", LYS_IN_YANG, &mod));
     assert_null(mod->compiled->data);
 
     /* choice in uses */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module h {yang-version 1.1;namespace urn:h;prefix h; grouping grp {choice gch {case gc1 { leaf y { type string;}} case gc2 {leaf z {type string;}}}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {yang-version 1.1;namespace urn:h;prefix h; grouping grp {choice gch {case gc1 { leaf y { type string;}} case gc2 {leaf z {type string;}}}}"
             "choice ch {case one { leaf x {type string;}} case two { uses grp;}}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
     choice = (const struct lysc_node_choice *)mod->compiled->data;
@@ -2357,7 +2126,7 @@
     assert_string_equal("gch", cs->child->name);
 
     /* top-level uses with augment and refine */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module i {namespace urn:i;prefix i; grouping grp {container g;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i; grouping grp {container g;}"
             "uses grp {augment g {leaf x {type int8;}} refine g {description \"dsc\";}}}",
             LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
@@ -2369,63 +2138,57 @@
     assert_string_equal("x", child->name);
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;uses missinggrp;}", LYS_IN_YANG, &mod));
-    logbuf_assert("Grouping \"missinggrp\" referenced by a uses statement not found. /aa:{uses='missinggrp'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;uses missinggrp;}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Grouping \"missinggrp\" referenced by a uses statement not found.", "/aa:{uses='missinggrp'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;uses grp;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;uses grp;"
             "grouping grp {leaf a{type string;}uses grp1;}"
             "grouping grp1 {leaf b {type string;}uses grp2;}"
             "grouping grp2 {leaf c {type string;}uses grp;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Grouping \"grp\" references itself through a uses statement. /bb:{uses='grp'}/{uses='grp1'}/{uses='grp2'}/{uses='grp'}");
+    CHECK_LOG_CTX("Grouping \"grp\" references itself through a uses statement.", "/bb:{uses='grp'}/{uses='grp1'}/{uses='grp2'}/{uses='grp'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;uses a:missingprefix;}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid prefix used for grouping reference. /cc:{uses='a:missingprefix'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;uses a:missingprefix;}", LYS_IN_YANG, &mod));
+    CHECK_LOG_CTX("Invalid prefix used for grouping reference.", "/cc:{uses='a:missingprefix'}");
 
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;grouping grp{leaf a{type string;}}"
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;grouping grp{leaf a{type string;}}"
             "leaf a {type string;}uses grp;}", LYS_IN_YANG, &mod));
-    logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /dd:{uses='grp'}/dd:a");
+    CHECK_LOG_CTX("Duplicate identifier \"a\" of data definition/RPC/action/notification statement.", "/dd:{uses='grp'}/dd:a");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;grouping grp {leaf l {type string; status deprecated;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;grouping grp {leaf l {type string; status deprecated;}}"
             "uses grp {status obsolete;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status. /ee:{uses='grp'}/ee:l");
+    CHECK_LOG_CTX("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status.", "/ee:{uses='grp'}/ee:l");
 
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;grouping grp {leaf l {type string;}}"
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;grouping grp {leaf l {type string;}}"
             "leaf l {type int8;}uses grp;}", LYS_IN_YANG, &mod));
-    logbuf_assert("Duplicate identifier \"l\" of data definition/RPC/action/notification statement. /ff:{uses='grp'}/ff:l");
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module fg {namespace urn:fg;prefix fg;grouping grp {leaf m {type string;}}"
+    CHECK_LOG_CTX("Duplicate identifier \"l\" of data definition/RPC/action/notification statement.", "/ff:{uses='grp'}/ff:l");
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module fg {namespace urn:fg;prefix fg;grouping grp {leaf m {type string;}}"
             "uses grp;leaf m {type int8;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Duplicate identifier \"m\" of data definition/RPC/action/notification statement. /fg:m");
+    CHECK_LOG_CTX("Duplicate identifier \"m\" of data definition/RPC/action/notification statement.", "/fg:m");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg; grouping grp {container g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg; grouping grp {container g;}"
             "leaf g {type string;}"
             "container top {uses grp {augment /g {leaf x {type int8;}}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid descendant-schema-nodeid value \"/g\" - name test expected instead of \"/\". /gg:top/{uses='grp'}/{augment='/g'}");
+    CHECK_LOG_CTX("Invalid descendant-schema-nodeid value \"/g\" - name test expected instead of \"/\".", "/gg:top/{uses='grp'}/{augment='/g'}");
 
-    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(ctx, "module hh {yang-version 1.1;namespace urn:hh;prefix hh;"
+    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module hh {yang-version 1.1;namespace urn:hh;prefix hh;"
             "grouping grp {notification g { description \"super g\";}}"
             "container top {notification h; uses grp {refine h {description \"ultra h\";}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Refine(s) target node \"h\" in grouping \"grp\" was not found. /hh:top/{uses='grp'}");
+    CHECK_LOG_CTX("Refine(s) target node \"h\" in grouping \"grp\" was not found.", "/hh:top/{uses='grp'}");
 
-    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(ctx, "module ii {yang-version 1.1;namespace urn:ii;prefix ii;"
+    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module ii {yang-version 1.1;namespace urn:ii;prefix ii;"
             "grouping grp {action g { description \"super g\";}}"
             "container top {action i; uses grp {refine i {description \"ultra i\";}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Refine(s) target node \"i\" in grouping \"grp\" was not found. /ii:top/{uses='grp'}");
+    CHECK_LOG_CTX("Refine(s) target node \"i\" in grouping \"grp\" was not found.", "/ii:top/{uses='grp'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {yang-version 1.1;namespace urn:jj;prefix jj;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj {yang-version 1.1;namespace urn:jj;prefix jj;"
             "grouping grp {leaf j { when \"1\"; type invalid;}}"
             "container top {uses grp;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Referenced type \"invalid\" not found. /jj:top/{uses='grp'}/j");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Referenced type \"invalid\" not found.", "/jj:top/{uses='grp'}/j");
 }
 
 static void
 test_refine(void **state)
 {
-    *state = test_refine;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     struct lysc_node *parent, *child;
     struct lysc_node_leaf *leaf;
@@ -2434,8 +2197,6 @@
     struct ly_in *in;
     const char *data, *feats1[] = {"f", NULL}, *feats2[] = {"fa", NULL};
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
     data = "module grp {yang-version 1.1;namespace urn:grp;prefix g; feature f;typedef mytype {type string; default cheers!;}"
             "grouping grp {container c {leaf l {type mytype; default goodbye;}"
             "leaf-list ll {type mytype; default goodbye; max-elements 6;}"
@@ -2444,7 +2205,7 @@
             "anydata a {mandatory false; if-feature f; description original; reference original;}"
             "container c {config false; leaf l {type string;}}}}}";
     assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
-    assert_int_equal(LY_SUCCESS, lys_parse(ctx, in, LYS_IN_YANG, feats1, NULL));
+    assert_int_equal(LY_SUCCESS, lys_parse(UTEST_LYCTX, in, LYS_IN_YANG, feats1, NULL));
 
     data = "module a {yang-version 1.1;namespace urn:a;prefix a;import grp {prefix g;}feature fa;"
             "uses g:grp {refine c/l {default hello; config false;}"
@@ -2455,7 +2216,7 @@
             "refine c/ll {max-elements 5;}"
             "refine c/c {config true;presence indispensable;}}}";
     ly_in_memory(in, data);
-    assert_int_equal(LY_SUCCESS, lys_parse(ctx, in, LYS_IN_YANG, feats2, &mod));
+    assert_int_equal(LY_SUCCESS, lys_parse(UTEST_LYCTX, in, LYS_IN_YANG, feats2, &mod));
     ly_in_free(in, 0);
 
     assert_non_null((parent = mod->compiled->data));
@@ -2507,7 +2268,7 @@
     assert_true(LYS_CONFIG_W & child->flags);
     assert_true(LYS_CONFIG_W & ((struct lysc_node_container *)child)->child->flags);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {yang-version 1.1;namespace urn:b;prefix b;import grp {prefix g;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1;namespace urn:b;prefix b;import grp {prefix g;}"
             "uses g:grp {status deprecated; refine c/x {default hello; mandatory false;}}}", LYS_IN_YANG, &mod));
     assert_non_null((leaf = (struct lysc_node_leaf *)((struct lysc_node_container *)mod->compiled->data)->child->prev->prev->prev));
     assert_int_equal(LYS_LEAF, leaf->nodetype);
@@ -2517,77 +2278,71 @@
     assert_int_equal(0, dynamic);
 
     /* invalid */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;import grp {prefix g;}"
             "uses g:grp {refine c {default hello;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid refine of container node - it is not possible to replace \"default\" property. /aa:{uses='g:grp'}/aa:c/{refine='c'}");
+    CHECK_LOG_CTX("Invalid refine of container node - it is not possible to replace \"default\" property.", "/aa:{uses='g:grp'}/aa:c/{refine='c'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;import grp {prefix g;}"
             "uses g:grp {refine c/l {default hello; default world;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid refine of leaf with too many (2) default properties. /bb:{uses='g:grp'}/bb:c/l/{refine='c/l'}");
+    CHECK_LOG_CTX("Invalid refine of leaf with too many (2) default properties.", "/bb:{uses='g:grp'}/bb:c/l/{refine='c/l'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;import grp {prefix g;}"
             "uses g:grp {refine c/ll {default hello; default world;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid refine of default in leaf-list - the default statement is allowed only in YANG 1.1 modules. /cc:{uses='g:grp'}/cc:c/ll/{refine='c/ll'}");
+    CHECK_LOG_CTX("Invalid refine of default in leaf-list - the default statement is allowed only in YANG 1.1 modules.", "/cc:{uses='g:grp'}/cc:c/ll/{refine='c/ll'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;import grp {prefix g;}"
             "uses g:grp {refine c/ll {mandatory true;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid refine of leaf-list node - it is not possible to replace \"mandatory\" property. /dd:{uses='g:grp'}/dd:c/ll/{refine='c/ll'}");
+    CHECK_LOG_CTX("Invalid refine of leaf-list node - it is not possible to replace \"mandatory\" property.", "/dd:{uses='g:grp'}/dd:c/ll/{refine='c/ll'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;import grp {prefix g;}"
             "uses g:grp {refine c/l {mandatory true;}}}", LYS_IN_YANG, &mod));
-    // logbuf_assert("Invalid refine of mandatory - leaf already has \"default\" statement. /ee:{uses='g:grp'}/{refine='c/l'}");
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /ee:{uses='g:grp'}/ee:c/l");
+    // CHECK_LOG_CTX("Invalid refine of mandatory - leaf already has \"default\" statement.", "/ee:{uses='g:grp'}/{refine='c/l'}");
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ee:{uses='g:grp'}/ee:c/l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ef {namespace urn:ef;prefix ef;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ef {namespace urn:ef;prefix ef;import grp {prefix g;}"
             "uses g:grp {refine c/ch {mandatory true;}}}", LYS_IN_YANG, &mod));
-    // logbuf_assert("Invalid refine of mandatory - choice already has \"default\" statement. /ef:{uses='g:grp'}/{refine='c/ch'}");
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /ef:{uses='g:grp'}/ef:c/ch");
+    // CHECK_LOG_CTX("Invalid refine of mandatory - choice already has \"default\" statement.", "/ef:{uses='g:grp'}/{refine='c/ch'}");
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ef:{uses='g:grp'}/ef:c/ch");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;import grp {prefix g;}"
             "uses g:grp {refine c/ch/ca/ca {mandatory true;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Mandatory node \"ca\" under the default case \"ca\". /ff:{uses='g:grp'}/ff:c/ch");
+    CHECK_LOG_CTX("Mandatory node \"ca\" under the default case \"ca\".", "/ff:{uses='g:grp'}/ff:c/ch");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;import grp {prefix g;}"
             "uses g:grp {refine c/x {default hello;}}}", LYS_IN_YANG, &mod));
-    // logbuf_assert("Invalid refine of default - the node is mandatory. /gg:{uses='g:grp'}/{refine='c/x'}");
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /gg:{uses='g:grp'}/gg:c/x");
+    // CHECK_LOG_CTX("Invalid refine of default - the node is mandatory.", "/gg:{uses='g:grp'}/{refine='c/x'}");
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/gg:{uses='g:grp'}/gg:c/x");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh {namespace urn:hh;prefix hh;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh;import grp {prefix g;}"
             "uses g:grp {refine c/c/l {config true;}}}", LYS_IN_YANG, &mod));
-    // logbuf_assert("Invalid refine of config - configuration node cannot be child of any state data node. /hh:{uses='g:grp'}/{refine='c/c/l'}");
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /hh:{uses='g:grp'}/hh:c/c/l");
+    // CHECK_LOG_CTX("Invalid refine of config - configuration node cannot be child of any state data node.", "/hh:{uses='g:grp'}/{refine='c/c/l'}");
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/hh:{uses='g:grp'}/hh:c/c/l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii {namespace urn:ii;prefix ii;grouping grp {leaf l {type string; status deprecated;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii {namespace urn:ii;prefix ii;grouping grp {leaf l {type string; status deprecated;}}"
             "uses grp {status obsolete;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status. /ii:{uses='grp'}/ii:l");
+    CHECK_LOG_CTX("A \"deprecated\" status is in conflict with the parent's \"obsolete\" status.", "/ii:{uses='grp'}/ii:l");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj {namespace urn:jj;prefix jj;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj {namespace urn:jj;prefix jj;import grp {prefix g;}"
             "uses g:grp {refine c/x {presence nonsence;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid refine of leaf node - it is not possible to replace \"presence\" property. /jj:{uses='g:grp'}/jj:c/x/{refine='c/x'}");
+    CHECK_LOG_CTX("Invalid refine of leaf node - it is not possible to replace \"presence\" property.", "/jj:{uses='g:grp'}/jj:c/x/{refine='c/x'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk {namespace urn:kk;prefix kk;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk {namespace urn:kk;prefix kk;import grp {prefix g;}"
             "uses g:grp {refine c/ch {must 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid refine of choice node - it is not possible to add \"must\" property. /kk:{uses='g:grp'}/kk:c/ch/{refine='c/ch'}");
+    CHECK_LOG_CTX("Invalid refine of choice node - it is not possible to add \"must\" property.", "/kk:{uses='g:grp'}/kk:c/ch/{refine='c/ch'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll {namespace urn:ll;prefix ll;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll {namespace urn:ll;prefix ll;import grp {prefix g;}"
             "uses g:grp {refine c/x {min-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid refine of leaf node - it is not possible to replace \"min-elements\" property. /ll:{uses='g:grp'}/ll:c/x/{refine='c/x'}");
+    CHECK_LOG_CTX("Invalid refine of leaf node - it is not possible to replace \"min-elements\" property.", "/ll:{uses='g:grp'}/ll:c/x/{refine='c/x'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm {namespace urn:mm;prefix mm;import grp {prefix g;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm {namespace urn:mm;prefix mm;import grp {prefix g;}"
             "uses g:grp {refine c/ll {min-elements 10;}}}", LYS_IN_YANG, &mod));
-    // logbuf_assert("Invalid refine of min-elements statement - \"min-elements\" is bigger than \"max-elements\". /mm:{uses='g:grp'}/{refine='c/ll'}");
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /mm:{uses='g:grp'}/mm:c/ll");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    // CHECK_LOG_CTX("Invalid refine of min-elements statement - \"min-elements\" is bigger than \"max-elements\".", "/mm:{uses='g:grp'}/{refine='c/ll'}");
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm:{uses='g:grp'}/mm:c/ll");
 }
 
 static void
 test_augment(void **state)
 {
-    *state = test_augment;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     const struct lysc_node *node;
     const struct lysc_node_choice *ch;
@@ -2596,20 +2351,18 @@
     const struct lysc_action *rpc;
     const struct lysc_notif *notif;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module a {namespace urn:a;prefix a; typedef atype {type string;}"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module a {namespace urn:a;prefix a; typedef atype {type string;}"
             "container top {leaf a {type string;}}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;import a {prefix a;}"
             "leaf b {type a:atype;}}", LYS_IN_YANG, &mod));
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module c {namespace urn:c;prefix c; import a {prefix a;}"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module c {namespace urn:c;prefix c; import a {prefix a;}"
             "augment /a:top { container c {leaf c {type a:atype;}}}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d;import a {prefix a;} import c {prefix c;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d;import a {prefix a;} import c {prefix c;}"
             "augment /a:top/c:c { leaf d {type a:atype;} leaf c {type string;}}}", LYS_IN_YANG, &mod));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "a")));
-    assert_non_null(ly_ctx_get_module_implemented(ctx, "b"));
-    assert_non_null(ly_ctx_get_module_implemented(ctx, "c"));
-    assert_non_null(ly_ctx_get_module_implemented(ctx, "d"));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "a")));
+    assert_non_null(ly_ctx_get_module_implemented(UTEST_LYCTX, "b"));
+    assert_non_null(ly_ctx_get_module_implemented(UTEST_LYCTX, "c"));
+    assert_non_null(ly_ctx_get_module_implemented(UTEST_LYCTX, "d"));
     assert_non_null(node = mod->compiled->data);
     assert_string_equal(node->name, "top");
     assert_non_null(node = lysc_node_children(node, 0));
@@ -2623,7 +2376,7 @@
     assert_non_null(node = node->next);
     assert_string_equal(node->name, "c");
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module e {namespace urn:e;prefix e;choice ch {leaf a {type string;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e;choice ch {leaf a {type string;}}"
             "augment /ch/c {when 1; leaf lc2 {type uint16;}}"
             "augment /ch { when 1; leaf b {type int8;} case c {leaf lc1 {type uint8;}}}}", LYS_IN_YANG, &mod));
     assert_non_null((ch = (const struct lysc_node_choice *)mod->compiled->data));
@@ -2649,15 +2402,15 @@
     assert_string_equal("a", c->child->name);
     assert_null(c->next);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {namespace urn:f;prefix f;grouping g {leaf a {type string;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;grouping g {leaf a {type string;}}"
             "container c;"
             "augment /c {uses g;}}", LYS_IN_YANG, &mod));
     assert_non_null(node = lysc_node_children(mod->compiled->data, 0));
     assert_string_equal(node->name, "a");
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule gsub {belongs-to g {prefix g;}"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule gsub {belongs-to g {prefix g;}"
             "augment /c {container sub;}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {namespace urn:g;prefix g;include gsub; container c;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g;include gsub; container c;"
             "augment /c/sub {leaf main {type string;}}}", LYS_IN_YANG, &mod));
     assert_non_null(mod->compiled->data);
     assert_string_equal("c", mod->compiled->data->name);
@@ -2666,8 +2419,8 @@
     assert_non_null(node = ((struct lysc_node_container *)node)->child);
     assert_string_equal("main", node->name);
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module himp {namespace urn:hi;prefix hi;container top; rpc func;}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module h {namespace urn:h;prefix h;import himp {prefix hi;}container top;"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module himp {namespace urn:hi;prefix hi;container top; rpc func;}");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {namespace urn:h;prefix h;import himp {prefix hi;}container top;"
             "augment /hi:top {container p {presence XXX; leaf x {mandatory true;type string;}}}"
             "augment /hi:top {list ll {key x;leaf x {type string;}leaf y {mandatory true; type string;}}}"
             "augment /hi:top {leaf l {type string; mandatory true; config false;}}"
@@ -2676,7 +2429,7 @@
     assert_non_null(node = ((struct lysc_node_container *)node)->child);
     assert_string_equal("l", node->name);
     assert_true(node->flags & LYS_MAND_TRUE);
-    assert_non_null(mod = ly_ctx_get_module_implemented(ctx, "himp"));
+    assert_non_null(mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "himp"));
     assert_non_null(node = mod->compiled->data);
     assert_non_null(node = ((struct lysc_node_container *)node)->child);
     assert_string_equal("p", node->name);
@@ -2686,10 +2439,10 @@
     assert_string_equal("l", node->name);
     assert_true(node->flags & LYS_CONFIG_R);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module i {namespace urn:i;prefix i;import himp {prefix hi;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i;import himp {prefix hi;}"
             "augment /hi:func/hi:input {leaf x {type string;}}"
             "augment /hi:func/hi:output {leaf y {type string;}}}", LYS_IN_YANG, NULL));
-    assert_non_null(mod = ly_ctx_get_module_implemented(ctx, "himp"));
+    assert_non_null(mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "himp"));
     assert_non_null(rpc = mod->compiled->rpcs);
     assert_int_equal(1, LY_ARRAY_COUNT(rpc));
     assert_non_null(rpc->input.data);
@@ -2699,7 +2452,7 @@
     assert_string_equal("y", rpc->output.data->name);
     assert_null(rpc->output.data->next);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;yang-version 1.1; container root;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module j {namespace urn:j;prefix j;yang-version 1.1; container root;"
             "grouping grp {notification grp-notif;}"
             "augment /root {uses grp;}}", LYS_IN_YANG, &mod));
     assert_non_null(cont = (const struct lysc_node_container *)mod->compiled->data);
@@ -2707,53 +2460,47 @@
     assert_non_null(notif = cont->notifs);
     assert_int_equal(1, LY_ARRAY_COUNT(notif));
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}"
             "augment /x/ {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid absolute-schema-nodeid value \"/x/\" - unexpected end of expression. /aa:{augment='/x/'}");
+    CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"/x/\" - unexpected end of expression.", "/aa:{augment='/x/'}");
 
-    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}"
+    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}"
             "augment /x {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Augment target node \"/x\" from module \"aa\" was not found.");
+    CHECK_LOG_CTX("Augment target node \"/x\" from module \"aa\" was not found.", NULL);
 
-    assert_int_equal(LY_EEXIST, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; container c {leaf a {type string;}}"
+    assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb; container c {leaf a {type string;}}"
             "augment /c {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Duplicate identifier \"a\" of data definition/RPC/action/notification statement. /bb:c/a");
+    CHECK_LOG_CTX("Duplicate identifier \"a\" of data definition/RPC/action/notification statement.", "/bb:c/a");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; container c {leaf a {type string;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc; container c {leaf a {type string;}}"
             "augment /c/a {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Augment's absolute-schema-nodeid \"/c/a\" refers to a leaf node which is not an allowed augment's target. /cc:{augment='/c/a'}");
+    CHECK_LOG_CTX("Augment's absolute-schema-nodeid \"/c/a\" refers to a leaf node which is not an allowed augment's target.", "/cc:{augment='/c/a'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd {namespace urn:dd;prefix dd; container c {leaf a {type string;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd; container c {leaf a {type string;}}"
             "augment /c {case b {leaf d {type int8;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid augment of container node which is not allowed to contain case node \"b\". /dd:{augment='/c'}");
+    CHECK_LOG_CTX("Invalid augment of container node which is not allowed to contain case node \"b\".", "/dd:{augment='/c'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee {namespace urn:ee;prefix ee; import himp {prefix hi;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee; import himp {prefix hi;}"
             "augment /hi:top {container c {leaf d {mandatory true; type int8;}}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid augment adding mandatory node \"c\" without making it conditional via when statement. /ee:{augment='/hi:top'}");
+    CHECK_LOG_CTX("Invalid augment adding mandatory node \"c\" without making it conditional via when statement.", "/ee:{augment='/hi:top'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff {namespace urn:ff;prefix ff; container top;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff; container top;"
             "augment ../top {leaf x {type int8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid absolute-schema-nodeid value \"../top\" - \"/\" expected instead of \"..\". /ff:{augment='../top'}");
+    CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"../top\" - \"/\" expected instead of \"..\".", "/ff:{augment='../top'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg {namespace urn:gg;prefix gg; rpc func;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg; rpc func;"
             "augment /func {leaf x {type int8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Augment's absolute-schema-nodeid \"/func\" refers to a RPC node which is not an allowed augment's target. /gg:{augment='/func'}");
+    CHECK_LOG_CTX("Augment's absolute-schema-nodeid \"/func\" refers to a RPC node which is not an allowed augment's target.", "/gg:{augment='/func'}");
 
-    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(ctx, "module hh {namespace urn:i;prefix i;import himp {prefix hi;}"
+    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:i;prefix i;import himp {prefix hi;}"
             "augment /hi:func/input {leaf x {type string;}}"
             "augment /hi:func/output {leaf y {type string;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Invalid absolute-schema-nodeid value \"/hi:func/input\" - target node not found. /hh:{augment='/hi:func/input'}");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"/hi:func/input\" - target node not found.", "/hh:{augment='/hi:func/input'}");
 }
 
 static void
 test_deviation(void **state)
 {
-    *state = test_deviation;
-
-    struct ly_ctx *ctx;
     const struct lys_module *mod;
     const struct lysc_node *node;
     const struct lysc_node_list *list;
@@ -2762,15 +2509,13 @@
     const char *str;
     uint8_t dynamic;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module a {namespace urn:a;prefix a;"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module a {namespace urn:a;prefix a;"
             "container top {leaf a {type string;} leaf b {type string;} leaf c {type string;}}"
             "choice ch {default c; case b {leaf b{type string;}} case a {leaf a{type string;} leaf x {type string;}}"
             " case c {leaf c{type string;}}}"
             "rpc func1 { input { leaf x {type int8;}} output {leaf y {type int8;}}}"
             "rpc func2;}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;import a {prefix a;}"
             "deviation /a:top/a:b {deviate not-supported;}"
             "deviation /a:ch/a:a/a:x {deviate not-supported;}"
             "deviation /a:ch/a:c {deviate not-supported;}"
@@ -2780,7 +2525,7 @@
             "deviation /a:func1/a:input {deviate not-supported;}"
             "deviation /a:func1/a:output {deviate not-supported;}"
             "deviation /a:func2 {deviate not-supported;}}", LYS_IN_YANG, NULL));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "a")));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "a")));
     assert_non_null(node = mod->compiled->data);
     assert_string_equal(node->name, "top");
     assert_non_null(node = lysc_node_children(node, 0));
@@ -2797,7 +2542,7 @@
     assert_null(mod->compiled->rpcs[0].input.data);
     assert_null(mod->compiled->rpcs[0].output.data);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module c {namespace urn:c;prefix c; typedef mytype {type string; units kilometers;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c; typedef mytype {type string; units kilometers;}"
             "leaf c1 {type mytype;} leaf c2 {type mytype; units meters;} leaf c3 {type mytype; units meters;}"
             "deviation /c1 {deviate add {units meters;}}"
             "deviation /c2 {deviate delete {units meters;}}"
@@ -2812,7 +2557,7 @@
     assert_string_equal("c3", node->name);
     assert_string_equal("centimeters", ((struct lysc_node_leaf *)node)->units);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module d {namespace urn:d;prefix d; leaf c1 {type string; must 1;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; leaf c1 {type string; must 1;}"
             "container c2 {presence yes; must 1; must 2;} leaf c3 {type string; must 1; must 3;}"
             "deviation /c1 {deviate add {must 3;}}"
             "deviation /c2 {deviate delete {must 2;}}"
@@ -2829,18 +2574,18 @@
     assert_string_equal("c3", node->name);
     assert_null(((struct lysc_node_leaf *)node)->musts);
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module e {yang-version 1.1; namespace urn:e;prefix e; typedef mytype {type string; default nothing;}"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module e {yang-version 1.1; namespace urn:e;prefix e; typedef mytype {type string; default nothing;}"
             "choice a {default aa;leaf aa {type string;} leaf ab {type string;} leaf ac {type string; mandatory true;}}"
             "choice b {default ba;leaf ba {type string;} leaf bb {type string;}}"
             "leaf c {default hello; type string;}"
             "leaf-list d {default hello; default world; type string;}"
             "leaf c2 {type mytype;} leaf-list d2 {type mytype;}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module f {yang-version 1.1; namespace urn:f;prefix f;import e {prefix x;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {yang-version 1.1; namespace urn:f;prefix f;import e {prefix x;}"
             "deviation /x:a {deviate delete {default aa;}}"
             "deviation /x:b {deviate delete {default ba;}}"
             "deviation /x:c {deviate delete {default hello;}}"
             "deviation /x:d {deviate delete {default world;}}}", LYS_IN_YANG, NULL));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "e")));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "e")));
     assert_non_null(node = mod->compiled->data);
     assert_null(((struct lysc_node_choice *)node)->dflt);
     assert_non_null(node = node->next);
@@ -2854,19 +2599,19 @@
     assert_non_null(leaf = (struct lysc_node_leaf *)llist->next);
     assert_string_equal("nothing", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
-    assert_int_equal(5, leaf->dflt->realtype->refcount); /* 3x type reference, 2x default value reference (typedef's default does not reference own type) */
+    assert_int_equal(5, leaf->dflt->realtype->refcount);     /* 3x type reference, 2x default value reference (typedef's default does not reference own type) */
     assert_non_null(llist = (struct lysc_node_leaflist *)leaf->next);
     assert_int_equal(1, LY_ARRAY_COUNT(llist->dflts));
     assert_string_equal("nothing", llist->dflts[0]->realtype->plugin->print(llist->dflts[0], LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module g {yang-version 1.1; namespace urn:g;prefix g;import e {prefix x;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {yang-version 1.1; namespace urn:g;prefix g;import e {prefix x;}"
             "deviation /x:b {deviate add {default x:ba;}}"
             "deviation /x:c {deviate add {default bye;}}"
             "deviation /x:d {deviate add {default all; default people;}}"
             "deviation /x:c2 {deviate add {default hi; must 1;}}"
             "deviation /x:d2 {deviate add {default hi; default all;}}}", LYS_IN_YANG, NULL));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "e")));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "e")));
     assert_non_null(node = mod->compiled->data);
     assert_null(((struct lysc_node_choice *)node)->dflt);
     assert_non_null(node = node->next);
@@ -2888,7 +2633,7 @@
     assert_non_null(leaf->dflt);
     assert_string_equal("hi", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
-    assert_int_equal(6, leaf->dflt->realtype->refcount); /* 3x type reference, 3x default value reference
+    assert_int_equal(6, leaf->dflt->realtype->refcount);     /* 3x type reference, 3x default value reference
     - previous type's default values were replaced by node's default values where d2 now has 2 default values */
     assert_int_equal(1, LY_ARRAY_COUNT(leaf->musts));
     assert_int_equal(0, LY_ARRAY_COUNT(leaf->musts[0].prefixes));
@@ -2899,10 +2644,10 @@
     assert_string_equal("all", llist->dflts[1]->realtype->plugin->print(llist->dflts[1], LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module h {yang-version 1.1; namespace urn:h;prefix h;import e {prefix x;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {yang-version 1.1; namespace urn:h;prefix h;import e {prefix x;}"
             "deviation /x:b {deviate replace {default x:ba;}}"
             "deviation /x:c {deviate replace {default hello;}}}", LYS_IN_YANG, NULL));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "e")));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "e")));
     assert_non_null(node = mod->compiled->data);
     assert_null(((struct lysc_node_choice *)node)->dflt);
     assert_non_null(node = node->next);
@@ -2913,16 +2658,16 @@
     assert_string_equal("hello", leaf->dflt->realtype->plugin->print(leaf->dflt, LY_PREF_SCHEMA, NULL, &dynamic));
     assert_int_equal(0, dynamic);
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module i {namespace urn:i;prefix i;"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module i {namespace urn:i;prefix i;"
             "list l1 {key a; leaf a {type string;} leaf b {type string;} leaf c {type string;}}"
             "list l2 {key a; unique \"b c\"; unique \"d\"; leaf a {type string;} leaf b {type string;}"
             "         leaf c {type string;} leaf d {type string;}}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module j {namespace urn:j;prefix j;import i {prefix i;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module j {namespace urn:j;prefix j;import i {prefix i;}"
             "augment /i:l1 {leaf j_c {type string;}}"
             "deviation /i:l1 {deviate add {unique \"i:b j_c\"; }}"
             "deviation /i:l1 {deviate add {unique \"i:c\";}}"
             "deviation /i:l2 {deviate delete {unique \"d\"; unique \"b c\";}}}", LYS_IN_YANG, NULL));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "i")));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "i")));
     assert_non_null(list = (struct lysc_node_list *)mod->compiled->data);
     assert_string_equal("l1", list->name);
     assert_int_equal(2, LY_ARRAY_COUNT(list->uniques));
@@ -2935,7 +2680,7 @@
     assert_string_equal("l2", list->name);
     assert_null(list->uniques);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module k {namespace urn:k;prefix k; leaf a {type string;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module k {namespace urn:k;prefix k; leaf a {type string;}"
             "container top {leaf x {type string;} leaf y {type string; config false;}}"
             "deviation /a {deviate add {config false; }}"
             "deviation /top {deviate add {config false;}}}", LYS_IN_YANG, &mod));
@@ -2952,7 +2697,7 @@
     assert_string_equal("y", node->name);
     assert_true(node->flags & LYS_CONFIG_R);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module l {namespace urn:l;prefix l; leaf a {config false; type string;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module l {namespace urn:l;prefix l; leaf a {config false; type string;}"
             "container top {config false; leaf x {type string;}}"
             "deviation /a {deviate replace {config true;}}"
             "deviation /top {deviate replace {config true;}}}", LYS_IN_YANG, &mod));
@@ -2966,7 +2711,7 @@
     assert_string_equal("x", node->name);
     assert_true(node->flags & LYS_CONFIG_W);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module m {namespace urn:m;prefix m;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module m {namespace urn:m;prefix m;"
             "container a {leaf a {type string;}}"
             "container b {leaf b {mandatory true; type string;}}"
             "deviation /a/a {deviate add {mandatory true;}}"
@@ -2977,10 +2722,10 @@
     assert_true((lysc_node_children(node, 0)->flags & LYS_MAND_MASK) == LYS_MAND_TRUE);
     assert_non_null(node = node->next);
     assert_string_equal("b", node->name);
-    assert_false(node->flags & LYS_MAND_MASK); /* just unset on container */
+    assert_false(node->flags & LYS_MAND_MASK);     /* just unset on container */
     assert_true((lysc_node_children(node, 0)->flags & LYS_MAND_MASK) == LYS_MAND_FALSE);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module n {yang-version 1.1; namespace urn:n;prefix n;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module n {yang-version 1.1; namespace urn:n;prefix n;"
             "leaf a {default test; type string;}"
             "leaf b {mandatory true; type string;}"
             "deviation /a {deviate add {mandatory true;} deviate delete {default test;}}"
@@ -2994,7 +2739,7 @@
     assert_non_null(((struct lysc_node_leaf *)node)->dflt);
     assert_true((node->flags & LYS_MAND_MASK) == LYS_MAND_FALSE);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module o {namespace urn:o;prefix o;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module o {namespace urn:o;prefix o;"
             "leaf-list a {type string;}"
             "list b {config false;}"
             "leaf-list c {min-elements 1; max-elements 10; type string;}"
@@ -3020,7 +2765,7 @@
     assert_int_equal(1, ((struct lysc_node_list *)node)->min);
     assert_int_equal(10, ((struct lysc_node_list *)node)->max);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module p {yang-version 1.1; namespace urn:p;prefix p; typedef mytype {type int8; default 1;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module p {yang-version 1.1; namespace urn:p;prefix p; typedef mytype {type int8; default 1;}"
             "leaf a {type string; default 10;} leaf-list b {type string;}"
             "deviation /a {deviate replace {type mytype;}}"
             "deviation /b {deviate replace {type mytype;}}}", LYS_IN_YANG, &mod));
@@ -3039,10 +2784,10 @@
     assert_int_equal(1, llist->dflts[0]->uint8);
 
     /* instance-identifiers with NULL canonical are changed to string types with a canonical value equal to the original value */
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module q {yang-version 1.1; namespace urn:q;prefix q; import e {prefix e;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module q {yang-version 1.1; namespace urn:q;prefix q; import e {prefix e;}"
             "leaf q {type instance-identifier; default \"/e:d2[.='a']\";}"
             "leaf-list ql {type instance-identifier; default \"/e:d[.='b']\"; default \"/e:d2[.='c']\";}}", LYS_IN_YANG, &mod));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module qdev {yang-version 1.1; namespace urn:qdev;prefix qd; import q {prefix q;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module qdev {yang-version 1.1; namespace urn:qdev;prefix qd; import q {prefix q;}"
             "deviation /q:q { deviate replace {type string;}}"
             "deviation /q:ql { deviate replace {type string;}}}", LYS_IN_YANG, NULL));
     assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
@@ -3056,7 +2801,7 @@
     assert_int_equal(LY_TYPE_STRING, llist->dflts[0]->realtype->basetype);
     assert_string_equal("/e:d2[.='c']", llist->dflts[1]->canonical);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module r {yang-version 1.1; namespace urn:r;prefix r;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module r {yang-version 1.1; namespace urn:r;prefix r;"
             "typedef mytype {type uint8; default 200;}"
             "leaf r {type mytype;} leaf-list lr {type mytype;}"
             "deviation /r:r {deviate replace {type string;}}"
@@ -3068,7 +2813,7 @@
     assert_string_equal("lr", llist->name);
     assert_null(llist->dflts);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module s {yang-version 1.1; namespace urn:s;prefix s;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module s {yang-version 1.1; namespace urn:s;prefix s;"
             "leaf s {type instance-identifier {require-instance true;} default /s:x;}"
             "leaf x {type string;} leaf y {type string;}"
             "deviation /s:s {deviate replace {default /s:y;}}}", LYS_IN_YANG, &mod));
@@ -3081,29 +2826,29 @@
         free((char *)str);
     }
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module t {namespace urn:t;prefix t;"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module t {namespace urn:t;prefix t;"
             "leaf l {type string;}}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module u {namespace urn:u;prefix u;import t {prefix t;}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module u {namespace urn:u;prefix u;import t {prefix t;}"
             "identity ident;"
             "deviation /t:l {deviate replace {type identityref {base ident;}}}"
             "}", LYS_IN_YANG, NULL));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "t")));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "t")));
     assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
     assert_string_equal("l", leaf->name);
     assert_int_equal(LY_TYPE_IDENT, leaf->type->basetype);
     assert_string_equal("ident", ((struct lysc_type_identityref *)leaf->type)->bases[0]->name);
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module v {namespace urn:v;prefix v;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module v {namespace urn:v;prefix v;"
             "identity ident; identity ident2 { base ident; }"
             "}", LYS_IN_YANG, NULL));
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule w-sub { belongs-to w { prefix w; }"
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule w-sub { belongs-to w { prefix w; }"
             "import v { prefix v_pref; }"
             "leaf l { type string; default \"v_pref:ident2\"; }"
             "}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module w {namespace urn:w;prefix w;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module w {namespace urn:w;prefix w;"
             "include w-sub;"
             "}", LYS_IN_YANG, &mod));
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module x {namespace urn:x;prefix x;"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module x {namespace urn:x;prefix x;"
             "import w { prefix w_pref; } import v { prefix v_pref; }"
             "deviation /w_pref:l { deviate replace { type identityref { base v_pref:ident; } } }"
             "}", LYS_IN_YANG, NULL));
@@ -3111,246 +2856,237 @@
     assert_string_equal("l", leaf->name);
     assert_int_equal(LY_TYPE_IDENT, leaf->type->basetype);
 
-    ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module y {namespace urn:y;prefix y;"
-                                  "container cont {leaf l {type string;}}"
-                                  "leaf bl2 {type string;}"
-                                  "}");
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module z {namespace urn:z;prefix z;"
-                                  "import y {prefix y;}"
-                                  "deviation \"/y:cont/y:l\" {deviate replace {type leafref {path \"/al\";}}}"
-                                  "leaf al {type string;}"
-                                  "leaf al2 {type leafref {path \"/y:bl2\";}}"
-                                  "}", LYS_IN_YANG, NULL));
-    assert_non_null((mod = ly_ctx_get_module_implemented(ctx, "y")));
+    ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module y {namespace urn:y;prefix y;"
+            "container cont {leaf l {type string;}}"
+            "leaf bl2 {type string;}"
+            "}");
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module z {namespace urn:z;prefix z;"
+            "import y {prefix y;}"
+            "deviation \"/y:cont/y:l\" {deviate replace {type leafref {path \"/al\";}}}"
+            "leaf al {type string;}"
+            "leaf al2 {type leafref {path \"/y:bl2\";}}"
+            "}", LYS_IN_YANG, NULL));
+    assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "y")));
     assert_non_null(leaf = (struct lysc_node_leaf *)lysc_node_children(mod->compiled->data, 0));
     assert_string_equal("l", leaf->name);
     assert_int_equal(LY_TYPE_LEAFREF, leaf->type->basetype);
 
-    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(ctx, "module aa1 {namespace urn:aa1;prefix aa1;import a {prefix a;}"
+    assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module aa1 {namespace urn:aa1;prefix aa1;import a {prefix a;}"
             "deviation /a:top/a:z {deviate not-supported;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Deviation(s) target node \"/a:top/a:z\" from module \"aa1\" was not found.");
+    CHECK_LOG_CTX("Deviation(s) target node \"/a:top/a:z\" from module \"aa1\" was not found.", NULL);
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa2 {namespace urn:aa2;prefix aa2;import a {prefix a;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa2 {namespace urn:aa2;prefix aa2;import a {prefix a;}"
             "deviation /a:top/a:a {deviate not-supported;}"
             "deviation /a:top/a:a {deviate add {default error;}}}", LYS_IN_YANG, NULL));
-    logbuf_assert("Multiple deviations of \"/a:top/a:a\" with one of them being \"not-supported\". /");
+    CHECK_LOG_CTX("Multiple deviations of \"/a:top/a:a\" with one of them being \"not-supported\".", "/");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb;import a {prefix a;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;import a {prefix a;}"
             "deviation a:top/a:a {deviate not-supported;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid absolute-schema-nodeid value \"a:top/a:a\" - \"/\" expected instead of \"a:top\". /bb:{deviation='a:top/a:a'}");
+    CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"a:top/a:a\" - \"/\" expected instead of \"a:top\".", "/bb:{deviation='a:top/a:a'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cc {namespace urn:cc;prefix cc; container c;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc; container c;"
             "deviation /c {deviate add {units meters;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of container node - it is not possible to add \"units\" property. /cc:{deviation='/c'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module cd {namespace urn:cd;prefix cd; leaf c {type string; units centimeters;}"
+    CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to add \"units\" property.", "/cc:{deviation='/c'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cd {namespace urn:cd;prefix cd; leaf c {type string; units centimeters;}"
             "deviation /c {deviate add {units meters;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"units\" property which already exists (with value \"centimeters\"). /cd:{deviation='/c'}");
+    CHECK_LOG_CTX("Invalid deviation adding \"units\" property which already exists (with value \"centimeters\").", "/cd:{deviation='/c'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd1 {namespace urn:dd1;prefix dd1; container c;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd1 {namespace urn:dd1;prefix dd1; container c;"
             "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of container node - it is not possible to delete \"units\" property. /dd1:{deviation='/c'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd2 {namespace urn:dd2;prefix dd2; leaf c {type string;}"
+    CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to delete \"units\" property.", "/dd1:{deviation='/c'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd2 {namespace urn:dd2;prefix dd2; leaf c {type string;}"
             "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"units\" property \"meters\" which is not present. /dd2:{deviation='/c'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module dd3 {namespace urn:dd3;prefix dd3; leaf c {type string; units centimeters;}"
+    CHECK_LOG_CTX("Invalid deviation deleting \"units\" property \"meters\" which is not present.", "/dd2:{deviation='/c'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd3 {namespace urn:dd3;prefix dd3; leaf c {type string; units centimeters;}"
             "deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"units\" property \"meters\" which does not match the target's property value \"centimeters\"."
-            " /dd3:{deviation='/c'}");
+    CHECK_LOG_CTX("Invalid deviation deleting \"units\" property \"meters\" which does not match the target's property value \"centimeters\".",
+            "/dd3:{deviation='/c'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee1 {namespace urn:ee1;prefix ee1; container c;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee1 {namespace urn:ee1;prefix ee1; container c;"
             "deviation /c {deviate replace {units meters;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of container node - it is not possible to replace \"units\" property. /ee1:{deviation='/c'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ee2 {namespace urn:ee2;prefix ee2; leaf c {type string;}"
+    CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to replace \"units\" property.", "/ee1:{deviation='/c'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee2 {namespace urn:ee2;prefix ee2; leaf c {type string;}"
             "deviation /c {deviate replace {units meters;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation replacing \"units\" property \"meters\" which is not present. /ee2:{deviation='/c'}");
+    CHECK_LOG_CTX("Invalid deviation replacing \"units\" property \"meters\" which is not present.", "/ee2:{deviation='/c'}");
 
     /* the default is already deleted in /e:a byt module f */
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff1 {namespace urn:ff1;prefix ff1; import e {prefix e;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff1 {namespace urn:ff1;prefix ff1; import e {prefix e;}"
             "deviation /e:a {deviate delete {default x:aa;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"default\" property \"x:aa\" which is not present. /ff1:{deviation='/e:a'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff3 {namespace urn:ff3;prefix ff3; import e {prefix e;}"
+    CHECK_LOG_CTX("Invalid deviation deleting \"default\" property \"x:aa\" which is not present.", "/ff1:{deviation='/e:a'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff3 {namespace urn:ff3;prefix ff3; import e {prefix e;}"
             "deviation /e:b {deviate delete {default e:b;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"default\" property \"e:b\" which does not match the target's property value \"x:ba\". /ff3:{deviation='/e:b'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff5 {namespace urn:ff5;prefix ff5; anyxml a;"
+    CHECK_LOG_CTX("Invalid deviation deleting \"default\" property \"e:b\" which does not match the target's property value \"x:ba\".", "/ff3:{deviation='/e:b'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff5 {namespace urn:ff5;prefix ff5; anyxml a;"
             "deviation /a {deviate delete {default x;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of anyxml node - it is not possible to delete \"default\" property. /ff5:{deviation='/a'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff6 {namespace urn:ff6;prefix ff6; import e {prefix e;}"
+    CHECK_LOG_CTX("Invalid deviation of anyxml node - it is not possible to delete \"default\" property.", "/ff5:{deviation='/a'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff6 {namespace urn:ff6;prefix ff6; import e {prefix e;}"
             "deviation /e:c {deviate delete {default hi;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"default\" property \"hi\" which does not match the target's property value \"hello\". /ff6:{deviation='/e:c'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ff7 {namespace urn:ff7;prefix ff7; import e {prefix e;}"
+    CHECK_LOG_CTX("Invalid deviation deleting \"default\" property \"hi\" which does not match the target's property value \"hello\".", "/ff6:{deviation='/e:c'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff7 {namespace urn:ff7;prefix ff7; import e {prefix e;}"
             "deviation /e:d {deviate delete {default hi;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"default\" property \"hi\" which does not match any of the target's property values. /ff7:{deviation='/e:d'}");
+    CHECK_LOG_CTX("Invalid deviation deleting \"default\" property \"hi\" which does not match any of the target's property values.", "/ff7:{deviation='/e:d'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg1 {namespace urn:gg1;prefix gg1; import e {prefix e;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg1 {namespace urn:gg1;prefix gg1; import e {prefix e;}"
             "deviation /e:b {deviate add {default e:a;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"default\" property which already exists (with value \"x:ba\"). /gg1:{deviation='/e:b'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg2 {namespace urn:gg2;prefix gg2; import e {prefix e;}"
+    CHECK_LOG_CTX("Invalid deviation adding \"default\" property which already exists (with value \"x:ba\").", "/gg1:{deviation='/e:b'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg2 {namespace urn:gg2;prefix gg2; import e {prefix e;}"
             "deviation /e:a {deviate add {default x:a;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation adding \"default\" property \"x:a\" of choice. "
+    /*CHECK_LOG_CTX("Invalid deviation adding \"default\" property \"x:a\" of choice. "
                   "The prefix does not match any imported module of the deviation module. /gg2:{deviation='/e:a'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /e:a");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg3 {namespace urn:gg3;prefix gg3; import e {prefix e;}"
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/e:a");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg3 {namespace urn:gg3;prefix gg3; import e {prefix e;}"
             "deviation /e:a {deviate add {default a;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation adding \"default\" property \"a\" of choice - the specified case does not exists. /gg3:{deviation='/e:a'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /e:a");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}"
+    /*CHECK_LOG_CTX("Invalid deviation adding \"default\" property \"a\" of choice - the specified case does not exists.", "/gg3:{deviation='/e:a'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/e:a");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}"
             "deviation /e:c {deviate add {default hi;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"default\" property which already exists (with value \"hello\"). /gg4:{deviation='/e:c'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}"
+    CHECK_LOG_CTX("Invalid deviation adding \"default\" property which already exists (with value \"hello\").", "/gg4:{deviation='/e:c'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}"
             "deviation /e:a {deviate add {default e:ac;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation adding \"default\" property \"e:ac\" of choice - mandatory node \"ac\" under the default case. /gg4:{deviation='/e:a'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /e:a");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module gg5 {namespace urn:gg5;prefix gg5; leaf x {type string; mandatory true;}"
+    /*CHECK_LOG_CTX("Invalid deviation adding \"default\" property \"e:ac\" of choice - mandatory node \"ac\" under the default case.", "/gg4:{deviation='/e:a'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/e:a");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg5 {namespace urn:gg5;prefix gg5; leaf x {type string; mandatory true;}"
             "deviation /x {deviate add {default error;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation combining default value and mandatory leaf. /gg5:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /gg5:x");
+    /*CHECK_LOG_CTX("Invalid deviation combining default value and mandatory leaf.", "/gg5:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/gg5:x");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module hh1 {yang-version 1.1; namespace urn:hh1;prefix hh1; import e {prefix e;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh1 {yang-version 1.1; namespace urn:hh1;prefix hh1; import e {prefix e;}"
             "deviation /e:d {deviate replace {default hi;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of leaf-list node - it is not possible to replace \"default\" property. /hh1:{deviation='/e:d'}");
+    CHECK_LOG_CTX("Invalid deviation of leaf-list node - it is not possible to replace \"default\" property.", "/hh1:{deviation='/e:d'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii1 {namespace urn:ii1;prefix ii1; import i {prefix i;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii1 {namespace urn:ii1;prefix ii1; import i {prefix i;}"
             "deviation /i:l1 {deviate delete {unique x;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"unique\" property \"x\" which does not match any of the target's property values. /ii1:{deviation='/i:l1'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii2 {namespace urn:ii2;prefix ii2; import i {prefix i;} leaf x { type string;}"
+    CHECK_LOG_CTX("Invalid deviation deleting \"unique\" property \"x\" which does not match any of the target's property values.", "/ii1:{deviation='/i:l1'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii2 {namespace urn:ii2;prefix ii2; import i {prefix i;} leaf x { type string;}"
             "deviation /i:l2 {deviate delete {unique d;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation deleting \"unique\" property \"d\" which does not match any of the target's property values. /ii2:{deviation='/i:l2'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii3 {namespace urn:ii3;prefix ii3; leaf x { type string;}"
+    CHECK_LOG_CTX("Invalid deviation deleting \"unique\" property \"d\" which does not match any of the target's property values.", "/ii2:{deviation='/i:l2'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii3 {namespace urn:ii3;prefix ii3; leaf x { type string;}"
             "deviation /x {deviate delete {unique d;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of leaf node - it is not possible to delete \"unique\" property. /ii3:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ii4 {namespace urn:ii4;prefix ii4; leaf x { type string;}"
+    CHECK_LOG_CTX("Invalid deviation of leaf node - it is not possible to delete \"unique\" property.", "/ii3:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii4 {namespace urn:ii4;prefix ii4; leaf x { type string;}"
             "deviation /x {deviate add {unique d;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of leaf node - it is not possible to add \"unique\" property. /ii4:{deviation='/x'}");
+    CHECK_LOG_CTX("Invalid deviation of leaf node - it is not possible to add \"unique\" property.", "/ii4:{deviation='/x'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj1 {namespace urn:jj1;prefix jj1; choice ch {case a {leaf a{type string;}}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj1 {namespace urn:jj1;prefix jj1; choice ch {case a {leaf a{type string;}}}"
             "deviation /ch/a {deviate add {config false;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of case node - it is not possible to add \"config\" property. /jj1:{deviation='/ch/a'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj2 {namespace urn:jj2;prefix jj2; container top {config false; leaf x {type string;}}"
+    CHECK_LOG_CTX("Invalid deviation of case node - it is not possible to add \"config\" property.", "/jj1:{deviation='/ch/a'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj2 {namespace urn:jj2;prefix jj2; container top {config false; leaf x {type string;}}"
             "deviation /top/x {deviate add {config true;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation of config - configuration node cannot be child of any state data node. /jj2:{deviation='/top/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /jj2:top/x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj3 {namespace urn:jj3;prefix jj3; container top {leaf x {type string;}}"
+    /*CHECK_LOG_CTX("Invalid deviation of config - configuration node cannot be child of any state data node.", "/jj2:{deviation='/top/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/jj2:top/x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj3 {namespace urn:jj3;prefix jj3; container top {leaf x {type string;}}"
             "deviation /top/x {deviate replace {config false;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation replacing \"config\" property \"config false\" which is not present. /jj3:{deviation='/top/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj4 {namespace urn:jj4;prefix jj4; choice ch {case a {leaf a{type string;}}}"
+    CHECK_LOG_CTX("Invalid deviation replacing \"config\" property \"config false\" which is not present.", "/jj3:{deviation='/top/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj4 {namespace urn:jj4;prefix jj4; choice ch {case a {leaf a{type string;}}}"
             "deviation /ch/a {deviate replace {config false;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of case node - it is not possible to replace \"config\" property. /jj4:{deviation='/ch/a'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj5 {namespace urn:jj5;prefix jj5; container top {leaf x {type string; config true;}}"
+    CHECK_LOG_CTX("Invalid deviation of case node - it is not possible to replace \"config\" property.", "/jj4:{deviation='/ch/a'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj5 {namespace urn:jj5;prefix jj5; container top {leaf x {type string; config true;}}"
             "deviation /top {deviate add {config false;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation of config - configuration node cannot be child of any state data node. /jj5:{deviation='/top'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /jj5:top");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module jj6 {namespace urn:jj6;prefix jj6; leaf x {config false; type string;}"
+    /*CHECK_LOG_CTX("Invalid deviation of config - configuration node cannot be child of any state data node.", "/jj5:{deviation='/top'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/jj5:top");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj6 {namespace urn:jj6;prefix jj6; leaf x {config false; type string;}"
             "deviation /x {deviate add {config true;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"config\" property which already exists (with value \"config false\"). /jj6:{deviation='/x'}");
+    CHECK_LOG_CTX("Invalid deviation adding \"config\" property which already exists (with value \"config false\").", "/jj6:{deviation='/x'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk1 {namespace urn:kk1;prefix kk1; container top {leaf a{type string;}}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk1 {namespace urn:kk1;prefix kk1; container top {leaf a{type string;}}"
             "deviation /top {deviate add {mandatory true;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of container node - it is not possible to add \"mandatory\" property. /kk1:{deviation='/top'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk2 {namespace urn:kk2;prefix kk2; container top {leaf a{type string;}}"
+    CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to add \"mandatory\" property.", "/kk1:{deviation='/top'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk2 {namespace urn:kk2;prefix kk2; container top {leaf a{type string;}}"
             "deviation /top {deviate replace {mandatory true;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of container node - it is not possible to replace \"mandatory\" property. /kk2:{deviation='/top'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk3 {namespace urn:kk3;prefix kk3; container top {leaf x {type string;}}"
+    CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to replace \"mandatory\" property.", "/kk2:{deviation='/top'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk3 {namespace urn:kk3;prefix kk3; container top {leaf x {type string;}}"
             "deviation /top/x {deviate replace {mandatory true;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation replacing \"mandatory\" property \"mandatory true\" which is not present. /kk3:{deviation='/top/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module kk4 {namespace urn:kk4;prefix kk4; leaf x {mandatory true; type string;}"
+    CHECK_LOG_CTX("Invalid deviation replacing \"mandatory\" property \"mandatory true\" which is not present.", "/kk3:{deviation='/top/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk4 {namespace urn:kk4;prefix kk4; leaf x {mandatory true; type string;}"
             "deviation /x {deviate add {mandatory false;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"mandatory\" property which already exists (with value \"mandatory true\"). /kk4:{deviation='/x'}");
+    CHECK_LOG_CTX("Invalid deviation adding \"mandatory\" property which already exists (with value \"mandatory true\").", "/kk4:{deviation='/x'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll1 {namespace urn:ll1;prefix ll1; leaf x {default test; type string;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll1 {namespace urn:ll1;prefix ll1; leaf x {default test; type string;}"
             "deviation /x {deviate add {mandatory true;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation combining default value and mandatory leaf. /ll1:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /ll1:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll2 {yang-version 1.1; namespace urn:ll2;prefix ll2; leaf-list x {default test; type string;}"
+    /*CHECK_LOG_CTX("Invalid deviation combining default value and mandatory leaf.", "/ll1:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ll1:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll2 {yang-version 1.1; namespace urn:ll2;prefix ll2; leaf-list x {default test; type string;}"
             "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation combining default value and mandatory leaf-list. /ll2:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /ll2:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module ll2 {namespace urn:ll2;prefix ll2; choice ch {default a; leaf a {type string;} leaf b {type string;}}"
+    /*CHECK_LOG_CTX("Invalid deviation combining default value and mandatory leaf-list.", "/ll2:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ll2:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll2 {namespace urn:ll2;prefix ll2; choice ch {default a; leaf a {type string;} leaf b {type string;}}"
             "deviation /ch {deviate add {mandatory true;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid deviation combining default case and mandatory choice. /ll2:{deviation='/ch'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /ll2:ch");
+    /*CHECK_LOG_CTX("Invalid deviation combining default case and mandatory choice.", "/ll2:{deviation='/ch'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ll2:ch");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm1 {namespace urn:mm1;prefix mm1; leaf-list x {min-elements 10; type string;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm1 {namespace urn:mm1;prefix mm1; leaf-list x {min-elements 10; type string;}"
             "deviation /x {deviate add {max-elements 5;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 10 is bigger than max value 5. /mm1:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /mm1:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm2 {namespace urn:mm2;prefix mm2; leaf-list x {max-elements 10; type string;}"
+    /*CHECK_LOG_CTX("Invalid combination of min-elements and max-elements after deviation: min value 10 is bigger than max value 5.", "/mm1:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm1:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm2 {namespace urn:mm2;prefix mm2; leaf-list x {max-elements 10; type string;}"
             "deviation /x {deviate add {min-elements 20;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 20 is bigger than max value 10. /mm2:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /mm2:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm3 {namespace urn:mm3;prefix mm3; list x {min-elements 5; max-elements 10; config false;}"
+    /*CHECK_LOG_CTX("Invalid combination of min-elements and max-elements after deviation: min value 20 is bigger than max value 10.", "/mm2:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm2:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm3 {namespace urn:mm3;prefix mm3; list x {min-elements 5; max-elements 10; config false;}"
             "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 5 is bigger than max value 1. /mm3:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /mm3:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm4 {namespace urn:mm4;prefix mm4; list x {min-elements 5; max-elements 10; config false;}"
+    /*CHECK_LOG_CTX("Invalid combination of min-elements and max-elements after deviation: min value 5 is bigger than max value 1.", "/mm3:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm3:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm4 {namespace urn:mm4;prefix mm4; list x {min-elements 5; max-elements 10; config false;}"
             "deviation /x {deviate replace {min-elements 20;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Invalid combination of min-elements and max-elements after deviation: min value 20 is bigger than max value 10. /mm4:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /mm4:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm5 {namespace urn:mm5;prefix mm5; leaf-list x {type string; min-elements 5;}"
+    /*CHECK_LOG_CTX("Invalid combination of min-elements and max-elements after deviation: min value 20 is bigger than max value 10.", "/mm4:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm4:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm5 {namespace urn:mm5;prefix mm5; leaf-list x {type string; min-elements 5;}"
             "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"min-elements\" property which already exists (with value \"5\"). /mm5:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm6 {namespace urn:mm6;prefix mm6; list x {config false; min-elements 5;}"
+    CHECK_LOG_CTX("Invalid deviation adding \"min-elements\" property which already exists (with value \"5\").", "/mm5:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm6 {namespace urn:mm6;prefix mm6; list x {config false; min-elements 5;}"
             "deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"min-elements\" property which already exists (with value \"5\"). /mm6:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm7 {namespace urn:mm7;prefix mm7; leaf-list x {type string; max-elements 5;}"
+    CHECK_LOG_CTX("Invalid deviation adding \"min-elements\" property which already exists (with value \"5\").", "/mm6:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm7 {namespace urn:mm7;prefix mm7; leaf-list x {type string; max-elements 5;}"
             "deviation /x {deviate add {max-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\"). /mm7:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm8 {namespace urn:mm8;prefix mm8; list x {config false; max-elements 5;}"
+    CHECK_LOG_CTX("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\").", "/mm7:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm8 {namespace urn:mm8;prefix mm8; list x {config false; max-elements 5;}"
             "deviation /x {deviate add {max-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\"). /mm8:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm9 {namespace urn:mm9;prefix mm9; leaf-list x {type string;}"
+    CHECK_LOG_CTX("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\").", "/mm8:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm9 {namespace urn:mm9;prefix mm9; leaf-list x {type string;}"
             "deviation /x {deviate replace {min-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation replacing \"min-elements\" property which is not present. /mm9:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm10 {namespace urn:mm10;prefix mm10; list x {config false;}"
+    CHECK_LOG_CTX("Invalid deviation replacing \"min-elements\" property which is not present.", "/mm9:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm10 {namespace urn:mm10;prefix mm10; list x {config false;}"
             "deviation /x {deviate replace {min-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation replacing \"min-elements\" property which is not present. /mm10:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm11 {namespace urn:mm11;prefix mm11; leaf-list x {type string;}"
+    CHECK_LOG_CTX("Invalid deviation replacing \"min-elements\" property which is not present.", "/mm10:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm11 {namespace urn:mm11;prefix mm11; leaf-list x {type string;}"
             "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation replacing \"max-elements\" property which is not present. /mm11:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module mm12 {namespace urn:mm12;prefix mm12; list x {config false; }"
+    CHECK_LOG_CTX("Invalid deviation replacing \"max-elements\" property which is not present.", "/mm11:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm12 {namespace urn:mm12;prefix mm12; list x {config false; }"
             "deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation replacing \"max-elements\" property which is not present. /mm12:{deviation='/x'}");
+    CHECK_LOG_CTX("Invalid deviation replacing \"max-elements\" property which is not present.", "/mm12:{deviation='/x'}");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module nn1 {namespace urn:nn1;prefix nn1; anyxml x;"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module nn1 {namespace urn:nn1;prefix nn1; anyxml x;"
             "deviation /x {deviate replace {type string;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid deviation of anyxml node - it is not possible to replace \"type\" property. /nn1:{deviation='/x'}");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module nn2 {namespace urn:nn2;prefix nn2; leaf-list x {type string;}"
+    CHECK_LOG_CTX("Invalid deviation of anyxml node - it is not possible to replace \"type\" property.", "/nn1:{deviation='/x'}");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module nn2 {namespace urn:nn2;prefix nn2; leaf-list x {type string;}"
             "deviation /x {deviate replace {type empty;}}}", LYS_IN_YANG, &mod));
-    /*logbuf_assert("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules. /nn2:{deviation='/x'}");*/
-    logbuf_assert("Compilation of a deviated and/or refined node failed. /nn2:x");
+    /*CHECK_LOG_CTX("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules.", "/nn2:{deviation='/x'}");*/
+    CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/nn2:x");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo1 {namespace urn:oo1;prefix oo1; leaf x {type uint16; default 300;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo1 {namespace urn:oo1;prefix oo1; leaf x {type uint16; default 300;}"
             "deviation /x {deviate replace {type uint8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid default - value does not fit the type "
-            "(Value \"300\" is out of uint8's min/max bounds.). /oo1:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo2 {yang-version 1.1;namespace urn:oo2;prefix oo2; leaf-list x {type uint16; default 10; default 300;}"
+    CHECK_LOG_CTX("Invalid default - value does not fit the type "
+            "(Value \"300\" is out of uint8's min/max bounds.).", "/oo1:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo2 {yang-version 1.1;namespace urn:oo2;prefix oo2; leaf-list x {type uint16; default 10; default 300;}"
             "deviation /x {deviate replace {type uint8;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid default - value does not fit the type "
-            "(Value \"300\" is out of uint8's min/max bounds.). /oo2:x");
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module oo3 {namespace urn:oo3;prefix oo3; leaf x {type uint8;}"
+    CHECK_LOG_CTX("Invalid default - value does not fit the type "
+            "(Value \"300\" is out of uint8's min/max bounds.).", "/oo2:x");
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo3 {namespace urn:oo3;prefix oo3; leaf x {type uint8;}"
             "deviation /x {deviate add {default 300;}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid default - value does not fit the type "
-            "(Value \"300\" is out of uint8's min/max bounds.). /oo3:x");
+    CHECK_LOG_CTX("Invalid default - value does not fit the type "
+            "(Value \"300\" is out of uint8's min/max bounds.).", "/oo3:x");
 
-    assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, "module pp {namespace urn:pp;prefix pp; leaf l { type leafref {path /c/x;}}"
+    assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module pp {namespace urn:pp;prefix pp; leaf l { type leafref {path /c/x;}}"
             "container c {leaf x {type string;} leaf y {type string;}}}", LYS_IN_YANG, &mod));
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module pp1 {namespace urn:pp1;prefix pp1; import pp {prefix pp;}"
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module pp1 {namespace urn:pp1;prefix pp1; import pp {prefix pp;}"
             "deviation /pp:c/pp:x {deviate not-supported;}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Not found node \"x\" in path. /pp:l");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("Not found node \"x\" in path.", "/pp:l");
 }
 
 static void
 test_when(void **state)
 {
-    *state = test_when;
-
-    struct ly_ctx *ctx;
-
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
-
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
             "module a {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -3376,9 +3112,9 @@
             "    }\n"
             "}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("When condition of \"val\" includes a self-reference (referenced by when of \"cont2\"). /a:cont/lst/val");
+    CHECK_LOG_CTX("When condition of \"val\" includes a self-reference (referenced by when of \"cont2\").", "/a:cont/lst/val");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
             "module a {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -3404,9 +3140,9 @@
             "    }\n"
             "}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("When condition of \"val\" includes a self-reference (referenced by when of \"cont2\"). /a:cont/lst/val");
+    CHECK_LOG_CTX("When condition of \"val\" includes a self-reference (referenced by when of \"cont2\").", "/a:cont/lst/val");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
             "module a {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -3416,9 +3152,9 @@
             "    }\n"
             "}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("When condition of \"val\" is accessing its own conditional node. /a:val");
+    CHECK_LOG_CTX("When condition of \"val\" is accessing its own conditional node.", "/a:val");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
             "module a {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -3432,9 +3168,9 @@
             "    }\n"
             "}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("When condition of \"val\" is accessing its own conditional node. /a:val");
+    CHECK_LOG_CTX("When condition of \"val\" is accessing its own conditional node.", "/a:val");
 
-    assert_int_equal(LY_EVALID, lys_parse_mem(ctx,
+    assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
             "module a {\n"
             "    namespace urn:a;\n"
             "    prefix a;\n"
@@ -3447,44 +3183,41 @@
             "    container cont;\n"
             "}",
             LYS_IN_YANG, NULL));
-    logbuf_assert("When condition of \"val\" is accessing its own conditional node. /a:cont/val");
-
-    *state = NULL;
-    ly_ctx_destroy(ctx, NULL);
+    CHECK_LOG_CTX("When condition of \"val\" is accessing its own conditional node.", "/a:cont/val");
 }
 
 int
 main(void)
 {
     const struct CMUnitTest tests[] = {
-        cmocka_unit_test_setup_teardown(test_module, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_name_collisions, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_length, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_range, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_pattern, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_enum, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_bits, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_dec64, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_instanceid, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_identityref, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_leafref, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_empty, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_union, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_type_dflt, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_status, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_node_container, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_node_leaflist, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_node_list, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_node_choice, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_node_anydata, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_action, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_notification, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_grouping, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_uses, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_refine, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_augment, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_deviation, logger_setup, logger_teardown),
-        cmocka_unit_test_setup_teardown(test_when, logger_setup, logger_teardown),
+        UTEST(test_module, setup),
+        UTEST(test_name_collisions, setup),
+        UTEST(test_type_length, setup),
+        UTEST(test_type_range, setup),
+        UTEST(test_type_pattern, setup),
+        UTEST(test_type_enum, setup),
+        UTEST(test_type_bits, setup),
+        UTEST(test_type_dec64, setup),
+        UTEST(test_type_instanceid, setup),
+        UTEST(test_type_identityref, setup),
+        UTEST(test_type_leafref, setup),
+        UTEST(test_type_empty, setup),
+        UTEST(test_type_union, setup),
+        UTEST(test_type_dflt, setup),
+        UTEST(test_status, setup),
+        UTEST(test_node_container, setup),
+        UTEST(test_node_leaflist, setup),
+        UTEST(test_node_list, setup),
+        UTEST(test_node_choice, setup),
+        UTEST(test_node_anydata, setup),
+        UTEST(test_action, setup),
+        UTEST(test_notification, setup),
+        UTEST(test_grouping, setup),
+        UTEST(test_uses, setup),
+        UTEST(test_refine, setup),
+        UTEST(test_augment, setup),
+        UTEST(test_deviation, setup),
+        UTEST(test_when, setup),
     };
 
     return cmocka_run_group_tests(tests, NULL, NULL);