Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
leak --(cherry picked from commit dd1330c53beec9c5abb8b23375062e6acf214632)
[simgrid.git] / tools / tesh / run_context.h
1 /* run_context -- stuff in which TESH runs a command                        */
2
3 /* Copyright (c) 2007-2010, 2012-2013. The SimGrid Team.
4  * All rights reserved.                                                     */
5
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. */
8
9 #ifndef TESH_RUN_CONTEXT_H
10 #define TESH_RUN_CONTEXT_H
11
12 #include "tesh.h"
13 #include "xbt/synchro_core.h"
14
15 typedef enum { e_output_check, e_output_display,
16   e_output_ignore
17 } e_output_handling_t;
18
19
20 typedef struct {
21   /* kind of job */
22   char *cmd;
23   char **env;
24   int env_size;
25   char *filepos;
26   int pid;
27   unsigned is_background:1;
28   unsigned is_empty:1;
29   unsigned is_stoppable:1;
30
31   unsigned brokenpipe:1;
32   unsigned timeout:1;
33
34   unsigned reader_done:1;       /* reader set this to true when he's done because
35                                    the child is dead. The main thread use it to detect
36                                    that the child is not dead before the end of timeout */
37
38   unsigned interrupted:1;       /* Whether we got stopped by an armageddon */
39   xbt_os_mutex_t interruption;  /* To allow main thread to kill a runner
40                                    one only at certain points */
41
42   e_output_handling_t output;
43
44   int status;
45
46   /* expected results */
47   int end_time;                 /* begin_time + timeout, as epoch */
48   char *expected_signal;        /* name of signal to raise (or NULL if none) */
49   int expected_return;          /* the exepeted return code of following command */
50   unsigned output_sort:1;       /* whether the output must be sorted before comparison */
51
52   /* buffers */
53   xbt_strbuff_t input;
54   xbt_strbuff_t output_wanted;
55   xbt_strbuff_t output_got;
56
57   /* Threads */
58   xbt_os_thread_t writer, reader;       /* IO handlers */
59   xbt_os_thread_t runner;       /* Main thread, counting for timeouts */
60
61   /* Pipes from/to the child */
62   int child_to, child_from;
63
64 } s_rctx_t, *rctx_t;
65
66 /* module mgmt */
67 void rctx_init(void);
68 void rctx_exit(void);
69
70 /* wait for all currently running background jobs */
71 void rctx_wait_bg(void);
72
73 /* kill forcefully all currently running background jobs */
74 extern rctx_t armageddon_initiator;
75 extern xbt_os_mutex_t armageddon_mutex;
76 void rctx_armageddon(rctx_t initiator, int exitcode);
77
78
79 /* create a new empty running context */
80 rctx_t rctx_new(void);
81 void rctx_free(rctx_t rctx);
82 void rctx_empty(rctx_t rc);     /*reset to empty */
83 void rctx_dump(rctx_t rctx, const char *str);
84
85
86 /* Launch the current command */
87 void rctx_start(void);
88 /* Wait till the end of this command */
89 void *rctx_wait(void *rctx);
90
91 /* Parse a line comming from the suite file, and add this into the rctx */
92 void rctx_pushline(const char *filepos, char kind, char *line);
93
94 #endif                          /* TESH_RUN_CONTEXT_H */