blob: 9428c2269aa5c5d3fb4591a79e6ad6afae4225fa [file] [log] [blame]
Michal Vaskocd958c62017-11-03 16:33:59 +01001#define _GNU_SOURCE
Michal Vasko22fdd752017-10-24 09:02:52 +02002
Michal Vaskocd958c62017-11-03 16:33:59 +01003#include <stdio.h>
4#include <stdlib.h>
5#include <valgrind/callgrind.h>
6
7#include "tests/config.h"
Jan Kundrátfd7a5c72017-10-26 17:45:06 +02008#include "libyang.h"
Michal Vasko22fdd752017-10-24 09:02:52 +02009
10int
11main(int argc, char **argv)
12{
13 int i;
Michal Vaskocd958c62017-11-03 16:33:59 +010014 char *path;
Michal Vasko22fdd752017-10-24 09:02:52 +020015 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 Vaskocd958c62017-11-03 16:33:59 +010028 asprintf(&path, "%s/callgrind/files/%s", TESTS_DIR, argv[i]);
29 if (!lys_parse_path(ctx, path, LYS_YANG)) {
30 free(path);
Michal Vasko22fdd752017-10-24 09:02:52 +020031 ly_ctx_destroy(ctx, NULL);
32 return 1;
33 }
Michal Vaskocd958c62017-11-03 16:33:59 +010034 free(path);
Michal Vasko22fdd752017-10-24 09:02:52 +020035 }
36
Michal Vaskocd958c62017-11-03 16:33:59 +010037 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 Vasko22fdd752017-10-24 09:02:52 +020044 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}