]>
git.proxmox.com Git - mirror_lxc.git/blob - src/tests/list.c
3 * Copyright © 2013 Canonical, Inc
4 * Author: Serge Hallyn <serge.hallyn@ubuntu.com>
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.
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.
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.
23 #include <lxc/lxccontainer.h>
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
))
30 struct lxc_container
**clist
;
33 printf("%-10s Counting containers\n", type
);
35 n
= func(lxcpath
, NULL
, NULL
);
36 printf("%-10s Counted %d containers\n", type
, n
);
37 printf("%-10s Get container struct only\n", type
);
39 n2
= func(lxcpath
, NULL
, &clist
);
41 printf("Warning: first call returned %d, second %d\n", n
, n2
);
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
);
54 printf("%-10s Get names only\n", type
);
55 n2
= func(lxcpath
, &names
, NULL
);
57 printf("Warning: first call returned %d, second %d\n", n
, n2
);
59 for (i
= 0; i
< n2
; i
++) {
60 printf("%-10s Got container name %s\n", type
, names
[i
]);
69 printf("%-10s Get names and containers\n", type
);
70 n2
= func(lxcpath
, &names
, &clist
);
72 printf("Warning: first call returned %d, second %d\n", n
, n2
);
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
]);
78 if (strcmp(c
->name
, names
[i
]))
79 fprintf(stderr
, "ERROR: name mismatch!\n");
91 int main(int argc
, char *argv
[])
93 const char *lxcpath
= NULL
;
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
);