Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 1 | /** |
| 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 Krejci | a9c8ce7 | 2016-01-21 17:25:56 +0100 | [diff] [blame] | 15 | #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 | |
| 24 | int 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 */ |
| 33 | ctx = ly_ctx_new(NULL); |
| 34 | 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 Krejci | 4026ad6 | 2016-08-08 14:16:31 +0200 | [diff] [blame^] | 60 | if (lyd_validate(&data, LYD_OPT_CONFIG)) { |
Radek Krejci | a9c8ce7 | 2016-01-21 17:25:56 +0100 | [diff] [blame] | 61 | goto cleanup; |
| 62 | } |
| 63 | //lyd_print_fd(fd, data, LYD_XML); |
| 64 | } |
Radek Krejci | 4026ad6 | 2016-08-08 14:16:31 +0200 | [diff] [blame^] | 65 | lyd_print_fd(fd, data, LYD_XML, LYP_WITHSIBLINGS | LYP_FORMAT); |
Radek Krejci | a9c8ce7 | 2016-01-21 17:25:56 +0100 | [diff] [blame] | 66 | close(fd); |
| 67 | |
| 68 | cleanup: |
| 69 | lyd_free_withsiblings(data); |
Radek Krejci | 7fbaacb | 2016-02-12 12:18:53 +0100 | [diff] [blame] | 70 | ly_ctx_destroy(ctx, NULL); |
Radek Krejci | a9c8ce7 | 2016-01-21 17:25:56 +0100 | [diff] [blame] | 71 | |
| 72 | return 0; |
| 73 | } |