Skip to content

Refactor utests: replace internal functions with API and clean up#2529

Open
HanzlikPetr wants to merge 5 commits into
CESNET:develfrom
HanzlikPetr:unit_test_change
Open

Refactor utests: replace internal functions with API and clean up#2529
HanzlikPetr wants to merge 5 commits into
CESNET:develfrom
HanzlikPetr:unit_test_change

Conversation

@HanzlikPetr

Copy link
Copy Markdown

No description provided.

@HanzlikPetr HanzlikPetr changed the title Refactor utests to replace internal functions with API and clean up Refactor utests: replace internal functions with API and clean up Jun 10, 2026

@Roytak Roytak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed a couple of possible places for improvement, but very good overall.

Comment on lines +22 to +23
// array coresponds to the following YANG module:
// module test { namespace "urn:test"; prefix t; description "XXX"; }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use block comment.

Comment on lines +21 to 28

enum ly_path_pred_type {
LY_PATH_PREDTYPE_POSITION, /**< position predicate - [2] */
LY_PATH_PREDTYPE_LIST, /**< keys predicate - [key1='val1'][key2='val2']... */
LY_PATH_PREDTYPE_LEAFLIST, /**< leaflist value predicate - [.='value'] */
LY_PATH_PREDTYPE_LIST_VAR /**< keys predicate with variable instead of value - [key1=$USER]... */
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just copying the enum from path.h verbatim feels very fragile, modifying this enum in path.h would break this test. Also the actual value comparison was removed from CHECK_LYD_VALUE_INST and only the array sizes are used - these values are never used. A plain int array would serve the same purpose. Also this same enum was also copied to union.c. My suggestion is to either:

  • add the value validation back to CHECK_LYD_VALUE_INST and #define these values in utests.h (based on a comment in path.h: "/**< Predicate type (see YANG ABNF) */", it would seem that these values are standardized, but I am not sure about that, you may try to find out more about it)
  • remove the enums from the tests completely, since the values are not checked anyways, and just pass integer arrays to CHECK_LYD_VALUE_INST

Comment on lines +21 to +27

enum ly_path_pred_type {
LY_PATH_PREDTYPE_POSITION, /**< position predicate - [2] */
LY_PATH_PREDTYPE_LIST, /**< keys predicate - [key1='val1'][key2='val2']... */
LY_PATH_PREDTYPE_LEAFLIST, /**< leaflist value predicate - [.='value'] */
LY_PATH_PREDTYPE_LIST_VAR /**< keys predicate with variable instead of value - [key1=$USER]... */
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the comment in instanceid.c.

Comment thread tests/utests/utests.h
Comment on lines 232 to +236
#define CHECK_LYSC_TYPE(NODE, TYPE, EXTS) \
assert_non_null(NODE); \
assert_int_equal((NODE)->basetype, TYPE); \
CHECK_ARRAY((NODE)->exts, EXTS); \
assert_ptr_equal((NODE)->plugin_ref, lyplg_type_plugin_find(NULL, "", NULL, ly_data_type2str[TYPE]))
assert_non_null((NODE)->plugin_ref)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks seems much weaker, would lysc_get_type_plugin work here possibly?

Comment thread tests/utests/utests.h
*/

#define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that the macro UNUSED is defined in compat.h, consider including it instead.

Comment on lines -1670 to -1673
static void
test_extension_compile(void **state)
{
struct lys_module *mod;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this not be rewritten via public API? For example parsing a module with md:annotation containing substatements (or other ext like structure), then inspecting the compiled lysc_ext_instance and verifying the compiled substatement could possibly work.

Comment on lines +1698 to +1704
const char *invalid[] = {
"invalid_path",
"..[",
"../",
"/",
"../../pref:id/xxx[predicate]/invalid!!!"
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why ".." was excluded? It was tested previously.

v1 = "::C:D:E:f:a/96";
type = lysc_get_type_plugin(lysc_type->plugin_ref);
v1 = "::C:D:E:f:a/112";
assert_int_equal(LY_SUCCESS, type->store(UTEST_LYCTX, lysc_type, v1, strlen(v1) * 8,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were the values swapped here?

Comment on lines 1273 to 1289
static void
test_lyds_free_metadata(void **state)
{
const char *schema;
struct lys_module *mod;
struct lyd_node *first, *node;

schema = "module a {namespace urn:tests:a;prefix a;yang-version 1.1;revision 2014-05-08;"
"leaf-list ll {type uint32;}}";
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);

assert_int_equal(lyd_new_term(NULL, mod, "ll", "1", 0, &first), LY_SUCCESS);
assert_int_equal(lyd_new_term(NULL, mod, "ll", "2", 0, &node), LY_SUCCESS);
assert_int_equal(lyd_insert_sibling(first, node, NULL), LY_SUCCESS);
lyds_free_metadata(first);
assert_null(first->meta);
assert_null(node->meta);

lyd_free_all(first);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this test doesn't really test anything now, consider removing/adjusting it.

Comment thread tests/utests/utests.h
Comment on lines 998 to 1006
#define CHECK_LYD_VALUE_INST(NODE, CANNONICAL_VAL, VALUE) \
assert_non_null(lyd_value_get_canonical(UTEST_LYCTX, &(NODE))); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_INST, (NODE).realtype->basetype); \
{ \
LY_ARRAY_COUNT_TYPE arr_size = sizeof(VALUE) / sizeof(VALUE[0]); \
assert_int_equal(arr_size, LY_ARRAY_COUNT((NODE).target)); \
for (LY_ARRAY_COUNT_TYPE it = 0; it < arr_size; it++) { \
if ((NODE).target[it].predicates) { \
assert_int_equal(VALUE[it], (NODE).target[it].predicates[0].type); \
} \
} \
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment in instanceid.c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants