blob: bc896f40a75ed70f60b5edc2ed93794a664afeee [file] [log] [blame]
Radek Krejci54f6fb32016-02-24 12:56:39 +01001/**
2 * @file addloop.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief performance test - adding data.
5 *
6 * Copyright (c) 2016 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
Radek Krejcia9c8ce72016-01-21 17:25:56 +010015#include <stdio.h>
16#include <string.h>
17#include <sys/types.h>
18#include <sys/stat.h>
19#include <fcntl.h>
20#include <unistd.h>
21
22#include <libyang/libyang.h>
23
24int main(int argc, char *argv[])
25{
26 int fd, i;
27 struct ly_ctx *ctx = NULL;
28 char buf[30];
29 struct lyd_node *data = NULL, *next;
30 const struct lys_module *mod;
31
32 /* libyang context */
Radek Krejcidd3263a2017-07-15 11:50:09 +020033 ctx = ly_ctx_new(NULL, 0);
Radek Krejcia9c8ce72016-01-21 17:25:56 +010034 if (!ctx) {
35 fprintf(stderr, "Failed to create context.\n");
36 return 1;
37 }
38
39 /* schema */
40 if (!(mod = lys_parse_path(ctx, argv[1], LYS_IN_YIN))) {
41 fprintf(stderr, "Failed to load data model.\n");
42 goto cleanup;
43 }
44
45 /* data */
46 data = NULL;
47 fd = open("./addloop_result.xml", O_WRONLY | O_CREAT, 0666);
48 data = NULL;
49 for(i = 1; i <= 5000; i++) {
50 next = lyd_new(NULL, mod, "ptest1");
51 // if (i == 2091) {sprintf(buf, "%d", 1);} else {
52 sprintf(buf, "%d", i);//}
53 lyd_new_leaf(next, mod, "index", buf);
54 lyd_new_leaf(next, mod, "p1", buf);
55 if (!data) {
56 data = next;
57 } else {
58 lyd_insert_after(data->prev, next);
59 }
Radek Krejcib2a2be92016-10-06 15:02:09 +020060 if (lyd_validate(&data, LYD_OPT_CONFIG, NULL)) {
Radek Krejcia9c8ce72016-01-21 17:25:56 +010061 goto cleanup;
62 }
63 //lyd_print_fd(fd, data, LYD_XML);
64 }
Radek Krejci4026ad62016-08-08 14:16:31 +020065 lyd_print_fd(fd, data, LYD_XML, LYP_WITHSIBLINGS | LYP_FORMAT);
Radek Krejcia9c8ce72016-01-21 17:25:56 +010066 close(fd);
67
68cleanup:
69 lyd_free_withsiblings(data);
Radek Krejci7fbaacb2016-02-12 12:18:53 +010070 ly_ctx_destroy(ctx, NULL);
Radek Krejcia9c8ce72016-01-21 17:25:56 +010071
72 return 0;
73}