]>
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.
25 #include <lxc/lxccontainer.h>
27 static void test_list_func(const char *lxcpath
, const char *type
,
28 int (*func
)(const char *path
, char ***names
,
29 struct lxc_container
***cret
))
32 struct lxc_container
**clist
;
35 printf("%-10s Counting containers\n", type
);
37 n
= func(lxcpath
, NULL
, NULL
);
38 printf("%-10s Counted %d containers\n", type
, n
);
39 printf("%-10s Get container struct only\n", type
);
41 n2
= func(lxcpath
, NULL
, &clist
);
43 printf("Warning: first call returned %d, second %d\n", n
, n2
);
45 for (i
= 0; i
< n2
; i
++) {
46 struct lxc_container
*c
= clist
[i
];
47 printf("%-10s Got container struct %s\n", type
, c
->name
);
56 printf("%-10s Get names only\n", type
);
57 n2
= func(lxcpath
, &names
, NULL
);
59 printf("Warning: first call returned %d, second %d\n", n
, n2
);
61 for (i
= 0; i
< n2
; i
++) {
62 printf("%-10s Got container name %s\n", type
, names
[i
]);
71 printf("%-10s Get names and containers\n", type
);
72 n2
= func(lxcpath
, &names
, &clist
);
74 printf("Warning: first call returned %d, second %d\n", n
, n2
);
76 for (i
= 0; i
< n2
; i
++) {
77 struct lxc_container
*c
= clist
[i
];
78 printf("%-10s Got container struct %s, name %s\n", type
, c
->name
, names
[i
]);
80 if (strcmp(c
->name
, names
[i
]))
81 fprintf(stderr
, "ERROR: name mismatch!\n");
93 int main(int argc
, char *argv
[])
95 const char *lxcpath
= NULL
;
100 test_list_func(lxcpath
, "Defined:", list_defined_containers
);
101 test_list_func(lxcpath
, "Active:", list_active_containers
);
102 test_list_func(lxcpath
, "All:", list_all_containers
);