Refactor utests: replace internal functions with API and clean up#2529
Refactor utests: replace internal functions with API and clean up#2529HanzlikPetr wants to merge 5 commits into
Conversation
f01e360 to
953755a
Compare
953755a to
b6a7042
Compare
Roytak
left a comment
There was a problem hiding this comment.
Noticed a couple of possible places for improvement, but very good overall.
| // array coresponds to the following YANG module: | ||
| // module test { namespace "urn:test"; prefix t; description "XXX"; } |
|
|
||
| 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]... */ | ||
| }; | ||
|
|
There was a problem hiding this comment.
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
#definethese values inutests.h(based on a comment inpath.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
|
|
||
| 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]... */ | ||
| }; |
There was a problem hiding this comment.
Related to the comment in instanceid.c.
| #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) |
There was a problem hiding this comment.
This checks seems much weaker, would lysc_get_type_plugin work here possibly?
| */ | ||
|
|
||
| #define UNUSED(x) UNUSED_ ## x __attribute__((__unused__)) | ||
|
|
There was a problem hiding this comment.
I see that the macro UNUSED is defined in compat.h, consider including it instead.
| static void | ||
| test_extension_compile(void **state) | ||
| { | ||
| struct lys_module *mod; |
There was a problem hiding this comment.
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.
| const char *invalid[] = { | ||
| "invalid_path", | ||
| "..[", | ||
| "../", | ||
| "/", | ||
| "../../pref:id/xxx[predicate]/invalid!!!" | ||
| }; |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Why were the values swapped here?
| 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); | ||
| } |
There was a problem hiding this comment.
It seems this test doesn't really test anything now, consider removing/adjusting it.
| #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); \ | ||
| } \ | ||
| } \ | ||
| } |
There was a problem hiding this comment.
See comment in instanceid.c.
No description provided.