blob: 0775a5ec5dfbda779d40e8dd93f60cef537f1408 [file] [log] [blame]
Pau Espin Pedrol5badb212024-05-15 14:36:53 +02001module PIPEasp_Templates {
2
3import from PIPEasp_PortType all;
4import from PIPEasp_Types all;
5
Pau Espin Pedrola674d612024-05-14 19:56:33 +02006template (value) ASP_PExecute ts_PExecute(template (value) charstring command,
7 template (value) charstring stdin) := {
8 command := command,
9 stdin := stdin
10}
11
12template (present) ASP_PResult tr_PResult(template (present) charstring stdout,
13 template (present) charstring stderr,
14 template (present) integer code) := {
15 stdout := stdout,
16 stderr := stderr,
17 code := code
18}
19
Pau Espin Pedrol5badb212024-05-15 14:36:53 +020020template (value) ASP_PExecuteBackground ts_ExecBg(charstring cmd) := {
21 command := cmd
22}
23
24template (present) ASP_PStdout tr_Stdout(template (present) charstring line) := {
25 stdout := line
26}
27
28template (present) ASP_PStderr tr_Stderr(template (present) charstring line) := {
29 stderr := line
30}
31
32template (value) ASP_PStdin ts_Stdin(template (value) charstring line) := {
33 stdin :=line
34}
35
36/* Ignore output from stderr: */
37altstep as_ignore_stderr(PIPEasp_PT pt) {
38[] pt.receive(tr_Stderr(?)) { repeat; }
39}
40
Pau Espin Pedrola674d612024-05-14 19:56:33 +020041/* User should map(component_name:PIPE, system:PIPE) before using this function. */
42function f_PIPEasp_exec_sync_PResult(PIPEasp_PT pt,
43 charstring cmdline,
44 template (present) ASP_PResult res_exp := tr_PResult(?,?,0),
45 float time_out := 10.0) return ASP_PResult {
46 var ASP_PResult res;
47 timer t;
48
49 if (time_out > 0.0) {
50 t.start(time_out);
51 }
52
53 log ("Executing: ", cmdline);
54 pt.send(ts_PExecute(cmdline, ""));
55
56 alt {
57 [] pt.receive(res_exp) -> value res;
58 [time_out > 0.0] t.timeout {
59 setverdict(fail, "Timeout: ", cmdline);
60 mtc.stop;
61 }
62 }
63 log ("Result: ", res);
64 return res;
65}
66
67function f_PIPEasp_exec_sync(PIPEasp_PT pt,
68 charstring cmdline,
69 template (present) integer rc := 0) return ASP_PResult {
70 return f_PIPEasp_exec_sync_PResult(pt, cmdline, tr_PResult(?, ?, rc));
71}
72
Pau Espin Pedrol5badb212024-05-15 14:36:53 +020073}