Skip to content

Commit

Permalink
#32: fix test build warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tlamonthezie committed Jul 18, 2024
1 parent 6d3d21b commit 5ae0492
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 62 deletions.
77 changes: 37 additions & 40 deletions tests/unit/api/test_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ struct InfoTestParam
{
public:

InfoTestParam(size_t num_objects, size_t num_ranks, size_t num_phases):
num_objects(num_objects), num_ranks(num_ranks), num_phases(num_phases) {

InfoTestParam(size_t in_num_objects, int16_t in_num_ranks, size_t in_num_phases):
num_objects(in_num_objects), num_ranks(in_num_ranks), num_phases(in_num_phases) {
}

friend std::ostream& operator<< (std::ostream& stream, const InfoTestParam& param) {
Expand All @@ -75,8 +74,8 @@ struct InfoTestParam
}

const size_t num_objects;
const size_t num_ranks;
const size_t num_phases;
const int16_t num_ranks;
const uint64_t num_phases;
};

/**
Expand Down Expand Up @@ -112,7 +111,7 @@ TEST_P(InfoTest, test_get_rank_ids) {
fmt::print("{}={}", param.num_phases, info.getNumPhases());

auto rank_ids = std::vector<NodeType>();
for (NodeType rank_id = 0; rank_id< param.num_ranks; rank_id++) {
for (NodeType rank_id = 0; rank_id < param.num_ranks; rank_id++) {
rank_ids.push_back(rank_id);
}

Expand All @@ -127,33 +126,11 @@ TEST_P(InfoTest, test_get_object_qoi_getter) {
Info info = Generator::makeInfo(param.num_objects, param.num_ranks, param.num_phases);

auto qoi_list = std::vector<std::string>({"load", "received_volume", "sent_volume", "max_volume", "id", "rank_id", "non-existent"});
for (auto const qoi: qoi_list) {
for (auto const& qoi: qoi_list) {
auto qoi_getter = info.getObjectQoiGetter(qoi);
}
}

/**
* Test Info:getObjectQoi
*/
TEST_P(InfoTest, test_get_object_qoi) {
InfoTestParam const & param = GetParam();

ObjectWork object_0 = ObjectWork(0, 2.0, {}, {}, {});

Info info = Info(
Generator::makeObjectInfoMap({{ 0, object_0 }}), // 1 object
Generator::makeRanks({{ 0, object_0 }}, 1, 1) // 1 phase 1 rank
);
auto qoi_list = std::vector<std::string>({"load", "received_volume", "sent_volume", "max_volume", "id", "rank_id", "non-existent"});
for (auto const qoi: qoi_list) {
if (qoi == "non-existent") {
EXPECT_THROW(info.getObjectQoi(0, 0, qoi), std::runtime_error);
} else {
auto qoi_value = info.getObjectQoi(0, 0, qoi);
}
}
}

/**
* Test Info:getAllObjectIDs returns same items as defined in the sample
*/
Expand Down Expand Up @@ -185,11 +162,11 @@ INSTANTIATE_TEST_SUITE_P(
InfoTestParam(2,5,1),
InfoTestParam(6,1,1)
),
[](const testing::TestParamInfo<InfoTest::ParamType>& info) {
[](const testing::TestParamInfo<InfoTest::ParamType>& in_info) {
// test suffix
return std::to_string(info.param.num_objects) + "_" +
std::to_string(info.param.num_ranks) + "_" +
std::to_string(info.param.num_phases);
return std::to_string(in_info.param.num_objects) + "_" +
std::to_string(in_info.param.num_ranks) + "_" +
std::to_string(in_info.param.num_phases);
}
);

Expand All @@ -203,9 +180,9 @@ TEST_F(InfoTest, test_add_info) {
std::vector<size_t> idx;

// Create object info and add to a map
ObjectInfo oInfo = ObjectInfo(0, 0, true, idx);
ObjectInfo o_info = ObjectInfo(0, 0, true, idx);
auto object_info_map = std::unordered_map<ElementIDType, ObjectInfo>();
object_info_map.insert(std::make_pair(oInfo.getID(), oInfo));
object_info_map.insert(std::make_pair(o_info.getID(), o_info));

// Create PhaseWork including one object work
auto object_work_objects = std::unordered_map<PhaseType, ObjectWork>();
Expand Down Expand Up @@ -385,6 +362,26 @@ TEST_F(InfoTest, test_get_max_volume) {
EXPECT_EQ(info.getMaxVolume(), 3.6);
}

/**
* Test Info:getObjectQoi
*/
TEST_F(InfoTest, test_get_object_qoi) {
ObjectWork object_0 = ObjectWork(0, 2.0, {}, {}, {});

Info info = Info(
Generator::makeObjectInfoMap({{ 0, object_0 }}), // 1 object
Generator::makeRanks({{ 0, object_0 }}, 1, 1) // 1 phase 1 rank
);
auto qoi_list = std::vector<std::string>({"load", "received_volume", "sent_volume", "max_volume", "id", "rank_id", "non-existent"});
for (auto const& qoi: qoi_list) {
if (qoi == "non-existent") {
EXPECT_THROW(info.getObjectQoi(0, 0, qoi), std::runtime_error);
} else {
ASSERT_NO_THROW(info.getObjectQoi(0, 0, qoi));
}
}
}

TEST_F(InfoTest, test_get_rank_qoi) {
auto objects_15 = Generator::makeObjects(2, 1.5, 0);
auto objects_18 = Generator::makeObjects(2, 1.8, 2);
Expand Down Expand Up @@ -416,7 +413,7 @@ TEST_F(InfoTest, test_get_rank_qoi) {
auto qoi_list = std::vector<std::string>({"load", "received_volume", "sent_volume", "number_of_objects",
"number_of_migratable_objects", "migratable_load", "sentinel_load", "id",
"attr1", "attr2" });
for (auto const qoi: qoi_list) {
for (auto const& qoi: qoi_list) {
auto qoi_getter = info.getRankQOIGetter(qoi);

if (qoi == "id") {
Expand All @@ -431,11 +428,11 @@ TEST_F(InfoTest, test_get_rank_qoi) {
}
}

ASSERT_EQ(std::get<int>(info.getRankAttribute(rank_0, "attr1", 0)), 12.0);
ASSERT_EQ(std::get<int>(info.getRankAttribute(rank_1, "attr1", 0)), 13.0);
ASSERT_EQ(std::get<int>(info.getRankAttribute(rank_0, "attr1")), 12.0);
ASSERT_EQ(std::get<int>(info.getRankAttribute(rank_1, "attr1")), 13.0);

ASSERT_EQ(std::get<std::string>(info.getRankAttribute(rank_0, "attr2", 0)), "ab");
ASSERT_EQ(std::get<std::string>(info.getRankAttribute(rank_1, "attr2", 0)), "cd");
ASSERT_EQ(std::get<std::string>(info.getRankAttribute(rank_0, "attr2")), "ab");
ASSERT_EQ(std::get<std::string>(info.getRankAttribute(rank_1, "attr2")), "cd");

// Test getRankQOIAtPhase method
ASSERT_EQ(info.getRankQOIAtPhase(0, 0, "sent_volume"), 2.0);
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/deps/test_vtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ namespace vt::tv::tests::unit::deps {
* Provides unit tests for the Vtk functions called from vt-tv
*/
class VtkTest :public ::testing::Test {
virtual void SetUp() {

void SetUp() override {
// This test is not testing vt-tv src.
// That's why it is skipped. But it might be useful locally.
GTEST_SKIP() << "Skipping VTK basic tests";
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ class Generator {
/**
* Make a map of new phases
*/
static const std::unordered_map<PhaseType, PhaseWork> makePhases(std::unordered_map<ElementIDType, ObjectWork> objects, const int num_phases = rand() % 10) {
static const std::unordered_map<PhaseType, PhaseWork> makePhases(std::unordered_map<ElementIDType, ObjectWork> objects, const uint64_t num_phases = rand() % 10) {
auto phase_info_map = std::unordered_map<PhaseType, PhaseWork>();
for (PhaseType phase_id = 0; phase_id < num_phases; phase_id++) {
for (uint64_t phase_id = 0; phase_id < num_phases; phase_id++) {
phase_info_map.insert(std::make_pair(phase_id, makePhase(phase_id, objects)));
}
return phase_info_map;
Expand All @@ -100,7 +100,7 @@ class Generator {
/**
* Make a map of new ranks
*/
static const std::unordered_map<NodeType, Rank> makeRanks(std::unordered_map<ElementIDType, ObjectWork> objects, int num_ranks = rand() % 10, int num_phases = rand() % 10) {
static const std::unordered_map<NodeType, Rank> makeRanks(std::unordered_map<ElementIDType, ObjectWork> objects, int16_t num_ranks = rand() % 10, uint64_t num_phases = rand() % 10) {
auto rank_map = std::unordered_map<NodeType, Rank>();
for (NodeType rank_id = 0; rank_id < num_ranks; rank_id++) {
auto rank = Rank(rank_id, makePhases(objects, num_phases));
Expand All @@ -126,7 +126,7 @@ class Generator {
}

static std::unordered_map<std::string, QOIVariantTypes> makeQOIVariants (
int num = rand() % 10,
uint64_t num = rand() % 10,
std::string key_prefix = "attr_",
std::string value_suffix = "_value"
) {
Expand All @@ -140,7 +140,7 @@ class Generator {
/**
* Make an Info instance
*/
static const Info makeInfo(int num_objects = rand() % 100, int num_ranks = rand() % 10, int num_phases = 10) {
static const Info makeInfo(int num_objects = rand() % 100, int num_ranks = rand() % 10, uint64_t num_phases = 10) {
auto objects = makeObjects(num_objects);
auto ranks = makeRanks(objects, num_ranks, num_phases);
return Info(makeObjectInfoMap(objects), ranks);
Expand All @@ -166,13 +166,13 @@ class Generator {

Info info = Info();

#ifdef VT_TV_N_THREADS
const int threads = VT_TV_N_THREADS;
#else
const int threads = 2;
#endif
#ifdef VT_TV_OPENMP_ENABLED
#if VT_TV_OPENMP_ENABLED
#ifdef VT_TV_N_THREADS
const int threads = VT_TV_N_THREADS;
#else
const int threads = 2;
#endif // VT_TV_N_THREADS
omp_set_num_threads(threads);
fmt::print("vt-tv: Using {} threads\n", threads);
# pragma omp parallel for
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/render/test_parse_render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ using ParseRender = vt::tv::utility::ParseRender;
* Provides unit tests for the vt::tv::utility::ParseRender class to test with config file input
*/
class ParseRenderTest :public ::testing::TestWithParam<std::string> {
virtual void SetUp() {

void SetUp() override {
// Disable this test because of gcc segfault at vtkWindowToImageFilter (memcpy) if save png is true in config
// GTEST_SKIP();
// return;
Expand Down Expand Up @@ -91,9 +92,9 @@ INSTANTIATE_TEST_SUITE_P(
"ccm-example.yaml",
"test-vt-tv.yaml"
),
[](const ::testing::TestParamInfo<std::string>& info) {
[](const ::testing::TestParamInfo<std::string>& in_info) {
// test suffix as slug
auto suffix = std::regex_replace(info.param, std::regex("\\.yaml"), "");
auto suffix = std::regex_replace(in_info.param, std::regex("\\.yaml"), "");
suffix = std::regex_replace(suffix, std::regex("-"), "_");
return suffix;
}
Expand Down
9 changes: 4 additions & 5 deletions tests/unit/render/test_render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace vt::tv::tests::unit::render {
*/
class RenderTest :public ::testing::TestWithParam<std::string> {

virtual void SetUp() {
void SetUp() override {
// Disable this test because of gcc segfault at vtkWindowToImageFilter (memcpy) if save png is true in config
// GTEST_SKIP();
// return;
Expand Down Expand Up @@ -140,11 +140,10 @@ TEST_P(RenderTest, test_render_from_config) {
render.generate(font_size, win_size);

// Verify that files are generated with 1 rank_mesh and 1 object mesh per rank
auto n_ranks = config["input"]["n_ranks"].as<int64_t>();
std::string output_file_stem = config["output"]["file_stem"].as<std::string>();

// Expect 1 output file per phase for both rank meshes and object meshes
for (int64_t i = 0; i<info.getNumPhases(); i++) {
for (uint64_t i = 0; i<info.getNumPhases(); i++) {
ASSERT_TRUE(std::filesystem::exists(fmt::format("{}{}_rank_mesh_{}.vtp", output_dir, output_file_stem, i))) << fmt::format("{}{}_rank_mesh_{}.vtp", output_dir, output_file_stem, i);
ASSERT_TRUE(std::filesystem::exists(fmt::format("{}{}_object_mesh_{}.vtp", output_dir, output_file_stem, i))) << fmt::format("{}{}_rank_mesh_{}.vtp", output_dir, output_file_stem, i);
}
Expand All @@ -162,9 +161,9 @@ INSTANTIATE_TEST_SUITE_P(
"ccm-example.yaml",
"test-vt-tv.yaml"
),
[](const ::testing::TestParamInfo<std::string>& info) {
[](const ::testing::TestParamInfo<std::string>& in_info) {
// test suffix as slug
auto suffix = std::regex_replace(info.param, std::regex("\\.yaml"), "");
auto suffix = std::regex_replace(in_info.param, std::regex("\\.yaml"), "");
suffix = std::regex_replace(suffix, std::regex("-"), "_");
return suffix;
}
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/render/test_standalone_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ namespace vt::tv::tests::unit::render {
* It is similar to the ParseRender tests except it runs as a separate process.
*/
class StandaloneAppTest :public ::testing::TestWithParam<std::tuple<std::string, int>> {
virtual void SetUp() {

void SetUp() override {
// This test is not testing vt-tv src.
// That's why it is skipped. But it might be useful locally.
GTEST_SKIP() << "Skipping standalone app tests";
Expand Down Expand Up @@ -138,9 +139,9 @@ INSTANTIATE_TEST_SUITE_P(
std::make_tuple<std::string, int>("ccm-example.yaml", 1)
// std::make_tuple<std::string, int>("test-vt-tv.yaml", 1)
),
[](const ::testing::TestParamInfo<std::tuple<std::string, int>>& info) {
[](const ::testing::TestParamInfo<std::tuple<std::string, int>>& in_info) {
// test suffix as slug
auto suffix = std::regex_replace(std::get<0>(info.param), std::regex("\\.yaml"), "");
auto suffix = std::regex_replace(std::get<0>(in_info.param), std::regex("\\.yaml"), "");
suffix = std::regex_replace(suffix, std::regex("-"), "_");
return suffix;
}
Expand Down

0 comments on commit 5ae0492

Please sign in to comment.