1 /* $NetBSD: process_helpers.c,v 1.3 2014/12/10 04:38:03 christos Exp $ */
4 * Automated Testing Framework (atf)
6 * Copyright (c) 2008 The NetBSD Foundation, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
19 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
29 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/types.h>
34 #include <assert.h> /* NO_CHECK_STYLE */
43 h_echo(const char *msg
)
60 kill(getpid(), SIGKILL
);
61 assert(0); /* NO_CHECK_STYLE */
74 h_stdout_stderr(const char *id
)
76 fprintf(stdout
, "Line 1 to stdout for %s\n", id
);
77 fprintf(stdout
, "Line 2 to stdout for %s\n", id
);
78 fprintf(stderr
, "Line 1 to stderr for %s\n", id
);
79 fprintf(stderr
, "Line 2 to stderr for %s\n", id
);
86 check_args(const int argc
, const char *const argv
[], const int required
)
88 if (argc
< required
) {
89 fprintf(stderr
, "Usage: %s helper-name [args]\n", argv
[0]);
95 main(int argc
, const char *const argv
[])
99 check_args(argc
, argv
, 2);
101 if (strcmp(argv
[1], "echo") == 0) {
102 check_args(argc
, argv
, 3);
103 exitcode
= h_echo(argv
[2]);
104 } else if (strcmp(argv
[1], "exit-failure") == 0)
105 exitcode
= h_exit_failure();
106 else if (strcmp(argv
[1], "exit-signal") == 0)
107 exitcode
= h_exit_signal();
108 else if (strcmp(argv
[1], "exit-success") == 0)
109 exitcode
= h_exit_success();
110 else if (strcmp(argv
[1], "stdout-stderr") == 0) {
111 check_args(argc
, argv
, 3);
112 exitcode
= h_stdout_stderr(argv
[2]);
114 fprintf(stderr
, "%s: Unknown helper %s\n", argv
[0], argv
[1]);
115 exitcode
= EXIT_FAILURE
;