]>
git.proxmox.com Git - mirror_lxc.git/blob - src/tests/state_server.c
3 * Copyright © 2017 Christian Brauner <christian.brauner@ubuntu.com>.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2, as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <sys/reboot.h>
30 #include <sys/types.h>
33 #include "lxc/lxccontainer.h"
35 #include "../lxc/compiler.h"
41 struct lxc_container
*c
;
44 __noreturn
static void *state_wrapper(void *data
)
46 struct thread_args
*args
= data
;
48 lxc_debug("Starting state server thread %d\n", args
->thread_id
);
50 args
->success
= args
->c
->shutdown(args
->c
, args
->timeout
);
52 lxc_debug("State server thread %d with shutdown timeout %d returned \"%s\"\n",
53 args
->thread_id
, args
->timeout
, args
->success
? "SUCCESS" : "FAILED");
58 int main(int argc
, char *argv
[])
62 pthread_t threads
[10];
63 struct thread_args args
[10];
64 struct lxc_container
*c
;
65 int ret
= EXIT_FAILURE
;
67 c
= lxc_container_new("state-server", NULL
);
69 lxc_error("%s", "Failed to create container \"state-server\"");
73 if (c
->is_defined(c
)) {
74 lxc_error("%s\n", "Container \"state-server\" is defined");
78 if (!c
->createl(c
, "busybox", NULL
, NULL
, 0, NULL
)) {
79 lxc_error("%s\n", "Failed to create busybox container \"state-server\"");
83 if (!c
->is_defined(c
)) {
84 lxc_error("%s\n", "Container \"state-server\" is not defined");
90 if (!c
->load_config(c
, NULL
)) {
91 lxc_error("%s\n", "Failed to load config for container \"state-server\"");
95 if (!c
->want_daemonize(c
, true)) {
96 lxc_error("%s\n", "Failed to mark container \"state-server\" daemonized");
100 pthread_attr_init(&attr
);
102 for (j
= 0; j
< 10; j
++) {
103 lxc_debug("Starting state server test iteration %d\n", j
);
105 if (!c
->startl(c
, 0, NULL
)) {
106 lxc_error("%s\n", "Failed to start container \"state-server\" daemonized");
112 for (i
= 0; i
< 10; i
++) {
113 args
[i
].thread_id
= i
;
115 args
[i
].timeout
= -1;
116 /* test non-blocking shutdown request */
120 ret
= pthread_create(&threads
[i
], &attr
, state_wrapper
, (void *) &args
[i
]);
125 for (i
= 0; i
< 10; i
++) {
126 ret
= pthread_join(threads
[i
], NULL
);
130 if (!args
[i
].success
) {
131 lxc_error("State server thread %d failed\n", args
[i
].thread_id
);
140 if (c
->is_running(c
) && !c
->stop(c
))
141 lxc_error("%s\n", "Failed to stop container \"state-server\"");
144 lxc_error("%s\n", "Failed to destroy container \"state-server\"");
147 lxc_container_put(c
);
148 if (ret
== EXIT_SUCCESS
)
149 lxc_debug("%s\n", "All state server tests passed");