process_test.cpp revision 4a53e3c2b83c476a93148eaee0272649beb221ca
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// Copyright (c) 2008 The NetBSD Foundation, Inc.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// All rights reserved.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// Redistribution and use in source and binary forms, with or without
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// modification, are permitted provided that the following conditions
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// 1. Redistributions of source code must retain the above copyright
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// notice, this list of conditions and the following disclaimer.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// 2. Redistributions in binary form must reproduce the above copyright
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// notice, this list of conditions and the following disclaimer in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// documentation and/or other materials provided with the distribution.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#include "atf-c++/detail/process.hpp"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#include "atf-c++/detail/test_helpers.hpp"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// TODO: Testing the fork function is a huge task and I'm afraid of
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// copy/pasting tons of stuff from the C version. I'd rather not do that
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// until some code can be shared, which cannot happen until the C++ binding
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// is cleaned by a fair amount. Instead... just rely (at the moment) on
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// the system tests for the tools using this module.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// ------------------------------------------------------------------------
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// Auxiliary functions.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// ------------------------------------------------------------------------
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (const char* const* ptr = array; *ptr != NULL; ptr++)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterexec_process_helpers(const atf::tests::tc& tc, const char* helper_name)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster argv.push_back(get_process_helpers_path(tc, true).leaf_name());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return exec(get_process_helpers_path(tc, true),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// ------------------------------------------------------------------------
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// Tests for the "argv_array" type.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster// ------------------------------------------------------------------------
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster set_md_var("descr", "Tests that argv_array is correctly constructed "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "from a C-style array of strings");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ATF_REQUIRE(std::strcmp(argv[0], carray[0]) == 0);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster const char* const carray[] = { "arg0", "arg1", "arg2", NULL };
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ATF_REQUIRE(std::strcmp(argv[0], carray[0]) == 0);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ATF_REQUIRE(std::strcmp(argv[1], carray[1]) == 0);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ATF_REQUIRE(std::strcmp(argv[2], carray[2]) == 0);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster set_md_var("descr", "Tests that argv_array is correctly constructed "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "from a string collection");
iter++) {
pos++;