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