// 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.
/// \file common_inttest.h
/// Common integration tests for the tester binaries.
#if defined(KYUA_COMMON_INTTEST_H)
# error "common_inttest.h can only be defined once"
#endif
/// Include guard.
#define KYUA_COMMON_INTTEST_H
#if !defined(INTERFACE)
# error "Must define INTERFACE to the name of the tester interface"
#endif
#include "cli.h" // For the EXIT_* constants only.
#include "defs.h"
/// Path to the installed testers.
static const char* default_testersdir = TESTERSDIR;
/// Returns the name of the current tester.
#define TESTER_BIN "kyua-" INTERFACE "-tester"
/// Returns the path to the helpers.
///
/// \param tc Pointer to the caller test case, to obtain the srcdir property.
///
/// \return A dynamically-allocated string; must be released with free(3).
static char*
helpers_path(const atf_tc_t* tc)
{
const char* srcdir = atf_tc_get_config_var(tc, "srcdir");
const char* name = INTERFACE "_helpers";
/// Returns the path to the tester.
///
/// \return A dynamically-allocated string; must be released with free(3).
static char*
tester_path(void)
{
const char* testersdir = getenv("TESTERSDIR");
if (testersdir == NULL)
testersdir = default_testersdir;
const char* name = TESTER_BIN;
/// Initializes the test case metadata and the helpers.
///
/// \param [in,out] tc The test case in which to set the property.
/// \param uses_helpers Whether the test uses the helpers or not.
static void
setup(atf_tc_t* tc, const bool uses_helpers)
{
char* tester = tester_path();
if (uses_helpers) {
char* helpers = helpers_path(tc);
atf_tc_set_md_var(tc, "require.progs", "%s %s", tester, helpers);
free(helpers);
} else {
atf_tc_set_md_var(tc, "require.progs", "%s", tester);
}
free(tester);
}
/// Executes the tester with the given set of variable arguments.
///
/// \param ap List of arguments to the tester.
static void
execute(va_list ap)
{
const char* args[16];