summaryrefslogtreecommitdiff
path: root/integration/helpers
diff options
context:
space:
mode:
authorBrooks Davis <brooks@FreeBSD.org>2020-03-17 16:56:50 +0000
committerBrooks Davis <brooks@FreeBSD.org>2020-03-17 16:56:50 +0000
commit08334c51dbb99d9ecd2bb86a2d94ed06da9e167a (patch)
treec43eb24d59bd5c963583a5190caef80fc8387322 /integration/helpers
Notes
Diffstat (limited to 'integration/helpers')
-rw-r--r--integration/helpers/.gitignore11
-rw-r--r--integration/helpers/Makefile.am.inc90
-rw-r--r--integration/helpers/bad_test_program.cpp50
-rw-r--r--integration/helpers/bogus_test_cases.cpp64
-rw-r--r--integration/helpers/config.cpp58
-rw-r--r--integration/helpers/dump_env.cpp74
-rw-r--r--integration/helpers/expect_all_pass.cpp92
-rw-r--r--integration/helpers/expect_some_fail.cpp94
-rw-r--r--integration/helpers/interrupts.cpp62
-rw-r--r--integration/helpers/metadata.cpp95
-rw-r--r--integration/helpers/race.cpp99
-rw-r--r--integration/helpers/simple_all_pass.cpp55
-rw-r--r--integration/helpers/simple_some_fail.cpp53
13 files changed, 897 insertions, 0 deletions
diff --git a/integration/helpers/.gitignore b/integration/helpers/.gitignore
new file mode 100644
index 000000000000..11634bcfeb85
--- /dev/null
+++ b/integration/helpers/.gitignore
@@ -0,0 +1,11 @@
+bad_test_program
+bogus_test_cases
+config
+dump_env
+expect_all_pass
+expect_some_fail
+interrupts
+metadata
+race
+simple_all_pass
+simple_some_fail
diff --git a/integration/helpers/Makefile.am.inc b/integration/helpers/Makefile.am.inc
new file mode 100644
index 000000000000..d835aba51c67
--- /dev/null
+++ b/integration/helpers/Makefile.am.inc
@@ -0,0 +1,90 @@
+# Copyright 2011 The Kyua Authors.
+# 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.
+
+if WITH_ATF
+tests_integration_helpersdir = $(pkgtestsdir)/integration/helpers
+
+tests_integration_helpers_PROGRAMS = integration/helpers/bad_test_program
+integration_helpers_bad_test_program_SOURCES = \
+ integration/helpers/bad_test_program.cpp
+
+tests_integration_helpers_PROGRAMS += integration/helpers/bogus_test_cases
+integration_helpers_bogus_test_cases_SOURCES = \
+ integration/helpers/bogus_test_cases.cpp
+integration_helpers_bogus_test_cases_CXXFLAGS = $(ATF_CXX_CFLAGS)
+integration_helpers_bogus_test_cases_LDADD = $(ATF_CXX_LIBS)
+
+tests_integration_helpers_PROGRAMS += integration/helpers/config
+integration_helpers_config_SOURCES = integration/helpers/config.cpp
+integration_helpers_config_CXXFLAGS = $(ATF_CXX_CFLAGS)
+integration_helpers_config_LDADD = $(ATF_CXX_LIBS)
+
+tests_integration_helpers_PROGRAMS += integration/helpers/dump_env
+integration_helpers_dump_env_SOURCES = integration/helpers/dump_env.cpp
+integration_helpers_dump_env_CXXFLAGS = $(UTILS_CFLAGS)
+integration_helpers_dump_env_LDADD = $(UTILS_LIBS)
+
+tests_integration_helpers_PROGRAMS += integration/helpers/expect_all_pass
+integration_helpers_expect_all_pass_SOURCES = \
+ integration/helpers/expect_all_pass.cpp
+integration_helpers_expect_all_pass_CXXFLAGS = $(ATF_CXX_CFLAGS)
+integration_helpers_expect_all_pass_LDADD = $(ATF_CXX_LIBS)
+
+tests_integration_helpers_PROGRAMS += integration/helpers/expect_some_fail
+integration_helpers_expect_some_fail_SOURCES = \
+ integration/helpers/expect_some_fail.cpp
+integration_helpers_expect_some_fail_CXXFLAGS = $(ATF_CXX_CFLAGS)
+integration_helpers_expect_some_fail_LDADD = $(ATF_CXX_LIBS)
+
+tests_integration_helpers_PROGRAMS += integration/helpers/interrupts
+integration_helpers_interrupts_SOURCES = integration/helpers/interrupts.cpp
+integration_helpers_interrupts_CXXFLAGS = $(ATF_CXX_CFLAGS)
+integration_helpers_interrupts_LDADD = $(ATF_CXX_LIBS)
+
+tests_integration_helpers_PROGRAMS += integration/helpers/metadata
+integration_helpers_metadata_SOURCES = integration/helpers/metadata.cpp
+integration_helpers_metadata_CXXFLAGS = $(ATF_CXX_CFLAGS)
+integration_helpers_metadata_LDADD = $(ATF_CXX_LIBS)
+
+tests_integration_helpers_PROGRAMS += integration/helpers/race
+integration_helpers_race_SOURCES = integration/helpers/race.cpp
+integration_helpers_race_CXXFLAGS = $(UTILS_CFLAGS)
+integration_helpers_race_LDADD = $(UTILS_LIBS)
+
+tests_integration_helpers_PROGRAMS += integration/helpers/simple_all_pass
+integration_helpers_simple_all_pass_SOURCES = \
+ integration/helpers/simple_all_pass.cpp
+integration_helpers_simple_all_pass_CXXFLAGS = $(ATF_CXX_CFLAGS)
+integration_helpers_simple_all_pass_LDADD = $(ATF_CXX_LIBS)
+
+tests_integration_helpers_PROGRAMS += integration/helpers/simple_some_fail
+integration_helpers_simple_some_fail_SOURCES = \
+ integration/helpers/simple_some_fail.cpp
+integration_helpers_simple_some_fail_CXXFLAGS = $(ATF_CXX_CFLAGS)
+integration_helpers_simple_some_fail_LDADD = $(ATF_CXX_LIBS)
+endif
diff --git a/integration/helpers/bad_test_program.cpp b/integration/helpers/bad_test_program.cpp
new file mode 100644
index 000000000000..210709ee8976
--- /dev/null
+++ b/integration/helpers/bad_test_program.cpp
@@ -0,0 +1,50 @@
+// Copyright 2011 The Kyua Authors.
+// 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.
+
+#include <cstdlib>
+#include <cstring>
+#include <fstream>
+#include <iostream>
+
+
+int
+main(void)
+{
+ std::cerr << "This is not a valid test program!\n";
+
+ const char* cookie = std::getenv("CREATE_COOKIE");
+ if (cookie != NULL && std::strlen(cookie) > 0) {
+ std::ofstream file(cookie);
+ if (!file)
+ std::abort();
+ file << "Cookie file\n";
+ file.close();
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/integration/helpers/bogus_test_cases.cpp b/integration/helpers/bogus_test_cases.cpp
new file mode 100644
index 000000000000..1a7c27031e1b
--- /dev/null
+++ b/integration/helpers/bogus_test_cases.cpp
@@ -0,0 +1,64 @@
+// Copyright 2011 The Kyua Authors.
+// 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.
+
+extern "C" {
+#include <signal.h>
+#include <unistd.h>
+}
+
+#include <cstdlib>
+
+#include <atf-c++.hpp>
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(die);
+ATF_TEST_CASE_BODY(die)
+{
+ ::kill(::getpid(), SIGKILL);
+}
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(exit);
+ATF_TEST_CASE_BODY(exit)
+{
+ std::exit(EXIT_SUCCESS);
+}
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(pass);
+ATF_TEST_CASE_BODY(pass)
+{
+}
+
+
+ATF_INIT_TEST_CASES(tcs)
+{
+ ATF_ADD_TEST_CASE(tcs, die);
+ ATF_ADD_TEST_CASE(tcs, exit);
+ ATF_ADD_TEST_CASE(tcs, pass);
+}
diff --git a/integration/helpers/config.cpp b/integration/helpers/config.cpp
new file mode 100644
index 000000000000..aa4fef291725
--- /dev/null
+++ b/integration/helpers/config.cpp
@@ -0,0 +1,58 @@
+// Copyright 2011 The Kyua Authors.
+// 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.
+
+#include <cstdlib>
+
+#include <atf-c++.hpp>
+
+
+ATF_TEST_CASE(get_variable);
+ATF_TEST_CASE_HEAD(get_variable)
+{
+ const char* output = ::getenv("CONFIG_VAR_FILE");
+ if (output == NULL) {
+ set_md_var("require.config", "the-variable");
+ } else {
+ if (has_config_var("the-variable")) {
+ atf::utils::create_file(output, get_config_var("the-variable") +
+ std::string("\n"));
+ } else {
+ atf::utils::create_file(output, "NOT DEFINED\n");
+ }
+ }
+}
+ATF_TEST_CASE_BODY(get_variable)
+{
+ ATF_REQUIRE_EQ("value2", get_config_var("the-variable"));
+}
+
+
+ATF_INIT_TEST_CASES(tcs)
+{
+ ATF_ADD_TEST_CASE(tcs, get_variable);
+}
diff --git a/integration/helpers/dump_env.cpp b/integration/helpers/dump_env.cpp
new file mode 100644
index 000000000000..a2e8313a0062
--- /dev/null
+++ b/integration/helpers/dump_env.cpp
@@ -0,0 +1,74 @@
+// Copyright 2015 The Kyua Authors.
+// 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.
+
+// Dumps all environment variables.
+//
+// This helper program allows comparing the printed environment variables
+// to what 'kyua report --verbose' may output. It does so by sorting the
+// variables and allowing the caller to customize how the output looks
+// like (indentation for each line and for continuation lines).
+
+#include <cstdlib>
+#include <iostream>
+
+#include "utils/env.hpp"
+#include "utils/text/operations.ipp"
+
+namespace text = utils::text;
+
+
+int
+main(const int argc, const char* const* const argv)
+{
+ if (argc != 3) {
+ std::cerr << "Usage: dump_env <prefix> <continuation-prefix>\n";
+ return EXIT_FAILURE;
+ }
+ const char* prefix = argv[1];
+ const char* continuation_prefix = argv[2];
+
+ const std::map< std::string, std::string > env = utils::getallenv();
+ for (std::map< std::string, std::string >::const_iterator
+ iter = env.begin(); iter != env.end(); ++iter) {
+ const std::string& name = (*iter).first;
+ const std::vector< std::string > value = text::split(
+ (*iter).second, '\n');
+
+ if (value.empty()) {
+ std::cout << prefix << name << "=\n";
+ } else {
+ std::cout << prefix << name << '=' << value[0] << '\n';
+ for (std::vector< std::string >::size_type i = 1;
+ i < value.size(); ++i) {
+ std::cout << continuation_prefix << value[i] << '\n';
+ }
+ }
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/integration/helpers/expect_all_pass.cpp b/integration/helpers/expect_all_pass.cpp
new file mode 100644
index 000000000000..a7df16e3a783
--- /dev/null
+++ b/integration/helpers/expect_all_pass.cpp
@@ -0,0 +1,92 @@
+// Copyright 2011 The Kyua Authors.
+// 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.
+
+extern "C" {
+#include <signal.h>
+#include <unistd.h>
+}
+
+#include <cstdlib>
+
+#include <atf-c++.hpp>
+
+#include "utils/test_utils.ipp"
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(die);
+ATF_TEST_CASE_BODY(die)
+{
+ expect_death("This is the reason for death");
+ utils::abort_without_coredump();
+}
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(exit);
+ATF_TEST_CASE_BODY(exit)
+{
+ expect_exit(12, "Exiting with correct code");
+ std::exit(12);
+}
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(failure);
+ATF_TEST_CASE_BODY(failure)
+{
+ expect_fail("Oh no");
+ fail("Forced failure");
+}
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(signal);
+ATF_TEST_CASE_BODY(signal)
+{
+ expect_signal(SIGTERM, "Exiting with correct signal");
+ ::kill(::getpid(), SIGTERM);
+}
+
+
+ATF_TEST_CASE(timeout);
+ATF_TEST_CASE_HEAD(timeout)
+{
+ set_md_var("timeout", "1");
+}
+ATF_TEST_CASE_BODY(timeout)
+{
+ expect_timeout("This times out");
+ ::sleep(10);
+}
+
+
+ATF_INIT_TEST_CASES(tcs)
+{
+ ATF_ADD_TEST_CASE(tcs, die);
+ ATF_ADD_TEST_CASE(tcs, exit);
+ ATF_ADD_TEST_CASE(tcs, failure);
+ ATF_ADD_TEST_CASE(tcs, signal);
+ ATF_ADD_TEST_CASE(tcs, timeout);
+}
diff --git a/integration/helpers/expect_some_fail.cpp b/integration/helpers/expect_some_fail.cpp
new file mode 100644
index 000000000000..da1a9f0ceb39
--- /dev/null
+++ b/integration/helpers/expect_some_fail.cpp
@@ -0,0 +1,94 @@
+// Copyright 2011 The Kyua Authors.
+// 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.
+
+extern "C" {
+#include <signal.h>
+#include <unistd.h>
+}
+
+#include <cstdlib>
+
+#include <atf-c++.hpp>
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(die);
+ATF_TEST_CASE_BODY(die)
+{
+ expect_death("Won't die");
+}
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(exit);
+ATF_TEST_CASE_BODY(exit)
+{
+ expect_exit(12, "Invalid exit code");
+ std::exit(34);
+}
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(failure);
+ATF_TEST_CASE_BODY(failure)
+{
+ expect_fail("Does not fail");
+}
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(pass);
+ATF_TEST_CASE_BODY(pass)
+{
+}
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(signal);
+ATF_TEST_CASE_BODY(signal)
+{
+ expect_signal(SIGTERM, "Invalid signal");
+ ::kill(::getpid(), SIGKILL);
+}
+
+
+ATF_TEST_CASE(timeout);
+ATF_TEST_CASE_HEAD(timeout)
+{
+ set_md_var("timeout", "1");
+}
+ATF_TEST_CASE_BODY(timeout)
+{
+ expect_timeout("Does not time out");
+}
+
+
+ATF_INIT_TEST_CASES(tcs)
+{
+ ATF_ADD_TEST_CASE(tcs, die);
+ ATF_ADD_TEST_CASE(tcs, exit);
+ ATF_ADD_TEST_CASE(tcs, failure);
+ ATF_ADD_TEST_CASE(tcs, pass);
+ ATF_ADD_TEST_CASE(tcs, signal);
+ ATF_ADD_TEST_CASE(tcs, timeout);
+}
diff --git a/integration/helpers/interrupts.cpp b/integration/helpers/interrupts.cpp
new file mode 100644
index 000000000000..b6c5a948098c
--- /dev/null
+++ b/integration/helpers/interrupts.cpp
@@ -0,0 +1,62 @@
+// Copyright 2011 The Kyua Authors.
+// 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.
+
+extern "C" {
+#include <unistd.h>
+}
+
+#include <atf-c++.hpp>
+
+#include <fstream>
+
+
+ATF_TEST_CASE_WITH_CLEANUP(block_body);
+ATF_TEST_CASE_HEAD(block_body)
+{
+ set_md_var("require.config", "body-cookie cleanup-cookie");
+}
+ATF_TEST_CASE_BODY(block_body)
+{
+ const std::string cookie(get_config_var("body-cookie"));
+ std::ofstream output(cookie.c_str());
+ output.close();
+ for (;;)
+ ::pause();
+}
+ATF_TEST_CASE_CLEANUP(block_body)
+{
+ const std::string cookie(get_config_var("cleanup-cookie"));
+ std::ofstream output(cookie.c_str());
+ output.close();
+}
+
+
+ATF_INIT_TEST_CASES(tcs)
+{
+ ATF_ADD_TEST_CASE(tcs, block_body);
+}
diff --git a/integration/helpers/metadata.cpp b/integration/helpers/metadata.cpp
new file mode 100644
index 000000000000..8005d7d9b68d
--- /dev/null
+++ b/integration/helpers/metadata.cpp
@@ -0,0 +1,95 @@
+// Copyright 2011 The Kyua Authors.
+// 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.
+
+#include <cstdlib>
+#include <iostream>
+
+#include <atf-c++.hpp>
+
+#include "utils/test_utils.ipp"
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(no_properties);
+ATF_TEST_CASE_BODY(no_properties)
+{
+}
+
+
+ATF_TEST_CASE(one_property);
+ATF_TEST_CASE_HEAD(one_property)
+{
+ set_md_var("descr", "Does nothing but has one metadata property");
+}
+ATF_TEST_CASE_BODY(one_property)
+{
+ utils::abort_without_coredump();
+}
+
+
+ATF_TEST_CASE(many_properties);
+ATF_TEST_CASE_HEAD(many_properties)
+{
+ set_md_var("descr", " A description with some padding");
+ set_md_var("require.arch", "some-architecture");
+ set_md_var("require.config", "var1 var2 var3");
+ set_md_var("require.files", "/my/file1 /some/other/file");
+ set_md_var("require.machine", "some-platform");
+ set_md_var("require.progs", "bin1 bin2 /nonexistent/bin3");
+ set_md_var("require.user", "root");
+ set_md_var("X-no-meaning", "I am a custom variable");
+}
+ATF_TEST_CASE_BODY(many_properties)
+{
+ utils::abort_without_coredump();
+}
+
+
+ATF_TEST_CASE_WITH_CLEANUP(with_cleanup);
+ATF_TEST_CASE_HEAD(with_cleanup)
+{
+ set_md_var("timeout", "250");
+}
+ATF_TEST_CASE_BODY(with_cleanup)
+{
+ std::cout << "Body message to stdout\n";
+ std::cerr << "Body message to stderr\n";
+}
+ATF_TEST_CASE_CLEANUP(with_cleanup)
+{
+ std::cout << "Cleanup message to stdout\n";
+ std::cerr << "Cleanup message to stderr\n";
+}
+
+
+ATF_INIT_TEST_CASES(tcs)
+{
+ ATF_ADD_TEST_CASE(tcs, no_properties);
+ ATF_ADD_TEST_CASE(tcs, one_property);
+ ATF_ADD_TEST_CASE(tcs, many_properties);
+ ATF_ADD_TEST_CASE(tcs, with_cleanup);
+}
diff --git a/integration/helpers/race.cpp b/integration/helpers/race.cpp
new file mode 100644
index 000000000000..39d4b04f3923
--- /dev/null
+++ b/integration/helpers/race.cpp
@@ -0,0 +1,99 @@
+// Copyright 2015 The Kyua Authors.
+// 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 integration/helpers/race.cpp
+/// Creates a file and reads it back, looking for races.
+///
+/// This program should fail with high chances if it is called multiple times at
+/// once with TEST_ENV_shared_file pointing to the same file.
+
+extern "C" {
+#include <sys/types.h>
+
+#include <unistd.h>
+}
+
+#include <cstdlib>
+#include <fstream>
+#include <iostream>
+
+#include "utils/format/macros.hpp"
+#include "utils/fs/operations.hpp"
+#include "utils/fs/path.hpp"
+#include "utils/env.hpp"
+#include "utils/optional.ipp"
+#include "utils/stream.hpp"
+
+namespace fs = utils::fs;
+
+using utils::optional;
+
+
+/// Entry point to the helper test program.
+///
+/// \return EXIT_SUCCESS if no race is detected; EXIT_FAILURE otherwise.
+int
+main(void)
+{
+ const optional< std::string > shared_file = utils::getenv(
+ "TEST_ENV_shared_file");
+ if (!shared_file) {
+ std::cerr << "Environment variable TEST_ENV_shared_file not defined\n";
+ std::exit(EXIT_FAILURE);
+ }
+ const fs::path shared_path(shared_file.get());
+
+ if (fs::exists(shared_path)) {
+ std::cerr << "Shared file already exists; created by a concurrent "
+ "test?";
+ std::exit(EXIT_FAILURE);
+ }
+
+ const std::string contents = F("%s") % ::getpid();
+
+ std::ofstream output(shared_path.c_str());
+ if (!output) {
+ std::cerr << "Failed to create shared file; conflict with a concurrent "
+ "test?";
+ std::exit(EXIT_FAILURE);
+ }
+ output << contents;
+ output.close();
+
+ ::usleep(10000);
+
+ const std::string read_contents = utils::read_file(shared_path);
+ if (read_contents != contents) {
+ std::cerr << "Shared file contains unexpected contents; modified by a "
+ "concurrent test?";
+ std::exit(EXIT_FAILURE);
+ }
+
+ fs::unlink(shared_path);
+ std::exit(EXIT_SUCCESS);
+}
diff --git a/integration/helpers/simple_all_pass.cpp b/integration/helpers/simple_all_pass.cpp
new file mode 100644
index 000000000000..4e168b4cca5f
--- /dev/null
+++ b/integration/helpers/simple_all_pass.cpp
@@ -0,0 +1,55 @@
+// Copyright 2011 The Kyua Authors.
+// 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.
+
+#include <iostream>
+
+#include <atf-c++.hpp>
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(pass);
+ATF_TEST_CASE_BODY(pass)
+{
+ std::cout << "This is the stdout of pass\n";
+ std::cerr << "This is the stderr of pass\n";
+}
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(skip);
+ATF_TEST_CASE_BODY(skip)
+{
+ std::cout << "This is the stdout of skip\n";
+ std::cerr << "This is the stderr of skip\n";
+ skip("The reason for skipping is this");
+}
+
+
+ATF_INIT_TEST_CASES(tcs)
+{
+ ATF_ADD_TEST_CASE(tcs, pass);
+ ATF_ADD_TEST_CASE(tcs, skip);
+}
diff --git a/integration/helpers/simple_some_fail.cpp b/integration/helpers/simple_some_fail.cpp
new file mode 100644
index 000000000000..909ffb6e2ee1
--- /dev/null
+++ b/integration/helpers/simple_some_fail.cpp
@@ -0,0 +1,53 @@
+// Copyright 2011 The Kyua Authors.
+// 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.
+
+#include <iostream>
+
+#include <atf-c++.hpp>
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(fail);
+ATF_TEST_CASE_BODY(fail)
+{
+ std::cout << "This is the stdout of fail\n";
+ std::cerr << "This is the stderr of fail\n";
+ fail("This fails on purpose");
+}
+
+
+ATF_TEST_CASE_WITHOUT_HEAD(pass);
+ATF_TEST_CASE_BODY(pass)
+{
+}
+
+
+ATF_INIT_TEST_CASES(tcs)
+{
+ ATF_ADD_TEST_CASE(tcs, fail);
+ ATF_ADD_TEST_CASE(tcs, pass);
+}