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_length(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)
195 /* avoid race with rctx_armageddon log messages */
196 filepos = rc->filepos;
200 for (i = 0, env_it = environ; *env_it; i++, env_it++);
202 for (env_it = rctx->env + i; *env_it; env_it++)
206 rc->env_size = i + 1;
207 rc->env = malloc(rc->env_size * sizeof(char *));
208 memcpy(rc->env, environ, rc->env_size * sizeof(char *));
211 rc->is_background = 0;
212 rc->is_stoppable = 0;
213 rc->output = e_output_check;
218 xbt_strbuff_empty(rc->input);
219 xbt_strbuff_empty(rc->output_wanted);
220 xbt_strbuff_empty(rc->output_got);
226 rctx_t res = xbt_new0(s_rctx_t, 1);
228 res->input = xbt_strbuff_new();
229 res->output_sort = 0;
230 res->output_wanted = xbt_strbuff_new();
231 res->output_got = xbt_strbuff_new();
232 res->interruption = xbt_os_mutex_init();
237 void rctx_free(rctx_t rctx)
239 XBT_DEBUG("RCTX: Free %p", rctx);
240 rctx_dump(rctx, "free");
251 for (i = 0, env_it = environ; *env_it; i++, env_it++);
252 for (env_it = rctx->env + i; *env_it; env_it++)
256 xbt_os_mutex_destroy(rctx->interruption);
257 xbt_strbuff_free(rctx->input);
258 xbt_strbuff_free(rctx->output_got);
259 xbt_strbuff_free(rctx->output_wanted);
263 void rctx_dump(rctx_t rctx, const char *str)
265 XBT_DEBUG("%s RCTX %p={in%p={%d,%10s}, want={%d,%10s}, out={%d,%10s}}",
267 rctx->input, rctx->input->used, rctx->input->data,
268 rctx->output_wanted->used, rctx->output_wanted->data,
269 rctx->output_got->used, rctx->output_got->data);
270 XBT_DEBUG("%s RCTX %p=[cmd%p=%10s, pid=%d]",
271 str, rctx, rctx->cmd, rctx->cmd, rctx->pid);
276 * Getting instructions from the file
279 void rctx_pushline(const char *filepos, char kind, char *line)
286 if (!rctx->is_empty) {
288 ("[%s] More than one command in this chunk of lines (previous: %s).\n"
289 " Cannot guess which input/output belongs to which command.",
291 XBT_ERROR("Test suite `%s': NOK (syntax error)", testsuite_name);
292 rctx_armageddon(rctx, 1);
296 XBT_VERB("[%s] More than one command in this chunk of lines", filepos);
299 rctx->is_background = 1;
301 rctx->is_background = 0;
303 rctx->cmd = xbt_strdup(line);
304 rctx->filepos = xbt_strdup(filepos);
306 rctx->cmd = bprintf("%s %s",rctx->cmd,option);
308 XBT_INFO("[%s] %s%s", filepos, rctx->cmd,
309 ((rctx->is_background) ? " (background command)" : ""));
315 xbt_strbuff_append(rctx->input, line);
316 xbt_strbuff_append(rctx->input, "\n");
321 xbt_strbuff_append(rctx->output_wanted, line);
322 xbt_strbuff_append(rctx->output_wanted, "\n");
329 if (!strncmp(line, "timeout no", strlen("timeout no"))) {
330 XBT_VERB("[%s] (disable timeout)", filepos);
332 } else if (!strncmp(line, "timeout ", strlen("timeout "))) {
333 timeout_value = atoi(line + strlen("timeout"));
334 XBT_VERB("[%s] (new timeout value: %d)", filepos, timeout_value);
336 } else if (!strncmp(line, "expect signal ", strlen("expect signal "))) {
337 rctx->expected_signal = strdup(line + strlen("expect signal "));
338 xbt_str_trim(rctx->expected_signal, " \n");
339 XBT_VERB("[%s] (next command must raise signal %s)",
340 filepos, rctx->expected_signal);
342 } else if (!strncmp(line, "expect return ", strlen("expect return "))) {
343 rctx->expected_return = atoi(line + strlen("expect return "));
344 XBT_VERB("[%s] (next command must return code %d)",
345 filepos, rctx->expected_return);
347 } else if (!strncmp(line, "output sort", strlen("output sort"))) {
348 sort_len = atoi(line + strlen("output sort"));
350 sort_len=SORT_LEN_DEFAULT;
351 rctx->output_sort = 1;
352 XBT_VERB("[%s] (sort output of next command)", filepos);
354 } else if (!strncmp(line, "output ignore", strlen("output ignore"))) {
355 rctx->output = e_output_ignore;
356 XBT_VERB("[%s] (ignore output of next command)", filepos);
358 } else if (!strncmp(line, "output display", strlen("output display"))) {
359 rctx->output = e_output_display;
360 XBT_VERB("[%s] (ignore output of next command)", filepos);
362 } else if (!strncmp(line, "setenv ", strlen("setenv "))) {
363 int len = strlen("setenv ");
364 char *eq = strchr(line + len, '=');
365 char *key = bprintf("%.*s", (int) (eq - line - len), line + len);
366 xbt_dict_set(env, key, xbt_strdup(eq + 1), xbt_free_f);
369 rctx->env = realloc(rctx->env, ++(rctx->env_size) * sizeof(char *));
370 rctx->env[rctx->env_size - 2] = xbt_strdup(line + len);
371 rctx->env[rctx->env_size - 1] = NULL;
372 XBT_VERB("[%s] setenv %s", filepos, line + len);
375 XBT_ERROR("%s: Malformed metacommand: %s", filepos, line);
376 XBT_ERROR("Test suite `%s': NOK (syntax error)", testsuite_name);
377 rctx_armageddon(rctx, 1);
385 * Actually doing the job
388 /* The IO of the childs are handled by the two following threads
389 (one pair per child) */
391 static void *thread_writer(void *r)
394 rctx_t rctx = (rctx_t) r;
395 for (posw = 0; posw < rctx->input->used && !rctx->brokenpipe;) {
397 XBT_DEBUG("Still %d chars to write", rctx->input->used - posw);
399 write(rctx->child_to, rctx->input->data + posw,
400 rctx->input->used - posw);
404 if (errno == EPIPE) {
405 rctx->brokenpipe = 1;
406 } else if (errno != EINTR && errno != EAGAIN && errno != EPIPE) {
407 perror("Error while writing input to child");
408 XBT_ERROR("Test suite `%s': NOK (system error)", testsuite_name);
409 rctx_armageddon(rctx, 4);
413 XBT_DEBUG("written %d chars so far", posw);
418 rctx->input->data[0] = '\0';
419 rctx->input->used = 0;
420 close(rctx->child_to);
425 static void *thread_reader(void *r)
427 rctx_t rctx = (rctx_t) r;
428 char *buffout = malloc(4096);
432 posr = read(rctx->child_from, buffout, 4095);
433 if (posr < 0 && errno != EINTR && errno != EAGAIN) {
434 perror("Error while reading output of child");
435 XBT_ERROR("Test suite `%s': NOK (system error)", testsuite_name);
436 rctx_armageddon(rctx, 4);
440 buffout[posr] = '\0';
441 xbt_strbuff_append(rctx->output_got, buffout);
445 } while (!rctx->timeout && posr != 0);
448 /* let this thread wait for the child so that the main thread can detect the timeout without blocking on the wait */
449 got_pid = waitpid(rctx->pid, &rctx->status, 0);
450 if (got_pid != rctx->pid) {
452 ("(%s) Cannot wait for the child %s (got pid %d where pid %d were expected;status=%d)",
453 xbt_thread_self_name(), rctx->cmd, (int) got_pid,
454 (int) rctx->pid, rctx->status));
455 XBT_ERROR("Test suite `%s': NOK (system error)", testsuite_name);
456 rctx_armageddon(rctx, 4);
460 rctx->reader_done = 1;
464 /* Special command: mkfile is a built-in creating a file with the input data as content */
465 static void rctx_mkfile(void)
467 char *filename = xbt_strdup(rctx->cmd + strlen("mkfile "));
470 xbt_str_trim(filename, NULL);
471 OUT = fopen(filename, "w");
473 THROWF(system_error, errno, "%s: Cannot create file %s: %s",
474 rctx->filepos, filename, strerror(errno));
476 err = (fprintf(OUT, "%s", rctx->input->data) < 0);
477 err = (fclose(OUT) == -1) || err;
479 THROWF(system_error, errno, "%s: Cannot write file %s: %s",
480 rctx->filepos, filename, strerror(errno));
485 /* function to be called from the child to start the actual process */
486 static void start_command(rctx_t rctx)
489 char *binary_name = NULL;
495 if (!strncmp(rctx->cmd, "mkfile ", strlen("mkfile "))) {
497 /* Valgrind detects memory leaks here.
498 * To correct those leaks, we must free objects allocated in main() or in
499 * handle_suite(), but we have no more reference to them at this point.
500 * A quick and dirty hack to make valgrind happy it to uncomment the
503 /* execlp("true", "true", (const char *)0); */
504 exit(0); /* end the working child */
507 cmd = xbt_str_split_quoted(rctx->cmd);
508 xbt_dynar_get_cpy(cmd, 0, &binary_name);
509 args = xbt_new(char *, xbt_dynar_length(cmd) + 1);
510 xbt_dynar_foreach(cmd, it, str) {
511 args[it] = xbt_strdup(str);
514 xbt_dynar_free_container(&cmd);
516 /* To search for the right executable path when not trivial */
517 struct stat stat_buf;
519 /* build the command line */
520 if (stat(binary_name, &stat_buf)) {
521 /* Damn. binary not in current dir. We'll have to dig the PATH to find it */
524 for (i = 0; environ[i]; i++) {
525 if (!strncmp("PATH=", environ[i], 5)) {
526 xbt_dynar_t path = xbt_str_split(environ[i] + 5, ":");
528 xbt_dynar_foreach(path, it, str) {
531 binary_name = bprintf("%s/%s", str, args[0]);
532 if (!stat(binary_name, &stat_buf)) {
534 XBT_DEBUG("Looked in the PATH for the binary. Found %s",
536 xbt_dynar_free(&path);
540 xbt_dynar_free(&path);
541 if (stat(binary_name, &stat_buf)) {
543 printf("TESH_ERROR Command %s not found\n", args[0]);
550 binary_name = xbt_strdup(args[0]);
553 errcode = execve(binary_name, args, rctx->env);
554 printf("TESH_ERROR %s: Cannot start %s: %s\n", rctx->filepos, rctx->cmd,
559 /* Start a new child, plug the pipes as expected and fire up the
560 helping threads. Is also waits for the child to end if this is a
561 foreground job, or fire up a thread to wait otherwise. */
562 void rctx_start(void)
567 XBT_DEBUG("Cmd before rewriting %s", rctx->cmd);
568 rctx->cmd = xbt_str_varsubst(rctx->cmd, env);
569 XBT_VERB("Start %s %s", rctx->cmd,
570 (rctx->is_background ? "(background job)" : ""));
571 xbt_os_mutex_acquire(armageddon_mutex);
572 if (armageddon_initiator) {
573 XBT_VERB("Armageddon in progress. Do not start job.");
574 xbt_os_mutex_release(armageddon_mutex);
577 if (pipe(child_in) || pipe(child_out)) {
578 perror("Cannot open the pipes");
579 XBT_ERROR("Test suite `%s': NOK (system error)", testsuite_name);
580 xbt_os_mutex_release(armageddon_mutex);
581 rctx_armageddon(rctx, 4);
586 perror("Cannot fork the command");
587 XBT_ERROR("Test suite `%s': NOK (system error)", testsuite_name);
588 xbt_os_mutex_release(armageddon_mutex);
589 rctx_armageddon(rctx, 4);
593 if (rctx->pid) { /* father */
595 rctx->child_to = child_in[1];
598 rctx->child_from = child_out[0];
600 if (timeout_value > 0)
601 rctx->end_time = time(NULL) + timeout_value;
605 rctx->reader_done = 0;
607 xbt_os_thread_create("reader", thread_reader, (void *) rctx, NULL);
609 xbt_os_thread_create("writer", thread_writer, (void *) rctx, NULL);
613 dup2(child_in[0], 0);
617 dup2(child_out[1], 1);
618 dup2(child_out[1], 2);
624 rctx->is_stoppable = 1;
626 if (!rctx->is_background) {
628 xbt_os_mutex_release(armageddon_mutex);
632 /* Damn. Copy the rctx and launch a thread to handle it */
634 xbt_os_thread_t runner;
637 XBT_DEBUG("RCTX: new bg=%p, new fg=%p", old, rctx);
639 XBT_DEBUG("Launch a thread to wait for %s %d", old->cmd, old->pid);
640 runner = xbt_os_thread_create(old->cmd, rctx_wait, (void *) old, NULL);
641 old->runner = runner;
642 XBT_VERB("Launched thread %p to wait for %s %d", runner, old->cmd,
644 xbt_dynar_push(bg_jobs, &old);
645 xbt_os_mutex_release(armageddon_mutex);
649 /* Helper function to sort the output */
650 static int cmpstringp(const void *p1, const void *p2) {
651 /* Sort only using the 19 first chars (date+pid)
652 * If the dates are the same, then, sort using pointer address (be stable wrt output of each process)
654 const char *s1 = *((const char**) p1);
655 const char *s2 = *((const char**) p2);
657 XBT_DEBUG("Compare strings '%s' and '%s'", s1, s2);
659 int res = strncmp(s1, s2, sort_len);
666 /* Waits for the child to end (or to timeout), and check its
667 ending conditions. This is launched from rctx_start but either in main
668 thread (for foreground jobs) or in a separate one for background jobs.
669 That explains the prototype, forced by xbt_os_thread_create. */
671 void *rctx_wait(void *r)
673 rctx_t rctx = (rctx_t) r;
675 int now = time(NULL);
677 rctx_dump(rctx, "wait");
679 if (!rctx->is_stoppable)
680 THROWF(unknown_error, 0, "Cmd '%s' not started yet. Cannot wait it",
683 /* Wait for the child to die or the timeout to happen (or an armageddon to happen) */
684 while (!rctx->reader_done
685 && (rctx->end_time < 0 || rctx->end_time >= now)) {
690 xbt_os_mutex_acquire(rctx->interruption);
691 if (!rctx->interrupted && rctx->end_time > 0 && rctx->end_time < now) {
692 XBT_INFO("<%s> timeouted. Kill the process.", rctx->filepos);
694 kill(rctx->pid, SIGTERM);
696 kill(rctx->pid, SIGKILL);
699 /* Make sure helper threads die.
700 Cannot block since they wait for the child we just killed
701 if not already dead. */
702 xbt_os_thread_join(rctx->writer, NULL);
703 xbt_os_thread_join(rctx->reader, NULL);
705 /* xbt_os_mutex_release(rctx->interruption);
706 if (rctx->interrupted)
708 xbt_os_mutex_acquire(rctx->interruption); */
710 xbt_strbuff_chomp(rctx->output_got);
711 xbt_strbuff_chomp(rctx->output_wanted);
712 xbt_strbuff_trim(rctx->output_got);
713 xbt_strbuff_trim(rctx->output_wanted);
715 /* Check for broken pipe */
716 if (rctx->brokenpipe)
718 ("Warning: Child did not consume all its input (I got broken pipe)");
720 /* Check for timeouts */
722 if (rctx->output_got->data[0])
723 XBT_INFO("<%s> Output on timeout:\n%s",
724 rctx->filepos, rctx->output_got->data);
726 XBT_INFO("<%s> No output before timeout", rctx->filepos);
727 XBT_ERROR("Test suite `%s': NOK (<%s> timeout after %d sec)",
728 testsuite_name, rctx->filepos, timeout_value);
729 XBT_DEBUG("<%s> Interrupted = %d", rctx->filepos, rctx->interrupted);
730 if (!rctx->interrupted) {
731 xbt_os_mutex_release(rctx->interruption);
732 rctx_armageddon(rctx, 3);
737 XBT_DEBUG("RCTX=%p (pid=%d)", rctx, rctx->pid);
738 XBT_DEBUG("Status(%s|%d)=%d", rctx->cmd, rctx->pid, rctx->status);
740 if (!rctx->interrupted) {
741 if (WIFSIGNALED(rctx->status) && !rctx->expected_signal) {
742 XBT_ERROR("Test suite `%s': NOK (<%s> got signal %s)",
743 testsuite_name, rctx->filepos,
744 signal_name(WTERMSIG(rctx->status), NULL));
745 errcode = WTERMSIG(rctx->status) + 4;
748 if (WIFSIGNALED(rctx->status) && rctx->expected_signal &&
749 strcmp(signal_name(WTERMSIG(rctx->status), rctx->expected_signal),
750 rctx->expected_signal)) {
751 XBT_ERROR("Test suite `%s': NOK (%s got signal %s instead of %s)",
752 testsuite_name, rctx->filepos,
753 signal_name(WTERMSIG(rctx->status), rctx->expected_signal),
754 rctx->expected_signal);
755 errcode = WTERMSIG(rctx->status) + 4;
758 if (!WIFSIGNALED(rctx->status) && rctx->expected_signal) {
759 XBT_ERROR("Test suite `%s': NOK (child %s expected signal %s)",
760 testsuite_name, rctx->filepos, rctx->expected_signal);
764 if (WIFEXITED(rctx->status)
765 && WEXITSTATUS(rctx->status) != rctx->expected_return) {
766 if (rctx->expected_return)
768 ("Test suite `%s': NOK (<%s> returned code %d instead of %d)",
769 testsuite_name, rctx->filepos, WEXITSTATUS(rctx->status),
770 rctx->expected_return);
772 XBT_ERROR("Test suite `%s': NOK (<%s> returned code %d)",
773 testsuite_name, rctx->filepos, WEXITSTATUS(rctx->status));
774 errcode = 40 + WEXITSTATUS(rctx->status);
777 rctx->expected_return = 0;
779 if (rctx->expected_signal) {
780 free(rctx->expected_signal);
781 rctx->expected_signal = NULL;
784 while (rctx->output_got->used
785 && !strncmp(rctx->output_got->data, "TESH_ERROR ",
786 strlen("TESH_ERROR "))) {
787 int marklen = strlen("TESH_ERROR ");
788 char *endline = strchr(rctx->output_got->data, '\n');
790 XBT_CRITICAL("%.*s", (int) (endline - rctx->output_got->data - marklen),
791 rctx->output_got->data + marklen);
792 memmove(rctx->output_got->data, rctx->output_got->data + marklen,
793 rctx->output_got->used - marklen);
794 rctx->output_got->used -= endline - rctx->output_got->data + 1;
795 rctx->output_got->data[rctx->output_got->used] = '\0';
799 if (rctx->output_sort) {
800 xbt_dynar_t a = xbt_str_split(rctx->output_got->data, "\n");
801 xbt_dynar_sort(a,cmpstringp);
802 char *sorted_output = xbt_str_join(a, "\n");
803 strcpy(rctx->output_got->data, sorted_output);
804 xbt_free(sorted_output);
806 /* If an empty line moved in first position, move it back to the end */
807 if (rctx->output_got->data[0]=='\n') {
808 memmove(rctx->output_got->data,rctx->output_got->data+1,rctx->output_got->used-1);
809 rctx->output_got->data[rctx->output_got->used-1] = '\n';
812 if ((errcode && errcode != 1) || rctx->interrupted) {
813 /* checking output, and matching */
814 xbt_dynar_t a = xbt_str_split(rctx->output_got->data, "\n");
815 char *out = xbt_str_join(a, "\n||");
817 XBT_INFO("Output of <%s> so far: \n||%s", rctx->filepos, out);
819 } else if (rctx->output == e_output_check
820 && (rctx->output_got->used != rctx->output_wanted->used
821 || strcmp(rctx->output_got->data,
822 rctx->output_wanted->data))) {
823 if (XBT_LOG_ISENABLED(tesh, xbt_log_priority_info)) {
825 xbt_str_diff(rctx->output_wanted->data, rctx->output_got->data);
826 XBT_ERROR("Output of <%s> mismatch:\n%s", rctx->filepos, diff);
829 XBT_ERROR("Test suite `%s': NOK (<%s> output mismatch)",
830 testsuite_name, rctx->filepos);
833 } else if (rctx->output == e_output_ignore) {
834 XBT_INFO("(ignoring the output of <%s> as requested)", rctx->filepos);
835 } else if (rctx->output == e_output_display) {
836 xbt_dynar_t a = xbt_str_split(rctx->output_got->data, "\n");
837 char *out = xbt_str_join(a, "\n||");
839 XBT_INFO("Here is the (ignored) command output: \n||%s", out);
843 if (!rctx->is_background) {
844 xbt_os_mutex_acquire(armageddon_mutex);
845 /* Don't touch rctx if armageddon is in progress. */
846 if (!armageddon_initiator)
848 xbt_os_mutex_release(armageddon_mutex);
851 if (!rctx->interrupted) {
852 xbt_os_mutex_release(rctx->interruption);
853 rctx_armageddon(rctx, errcode);
858 xbt_os_mutex_release(rctx->interruption);