// Copyright 2012 Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Google Inc. nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/// Template for the creation of the temporary work directories.
#define WORKDIR_TEMPLATE "kyua.plain-tester.XXXXXX"
/// Name of the fake test case exposed by the program.
const char* const fake_test_case_name = "main";
/// Converts the exit status of a program to a result.
///
/// \param status Exit status of the test program, as returned by waitpid().
/// \param timed_out Whether the test program timed out or not.
/// \param result_file Path to the result file to create.
/// \param [out] success Set to true if the test program returned with a
/// successful condition.
///
/// \return An error if something went wrong.
static kyua_error_t
status_to_result(int status, const bool timed_out, const char* result_file,
bool* success)
{
if (timed_out) {
*success = false;
return kyua_result_write(result_file, KYUA_RESULT_BROKEN,
"Test case timed out");
}
/// Lists the test cases in a test program.
///
/// \param unused_test_program Path to the test program for which to list the
/// test cases. Should be absolute.
/// \param unused_run_params Execution parameters to configure the test process.
///
/// \return An error if the listing fails; OK otherwise.
static kyua_error_t
list_test_cases(const char* KYUA_DEFS_UNUSED_PARAM(test_program),
const kyua_run_params_t* KYUA_DEFS_UNUSED_PARAM(run_params))
{
printf("test_case{name='%s'}\n", fake_test_case_name);
return kyua_error_ok();
}
/// Runs a single test cases of a test program.
///
/// \param test_program Path to the test program for which to list the test
/// cases. Should be absolute.
/// \param test_case Name of the test case to run.
/// \param result_file Path to the file to which to write the result of the
/// test. Should be absolute.
/// \param user_variables Array of name=value pairs that describe the user
/// configuration variables for the test case.
/// \param run_params Execution parameters to configure the test process.
/// \param [out] success Set to true if the test case reported a valid exit
/// condition (like "passed" or "skipped"); false otherwise. This is
/// only updated if the method returns OK.
///
/// \return An error if the listing fails; OK otherwise.
static kyua_error_t
run_test_case(const char* test_program, const char* test_case,
const char* result_file, const char* const user_variables[],
const kyua_run_params_t* run_params,
bool* success)
{
kyua_error_t error;
if (strcmp(test_case, fake_test_case_name) != 0) {
error = kyua_generic_error_new("Unknown test case '%s'", test_case);
goto out;
}