Commit | Line | Data |
---|---|---|
b1a20bee MW |
1 | /* -*-c-*- |
2 | * | |
3 | * Test-vector framework timeout extension | |
4 | * | |
5 | * (c) 2024 Straylight/Edgeware | |
6 | */ | |
7 | ||
8 | /*----- Licensing notice --------------------------------------------------* | |
9 | * | |
10 | * This file is part of the mLib utilities library. | |
11 | * | |
12 | * mLib is free software: you can redistribute it and/or modify it under | |
13 | * the terms of the GNU Library General Public License as published by | |
14 | * the Free Software Foundation; either version 2 of the License, or (at | |
15 | * your option) any later version. | |
16 | * | |
17 | * mLib is distributed in the hope that it will be useful, but WITHOUT | |
18 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
19 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | |
20 | * License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU Library General Public | |
23 | * License along with mLib. If not, write to the Free Software | |
24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
25 | * USA. | |
26 | */ | |
27 | ||
28 | #ifndef MLIB_TVEC_TIMEOUT_H | |
29 | #define MLIB_TVEC_TIMEOUT_H | |
30 | ||
31 | #ifdef __cplusplus | |
32 | extern "C" { | |
33 | #endif | |
34 | ||
35 | /*----- Header files ------------------------------------------------------*/ | |
36 | ||
37 | #include <sys/time.h> | |
38 | ||
39 | #ifndef MLIB_TVEC_H | |
40 | # include "tvec.h" | |
41 | #endif | |
42 | ||
43 | /*----- Test environment --------------------------------------------------*/ | |
44 | ||
45 | struct tvec_timeoutenv { | |
46 | /* Timeout environment definition. */ | |
47 | ||
48 | struct tvec_env _env; | |
49 | int timer; /* the timer (@ITIMER_...@) */ | |
50 | double t; /* time to wait (in seconds) */ | |
51 | const struct tvec_env *env; /* subsidiary environment */ | |
52 | }; | |
53 | ||
54 | struct tvec_timeoutctx { | |
55 | /* Timeout environment context; private. */ | |
56 | ||
57 | const struct tvec_timeoutenv *te; /* saved environment description */ | |
58 | int timer; /* timer code (as overridden) */ | |
59 | double t; /* time to wait (as overridden) */ | |
60 | unsigned f; /* flags */ | |
61 | #define TVTF_SETTMO 1u /* set `@timeout' */ | |
62 | #define TVTF_SETTMR 2u /* set `@timer' */ | |
63 | #define TVTF_SETMASK (TVTF_SETTMO | TVTF_SETTMR) | |
64 | /* mask of @TVTF_SET...@ */ | |
65 | void *subctx; /* subordinate environment context */ | |
66 | }; | |
67 | ||
68 | /* --- Environment implementation --- * | |
69 | * | |
70 | * The following special variables are supported. | |
71 | * | |
72 | * * %|@timeout|% is the duration to wait before killing the process. | |
73 | * | |
74 | * * %|@timer|% is the timer to use to measure the duration. | |
75 | * | |
76 | * Unrecognized variables are passed to the subordinate environment, if there | |
77 | * is one. Other events are passed through to the subordinate environment. | |
78 | */ | |
79 | ||
80 | extern tvec_envsetupfn tvec_timeoutsetup; | |
81 | extern tvec_envfindvarfn tvec_timeoutfindvar; | |
82 | extern tvec_envbeforefn tvec_timeoutbefore; | |
83 | extern tvec_envrunfn tvec_timeoutrun; | |
84 | extern tvec_envafterfn tvec_timeoutafter; | |
85 | extern tvec_envteardownfn tvec_timeoutteardown; | |
86 | ||
87 | #define TVEC_TIMEOUTENV \ | |
88 | { sizeof(struct tvec_timeoutctx), \ | |
89 | tvec_timeoutsetup, \ | |
90 | tvec_timeoutfindvar, \ | |
91 | tvec_timeoutbefore, \ | |
92 | tvec_timeoutrun, \ | |
93 | tvec_timeoutafter, \ | |
94 | tvec_timeoutteardown } | |
95 | #define TVEC_TIMEOUTINIT(timer, t) TVEC_TIMEOUTENV, timer, t | |
96 | ||
97 | /*----- That's all, folks -------------------------------------------------*/ | |
98 | ||
99 | #ifdef __cplusplus | |
100 | } | |
101 | #endif | |
102 | ||
103 | #endif |