]> git.proxmox.com Git - mirror_lxc.git/blame - src/tests/createtest.c
tests: use busybox in lxc-test-unpriv
[mirror_lxc.git] / src / tests / createtest.c
CommitLineData
72d0e1cb
SG
1/* liblxcapi
2 *
3 * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
4 * Copyright © 2012 Canonical Ltd.
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 */
948955a2 19#include <lxc/lxccontainer.h>
72d0e1cb
SG
20
21#include <unistd.h>
22#include <signal.h>
23#include <stdio.h>
24#include <sys/types.h>
25#include <sys/wait.h>
26#include <stdlib.h>
27#include <errno.h>
28
29#define MYNAME "lxctest1"
30
31int main(int argc, char *argv[])
32{
33 struct lxc_container *c;
34 int ret = 1;
35
afeecbba 36 if ((c = lxc_container_new(MYNAME, NULL)) == NULL) {
72d0e1cb
SG
37 fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
38 ret = 1;
39 goto out;
40 }
41
42 if (c->is_defined(c)) {
43 fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME);
44 goto out;
45 }
46
7fa3f2e9 47 if (!c->set_config_item(c, "lxc.net.0.type", "veth")) {
72d0e1cb
SG
48 fprintf(stderr, "%d: failed to set network type\n", __LINE__);
49 goto out;
50 }
56aff0c4 51
7fa3f2e9 52 c->set_config_item(c, "lxc.net.0.link", "lxcbr0");
53 c->set_config_item(c, "lxc.net.0.flags", "up");
56aff0c4 54
787c3ebe 55 if (!c->createl(c, "busybox", NULL, NULL, 0, NULL)) {
e403a064 56 fprintf(stderr, "%d: failed to create a trusty container\n", __LINE__);
72d0e1cb
SG
57 goto out;
58 }
59
60 if (!c->is_defined(c)) {
61 fprintf(stderr, "%d: %s thought it was not defined\n", __LINE__, MYNAME);
62 goto out;
63 }
64
80a873c2 65 c->clear_config(c);
72d0e1cb 66 c->load_config(c, NULL);
540f932a 67 c->want_daemonize(c, true);
56aff0c4 68
72d0e1cb
SG
69 if (!c->startl(c, 0, NULL)) {
70 fprintf(stderr, "%d: failed to start %s\n", __LINE__, MYNAME);
71 goto out;
72 }
72d0e1cb
SG
73
74 if (!c->stop(c)) {
75 fprintf(stderr, "%d: failed to stop %s\n", __LINE__, MYNAME);
76 goto out;
77 }
78
79 if (!c->destroy(c)) {
80 fprintf(stderr, "%d: error deleting %s\n", __LINE__, MYNAME);
81 goto out;
82 }
83
84 if (c->is_defined(c)) {
85 fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME);
86 goto out;
87 }
88
89 fprintf(stderr, "all lxc_container tests passed for %s\n", c->name);
90 ret = 0;
56aff0c4 91
72d0e1cb
SG
92out:
93 lxc_container_put(c);
94 exit(ret);
95}