-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OgsTester. Add test definitions to project files. #2255
Conversation
Note to self:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good feature: Easier to read than Tests.cmake
. And can be extended without having to dig into CMake.
Some general comments:
- Renaming of the reference files s.t. they match the solution files seems to be mandatory. That might be inconvenient if one develops a test case or if one wants to compare several time steps to an analytical solution.
- There should be proper escaping for the
system()
calls. Otherwise, e.g., external people could hijack our CI servers by making a PR. OK, they can hijack them anyway, e.g., by adding something nasty to the cmake files. 😄
Applications/CLI/ogs.cpp
Outdated
@@ -86,7 +86,7 @@ int main(int argc, char* argv[]) | |||
#else | |||
"all", | |||
#endif | |||
"log level"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's for the cmdline help text?
Maybe also PROJECT_FILE
in L71?
std::string convert_to_string(double const& value) | ||
{ | ||
// TODO (naumov) Replace this with fmt library. | ||
char buffer[1024]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty much for a formatted double value. 😄
// TODO (naumov) Replace this with fmt library. | ||
char buffer[1024]; | ||
int const chars_written = std::snprintf(buffer, 1024, "%g", value); | ||
if (chars_written < 0 || chars_written > 1024) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Off by one: > 1023
.
https://en.cppreference.com/w/cpp/io/c/fprintf:
- Number of characters that would have been written for a sufficiently large buffer if successful (not including the terminating null character), or a negative value if an error occurred. Thus, the (null-terminated) output has been completely written if and only if the returned value is nonnegative and less than buf_size.
/// Wraps a string into double ticks. | ||
std::string safeString(std::string s) | ||
{ | ||
return "\"" + s + "\""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only safe if all "
in s
are escaped.
// | ||
int const return_value = | ||
// TODO (naumov) replace system call with output consuming call. | ||
// and extract the vtkdiff call to common function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and properly escape any strings occuring in command lines.
<test_definition> | ||
<vtkdiff> | ||
<file>cube_1e0_pcs_0_ts_1_t_0.000100.vtu</file> | ||
<field>displacement</field> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned before: ref_field
and field
might be good.
@@ -12,6 +12,8 @@ | |||
<youngs_modulus>E</youngs_modulus> | |||
<poissons_ratio>nu</poissons_ratio> | |||
</constitutive_relation> | |||
<solid_density>rho_sr</solid_density> | |||
<specific_body_force>0 0 0</specific_body_force> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this was never tested before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LIS only, and there is no LIS build in CI ;(
endif() | ||
|
||
set(OgsTest_SOURCE_DIR "${Data_SOURCE_DIR}/${OgsTest_DIR}") | ||
set(OgsTest_BINARY_DIR "${Data_BINARY_DIR}/${OgsTest_DIR}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work if OGS is installed systemwide? Or if a test resides outside the source/build directory?
OK, the cmake stuff won't work without source/build dirs. But does the feature itself (ogs --reference ...
) work? Or do you need to set some environment variables s.t. it works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as promised from anywhere. Only if vtkdiff is not in current PATH and not in ./bin
the VTKDIFF_BINARY should be set...
scripts/cmake/test/AddTest.cmake
Outdated
@@ -61,10 +61,12 @@ function (AddTest) | |||
set (AddTest_REQUIREMENTS TRUE) | |||
endif() | |||
|
|||
set(X_PRJ_FILE ${AddTest_EXECUTABLE_ARGS}) # For easier retrival later on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easier retrieval of what?
} | ||
return return_value; | ||
}); | ||
return all_of(begin(return_values), end(return_values), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO the test should fail if return_values
is empty (configuration error, no tests defined).
@endJunction @chleh Jenkins CI jobs are submitted for members of our GitHub ufz-organization only (https://github.com/orgs/ufz/teams/members/members). |
@bilke, great! |
@endJunction I guess for a clean implementation of file globbing we need either |
std::string const absolute_tolerance_parameter = | ||
absolute_tolerance == boost::none | ||
? "" | ||
: "--abs " + convert_to_string(*absolute_tolerance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw: the precedence of +
over :
is probably not working knowledge of everybody.
The conversion scripts, previously added in the AddTest.cmake are in the last commit on OgsTesterConversionScripts branch. |
if (reference_path.empty()) | ||
{ | ||
OGS_FATAL( | ||
"Reference path containting expected result files can not be " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
containting -> containing ✔️
Add --reference PATH option to ogs, which when present will execute tests (vtkdiff) constructed from the <test_definiton> section in the project file. This section contains the tester (vtkdiff for now) the file, field, and absolute and relative tolerances. This allows the user to run tests w/o cmake and includes the previously separated test description into the project file.
Convert sigma_.. to vectorial sigma. Update output prefix. Move search length to top.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
namespace | ||
{ | ||
/// Safe conversion of a double to a string using decimal or decimal exponent | ||
/// notation. See std::snprintf() for details for "%g" conversion specifier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about std::ostringstream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Even better, I rewrote that part to avoid any conversion. Could you please check the changes in the last commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new changes look good.
//! \ogs_file_param{prj__test_definition__vtkdiff__absolute_tolerance} | ||
vtkdiff_config.getConfigParameterOptional<double>( | ||
"absolute_tolerance"); | ||
vtkdiff_config.getConfigParameter<std::string>("absolute_tolerance", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoided the conversion by this way, 👍.
Pass the value directly instead and only check if the string convertible to a double if not empty. This avoids possible losses due to conversion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just compiled with gnu compiler, got one warning and one error.
pos, s.c_str()); | ||
} | ||
|
||
if (std::isnan(value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compilation error with g++: error: ‘isnan’ is not a member of ‘std’
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been fixed here 66eb63a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bilke Thanks.
bool isConvertibleToDouble(std::string const& s) | ||
{ | ||
std::size_t pos = 0; | ||
double value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compilation warning: warning: variable ‘value’ set but not used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning is gone now.
OpenGeoSys development has been moved to GitLab. |
Move test definitions into the project files and add a "test mode" to the ogs executable.