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