xref: /netbsd-src/external/bsd/kyua-testers/dist/cli.h (revision 754f425fc237c181450c91977727274098801c74)
1 // Copyright 2012 Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 //   notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 //   notice, this list of conditions and the following disclaimer in the
12 //   documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 //   may be used to endorse or promote products derived from this software
15 //   without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 /// \file cli.h
30 /// Generic command-line implementation of a tester.
31 ///
32 /// The cli module implements a generic command-line for a tester
33 /// regardless of the test interface it implements.  This command-line must
34 /// be consistent across all implementations so that the Kyua runtime does
35 /// not need to have any knowledge of the specific test interfaces.
36 
37 #if !defined(KYUA_CLI_H)
38 #define KYUA_CLI_H
39 
40 #include "cli_fwd.h"
41 
42 #include <stdbool.h>
43 
44 #include "error_fwd.h"
45 #include "run_fwd.h"
46 
47 
48 // Error codes returned by the CLI are as follows.  These match the rationale of
49 // the return values of the kyua(1) tool.
50 //
51 // EXIT_SUCCESS -> The command and the tester ran correctly.
52 // EXIT_FAILURE -> The command reported an error, but the tester ran correctly.
53 //     For example: the test command reports that the test itself failed, but
54 //     nothing in the tester misbehaved.
55 // EXIT_INTERNAL_ERROR -> The tester itself failed.
56 // EXIT_USAGE_ERROR -> The user caused an error in the command line.
57 
58 /// Constant to indicate an unexpected error in the tester.
59 #define EXIT_INTERNAL_ERROR 2
60 /// Constant to indicate a usage error.
61 #define EXIT_USAGE_ERROR 3
62 
63 
64 /// Description of a tester.
65 struct kyua_cli_tester {
66     /// Lists the test cases in a test program.
67     ///
68     /// \param test_program Path to the test program for which to list the test
69     ///     cases.  Should be absolute.
70     /// \param run_params Execution parameters to configure the test process.
71     ///
72     /// \return An error if the listing fails; OK otherwise.
73     kyua_error_t (*list_test_cases)(const char* test_program,
74                                     const kyua_run_params_t* run_params);
75 
76     /// Runs a single test cases of a test program.
77     ///
78     /// \param test_program Path to the test program for which to list the test
79     ///     cases.  Should be absolute.
80     /// \param test_case Name of the test case to run.
81     /// \param result_file Path to the file to which to write the result of the
82     ///     test.  Should be absolute.
83     /// \param user_variables Array of name=value pairs that describe the user
84     ///     configuration variables for the test case.
85     /// \param run_params Execution parameters to configure the test process.
86     /// \param [out] success Set to true if the test case reported a valid exit
87     ///     condition (like "passed" or "skipped"); false otherwise.  This is
88     ///     only updated if the method returns OK.
89     ///
90     /// \return An error if the listing fails; OK otherwise.
91     kyua_error_t (*run_test_case)(const char* test_program,
92                                   const char* test_case,
93                                   const char* result_file,
94                                   const char* const user_variables[],
95                                   const kyua_run_params_t* run_params,
96                                   bool* success);
97 };
98 
99 
100 int kyua_cli_main(const int, char* const* const, const kyua_cli_tester_t*);
101 
102 
103 #endif  // !defined(KYUA_CLI_H)
104