Michal Vasko | cd958c6 | 2017-11-03 16:33:59 +0100 | [diff] [blame] | 1 | #define _GNU_SOURCE |
Michal Vasko | 22fdd75 | 2017-10-24 09:02:52 +0200 | [diff] [blame] | 2 | |
Michal Vasko | cd958c6 | 2017-11-03 16:33:59 +0100 | [diff] [blame] | 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <valgrind/callgrind.h> |
| 6 | |
| 7 | #include "tests/config.h" |
Jan Kundrát | fd7a5c7 | 2017-10-26 17:45:06 +0200 | [diff] [blame] | 8 | #include "libyang.h" |
Michal Vasko | 22fdd75 | 2017-10-24 09:02:52 +0200 | [diff] [blame] | 9 | |
| 10 | int |
| 11 | main(int argc, char **argv) |
| 12 | { |
| 13 | int i; |
Michal Vasko | cd958c6 | 2017-11-03 16:33:59 +0100 | [diff] [blame] | 14 | char *path; |
Michal Vasko | 22fdd75 | 2017-10-24 09:02:52 +0200 | [diff] [blame] | 15 | struct ly_ctx *ctx; |
| 16 | struct lyd_node *data; |
| 17 | |
| 18 | if (argc < 3) { |
| 19 | return 1; |
| 20 | } |
| 21 | |
| 22 | ctx = ly_ctx_new(NULL, 0); |
| 23 | if (!ctx) { |
| 24 | return 1; |
| 25 | } |
| 26 | |
| 27 | for (i = 1; i < argc - 1; ++i) { |
Michal Vasko | cd958c6 | 2017-11-03 16:33:59 +0100 | [diff] [blame] | 28 | asprintf(&path, "%s/callgrind/files/%s", TESTS_DIR, argv[i]); |
| 29 | if (!lys_parse_path(ctx, path, LYS_YANG)) { |
| 30 | free(path); |
Michal Vasko | 22fdd75 | 2017-10-24 09:02:52 +0200 | [diff] [blame] | 31 | ly_ctx_destroy(ctx, NULL); |
| 32 | return 1; |
| 33 | } |
Michal Vasko | cd958c6 | 2017-11-03 16:33:59 +0100 | [diff] [blame] | 34 | free(path); |
Michal Vasko | 22fdd75 | 2017-10-24 09:02:52 +0200 | [diff] [blame] | 35 | } |
| 36 | |
Michal Vasko | cd958c6 | 2017-11-03 16:33:59 +0100 | [diff] [blame] | 37 | asprintf(&path, "%s/callgrind/files/%s", TESTS_DIR, argv[argc - 1]); |
| 38 | |
| 39 | CALLGRIND_START_INSTRUMENTATION; |
| 40 | data = lyd_parse_path(ctx, path, LYD_XML, LYD_OPT_STRICT | LYD_OPT_DATA_NO_YANGLIB); |
| 41 | CALLGRIND_STOP_INSTRUMENTATION; |
| 42 | |
| 43 | free(path); |
Michal Vasko | 22fdd75 | 2017-10-24 09:02:52 +0200 | [diff] [blame] | 44 | if (!data) { |
| 45 | ly_ctx_destroy(ctx, NULL); |
| 46 | return 1; |
| 47 | } |
| 48 | |
| 49 | lyd_free_withsiblings(data); |
| 50 | ly_ctx_destroy(ctx, NULL); |
| 51 | return 0; |
| 52 | } |