-
Notifications
You must be signed in to change notification settings - Fork 6
Update testing to use Catch2 and CMake #16
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [submodule "vendor/Catch2"] | ||
| path = vendor/Catch2 | ||
| url = https://github.com/catchorg/Catch2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| cmake_minimum_required(VERSION 3.15) | ||
| project(sandbox LANGUAGES CXX) | ||
|
|
||
| # Setup Catch2 | ||
| if(NOT EXISTS "${PROJECT_SOURCE_DIR}/vendor/Catch2/CMakeLists.txt") | ||
| message(FATAL_ERROR "The git submodule vendor/Catch2 is missing.\nTry running `git submodule update --init`.") | ||
| endif() | ||
|
|
||
| add_subdirectory(vendor/Catch2) | ||
|
|
||
| list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") | ||
|
|
||
| # Load catch2 cmake module | ||
| include(CTest) | ||
| include(Catch) | ||
|
|
||
| add_subdirectory(tests) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| file(GLOB test_cases CONFIGURE_DEPENDS "*.cpp") | ||
|
|
||
| foreach(test_file IN LISTS test_cases) | ||
| if(EXISTS "${test_file}") | ||
| get_filename_component(exe_name "${test_file}" NAME_WE) | ||
|
|
||
| add_executable(${exe_name} ${test_file}) | ||
| target_include_directories(${exe_name} PUBLIC ../include/) | ||
| target_link_libraries(${exe_name} PRIVATE | ||
| Catch2::Catch2WithMain | ||
| ) | ||
|
|
||
| catch_discover_tests(${exe_name}) | ||
| else() | ||
| message(FATAL_ERROR "No file named ${test_file}") | ||
| endif() | ||
| endforeach() |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,57 +1,40 @@ | ||
| #include "test_helper.hpp" | ||
|
|
||
| template <typename T> struct test_abs { | ||
| bool operator()(sycl::queue &Q, T init_re, T init_im) { | ||
| bool pass = true; | ||
| TEMPLATE_TEST_CASE("Test complex abs", "[abs]", double, float, sycl::half) { | ||
| using T = TestType; | ||
|
|
||
| auto std_in = init_std_complex(init_re, init_im); | ||
| sycl::ext::cplx::complex<T> cplx_input{init_re, init_im}; | ||
| sycl::queue Q; | ||
|
|
||
| // Test cases | ||
| cmplx<T> input = GENERATE( | ||
| cmplx<T>{4.42, 2.02}, cmplx<T>{inf_val<T>, 2.02}, | ||
| cmplx<T>{4.42, inf_val<T>}, cmplx<T>{inf_val<T>, inf_val<T>}, | ||
| cmplx<T>{nan_val<T>, 2.02}, cmplx<T>{4.42, nan_val<T>}, | ||
| cmplx<T>{nan_val<T>, nan_val<T>}, cmplx<T>{nan_val<T>, inf_val<T>}, | ||
| cmplx<T>{inf_val<T>, nan_val<T>}); | ||
|
|
||
| auto std_in = init_std_complex(input); | ||
| sycl::ext::cplx::complex<T> cplx_input{input.re, input.im}; | ||
|
|
||
| T std_out{}; | ||
| auto *cplx_out = sycl::malloc_shared<T>(1, Q); | ||
| T std_out{}; | ||
| auto *cplx_out = sycl::malloc_shared<T>(1, Q); | ||
|
|
||
| // Get std::complex output | ||
| std_out = std::abs(std_in); | ||
| // Get std::complex output | ||
| std_out = std::abs(std_in); | ||
|
|
||
| // Check cplx::complex output from device | ||
| // Check cplx::complex output from device | ||
| if (is_type_supported<T>(Q)) { | ||
| Q.single_task([=]() { | ||
| cplx_out[0] = sycl::ext::cplx::abs<T>(cplx_input); | ||
| }).wait(); | ||
|
|
||
| pass &= check_results(cplx_out[0], std_out, /*is_device*/ true); | ||
|
|
||
| // Check cplx::complex output from host | ||
| cplx_out[0] = sycl::ext::cplx::abs<T>(cplx_input); | ||
|
|
||
| pass &= check_results(cplx_out[0], std_out, /*is_device*/ false); | ||
|
|
||
| sycl::free(cplx_out, Q); | ||
|
|
||
| return pass; | ||
| check_results(cplx_out[0], std_out); | ||
| } | ||
| }; | ||
|
|
||
| int main() { | ||
| sycl::queue Q; | ||
|
|
||
| bool test_passes = true; | ||
| test_passes &= test_valid_types<test_abs>(Q, 4.42, 2.02); | ||
|
|
||
| test_passes &= test_valid_types<test_abs>(Q, INFINITY, 2.02); | ||
| test_passes &= test_valid_types<test_abs>(Q, 4.42, INFINITY); | ||
| test_passes &= test_valid_types<test_abs>(Q, INFINITY, INFINITY); | ||
|
|
||
| test_passes &= test_valid_types<test_abs>(Q, NAN, 2.02); | ||
| test_passes &= test_valid_types<test_abs>(Q, 4.42, NAN); | ||
| test_passes &= test_valid_types<test_abs>(Q, NAN, NAN); | ||
|
|
||
| test_passes &= test_valid_types<test_abs>(Q, NAN, INFINITY); | ||
| test_passes &= test_valid_types<test_abs>(Q, INFINITY, NAN); | ||
| test_passes &= test_valid_types<test_abs>(Q, NAN, INFINITY); | ||
| test_passes &= test_valid_types<test_abs>(Q, INFINITY, NAN); | ||
| // Check cplx::complex output from host | ||
| cplx_out[0] = sycl::ext::cplx::abs<T>(cplx_input); | ||
|
|
||
| if (!test_passes) | ||
| std::cerr << "acos complex test fails\n"; | ||
| check_results(cplx_out[0], std_out); | ||
|
|
||
| return !test_passes; | ||
| sycl::free(cplx_out, Q); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,37 @@ | ||
| #include "test_helper.hpp" | ||
|
|
||
| template <typename T> struct test_acosh { | ||
| bool operator()(sycl::queue &Q, T init_re, T init_im, | ||
| bool is_error_checking = false) { | ||
| bool pass = true; | ||
| TEMPLATE_TEST_CASE("Test complex acosh", "[acosh]", double, float, sycl::half) { | ||
| using T = TestType; | ||
| using std::make_tuple; | ||
|
|
||
| auto std_in = init_std_complex(init_re, init_im); | ||
| sycl::ext::cplx::complex<T> cplx_input{init_re, init_im}; | ||
| sycl::queue Q; | ||
|
|
||
| cmplx<T> input; | ||
| bool is_error_checking; | ||
|
|
||
| std::tie(input, is_error_checking) = GENERATE(table<cmplx<T>, bool>( | ||
| {make_tuple(cmplx<T>{4.42, 2.02}, false), | ||
| make_tuple(cmplx<T>{inf_val<T>, 2.02}, true), | ||
| make_tuple(cmplx<T>{4.42, inf_val<T>}, true), | ||
| make_tuple(cmplx<T>{inf_val<T>, inf_val<T>}, true), | ||
| make_tuple(cmplx<T>{nan_val<T>, 2.02}, true), | ||
| make_tuple(cmplx<T>{4.42, nan_val<T>}, true), | ||
| make_tuple(cmplx<T>{nan_val<T>, nan_val<T>}, true), | ||
| make_tuple(cmplx<T>{nan_val<T>, inf_val<T>}, true), | ||
| make_tuple(cmplx<T>{inf_val<T>, nan_val<T>}, true)})); | ||
|
|
||
| auto std_in = init_std_complex(input); | ||
| sycl::ext::cplx::complex<T> cplx_input{input.re, input.im}; | ||
|
|
||
| std::complex<T> std_out{init_re, init_im}; | ||
| auto *cplx_out = sycl::malloc_shared<sycl::ext::cplx::complex<T>>(1, Q); | ||
| std::complex<T> std_out{input.re, input.im}; | ||
| auto *cplx_out = sycl::malloc_shared<sycl::ext::cplx::complex<T>>(1, Q); | ||
|
|
||
| // Get std::complex output | ||
| if (is_error_checking) | ||
| std_out = std::acosh(std_in); | ||
| // Get std::complex output | ||
| if (is_error_checking) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not important but I think the But thinking more can we use CTEST to only run those tests if The tests assume that the type is supported, and it's ctests / catch2 responsibility to run then if possible. I don't know if it's possible, I know nothing about ctests / catch2...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think |
||
| std_out = std::acosh(std_in); | ||
|
|
||
| // Check cplx::complex output from device | ||
| // Check cplx::complex output from device | ||
| if (is_type_supported<T>(Q)) { | ||
| if (is_error_checking) { | ||
| Q.single_task( | ||
| [=]() { cplx_out[0] = sycl::ext::cplx::acosh<T>(cplx_input); }); | ||
|
|
@@ -26,47 +42,18 @@ template <typename T> struct test_acosh { | |
| }); | ||
| } | ||
| Q.wait(); | ||
|
|
||
| pass &= check_results(cplx_out[0], std_out, /*is_device*/ true, | ||
| /*tol_multiplier*/ 2); | ||
|
|
||
| // Check cplx::complex output from host | ||
| if (is_error_checking) | ||
| cplx_out[0] = sycl::ext::cplx::acosh<T>(cplx_input); | ||
| else | ||
| cplx_out[0] = | ||
| sycl::ext::cplx::cosh<T>(sycl::ext::cplx::acosh<T>(cplx_input)); | ||
|
|
||
| pass &= check_results(cplx_out[0], std_out, /*is_device*/ false, | ||
| /*tol_multiplier*/ 2); | ||
|
|
||
| sycl::free(cplx_out, Q); | ||
|
|
||
| return pass; | ||
| } | ||
| }; | ||
|
|
||
| int main() { | ||
| sycl::queue Q; | ||
|
|
||
| bool test_passes = true; | ||
| test_passes &= test_valid_types<test_acosh>(Q, 4.42, 2.02); | ||
|
|
||
| test_passes &= test_valid_types<test_acosh>(Q, INFINITY, 2.02, true); | ||
| test_passes &= test_valid_types<test_acosh>(Q, 4.42, INFINITY, true); | ||
| test_passes &= test_valid_types<test_acosh>(Q, INFINITY, INFINITY, true); | ||
|
|
||
| test_passes &= test_valid_types<test_acosh>(Q, NAN, 2.02, true); | ||
| test_passes &= test_valid_types<test_acosh>(Q, 4.42, NAN, true); | ||
| test_passes &= test_valid_types<test_acosh>(Q, NAN, NAN, true); | ||
| check_results(cplx_out[0], std_out, /*tol_multiplier*/ 2); | ||
|
|
||
| test_passes &= test_valid_types<test_acosh>(Q, NAN, INFINITY, true); | ||
| test_passes &= test_valid_types<test_acosh>(Q, INFINITY, NAN, true); | ||
| test_passes &= test_valid_types<test_acosh>(Q, NAN, INFINITY, true); | ||
| test_passes &= test_valid_types<test_acosh>(Q, INFINITY, NAN, true); | ||
| // Check cplx::complex output from host | ||
| if (is_error_checking) | ||
| cplx_out[0] = sycl::ext::cplx::acosh<T>(cplx_input); | ||
| else | ||
| cplx_out[0] = | ||
| sycl::ext::cplx::cosh<T>(sycl::ext::cplx::acosh<T>(cplx_input)); | ||
|
|
||
| if (!test_passes) | ||
| std::cerr << "acosh complex test fails\n"; | ||
| check_results(cplx_out[0], std_out, /*tol_multiplier*/ 2); | ||
|
|
||
| return !test_passes; | ||
| } | ||
| sycl::free(cplx_out, Q); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
I guess we can just do
std_out{input}(or maybeinit_std_complexfor taking care of half)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 unfortunately I cant do
std_out{input}as input is of typecmplxwhich is just a helper struct of real and imaginary components. std::complex does not have a constructor for my helper structcmplx.Also in this case we don't want the
half'sto be be translated intofloatsas this is the output value which should have the half type. As no operation is being performed on the output type this is valid, the reason we are initializing it to the input values is for the case were we are checking ifacoshcan undocosh. However when error codes are tested this value is overwritten.Uh oh!
There was an error while loading. Please reload this page.
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.
Oh yes ofc! I'm stupid, it's a
std::complexnot our complex! Sorry, after coming back from vacation, my brain is slower than usual :)Thanks for the explanation