Unverified Commit fbeb7a1a by 2xsec

tests: cleanup concurrent.c

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