-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit testing for policy factory
Problem: the policy factory in the resource module has no unit testing. Solution: add a series of unit tests to validate the parsing and selection of policy options in the factory.
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
resource/policies/base/test/matcher_policy_factory_test02.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/*****************************************************************************\ | ||
* Copyright 2024 Lawrence Livermore National Security, LLC | ||
* (c.f. AUTHORS, NOTICE.LLNS, LICENSE) | ||
* | ||
* This file is part of the Flux resource manager framework. | ||
* For details, see https://github.com/flux-framework. | ||
* | ||
* SPDX-License-Identifier: LGPL-3.0 | ||
\*****************************************************************************/ | ||
|
||
/* | ||
* Test for the dfu_match_policy class(es). Compares shared pointers | ||
* expected values to string inputs to these classes. Strings can be | ||
* specified in config for custom policies, or some are provided. | ||
*/ | ||
|
||
extern "C" { | ||
#if HAVE_CONFIG_H | ||
#include <config.h> | ||
#endif | ||
} | ||
|
||
#include <string> | ||
#include <boost/lexical_cast.hpp> | ||
#include "resource/policies/dfu_match_policy_factory.hpp" | ||
#include "src/common/libtap/tap.h" | ||
|
||
using namespace Flux; | ||
using namespace Flux::resource_model; | ||
|
||
int test_parsers () | ||
{ | ||
std::map<std::string, bool> container; | ||
bool first = Flux::resource_model::parse_custom_match_policy("high=true node_centric=true node_exclusive=true stop_on_1_matches=false blah=4", container); | ||
ok (first == false, "blah is an unrecognized policy option"); | ||
|
||
std::map<std::string, bool> container2; | ||
bool second = Flux::resource_model::parse_custom_match_policy("high=1 node_centric=true node_exclusive=true stop_on_1_matches=false", container2); | ||
ok (second == false, "1 is an invalid option, must be true or false"); | ||
|
||
std::map<std::string, bool> container3; | ||
bool third = Flux::resource_model::parse_custom_match_policy("high=true node_centric=true stop_on_1_matches=true", container3); | ||
ok (third == true, "first is a valid policy"); | ||
|
||
bool fourth = Flux::resource_model::parse_bool_match_options ("high", container3); | ||
ok (fourth == true, "policy first uses option high"); | ||
|
||
bool fifth = Flux::resource_model::parse_bool_match_options ("node_centric", container3); | ||
ok (fifth == true, "policy first uses option node_centric"); | ||
|
||
bool sixth = Flux::resource_model::parse_bool_match_options ("stop_on_1_matches", container3); | ||
ok (sixth == true, "policy first uses option stop_on_1_matches"); | ||
|
||
bool seventh = Flux::resource_model::parse_bool_match_options ("low", container3); | ||
ok (seventh == false, "policy first does not use option low"); | ||
|
||
return 0; | ||
} | ||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
plan (7); | ||
test_parsers (); | ||
done_testing (); | ||
return 0; | ||
} | ||
|
||
/* | ||
* vi: ts=4 sw=4 expandtab | ||
*/ |