1 /* run_context -- stuff in which TESH runs a command */
3 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
12 #include <sys/types.h>
17 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
20 xbt_dynar_t bg_jobs = NULL;
21 rctx_t armageddon_initiator = NULL;
22 xbt_os_mutex_t armageddon_mutex = NULL;
26 } oldact[3]; /* SIGINT, SIGQUIT, SIGTERM */
28 xbt_os_thread_t sigwaiter_thread;
29 xbt_os_mutex_t sigwaiter_mutex;
30 xbt_os_cond_t sigwaiter_cond;
31 int armageddon_requested = 0;
32 int caught_signum = 0;
38 static void armageddon_sighandler(int signum)
40 xbt_os_mutex_acquire(sigwaiter_mutex);
41 caught_signum = signum;
42 armageddon_requested = 1;
43 xbt_os_cond_signal(sigwaiter_cond);
44 xbt_os_mutex_release(sigwaiter_mutex);
47 static void *armageddon_sigwaiter(_XBT_GNUC_UNUSED void *arg)
49 xbt_os_mutex_acquire(sigwaiter_mutex);
50 /* Inform main thread that it started. */
51 xbt_os_cond_signal(sigwaiter_cond);
52 /* Wait for ending signal... */
53 xbt_os_cond_wait(sigwaiter_cond, sigwaiter_mutex);
54 if (armageddon_requested) {
55 XBT_ERROR("Test suite `%s': caught signal %d", testsuite_name, caught_signum);
56 rctx_armageddon(rctx, 3);
58 xbt_os_mutex_release(sigwaiter_mutex);
62 static void wait_it(rctx_t rctx)
64 XBT_VERB("Join thread %p which were running background cmd <%s>",
65 rctx->runner, rctx->filepos);
66 xbt_os_thread_join(rctx->runner, NULL);
69 static void kill_it(void *r)
71 rctx_t rctx = *(rctx_t *) r;
78 struct sigaction newact;
81 bg_jobs = xbt_dynar_new_sync(sizeof(rctx_t), kill_it);
82 armageddon_mutex = xbt_os_mutex_init();
83 armageddon_initiator = NULL;
84 sigwaiter_mutex = xbt_os_mutex_init();
85 sigwaiter_cond = xbt_os_cond_init();
86 xbt_os_mutex_acquire(sigwaiter_mutex);
87 sigwaiter_thread = xbt_os_thread_create("Armaggedon request waiter",
88 armageddon_sigwaiter, NULL, NULL);
89 /* Wait for thread to start... */
90 xbt_os_cond_wait(sigwaiter_cond, sigwaiter_mutex);
91 xbt_os_mutex_release(sigwaiter_mutex);
92 memset(&newact, 0, sizeof(newact));
93 newact.sa_handler = armageddon_sighandler;
94 oldact[0].num = SIGINT;
95 oldact[1].num = SIGQUIT;
96 oldact[2].num = SIGTERM;
97 for (i = 0; i < 3; i++)
98 sigaction(oldact[i].num, &newact, &oldact[i].act);
104 for (i = 0; i < 3; i++)
105 sigaction(oldact[i].num, &oldact[i].act, NULL);
106 xbt_os_cond_signal(sigwaiter_cond);
107 xbt_os_thread_join(sigwaiter_thread, NULL);
108 xbt_dynar_free(&bg_jobs);
109 xbt_os_cond_destroy(sigwaiter_cond);
110 xbt_os_mutex_destroy(sigwaiter_mutex);
111 xbt_os_mutex_destroy(armageddon_mutex);
114 void rctx_wait_bg(void)
116 /* Do not use xbt_dynar_free or it will lock the dynar, preventing armageddon
118 while (!xbt_dynar_is_empty(bg_jobs)) {
119 rctx_t rctx = xbt_dynar_getlast_as(bg_jobs, rctx_t);
121 xbt_dynar_pop(bg_jobs, &rctx);
124 xbt_dynar_reset(bg_jobs);
127 static void rctx_armageddon_kill_one(rctx_t initiator, const char *filepos,
130 if (rctx != initiator) {
131 XBT_INFO("Kill <%s> because <%s> failed", rctx->filepos, filepos);
132 xbt_os_mutex_acquire(rctx->interruption);
133 if (!rctx->reader_done) {
134 rctx->interrupted = 1;
135 kill(rctx->pid, SIGTERM);
137 kill(rctx->pid, SIGKILL);
139 xbt_os_mutex_release(rctx->interruption);
143 void rctx_armageddon(rctx_t initiator, int exitcode)
147 const char *filepos = initiator && initiator->filepos ?
148 initiator->filepos : "(master)";
150 XBT_DEBUG("Armageddon request by <%s> (exit=%d)", filepos, exitcode);
151 xbt_os_mutex_acquire(armageddon_mutex);
152 if (armageddon_initiator != NULL) {
153 XBT_VERB("Armageddon already started. Let it go");
154 xbt_os_mutex_release(armageddon_mutex);
157 XBT_DEBUG("Armageddon request by <%s> got the lock. Let's go amok",
159 armageddon_initiator = initiator;
160 xbt_os_mutex_release(armageddon_mutex);
162 /* Kill foreground command */
164 rctx_armageddon_kill_one(initiator, filepos, rctx);
166 /* Kill any background commands */
167 xbt_dynar_foreach(bg_jobs, cursor, job) {
168 rctx_armageddon_kill_one(initiator, filepos, job);
171 /* Give runner threads a chance to acknowledge the processes deaths */
173 /* Ensure that nobody is running rctx_wait on exit */
175 xbt_os_mutex_acquire(rctx->interruption);
176 xbt_dynar_foreach(bg_jobs, cursor, job)
177 xbt_os_mutex_acquire(job->interruption);
178 XBT_VERB("Shut everything down!");
186 void rctx_empty(rctx_t rc)
194 /* avoid race with rctx_armageddon log messages */
195 filepos = rc->filepos;
198 for (i = 0, env_it = environ; *env_it; i++, env_it++);
200 for (env_it = rctx->env + i; *env_it; env_it++)
204 rc->env_size = i + 1;
205 rc->env = malloc(rc->env_size * sizeof(char *));
206 memcpy(rc->env, environ, rc->env_size * sizeof(char *));
209 rc->is_background = 0;
210 rc->is_stoppable = 0;
211 rc->output = e_output_check;
216 xbt_strbuff_empty(rc->input);
217 xbt_strbuff_empty(rc->output_wanted);
218 xbt_strbuff_empty(rc->output_got);
224 rctx_t res = xbt_new0(s_rctx_t, 1);
226 res->input = xbt_strbuff_new();
227 res->output_sort = 0;
228 res->output_wanted = xbt_strbuff_new();
229 res->output_got = xbt_strbuff_new();
230 res->interruption = xbt_os_mutex_init();
235 void rctx_free(rctx_t rctx)
237 XBT_DEBUG("RCTX: Free %p", rctx);
238 rctx_dump(rctx, "free");
247 for (i = 0, env_it = environ; *env_it; i++, env_it++);
248 for (env_it = rctx->env + i; *env_it; env_it++)
252 xbt_os_mutex_destroy(rctx->interruption);
253 xbt_strbuff_free(rctx->input);
254 xbt_strbuff_free(rctx->output_got);
255 xbt_strbuff_free(rctx->output_wanted);
259 void rctx_dump(rctx_t rctx, const char *str)
261 XBT_DEBUG("%s RCTX %p={in%p={%d,%10s}, want={%d,%10s}, out={%d,%10s}}",
263 rctx->input, rctx->input->used, rctx->input->data,
264 rctx->output_wanted->used, rctx->output_wanted->data,
265 rctx->output_got->used, rctx->output_got->data);
266 XBT_DEBUG("%s RCTX %p=[cmd%p=%10s, pid=%d]",
267 str, rctx, rctx->cmd, rctx->cmd, rctx->pid);
272 * Getting instructions from the file
275 void rctx_pushline(const char *filepos, char kind, char *line)
282 if (!rctx->is_empty) {
284 ("[%s] More than one command in this chunk of lines (previous: %s).\n"
285 " Cannot guess which input/output belongs to which command.",
287 XBT_ERROR("Test suite `%s': NOK (syntax error)", testsuite_name);
288 rctx_armageddon(rctx, 1);
292 XBT_VERB("[%s] More than one command in this chunk of lines", filepos);
295 rctx->is_background = 1;
297 rctx->is_background = 0;
299 rctx->cmd = xbt_strdup(line);
300 rctx->filepos = xbt_strdup(filepos);
302 rctx->cmd = bprintf("%s %s",rctx->cmd,option);
304 XBT_INFO("[%s] %s%s", filepos, rctx->cmd,
305 ((rctx->is_background) ? " (background command)" : ""));
311 xbt_strbuff_append(rctx->input, line);
312 xbt_strbuff_append(rctx->input, "\n");
317 xbt_strbuff_append(rctx->output_wanted, line);
318 xbt_strbuff_append(rctx->output_wanted, "\n");
325 if (!strncmp(line, "timeout no", strlen("timeout no"))) {
326 XBT_VERB("[%s] (disable timeout)", filepos);
328 } else if (!strncmp(line, "timeout ", strlen("timeout "))) {
329 timeout_value = atoi(line + strlen("timeout"));
330 XBT_VERB("[%s] (new timeout value: %d)", filepos, timeout_value);
332 } else if (!strncmp(line, "expect signal ", strlen("expect signal "))) {
333 rctx->expected_signal = strdup(line + strlen("expect signal "));
334 xbt_str_trim(rctx->expected_signal, " \n");
335 XBT_VERB("[%s] (next command must raise signal %s)",
336 filepos, rctx->expected_signal);
338 } else if (!strncmp(line, "expect return ", strlen("expect return "))) {
339 rctx->expected_return = atoi(line + strlen("expect return "));
340 XBT_VERB("[%s] (next command must return code %d)",
341 filepos, rctx->expected_return);
343 } else if (!strncmp(line, "output sort", strlen("output sort"))) {
344 sort_len = atoi(line + strlen("output sort"));
346 sort_len=SORT_LEN_DEFAULT;
347 rctx->output_sort = 1;
348 XBT_VERB("[%s] (sort output of next command)", filepos);
350 } else if (!strncmp(line, "output ignore", strlen("output ignore"))) {
351 rctx->output = e_output_ignore;
352 XBT_VERB("[%s] (ignore output of next command)", filepos);
354 } else if (!strncmp(line, "output display", strlen("output display"))) {
355 rctx->output = e_output_display;
356 XBT_VERB("[%s] (ignore output of next command)", filepos);
358 } else if (!strncmp(line, "setenv ", strlen("setenv "))) {
359 int len = strlen("setenv ");
360 char *eq = strchr(line + len, '=');
361 char *key = bprintf("%.*s", (int) (eq - line - len), line + len);
362 xbt_dict_set(env, key, xbt_strdup(eq + 1), xbt_free_f);
365 rctx->env = realloc(rctx->env, ++(rctx->env_size) * sizeof(char *));
366 rctx->env[rctx->env_size - 2] = xbt_strdup(line + len);
367 rctx->env[rctx->env_size - 1] = NULL;
368 XBT_VERB("[%s] setenv %s", filepos, line + len);
371 XBT_ERROR("%s: Malformed metacommand: %s", filepos, line);
372 XBT_ERROR("Test suite `%s': NOK (syntax error)", testsuite_name);
373 rctx_armageddon(rctx, 1);
381 * Actually doing the job
384 /* The IO of the childs are handled by the two following threads
385 (one pair per child) */
387 static void *thread_writer(void *r)
390 rctx_t rctx = (rctx_t) r;
391 for (posw = 0; posw < rctx->input->used && !rctx->brokenpipe;) {
393 XBT_DEBUG("Still %d chars to write", rctx->input->used - posw);
395 write(rctx->child_to, rctx->input->data + posw,
396 rctx->input->used - posw);
400 if (errno == EPIPE) {
401 rctx->brokenpipe = 1;
402 } else if (errno != EINTR && errno != EAGAIN && errno != EPIPE) {
403 perror("Error while writing input to child");
404 XBT_ERROR("Test suite `%s': NOK (system error)", testsuite_name);
405 rctx_armageddon(rctx, 4);
409 XBT_DEBUG("written %d chars so far", posw);
414 rctx->input->data[0] = '\0';
415 rctx->input->used = 0;
416 close(rctx->child_to);
421 static void *thread_reader(void *r)
423 rctx_t rctx = (rctx_t) r;
424 char *buffout = malloc(4096);
428 posr = read(rctx->child_from, buffout, 4095);
429 if (posr < 0 && errno != EINTR && errno != EAGAIN) {
430 perror("Error while reading output of child");
431 XBT_ERROR("Test suite `%s': NOK (system error)", testsuite_name);
432 rctx_armageddon(rctx, 4);
436 buffout[posr] = '\0';
437 xbt_strbuff_append(rctx->output_got, buffout);
441 } while (!rctx->timeout && posr != 0);
444 /* let this thread wait for the child so that the main thread can detect the timeout without blocking on the wait */
445 got_pid = waitpid(rctx->pid, &rctx->status, 0);
446 if (got_pid != rctx->pid) {
448 ("(%s) Cannot wait for the child %s (got pid %d where pid %d were expected;status=%d)",
449 xbt_thread_self_name(), rctx->cmd, (int) got_pid,
450 (int) rctx->pid, rctx->status));
451 XBT_ERROR("Test suite `%s': NOK (system error)", testsuite_name);
452 rctx_armageddon(rctx, 4);
456 rctx->reader_done = 1;
460 /* Special command: mkfile is a built-in creating a file with the input data as content */
461 static void rctx_mkfile(void)
463 char *filename = xbt_strdup(rctx->cmd + strlen("mkfile "));
466 xbt_str_trim(filename, NULL);
467 OUT = fopen(filename, "w");
469 THROWF(system_error, errno, "%s: Cannot create file %s: %s",
470 rctx->filepos, filename, strerror(errno));
472 err = (fprintf(OUT, "%s", rctx->input->data) < 0);
473 err = (fclose(OUT) == -1) || err;
475 THROWF(system_error, errno, "%s: Cannot write file %s: %s",
476 rctx->filepos, filename, strerror(errno));
481 /* function to be called from the child to start the actual process */
482 static void start_command(rctx_t rctx)
485 char *binary_name = NULL;
491 if (!strncmp(rctx->cmd, "mkfile ", strlen("mkfile "))) {
493 /* Valgrind detects memory leaks here.
494 * To correct those leaks, we must free objects allocated in main() or in
495 * handle_suite(), but we have no more reference to them at this point.
496 * A quick and dirty hack to make valgrind happy it to uncomment the
499 /* execlp("true", "true", (const char *)0); */
500 exit(0); /* end the working child */
503 cmd = xbt_str_split_quoted(rctx->cmd);
504 xbt_dynar_get_cpy(cmd, 0, &binary_name);
505 args = xbt_new(char *, xbt_dynar_length(cmd) + 1);
506 xbt_dynar_foreach(cmd, it, str) {
507 args[it] = xbt_strdup(str);
510 xbt_dynar_free_container(&cmd);
512 /* To search for the right executable path when not trivial */
513 struct stat stat_buf;
515 /* build the command line */
516 if (stat(binary_name, &stat_buf)) {
517 /* Damn. binary not in current dir. We'll have to dig the PATH to find it */
520 for (i = 0; environ[i]; i++) {
521 if (!strncmp("PATH=", environ[i], 5)) {
522 xbt_dynar_t path = xbt_str_split(environ[i] + 5, ":");
524 xbt_dynar_foreach(path, it, str) {
526 binary_name = bprintf("%s/%s", str, args[0]);
527 if (!stat(binary_name, &stat_buf)) {
529 XBT_DEBUG("Looked in the PATH for the binary. Found %s",
531 xbt_dynar_free(&path);
535 xbt_dynar_free(&path);
536 if (stat(binary_name, &stat_buf)) {
538 printf("TESH_ERROR Command %s not found\n", args[0]);
545 binary_name = xbt_strdup(args[0]);
548 errcode = execve(binary_name, args, rctx->env);
549 printf("TESH_ERROR %s: Cannot start %s: %s\n", rctx->filepos, rctx->cmd,
554 /* Start a new child, plug the pipes as expected and fire up the
555 helping threads. Is also waits for the child to end if this is a
556 foreground job, or fire up a thread to wait otherwise. */
557 void rctx_start(void)
562 XBT_DEBUG("Cmd before rewriting %s", rctx->cmd);
563 rctx->cmd = xbt_str_varsubst(rctx->cmd, env);
564 XBT_VERB("Start %s %s", rctx->cmd,
565 (rctx->is_background ? "(background job)" : ""));
566 xbt_os_mutex_acquire(armageddon_mutex);
567 if (armageddon_initiator) {
568 XBT_VERB("Armageddon in progress. Do not start job.");
569 xbt_os_mutex_release(armageddon_mutex);
572 if (pipe(child_in) || pipe(child_out)) {
573 perror("Cannot open the pipes");
574 XBT_ERROR("Test suite `%s': NOK (system error)", testsuite_name);
575 xbt_os_mutex_release(armageddon_mutex);
576 rctx_armageddon(rctx, 4);
581 perror("Cannot fork the command");
582 XBT_ERROR("Test suite `%s': NOK (system error)", testsuite_name);
583 xbt_os_mutex_release(armageddon_mutex);
584 rctx_armageddon(rctx, 4);
588 if (rctx->pid) { /* father */
590 rctx->child_to = child_in[1];
593 rctx->child_from = child_out[0];
595 if (timeout_value > 0)
596 rctx->end_time = time(NULL) + timeout_value;
600 rctx->reader_done = 0;
602 xbt_os_thread_create("reader", thread_reader, (void *) rctx, NULL);
604 xbt_os_thread_create("writer", thread_writer, (void *) rctx, NULL);
608 dup2(child_in[0], 0);
612 dup2(child_out[1], 1);
613 dup2(child_out[1], 2);
619 rctx->is_stoppable = 1;
621 if (!rctx->is_background) {
623 xbt_os_mutex_release(armageddon_mutex);
627 /* Damn. Copy the rctx and launch a thread to handle it */
629 xbt_os_thread_t runner;
632 XBT_DEBUG("RCTX: new bg=%p, new fg=%p", old, rctx);
634 XBT_DEBUG("Launch a thread to wait for %s %d", old->cmd, old->pid);
635 runner = xbt_os_thread_create(old->cmd, rctx_wait, (void *) old, NULL);
636 old->runner = runner;
637 XBT_VERB("Launched thread %p to wait for %s %d", runner, old->cmd,
639 xbt_dynar_push(bg_jobs, &old);
640 xbt_os_mutex_release(armageddon_mutex);
644 /* Helper function to sort the output */
645 static int cmpstringp(const void *p1, const void *p2) {
646 /* Sort only using the 19 first chars (date+pid)
647 * If the dates are the same, then, sort using pointer address (be stable wrt output of each process)
649 const char *s1 = *((const char**) p1);
650 const char *s2 = *((const char**) p2);
652 XBT_DEBUG("Compare strings '%s' and '%s'", s1, s2);
654 int res = strncmp(s1, s2, sort_len);
661 /* Waits for the child to end (or to timeout), and check its
662 ending conditions. This is launched from rctx_start but either in main
663 thread (for foreground jobs) or in a separate one for background jobs.
664 That explains the prototype, forced by xbt_os_thread_create. */
666 void *rctx_wait(void *r)
668 rctx_t rctx = (rctx_t) r;
670 int now = time(NULL);
672 rctx_dump(rctx, "wait");
674 if (!rctx->is_stoppable)
675 THROWF(unknown_error, 0, "Cmd '%s' not started yet. Cannot wait it",
678 /* Wait for the child to die or the timeout to happen (or an armageddon to happen) */
679 while (!rctx->reader_done
680 && (rctx->end_time < 0 || rctx->end_time >= now)) {
685 xbt_os_mutex_acquire(rctx->interruption);
686 if (!rctx->interrupted && rctx->end_time > 0 && rctx->end_time < now) {
687 XBT_INFO("<%s> timeouted. Kill the process.", rctx->filepos);
689 kill(rctx->pid, SIGTERM);
691 kill(rctx->pid, SIGKILL);
694 /* Make sure helper threads die.
695 Cannot block since they wait for the child we just killed
696 if not already dead. */
697 xbt_os_thread_join(rctx->writer, NULL);
698 xbt_os_thread_join(rctx->reader, NULL);
700 /* xbt_os_mutex_release(rctx->interruption);
701 if (rctx->interrupted)
703 xbt_os_mutex_acquire(rctx->interruption); */
706 xbt_dynar_t a = xbt_str_split(rctx->output_got->data, "\n");
707 xbt_dynar_t b = xbt_dynar_new(sizeof(char *), NULL);
710 xbt_dynar_foreach(a, cpt, str) {
711 if (strncmp(str, "TESH_ERROR ", (sizeof "TESH_ERROR ") - 1) == 0) {
712 XBT_CRITICAL("%s", str);
714 } else if (coverage &&
715 strncmp(str, "profiling:", (sizeof "profiling:") - 1) == 0) {
716 XBT_DEBUG("Remove line [%u]: '%s'", cpt, str);
718 xbt_dynar_push_as(b, char *, str);
722 if (rctx->output_sort) {
723 xbt_dynar_sort(b, cmpstringp);
724 /* If empty lines moved in first position, remove them */
725 while (!xbt_dynar_is_empty(b) && *xbt_dynar_getfirst_as(b, char*) == '\0')
726 xbt_dynar_shift(b, NULL);
729 if (rctx->output_sort || xbt_dynar_length(b) != xbt_dynar_length(a)) {
730 char *newbuf = xbt_str_join(b, "\n");
731 strcpy(rctx->output_got->data, newbuf);
732 rctx->output_got->used = strlen(newbuf);
740 xbt_strbuff_chomp(rctx->output_got);
741 xbt_strbuff_chomp(rctx->output_wanted);
742 xbt_strbuff_trim(rctx->output_got);
743 xbt_strbuff_trim(rctx->output_wanted);
745 /* Check for broken pipe */
746 if (rctx->brokenpipe)
748 ("Warning: Child did not consume all its input (I got broken pipe)");
750 /* Check for timeouts */
752 if (rctx->output_got->data[0])
753 XBT_INFO("<%s> Output on timeout:\n%s",
754 rctx->filepos, rctx->output_got->data);
756 XBT_INFO("<%s> No output before timeout", rctx->filepos);
757 XBT_ERROR("Test suite `%s': NOK (<%s> timeout after %d sec)",
758 testsuite_name, rctx->filepos, timeout_value);
759 XBT_DEBUG("<%s> Interrupted = %d", rctx->filepos, rctx->interrupted);
760 if (!rctx->interrupted) {
761 xbt_os_mutex_release(rctx->interruption);
762 rctx_armageddon(rctx, 3);
767 XBT_DEBUG("RCTX=%p (pid=%d)", rctx, rctx->pid);
768 XBT_DEBUG("Status(%s|%d)=%d", rctx->cmd, rctx->pid, rctx->status);
770 if (!rctx->interrupted) {
771 if (WIFSIGNALED(rctx->status) && !rctx->expected_signal) {
772 XBT_ERROR("Test suite `%s': NOK (<%s> got signal %s)",
773 testsuite_name, rctx->filepos,
774 signal_name(WTERMSIG(rctx->status), NULL));
775 errcode = WTERMSIG(rctx->status) + 4;
778 if (WIFSIGNALED(rctx->status) && rctx->expected_signal &&
779 strcmp(signal_name(WTERMSIG(rctx->status), rctx->expected_signal),
780 rctx->expected_signal)) {
781 XBT_ERROR("Test suite `%s': NOK (%s got signal %s instead of %s)",
782 testsuite_name, rctx->filepos,
783 signal_name(WTERMSIG(rctx->status), rctx->expected_signal),
784 rctx->expected_signal);
785 errcode = WTERMSIG(rctx->status) + 4;
788 if (!WIFSIGNALED(rctx->status) && rctx->expected_signal) {
789 XBT_ERROR("Test suite `%s': NOK (child %s expected signal %s)",
790 testsuite_name, rctx->filepos, rctx->expected_signal);
794 if (WIFEXITED(rctx->status)
795 && WEXITSTATUS(rctx->status) != rctx->expected_return) {
796 if (rctx->expected_return)
798 ("Test suite `%s': NOK (<%s> returned code %d instead of %d)",
799 testsuite_name, rctx->filepos, WEXITSTATUS(rctx->status),
800 rctx->expected_return);
802 XBT_ERROR("Test suite `%s': NOK (<%s> returned code %d)",
803 testsuite_name, rctx->filepos, WEXITSTATUS(rctx->status));
804 errcode = 40 + WEXITSTATUS(rctx->status);
807 rctx->expected_return = 0;
809 free(rctx->expected_signal);
810 rctx->expected_signal = NULL;
813 if ((errcode && errcode != 1) || rctx->interrupted) {
814 /* checking output, and matching */
815 xbt_dynar_t a = xbt_str_split(rctx->output_got->data, "\n");
816 char *out = xbt_str_join(a, "\n||");
818 XBT_INFO("Output of <%s> so far: \n||%s", rctx->filepos, out);
820 } else if (rctx->output == e_output_check
821 && (rctx->output_got->used != rctx->output_wanted->used
822 || strcmp(rctx->output_got->data,
823 rctx->output_wanted->data))) {
824 if (XBT_LOG_ISENABLED(tesh, xbt_log_priority_info)) {
826 xbt_str_diff(rctx->output_wanted->data, rctx->output_got->data);
827 XBT_ERROR("Output of <%s> mismatch:\n%s", rctx->filepos, diff);
830 XBT_ERROR("Test suite `%s': NOK (<%s> output mismatch)",
831 testsuite_name, rctx->filepos);
834 } else if (rctx->output == e_output_ignore) {
835 XBT_INFO("(ignoring the output of <%s> as requested)", rctx->filepos);
836 } else if (rctx->output == e_output_display) {
837 xbt_dynar_t a = xbt_str_split(rctx->output_got->data, "\n");
838 char *out = xbt_str_join(a, "\n||");
840 XBT_INFO("Here is the (ignored) command output: \n||%s", out);
844 if (!rctx->is_background) {
845 xbt_os_mutex_acquire(armageddon_mutex);
846 /* Don't touch rctx if armageddon is in progress. */
847 if (!armageddon_initiator)
849 xbt_os_mutex_release(armageddon_mutex);
852 if (!rctx->interrupted) {
853 xbt_os_mutex_release(rctx->interruption);
854 rctx_armageddon(rctx, errcode);
859 xbt_os_mutex_release(rctx->interruption);