]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/list.c
spelling: timeout
[mirror_lxc.git] / src / tests / list.c
1 /* list.c
2 *
3 * Copyright © 2013 Canonical, Inc
4 * Author: Serge Hallyn <serge.hallyn@ubuntu.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <lxc/lxccontainer.h>
24
25 static void test_list_func(const char *lxcpath, const char *type,
26 int (*func)(const char *path, char ***names,
27 struct lxc_container ***cret))
28 {
29 int i, n, n2;
30 struct lxc_container **clist;
31 char **names;
32
33 printf("%-10s Counting containers\n", type);
34
35 n = func(lxcpath, NULL, NULL);
36 printf("%-10s Counted %d containers\n", type, n);
37 printf("%-10s Get container struct only\n", type);
38
39 n2 = func(lxcpath, NULL, &clist);
40 if (n2 != n)
41 printf("Warning: first call returned %d, second %d\n", n, n2);
42
43 for (i = 0; i < n2; i++) {
44 struct lxc_container *c = clist[i];
45 printf("%-10s Got container struct %s\n", type, c->name);
46 lxc_container_put(c);
47 }
48
49 if (n2 > 0) {
50 free(clist);
51 clist = NULL;
52 }
53
54 printf("%-10s Get names only\n", type);
55 n2 = func(lxcpath, &names, NULL);
56 if (n2 != n)
57 printf("Warning: first call returned %d, second %d\n", n, n2);
58
59 for (i = 0; i < n2; i++) {
60 printf("%-10s Got container name %s\n", type, names[i]);
61 free(names[i]);
62 }
63
64 if (n2 > 0) {
65 free(names);
66 names = NULL;
67 }
68
69 printf("%-10s Get names and containers\n", type);
70 n2 = func(lxcpath, &names, &clist);
71 if (n2 != n)
72 printf("Warning: first call returned %d, second %d\n", n, n2);
73
74 for (i = 0; i < n2; i++) {
75 struct lxc_container *c = clist[i];
76 printf("%-10s Got container struct %s, name %s\n", type, c->name, names[i]);
77
78 if (strcmp(c->name, names[i]))
79 fprintf(stderr, "ERROR: name mismatch!\n");
80
81 free(names[i]);
82 lxc_container_put(c);
83 }
84
85 if (n2 > 0) {
86 free(names);
87 free(clist);
88 }
89 }
90
91 int main(int argc, char *argv[])
92 {
93 const char *lxcpath = NULL;
94
95 if (argc > 1)
96 lxcpath = argv[1];
97
98 test_list_func(lxcpath, "Defined:", list_defined_containers);
99 test_list_func(lxcpath, "Active:", list_active_containers);
100 test_list_func(lxcpath, "All:", list_all_containers);
101
102 exit(0);
103 }