Skip to content

Commit

Permalink
#105: post rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tlamonthezie committed Sep 4, 2024
1 parent a5c552a commit 4e43893
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 88 deletions.
4 changes: 2 additions & 2 deletions tests/unit/deps/test_vtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ TEST_F(VtkTest, test_vtk_screenshot_example) {
w2i->SetMagnification(2); // image quality
#endif
w2i->SetInputBufferTypeToRGBA(); // also record the alpha
// (transparency) channel
// (transparency) channel
w2i->ReadFrontBufferOff(); // read from the back buffer
w2i->Update();

Expand All @@ -126,4 +126,4 @@ TEST_F(VtkTest, test_vtk_screenshot_example) {
writer->SetInputConnection(windowToImageFilter->GetOutputPort());
}

} // namespace vt::tv::tests::unit::deps
} // namespace vt::tv::tests::unit::deps
3 changes: 2 additions & 1 deletion tests/unit/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ void __asan_on_error() {

int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();;
return RUN_ALL_TESTS();
;
}
114 changes: 34 additions & 80 deletions tests/unit/render/test_render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//@HEADER
// *****************************************************************************
//
// test_render.cc
// test_parse_render.cc
// DARMA/vt-tv => Virtual Transport -- Task Visualizer
//
// Copyright 2019-2024 National Technology & Engineering Solutions of Sandia, LLC
Expand Down Expand Up @@ -43,124 +43,78 @@

#include <yaml-cpp/yaml.h>

#include <vt-tv/utility/parse_render.h>

#include <regex>

#include <vtkCellData.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkPolyDataReader.h>
#include <vtkXMLPolyDataReader.h>

#include <vt-tv/render/render.h>
#include <vt-tv/utility/json_reader.h>
#include <vt-tv/utility/parse_render.h>

#include <set>
#include <regex>

#include "../generator.h"
#include "../util.h"

namespace vt::tv::tests::unit::render {

using ParseRender = vt::tv::utility::ParseRender;
using Util = vt::tv::tests::unit::Util;

/**
* Provides unit tests for the vt::tv::render::Render class to test with config file input
* Note: PNG output is turned off for these tests.
* Provides unit tests for the vt::tv::utility::ParseRender class to test with config file input
*/
class RenderTest :public ::testing::TestWithParam<std::string> {

protected:
Render createRender(YAML::Node config, Info info, std::string& output_dir) {
// change output directory to use specific one for these tests
output_dir = Util::resolveDir(SRC_DIR, "output/tests/render", true);

return Render(
{config["viz"]["rank_qoi"].as<std::string>(), "",
config["viz"]["object_qoi"].as<std::string>()},
config["viz"]["force_continuous_object_qoi"].as<bool>(), info,
{config["viz"]["x_ranks"].as<uint64_t>(),
config["viz"]["y_ranks"].as<uint64_t>(),
config["viz"]["z_ranks"].as<uint64_t>()},
config["viz"]["object_jitter"].as<double>(), output_dir,
config["output"]["file_stem"].as<std::string>(), 1.0,
config["viz"]["save_meshes"].as<bool>(), false,
std::numeric_limits<PhaseType>::max());
}
};
class ParseRenderTest : public ::testing::TestWithParam<std::string> { };

/**
* Test Render:generate correcty run the different configuration files and generates mesh files (.vtp)
* Test ParseRender:parseAndRender correcty run the different configuration files
*/
TEST_P(RenderTest, test_render_from_config_with_png) {
std::string const & config_file = GetParam();
YAML::Node config = YAML::LoadFile(fmt::format("{}/tests/config/{}", SRC_DIR, config_file));
TEST_P(ParseRenderTest, test_parse_config_and_render_no_png) {
std::string const& config_file = GetParam();
auto parse_render =
ParseRender(fmt::format("{}/tests/config/{}", SRC_DIR, config_file));
YAML::Node config =
YAML::LoadFile(fmt::format("{}/tests/config/{}", SRC_DIR, config_file));
Info info = Generator::loadInfoFromConfig(config);

uint64_t win_size = 2000;
uint64_t font_size = 50;

std::string output_dir;
std::string output_file_stem = config["output"]["file_stem"].as<std::string>();

// Render
Render render = createRender(config, info, output_dir);
auto output_dir = Util::resolveDir(
SRC_DIR, config["output"]["directory"].as<std::string>(), true);
std::filesystem::create_directories(output_dir);

render.generate(font_size, win_size);
auto output_file_stem = config["output"]["file_stem"].as<std::string>();

// generate file containing object jitter dimensions for output trace and input usage
// this is needed for image and mesh tests
ASSERT_NO_THROW(parse_render.parseAndRender());

// Check: that number of generated mesh files (*.vtp) correspond to the number of phases
std::string output_file_stem =
config["output"]["file_stem"].as<std::string>();
for (uint64_t i = 0; i < info.getNumPhases(); i++) {
auto rank_mesh_file =
fmt::format("{}{}_rank_mesh_{}.vtp", output_dir, output_file_stem, i);
auto object_mesh_file =
fmt::format("{}{}_object_mesh_{}.vtp", output_dir, output_file_stem, i);
auto png_file = fmt::format("{}{}{}.png", output_dir, output_file_stem, i);

fmt::print("----- Test phase {} -----\n", i);
// 1. test files exist: rank mesh, object mesh, png
ASSERT_TRUE(std::filesystem::exists(rank_mesh_file))
<< fmt::format("Error: rank mesh not generated at {}", object_mesh_file);
<< fmt::format("Error: rank mesh not generated at {}", rank_mesh_file);
ASSERT_TRUE(std::filesystem::exists(object_mesh_file)) << fmt::format(
"Error: object mesh not generated at {}", object_mesh_file);
}
ASSERT_FALSE(std::filesystem::exists(png_file))
<< fmt::format("Error: PNG image not generated at {}", png_file);

} // end phases loop
}

/* Run with different configuration files */
INSTANTIATE_TEST_SUITE_P(
RenderTests, RenderTest,
::testing::Values<std::string>("conf.yaml", "ccm-example.yaml"),
ParseRenderTests, ParseRenderTest,
::testing::Values<std::string>("conf-no-png.yaml", "ccm-example-no-png.yaml"),
[](const ::testing::TestParamInfo<std::string>& in_info) {
// test suffix as slug
auto suffix = std::regex_replace(in_info.param, std::regex("\\.yaml"), "");
suffix = std::regex_replace(suffix, std::regex("-"), "_");
return suffix;
});

TEST_F(RenderTest, test_render_construct_from_info) {
// old example2 now as a test
using namespace vt;
using namespace tv;
// Read JSON file and input data

std::filesystem::path p = std::filesystem::path(SRC_DIR) / "data/lb_test_data/";
std::string path = std::filesystem::absolute(p).string();

NodeType n_ranks = 4;

std::unique_ptr<Info> info = std::make_unique<Info>();

for (NodeType rank = 0; rank < n_ranks; rank++) {
utility::JSONReader reader{rank};
reader.readFile(path + "/data." + std::to_string(rank) + ".json");
auto tmpInfo = reader.parse();
info->addInfo(tmpInfo->getObjectInfo(), tmpInfo->getRank(rank));
}

fmt::print("Num ranks={}\n", info->getNumRanks());

// Instantiate render
auto r = Render(*info);
r.generate();

SUCCEED();
}

} // namespace vt::tv::tests::unit::render
} // namespace vt::tv::tests::unit::render
3 changes: 2 additions & 1 deletion tests/unit/render/test_standalone_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ struct StandaloneAppTest
return;

