Unverified Commit eedf8b38 by 2xsec Committed by Christian Brauner

tests: cleanup concurrent.c

Signed-off-by: 's avatar2xsec <dh48.jeong@samsung.com>
parent bdad17c8
......@@ -71,13 +71,14 @@ struct thread_args {
static void do_function(void *arguments)
{
char name[NAME_MAX+1];
char name[NAME_MAX + 1];
struct thread_args *args = arguments;
struct lxc_container *c;
sprintf(name, "lxc-test-concurrent-%d", args->thread_id);
args->return_code = 1;
c = lxc_container_new(name, NULL);
if (!c) {
fprintf(stderr, "Unable to instantiate container (%s)\n", name);
......@@ -97,14 +98,17 @@ static void do_function(void *arguments)
} else if(strcmp(args->mode, "start") == 0) {
if (c->is_defined(c) && !c->is_running(c)) {
c->want_daemonize(c, true);
if (!c->start(c, false, NULL)) {
fprintf(stderr, "Starting the container (%s) failed...\n", name);
goto out;
}
if (!c->wait(c, "RUNNING", 15)) {
fprintf(stderr, "Waiting the container (%s) to start failed...\n", name);
goto out;
}
sleep(delay);
}
} else if(strcmp(args->mode, "stop") == 0) {
......@@ -113,6 +117,7 @@ static void do_function(void *arguments)
fprintf(stderr, "Stopping the container (%s) failed...\n", name);
goto out;
}
if (!c->wait(c, "STOPPED", 15)) {
fprintf(stderr, "Waiting the container (%s) to stop failed...\n", name);
goto out;
......@@ -126,9 +131,12 @@ static void do_function(void *arguments)
}
}
}
args->return_code = 0;
out:
lxc_container_put(c);
if (debug)
lxc_log_close();
}
......@@ -189,6 +197,7 @@ int main(int argc, char *argv[]) {
}
modes[i] = tok;
}
if (modes)
modes[i] = NULL;
break;
......@@ -208,6 +217,7 @@ int main(int argc, char *argv[]) {
for (iter = 1; iter <= iterations; iter++) {
int fd;
fd = open("/", O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Failed to open /\n");
......@@ -216,11 +226,13 @@ int main(int argc, char *argv[]) {
if (!quiet)
printf("\nIteration %d/%d maxfd:%d\n", iter, iterations, fd);
close(fd);
for (i = 0; modes[i];i++) {
if (!quiet)
printf("Executing (%s) for %d containers...\n", modes[i], nthreads);
for (j = 0; j < nthreads; j++) {
args[j].thread_id = j;
args[j].mode = modes[i];
......@@ -242,6 +254,7 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}
}
if (args[j].return_code) {
fprintf(stderr, "thread returned error %d\n", args[j].return_code);
exit(EXIT_FAILURE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment