13 #include <catch2/catch.hpp>
16 struct DummyMapper :
Mapper {
18 DummyMapper(std::shared_ptr<CGRA> cgra,
int timelimit) :
Mapper(cgra, timelimit) {}
19 Mapping mapOpGraph(std::shared_ptr<OpGraph> opgraph,
int II,
const MRRG& mrrg, std::unordered_map<std::string, std::string> fix_port) {
21 return Mapping(cgra, II, opgraph);
25 void runArgsTest(
ConfigStore in_args,
ConfigStore expcected_out_args,
bool expect_pass,
bool is_composite);
26 void runArgsTest_Success(
ConfigStore in_args,
ConfigStore expcected_out_args) {
return runArgsTest(in_args, expcected_out_args,
true,
false); }
27 void runArgsTest_Failure(
ConfigStore in_args,
ConfigStore expcected_out_args) {
return runArgsTest(in_args, expcected_out_args,
false,
false); }
28 void runArgsTest_Composite_Success(
ConfigStore in_args,
ConfigStore expcected_out_args) {
return runArgsTest(in_args, expcected_out_args,
true,
true); }
29 void runArgsTest_Composite_Failure(
ConfigStore in_args,
ConfigStore expcected_out_args) {
return runArgsTest(in_args, expcected_out_args,
false,
true); }
31 void runArgsFilterTest(std::vector<std::string> in_args, std::vector<std::string> required_args, std::vector<std::string> optional_regexes,
bool expect_pass);
32 void runArgsFilterTest_Success(std::vector<std::string> in_args, std::vector<std::string> required_args, std::vector<std::string> optional_regexes) {
return runArgsFilterTest(in_args, required_args, optional_regexes,
true); }
33 void runArgsFilterTest_Failure(std::vector<std::string> in_args, std::vector<std::string> required_args, std::vector<std::string> optional_regexes) {
return runArgsFilterTest(in_args, required_args, optional_regexes,
false); }
36 SCENARIO (
"MapperRegistry Test -- Direct args, success",
"[mapper registry]") {
48 SCENARIO (
"MapperRegistry Test -- Direct args, failure",
"[mapper registry]") {
60 SCENARIO (
"MapperRegistry Test -- Direct args to another mapper",
"[mapper registry]") {
63 {
"not_the_checker.arg1", 1},
64 {
"not_the_checker.arg2", 2},
70 SCENARIO (
"MapperRegistry Test -- AllMappers args",
"[mapper registry]") {
73 {
"AllMappers.arg1", 1},
74 {
"AllMappers.arg2", 2},
82 SCENARIO (
"MapperRegistry Test -- AllMappers + Direct args",
"[mapper registry]") {
85 {
"AllMappers.arg1", 1},
94 SCENARIO (
"MapperRegistry Test -- AllMappers + Direct args to wrong mapper",
"[mapper registry]") {
97 {
"AllMappers.arg1", 1},
98 {
"not_the_checker.arg2", 2},
105 SCENARIO (
"MapperRegistry Test -- Composite -- Direct args, success",
"[mapper registry]") {
106 runArgsTest_Composite_Success(
117 SCENARIO (
"MapperRegistry Test -- Composite -- Direct args, failure",
"[mapper registry]") {
118 runArgsTest_Composite_Failure(
129 SCENARIO (
"MapperRegistry Test -- Composite -- Direct args to another mapper",
"[mapper registry]") {
130 runArgsTest_Composite_Success(
132 {
"not_the_checker.arg1", 1},
133 {
"not_the_checker.arg2", 2},
135 {
"not_the_checker.arg1", 1},
136 {
"not_the_checker.arg2", 2},
141 SCENARIO (
"MapperRegistry Test -- Composite -- AllMappers args",
"[mapper registry]") {
142 runArgsTest_Composite_Success(
144 {
"AllMappers.arg1", 1},
145 {
"AllMappers.arg2", 2},
147 {
"AllMappers.arg1", 1},
148 {
"AllMappers.arg2", 2},
155 SCENARIO (
"MapperRegistry Test -- Composite -- nested args",
"[mapper registry]") {
156 runArgsTest_Composite_Success(
158 {
"checker.nested.arg1", 1},
160 {
"checker.nested.arg1", 1},
166 SCENARIO (
"MapperRegistry Test -- Composite -- doubly nested arg overwrites",
"[mapper registry]") {
167 runArgsTest_Composite_Success(
169 {
"checker.nested.arg1", 1},
170 {
"checker.checker.nested.arg1", 1},
173 {
"checker.nested.arg1", 1},
174 {
"checker.checker.nested.arg1", 1},
179 SCENARIO (
"MapperRegistry Test -- Composite -- AllMappers + Direct args",
"[mapper registry]") {
180 runArgsTest_Composite_Success(
182 {
"AllMappers.arg1", 1},
185 {
"AllMappers.arg1", 1},
192 SCENARIO (
"MapperRegistry Test -- Composite -- AllMappers + Direct arg override",
"[mapper registry]") {
193 runArgsTest_Composite_Success(
195 {
"AllMappers.arg1", 1},
199 {
"AllMappers.arg1", 1},
206 SCENARIO (
"MapperRegistry Test -- Composite -- AllMappers + Direct args to wrong mapper",
"[mapper registry]") {
207 runArgsTest_Composite_Success(
209 {
"AllMappers.arg1", 1},
210 {
"not_the_checker.arg2", 2},
212 {
"AllMappers.arg1", 1},
213 {
"not_the_checker.arg2", 2},
219 SCENARIO (
"MapperRegistry Test -- Arg Checking -- no args & none given",
"[mapper registry]") {
220 runArgsFilterTest_Success(
228 SCENARIO (
"MapperRegistry Test -- Arg Checking -- one required arg expected & given",
"[mapper registry]") {
229 runArgsFilterTest_Success(
239 SCENARIO (
"MapperRegistry Test -- Arg Checking -- two required args expected & given",
"[mapper registry]") {
240 runArgsFilterTest_Success(
252 SCENARIO (
"MapperRegistry Test -- Arg Checking -- one required arg expected & none given",
"[mapper registry]") {
253 runArgsFilterTest_Failure(
262 SCENARIO (
"MapperRegistry Test -- Arg Checking -- two required args expected & one given",
"[mapper registry]") {
263 runArgsFilterTest_Failure(
274 SCENARIO (
"MapperRegistry Test -- Arg Checking -- one optional arg allowed & none given",
"[mapper registry]") {
275 runArgsFilterTest_Success(
284 SCENARIO (
"MapperRegistry Test -- Arg Checking -- one optional arg allowed & given -- non-regex",
"[mapper registry]") {
285 runArgsFilterTest_Success(
295 SCENARIO (
"MapperRegistry Test -- Arg Checking -- one optional arg allowed & given",
"[mapper registry]") {
296 runArgsFilterTest_Success(
306 SCENARIO (
"MapperRegistry Test -- Arg Checking -- two optional args allowed & given",
"[mapper registry]") {
307 runArgsFilterTest_Success(
319 SCENARIO (
"MapperRegistry Test -- Arg Checking -- one optional arg allowed & non-matching given",
"[mapper registry]") {
320 runArgsFilterTest_Failure(
330 SCENARIO (
"MapperRegistry Test -- INI printing",
"[mapper registry]") {
332 {
"common1", 1,
"a common1 arg\n\ntesting common1"},
333 {
"common2", 2,
"a common2 arg\n\ntesting common2"},
337 {
"arg1", 11,
"the arg1\n\narg1 long description"},
338 {
"arg2", 22,
"the arg2"},
341 {
"regex.*",
"a regex"},
344 mr.registerMapper(
"checker2",
nullptr,
false,
"a checker", {
345 {
"arg2", 22,
"the arg2"},
349 {
"regex.*",
"a regex"},
352 mr.registerMapper(
"checker3",
nullptr,
false,
"a checker", {
354 {
"common2", 2,
"means something special"},
356 {
"regex.*",
"a regex"},
359 std::stringstream ini_dump_ss;
360 mr.printDefaultsAsINI(ini_dump_ss);
362 const auto expected = std::string(
364 "# Gobal settings & defaults\n"
374 "# The rest are mapper-specific & overrides\n"
390 "# means something special\n"
394 CHECK(ini_dump_ss.str() == expected);
399 void runArgsTest(
ConfigStore in_args,
ConfigStore expcected_out_args,
bool expect_pass,
bool is_composite) {
403 mr.registerMapper(
"checker", [&](
auto&& cgra,
int timeout,
const ConfigStore& args) {
405 return std::unique_ptr<Mapper>(std::make_unique<DummyMapper>(cgra, timeout));
406 }, is_composite,
"a checker", {}, { {
"arg.*",
""} });
408 auto cgra = std::make_shared<CGRA>();
409 mr.createMapper(
"checker", cgra, 0, in_args);
412 CHECK(out_args == expcected_out_args);
414 CHECK(out_args != expcected_out_args);
418 void runArgsFilterTest(std::vector<std::string> in_args, std::vector<std::string> required_args, std::vector<std::string> optional_regexes,
bool expect_pass) {
419 std::vector<ImplicitTuple<std::string, ImplicitlyToString, std::string>> required_arg_names_defaults_and_descriptions;
420 for (
const auto& arg : required_args) {
421 required_arg_names_defaults_and_descriptions.push_back({arg,
"dflt",
""});
424 std::vector<std::pair<std::string, std::string>> optional_arg_regexes_and_descriptions;
425 for (
const auto& regex : optional_regexes) {
426 optional_arg_regexes_and_descriptions.push_back({regex,
""});
430 for (
const auto& arg : in_args) {
431 in_args_cs.
setString(
"checker." + arg,
"in");
434 auto do_test = [&](
bool is_composite) {
435 WHEN (
"Testing a " << (is_composite ?
"" :
"non-") <<
"composite mapper") {
438 return std::unique_ptr<Mapper>(std::make_unique<DummyMapper>(cgra, timeout));
439 }, is_composite,
"a checker", required_arg_names_defaults_and_descriptions, optional_arg_regexes_and_descriptions);
441 auto cgra = std::make_shared<CGRA>();
443 mr.createMapper(
"checker", cgra, 0, in_args_cs);
445 CHECK_THROWS(mr.createMapper(
"checker", cgra, 0, in_args_cs));