// Make the output directory for these tests
std::filesystem::create_directories(fmt::format("{}/output/tests", SRC_DIR));
std::filesystem::create_directories(
fmt::format("{}/output/tests", SRC_DIR));
}
};

Expand Down
12 changes: 8 additions & 4 deletions tests/unit/utility/test_json_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ using JSONReader = vt::tv::utility::JSONReader;
struct JSONReaderTest : public ::testing::Test { };

TEST_F(JSONReaderTest, test_json_reader_1) {
std::filesystem::path p = std::filesystem::path(SRC_DIR) / "data/lb_test_data" ;
std::filesystem::path p =
std::filesystem::path(SRC_DIR) / "data/lb_test_data";
std::string path = std::filesystem::absolute(p).string();

NodeType rank = 0;
Expand Down Expand Up @@ -112,7 +113,8 @@ TEST_F(JSONReaderTest, test_json_reader_1) {
}

TEST_F(JSONReaderTest, test_json_reader_metadata_attributes) {
std::filesystem::path p = std::filesystem::path(SRC_DIR) / "data/lb_test_data" ;
std::filesystem::path p =
std::filesystem::path(SRC_DIR) / "data/lb_test_data";
std::string path = std::filesystem::absolute(p).string();

NodeType rank = 0;
Expand All @@ -135,7 +137,8 @@ TEST_F(JSONReaderTest, test_json_reader_metadata_attributes) {
}

TEST_F(JSONReaderTest, test_json_reader_object_info_attributes) {
std::filesystem::path p = std::filesystem::path(SRC_DIR) / "data/lb_test_data" ;
std::filesystem::path p =
std::filesystem::path(SRC_DIR) / "data/lb_test_data";
std::string path = std::filesystem::absolute(p).string();

NodeType rank = 0;
Expand Down Expand Up @@ -185,7 +188,8 @@ TEST_F(JSONReaderTest, test_json_reader_qoi_serializer) {
}

TEST_F(JSONReaderTest, test_json_reader_object_work_user_defined) {
std::filesystem::path p = std::filesystem::path(SRC_DIR) / "data/lb_test_data" ;
std::filesystem::path p =
std::filesystem::path(SRC_DIR) / "data/lb_test_data";
std::string path = std::filesystem::absolute(p).string();

NodeType rank = 0;
Expand Down

0 comments on commit 4e43893

Please sign in to comment.