1 // Copyright 2011 The Kyua Authors.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <atf-c++.hpp>
35 #include "engine/config.hpp"
36 #include "engine/kyuafile.hpp"
37 #include "engine/plain.hpp"
38 #include "engine/scheduler.hpp"
39 #include "model/metadata.hpp"
40 #include "model/test_program.hpp"
41 #include "utils/config/tree.ipp"
42 #include "utils/env.hpp"
43 #include "utils/fs/operations.hpp"
44 #include "utils/fs/path.hpp"
45 #include "utils/logging/operations.hpp"
46 #include "utils/optional.ipp"
47 #include "utils/passwd.hpp"
49 namespace config = utils::config;
50 namespace fs = utils::fs;
51 namespace passwd = utils::passwd;
52 namespace scheduler = engine::scheduler;
60 /// Gets the path to an example file.
62 /// \param name The name of the example file.
64 /// \return A path to the desired example file. This can either be inside the
65 /// source tree before installing Kyua or in the target installation directory
66 /// after installation.
68 example_file(const char* name)
70 const fs::path examplesdir(utils::getenv_with_default(
71 "KYUA_EXAMPLESDIR", KYUA_EXAMPLESDIR));
72 return examplesdir / name;
76 } // anonymous namespace
79 ATF_TEST_CASE(kyua_conf);
80 ATF_TEST_CASE_HEAD(kyua_conf)
82 utils::logging::set_inmemory();
83 set_md_var("require.files", example_file("kyua.conf").str());
85 ATF_TEST_CASE_BODY(kyua_conf)
87 std::vector< passwd::user > users;
88 users.push_back(passwd::user("nobody", 1, 2));
89 passwd::set_mock_users_for_testing(users);
91 const config::tree user_config = engine::load_config(
92 example_file("kyua.conf"));
96 user_config.lookup< config::string_node >("architecture"));
99 user_config.lookup< config::positive_int_node >("parallelism"));
102 user_config.lookup< config::string_node >("platform"));
106 user_config.lookup< engine::user_node >("unprivileged_user").name);
108 config::properties_map exp_test_suites;
109 exp_test_suites["test_suites.kyua.run_coredump_tests"] = "false";
110 exp_test_suites["test_suites.FreeBSD.iterations"] = "1000";
111 exp_test_suites["test_suites.FreeBSD.run_old_tests"] = "false";
112 exp_test_suites["test_suites.NetBSD.file_systems"] = "ffs lfs ext2fs";
113 exp_test_suites["test_suites.NetBSD.iterations"] = "100";
114 exp_test_suites["test_suites.NetBSD.run_broken_tests"] = "true";
115 ATF_REQUIRE(exp_test_suites == user_config.all_properties("test_suites"));
119 ATF_TEST_CASE(kyuafile_top__no_matches);
120 ATF_TEST_CASE_HEAD(kyuafile_top__no_matches)
122 utils::logging::set_inmemory();
123 set_md_var("require.files", example_file("Kyuafile.top").str());
125 ATF_TEST_CASE_BODY(kyuafile_top__no_matches)
127 scheduler::scheduler_handle handle = scheduler::setup();
129 fs::mkdir(fs::path("root"), 0755);
130 const fs::path source_path = example_file("Kyuafile.top");
131 ATF_REQUIRE(::symlink(source_path.c_str(), "root/Kyuafile") != -1);
133 atf::utils::create_file("root/file", "");
134 fs::mkdir(fs::path("root/subdir"), 0755);
136 const engine::kyuafile kyuafile = engine::kyuafile::load(
137 fs::path("root/Kyuafile"), none, engine::default_config(), handle);
138 ATF_REQUIRE_EQ(fs::path("root"), kyuafile.source_root());
139 ATF_REQUIRE_EQ(fs::path("root"), kyuafile.build_root());
140 ATF_REQUIRE(kyuafile.test_programs().empty());
146 ATF_TEST_CASE(kyuafile_top__some_matches);
147 ATF_TEST_CASE_HEAD(kyuafile_top__some_matches)
149 utils::logging::set_inmemory();
150 set_md_var("require.files", example_file("Kyuafile.top").str());
152 ATF_TEST_CASE_BODY(kyuafile_top__some_matches)
154 scheduler::scheduler_handle handle = scheduler::setup();
156 fs::mkdir(fs::path("root"), 0755);
157 const fs::path source_path = example_file("Kyuafile.top");
158 ATF_REQUIRE(::symlink(source_path.c_str(), "root/Kyuafile") != -1);
160 atf::utils::create_file("root/file", "");
162 fs::mkdir(fs::path("root/subdir1"), 0755);
163 atf::utils::create_file("root/subdir1/Kyuafile",
165 "plain_test_program{name='a', test_suite='b'}\n");
166 atf::utils::create_file("root/subdir1/a", "");
168 fs::mkdir(fs::path("root/subdir2"), 0755);
169 atf::utils::create_file("root/subdir2/Kyuafile",
171 "plain_test_program{name='c', test_suite='d'}\n");
172 atf::utils::create_file("root/subdir2/c", "");
173 atf::utils::create_file("root/subdir2/Kyuafile.etc", "invalid");
175 const engine::kyuafile kyuafile = engine::kyuafile::load(
176 fs::path("root/Kyuafile"), none, engine::default_config(), handle);
177 ATF_REQUIRE_EQ(fs::path("root"), kyuafile.source_root());
178 ATF_REQUIRE_EQ(fs::path("root"), kyuafile.build_root());
180 const model::test_program exp_test_program_a = model::test_program_builder(
181 "plain", fs::path("subdir1/a"), fs::path("root").to_absolute(), "b")
182 .add_test_case("main")
184 const model::test_program exp_test_program_c = model::test_program_builder(
185 "plain", fs::path("subdir2/c"), fs::path("root").to_absolute(), "d")
186 .add_test_case("main")
189 ATF_REQUIRE_EQ(2, kyuafile.test_programs().size());
190 ATF_REQUIRE((exp_test_program_a == *kyuafile.test_programs()[0] &&
191 exp_test_program_c == *kyuafile.test_programs()[1])
193 (exp_test_program_a == *kyuafile.test_programs()[1] &&
194 exp_test_program_c == *kyuafile.test_programs()[0]));
200 ATF_INIT_TEST_CASES(tcs)
202 scheduler::register_interface(
203 "plain", std::shared_ptr< scheduler::interface >(
204 new engine::plain_interface()));
206 ATF_ADD_TEST_CASE(tcs, kyua_conf);
208 ATF_ADD_TEST_CASE(tcs, kyuafile_top__no_matches);
209 ATF_ADD_TEST_CASE(tcs, kyuafile_top__some_matches);