aboutsummaryrefslogtreecommitdiffstats
path: root/examples
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 /examples
downloadsrc-vendor/kyua.tar.gz
src-vendor/kyua.zip
Import the kyua testing framework for infrastructure softwarevendor/kyua/0.13-a685f91vendor/kyua
Imported at 0.13 plus assumulated changes to git hash a685f91. Obtained from: https://github.com/jmmv/kyua Sponsored by: DARPA
Notes
Notes: svn path=/vendor/kyua/dist/; revision=359042 svn path=/vendor/kyua/0.13-a685f91/; revision=359043; tag=vendor/kyua/0.13-a685f91
Diffstat (limited to 'examples')
-rw-r--r--examples/Kyuafile5
-rw-r--r--examples/Kyuafile.top52
-rw-r--r--examples/Makefile.am.inc45
-rw-r--r--examples/kyua.conf69
-rw-r--r--examples/syntax_test.cpp210
5 files changed, 381 insertions, 0 deletions
diff --git a/examples/Kyuafile b/examples/Kyuafile
new file mode 100644
index 000000000000..2c8f39baad58
--- /dev/null
+++ b/examples/Kyuafile
@@ -0,0 +1,5 @@
+syntax(2)
+
+test_suite("kyua")
+
+atf_test_program{name="syntax_test"}
diff --git a/examples/Kyuafile.top b/examples/Kyuafile.top
new file mode 100644
index 000000000000..3c28945f0cf5
--- /dev/null
+++ b/examples/Kyuafile.top
@@ -0,0 +1,52 @@
+-- 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.
+
+-- Example top-level Kyuafile.
+--
+-- This sample top-level Kyuafile looks for any */Kyuafile files and includes
+-- them in order to process all the test cases within a test suite.
+--
+-- This file is supposed to be installed in the root directory of the tests
+-- hierarchy; typically, this is /usr/tests/Kyuafile (note that the .top
+-- extension has been dropped). Third-party packages install tests as
+-- subdirectories of /usr/tests. When doing so, they should not have to update
+-- the contents of the top-level Kyuafile; in other words, Kyua needs to
+-- discover tests in such subdirectories automatically.
+
+syntax(2)
+
+for file in fs.files(".") do
+ if file == "." or file == ".." then
+ -- Skip these special entries.
+ else
+ local kyuafile = fs.join(file, "Kyuafile")
+ if fs.exists(kyuafile) then
+ include(kyuafile)
+ end
+ end
+end
diff --git a/examples/Makefile.am.inc b/examples/Makefile.am.inc
new file mode 100644
index 000000000000..3c9b27dae6a9
--- /dev/null
+++ b/examples/Makefile.am.inc
@@ -0,0 +1,45 @@
+# 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.
+
+dist_examples_DATA = examples/Kyuafile.top
+dist_examples_DATA += examples/kyua.conf
+
+if WITH_ATF
+tests_examplesdir = $(pkgtestsdir)/examples
+
+tests_examples_DATA = examples/Kyuafile
+EXTRA_DIST += $(tests_examples_DATA)
+
+tests_examples_PROGRAMS = examples/syntax_test
+examples_syntax_test_SOURCES = examples/syntax_test.cpp
+examples_syntax_test_CPPFLAGS = -DKYUA_EXAMPLESDIR="\"$(examplesdir)\""
+examples_syntax_test_CXXFLAGS = $(ENGINE_CFLAGS) $(UTILS_CFLAGS) \
+ $(ATF_CXX_CFLAGS)
+examples_syntax_test_LDADD = $(ENGINE_LIBS) $(UTILS_LIBS) \
+ $(ATF_CXX_LIBS)
+endif
diff --git a/examples/kyua.conf b/examples/kyua.conf
new file mode 100644
index 000000000000..83418a320dc4
--- /dev/null
+++ b/examples/kyua.conf
@@ -0,0 +1,69 @@
+-- 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.
+
+-- Example file for the configuration of Kyua.
+--
+-- All the values shown here do not reflect the default values that Kyua
+-- is using on this installation: these are just fictitious settings that
+-- may or may not work.
+--
+-- To write your own configuration file, it is recommended that you start
+-- from a blank file and then define only those settings that you want to
+-- override. If you want to use this file as a template, you will have
+-- to comment out all the settings first to prevent any side-effects.
+
+-- The file must start by declaring the name and version of its format.
+syntax(2)
+
+-- Name of the system architecture (aka processor type).
+architecture = "x86_64"
+
+-- Maximum number of jobs (such as test case runs) to execute concurrently.
+parallelism = 16
+
+-- Name of the system platform (aka machine type).
+platform = "amd64"
+
+-- The name or UID of the unprivileged user.
+--
+-- If set, this user must exist in the system and his privileges will be
+-- used to run test cases that need regular privileges when Kyua is
+-- executed as root.
+unprivileged_user = "nobody"
+
+-- Set actual configuration properties for the test suite named 'kyua'.
+test_suites.kyua.run_coredump_tests = "false"
+
+-- Set fictitious configuration properties for the test suite named 'FreeBSD'.
+test_suites.FreeBSD.iterations = "1000"
+test_suites.FreeBSD.run_old_tests = "false"
+
+-- Set fictitious configuration properties for the test suite named 'NetBSD'.
+test_suites.NetBSD.file_systems = "ffs lfs ext2fs"
+test_suites.NetBSD.iterations = "100"
+test_suites.NetBSD.run_broken_tests = "true"
diff --git a/examples/syntax_test.cpp b/examples/syntax_test.cpp
new file mode 100644
index 000000000000..a90acb810d4f
--- /dev/null
+++ b/examples/syntax_test.cpp
@@ -0,0 +1,210 @@
+// 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 "engine/config.hpp"
+#include "engine/kyuafile.hpp"
+#include "engine/plain.hpp"
+#include "engine/scheduler.hpp"
+#include "model/metadata.hpp"
+#include "model/test_program.hpp"
+#include "utils/config/tree.ipp"
+#include "utils/env.hpp"
+#include "utils/fs/operations.hpp"
+#include "utils/fs/path.hpp"
+#include "utils/logging/operations.hpp"
+#include "utils/optional.ipp"
+#include "utils/passwd.hpp"
+
+namespace config = utils::config;
+namespace fs = utils::fs;
+namespace passwd = utils::passwd;
+namespace scheduler = engine::scheduler;
+
+using utils::none;
+
+
+namespace {
+
+
+/// Gets the path to an example file.
+///
+/// \param name The name of the example file.
+///
+/// \return A path to the desired example file. This can either be inside the
+/// source tree before installing Kyua or in the target installation directory
+/// after installation.
+static fs::path
+example_file(const char* name)
+{
+ const fs::path examplesdir(utils::getenv_with_default(
+ "KYUA_EXAMPLESDIR", KYUA_EXAMPLESDIR));
+ return examplesdir / name;
+}
+
+
+} // anonymous namespace
+
+
+ATF_TEST_CASE(kyua_conf);
+ATF_TEST_CASE_HEAD(kyua_conf)
+{
+ utils::logging::set_inmemory();
+ set_md_var("require.files", example_file("kyua.conf").str());
+}
+ATF_TEST_CASE_BODY(kyua_conf)
+{
+ std::vector< passwd::user > users;
+ users.push_back(passwd::user("nobody", 1, 2));
+ passwd::set_mock_users_for_testing(users);
+
+ const config::tree user_config = engine::load_config(
+ example_file("kyua.conf"));
+
+ ATF_REQUIRE_EQ(
+ "x86_64",
+ user_config.lookup< config::string_node >("architecture"));
+ ATF_REQUIRE_EQ(
+ 16,
+ user_config.lookup< config::positive_int_node >("parallelism"));
+ ATF_REQUIRE_EQ(
+ "amd64",
+ user_config.lookup< config::string_node >("platform"));
+
+ ATF_REQUIRE_EQ(
+ "nobody",
+ user_config.lookup< engine::user_node >("unprivileged_user").name);
+
+ config::properties_map exp_test_suites;
+ exp_test_suites["test_suites.kyua.run_coredump_tests"] = "false";
+ exp_test_suites["test_suites.FreeBSD.iterations"] = "1000";
+ exp_test_suites["test_suites.FreeBSD.run_old_tests"] = "false";
+ exp_test_suites["test_suites.NetBSD.file_systems"] = "ffs lfs ext2fs";
+ exp_test_suites["test_suites.NetBSD.iterations"] = "100";
+ exp_test_suites["test_suites.NetBSD.run_broken_tests"] = "true";
+ ATF_REQUIRE(exp_test_suites == user_config.all_properties("test_suites"));
+}
+
+
+ATF_TEST_CASE(kyuafile_top__no_matches);
+ATF_TEST_CASE_HEAD(kyuafile_top__no_matches)
+{
+ utils::logging::set_inmemory();
+ set_md_var("require.files", example_file("Kyuafile.top").str());
+}
+ATF_TEST_CASE_BODY(kyuafile_top__no_matches)
+{
+ scheduler::scheduler_handle handle = scheduler::setup();
+
+ fs::mkdir(fs::path("root"), 0755);
+ const fs::path source_path = example_file("Kyuafile.top");
+ ATF_REQUIRE(::symlink(source_path.c_str(), "root/Kyuafile") != -1);
+
+ atf::utils::create_file("root/file", "");
+ fs::mkdir(fs::path("root/subdir"), 0755);
+
+ const engine::kyuafile kyuafile = engine::kyuafile::load(
+ fs::path("root/Kyuafile"), none, engine::default_config(), handle);
+ ATF_REQUIRE_EQ(fs::path("root"), kyuafile.source_root());
+ ATF_REQUIRE_EQ(fs::path("root"), kyuafile.build_root());
+ ATF_REQUIRE(kyuafile.test_programs().empty());
+
+ handle.cleanup();
+}
+
+
+ATF_TEST_CASE(kyuafile_top__some_matches);
+ATF_TEST_CASE_HEAD(kyuafile_top__some_matches)
+{
+ utils::logging::set_inmemory();
+ set_md_var("require.files", example_file("Kyuafile.top").str());
+}
+ATF_TEST_CASE_BODY(kyuafile_top__some_matches)
+{
+ scheduler::scheduler_handle handle = scheduler::setup();
+
+ fs::mkdir(fs::path("root"), 0755);
+ const fs::path source_path = example_file("Kyuafile.top");
+ ATF_REQUIRE(::symlink(source_path.c_str(), "root/Kyuafile") != -1);
+
+ atf::utils::create_file("root/file", "");
+
+ fs::mkdir(fs::path("root/subdir1"), 0755);
+ atf::utils::create_file("root/subdir1/Kyuafile",
+ "syntax(2)\n"
+ "plain_test_program{name='a', test_suite='b'}\n");
+ atf::utils::create_file("root/subdir1/a", "");
+
+ fs::mkdir(fs::path("root/subdir2"), 0755);
+ atf::utils::create_file("root/subdir2/Kyuafile",
+ "syntax(2)\n"
+ "plain_test_program{name='c', test_suite='d'}\n");
+ atf::utils::create_file("root/subdir2/c", "");
+ atf::utils::create_file("root/subdir2/Kyuafile.etc", "invalid");
+
+ const engine::kyuafile kyuafile = engine::kyuafile::load(
+ fs::path("root/Kyuafile"), none, engine::default_config(), handle);
+ ATF_REQUIRE_EQ(fs::path("root"), kyuafile.source_root());
+ ATF_REQUIRE_EQ(fs::path("root"), kyuafile.build_root());
+
+ const model::test_program exp_test_program_a = model::test_program_builder(
+ "plain", fs::path("subdir1/a"), fs::path("root").to_absolute(), "b")
+ .add_test_case("main")
+ .build();
+ const model::test_program exp_test_program_c = model::test_program_builder(
+ "plain", fs::path("subdir2/c"), fs::path("root").to_absolute(), "d")
+ .add_test_case("main")
+ .build();
+
+ ATF_REQUIRE_EQ(2, kyuafile.test_programs().size());
+ ATF_REQUIRE((exp_test_program_a == *kyuafile.test_programs()[0] &&
+ exp_test_program_c == *kyuafile.test_programs()[1])
+ ||
+ (exp_test_program_a == *kyuafile.test_programs()[1] &&
+ exp_test_program_c == *kyuafile.test_programs()[0]));
+
+ handle.cleanup();
+}
+
+
+ATF_INIT_TEST_CASES(tcs)
+{
+ scheduler::register_interface(
+ "plain", std::shared_ptr< scheduler::interface >(
+ new engine::plain_interface()));
+
+ ATF_ADD_TEST_CASE(tcs, kyua_conf);
+
+ ATF_ADD_TEST_CASE(tcs, kyuafile_top__no_matches);
+ ATF_ADD_TEST_CASE(tcs, kyuafile_top__some_matches);
+}