Skip to content

Commit ec49b80

Browse files
fredrik-perssonmichalvasko
authored andcommitted
tests UPDATE perf cases for validation producing a diff
perf.yang declares no defaults and no when conditions, and test_validate passes NULL for the diff, so lyd_val_diff_add() is never reached and the cost of building a validation diff is not measured anywhere. Add perf_dflt.yang, where every list instance offers four alternative sets of defaults gated on the same leaf, so only one set can ever apply. Two cases validate that data, one asking for a diff and one not.
1 parent f1a86c1 commit ec49b80

2 files changed

Lines changed: 528 additions & 0 deletions

File tree

‎tests/perf/perf.c‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,78 @@ setup_data_offset_tree(const struct lys_module *mod, uint32_t count, struct test
342342
}
343343

344344
/* TEST CB */
345+
static LY_ERR
346+
setup_data_dflt_tree(const struct lys_module *mod, uint32_t count, struct test_state *state)
347+
{
348+
const struct lys_module *dflt_mod;
349+
struct lyd_node *parent;
350+
char buf[64];
351+
uint32_t i;
352+
LY_ERR r;
353+
354+
state->count = count;
355+
356+
dflt_mod = ly_ctx_get_module_implemented(mod->ctx, "perf_dflt");
357+
if (!dflt_mod) {
358+
return LY_ENOTFOUND;
359+
}
360+
state->mod = dflt_mod;
361+
362+
for (i = 0; i < count; ++i) {
363+
sprintf(buf, "/perf_dflt:cont/lst[k='%" PRIu32 "']", i);
364+
if ((r = lyd_new_path(state->data1, mod->ctx, buf, NULL, 0, &parent))) {
365+
return r;
366+
}
367+
if (!state->data1) {
368+
state->data1 = parent;
369+
}
370+
371+
sprintf(buf, "/perf_dflt:cont/lst[k='%" PRIu32 "']/type", i);
372+
if ((r = lyd_new_path(state->data1, mod->ctx, buf, "a", 0, NULL))) {
373+
return r;
374+
}
375+
}
376+
377+
return LY_SUCCESS;
378+
}
379+
380+
static LY_ERR
381+
test_validate_dflt(struct test_state *state, struct timespec *ts_start, struct timespec *ts_end, uint32_t *size)
382+
{
383+
LY_ERR r;
384+
385+
*size = 0;
386+
TEST_START(ts_start);
387+
388+
if ((r = lyd_validate_all(&state->data1, NULL, LYD_VALIDATE_PRESENT, NULL))) {
389+
return r;
390+
}
391+
392+
TEST_END(ts_end);
393+
394+
return LY_SUCCESS;
395+
}
396+
397+
static LY_ERR
398+
test_validate_dflt_diff(struct test_state *state, struct timespec *ts_start, struct timespec *ts_end, uint32_t *size)
399+
{
400+
struct lyd_node *diff = NULL;
401+
LY_ERR r;
402+
403+
*size = 0;
404+
TEST_START(ts_start);
405+
406+
if ((r = lyd_validate_all(&state->data1, NULL, LYD_VALIDATE_PRESENT, &diff))) {
407+
return r;
408+
}
409+
410+
TEST_END(ts_end);
411+
412+
lyd_free_siblings(diff);
413+
414+
return LY_SUCCESS;
415+
}
416+
345417
static LY_ERR
346418
test_create_new_text(struct test_state *state, struct timespec *ts_start, struct timespec *ts_end, uint32_t *size)
347419
{
@@ -820,6 +892,8 @@ struct test tests[] = {
820892
{"create new text", setup_basic, test_create_new_text},
821893
{"create path", setup_basic, test_create_path},
822894
{"validate", setup_data_single_tree, test_validate},
895+
{"validate defaults", setup_data_dflt_tree, test_validate_dflt},
896+
{"validate defaults diff", setup_data_dflt_tree, test_validate_dflt_diff},
823897
{"parse xml mem validate", setup_data_single_tree, test_parse_xml_mem_validate},
824898
{"parse xml mem no validate", setup_data_single_tree, test_parse_xml_mem_no_validate},
825899
{"parse xml file no validate format", setup_data_single_tree, test_parse_xml_file_no_validate_format},
@@ -887,6 +961,10 @@ main(int argc, char **argv)
887961
ret = LY_ENOTFOUND;
888962
goto cleanup;
889963
}
964+
if (!ly_ctx_load_module(ctx, "perf_dflt", NULL, NULL)) {
965+
ret = LY_ENOTFOUND;
966+
goto cleanup;
967+
}
890968

891969
/* tests */
892970
name_len = 0;

0 commit comments

Comments
 (0)