-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #784 from wildmeshing/dzint/fixing_integration_tests
Dzint/fixing integration tests
- Loading branch information
Showing
8 changed files
with
196 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
# Guide for Using Integration Test | ||
|
||
When you want to start a new integration test, then you need to have following a few steps to set up the test. | ||
1. Write a JSON file under the folder `/data/unit_test/`, you can refer to those existing JSON files to learn how to write it. | ||
2. Put the mesh for your test under the folder `/data/unit_test/meshes`. Please check first, if one of the existing meshes is suitable for your integration test. | ||
3. Add the JSON file's name to `/components/tests/integration_test.cpp`, i.e. add the line `WMTK_INTEGRATION("YOUR TEST NAME", false);`. | ||
4. The first time you run your integration test, set the `DO_VALIDATION` parameter `false`, i.e. `WMTK_INTEGRATION("YOUR TEST NAME", false);`. The integration test will then add the test output (number of simplices) to your JSON. Afterward, set the parameter to `true`. Now, the integration test will compare the result with your original output and fail if the two do not match. | ||
5. Push the JSON and meshes to the [wmtk data repo](https://github.com/wildmeshing/data). | ||
|
||
- First, write a JSON file under the folder `/data/unit_test/`, you can refer to those existing JSON files to learn how to write it. | ||
- Second, you need the model to run your integration test. Put your model under the folder `/data/unit_test/meshes`.(you may have to update the wmtkdata) | ||
- Third, after you have done the steps above, you should add the JSON file's name to `/components/tests/integration_test.cpp`. Such as `WMTK_INTEGRATION("YOUR TEST NAME", false);` | ||
- Fourth, for the first time you run your integration test, you should set `DO_VALIDATION` parameter `true` in `WMTK_INTEGRATION`. Then `integraion_test.cpp` will generate the original performance of your code. After that, you should set the parameter as `false`. In the later integration test, `integraion_test.cpp` will compare the result with your original performance to make sure your new version code's performance always consistent with the original one. | ||
|
||
NOTE: you can have a look at the `integrations_test.cpp` to get more details if you want. | ||
Look at `integrations_test.cpp` for more details. |
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
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
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
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
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
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,60 @@ | ||
#include "Stopwatch.hpp" | ||
|
||
|
||
#include <spdlog/common.h> | ||
|
||
namespace wmtk::utils { | ||
|
||
|
||
StopWatch::StopWatch(const std::string& name) | ||
: StopWatch(name, spdlog::level::info) | ||
{} | ||
|
||
StopWatch::StopWatch(const std::string& name, const spdlog::level::level_enum log_level) | ||
: m_name(name) | ||
, m_log_level(log_level) | ||
{ | ||
start(); | ||
} | ||
|
||
StopWatch::~StopWatch() | ||
{ | ||
if (m_is_running) { | ||
stop(); | ||
log_msg(); | ||
} | ||
} | ||
|
||
void StopWatch::start() | ||
{ | ||
m_is_running = true; | ||
m_start = std::chrono::high_resolution_clock::now(); | ||
} | ||
|
||
void StopWatch::stop() | ||
{ | ||
if (!m_is_running) { | ||
return; | ||
} | ||
m_is_running = false; | ||
m_stop = std::chrono::high_resolution_clock::now(); | ||
} | ||
|
||
inline void StopWatch::log_msg() | ||
{ | ||
int64_t h = getElapsedTime<std::chrono::hours>(); | ||
int64_t m = getElapsedTime<std::chrono::minutes>() % 60; | ||
int64_t s = getElapsedTime<std::chrono::seconds>() % 60; | ||
int64_t ms = getElapsedTime<std::chrono::milliseconds>() % 1000; | ||
|
||
logger().log( | ||
m_log_level, | ||
"[runtime h:m:s.ms] {}: {:02d}:{:02d}:{:02d}.{:03d}", | ||
m_name, | ||
h, | ||
m, | ||
s, | ||
ms); | ||
} | ||
|
||
} // namespace wmtk::utils |
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,43 @@ | ||
#pragma once | ||
|
||
#include <spdlog/common.h> | ||
#include <chrono> | ||
#include <type_traits> | ||
#include <wmtk/utils/Logger.hpp> | ||
|
||
namespace wmtk::utils { | ||
|
||
class StopWatch | ||
{ | ||
public: | ||
StopWatch(const std::string& name); | ||
StopWatch(const std::string& name, const spdlog::level::level_enum log_level); | ||
|
||
virtual ~StopWatch(); | ||
|
||
void start(); | ||
void stop(); | ||
|
||
template <typename T = std::chrono::seconds> | ||
int64_t getElapsedTime(); | ||
|
||
void log_msg(); | ||
|
||
|
||
private: | ||
std::string m_name; | ||
spdlog::level::level_enum m_log_level = spdlog::level::info; | ||
std::chrono::high_resolution_clock::time_point m_start; | ||
std::chrono::high_resolution_clock::time_point m_stop; | ||
|
||
bool m_is_running = false; | ||
}; | ||
|
||
template <typename T> | ||
inline int64_t StopWatch::getElapsedTime() | ||
{ | ||
auto duration = std::chrono::duration_cast<T>(m_stop - m_start); | ||
return duration.count(); | ||
} | ||
|
||
} // namespace wmtk::utils |