Logo AND Algorithmique Numérique Distribuée

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