-
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 3 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") | ||
| # find_package(DPCPP) | ||
|
|
||
| # Load catch2 cmake module | ||
| include(CTest) | ||
| include(Catch) | ||
|
|
||
| add_subdirectory(tests) | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,45 @@ | ||||||||
| file(GLOB test_cases CONFIGURE_DEPENDS "*.cpp") | ||||||||
|
|
||||||||
| # set(test_cases | ||||||||
|
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. I guess we can remove the comments now :)
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. Haha thanks for catching this. I have removed the comments |
||||||||
| # "abs_complex.cpp" | ||||||||
| # "acos_complex.cpp" | ||||||||
| # "acosh_complex.cpp" | ||||||||
| # "arg_complex.cpp" | ||||||||
| # "asin_complex.cpp" | ||||||||
| # "asinh_complex.cpp" | ||||||||
| # "atan_complex.cpp" | ||||||||
| # "atanh_complex.cpp" | ||||||||
| # "cos_complex.cpp" | ||||||||
| # "cosh_complex.cpp" | ||||||||
| # "exp_complex.cpp" | ||||||||
| # "log_complex.cpp" | ||||||||
| # "log10_complex.cpp" | ||||||||
| # "norm_complex.cpp" | ||||||||
| # "polar_complex.cpp" | ||||||||
| # "pow_complex.cpp" | ||||||||
| # "sin_complex.cpp" | ||||||||
| # "sinh_complex.cpp" | ||||||||
| # "sqrt_complex.cpp" | ||||||||
| # "tan_complex.cpp" | ||||||||
| # "tanh_complex.cpp" | ||||||||
| # "test_complex_types.cpp" | ||||||||
| # "test_gencomplex.cpp" | ||||||||
| # "test_operator_complex.cpp" | ||||||||
| # "test_stream_operator.cpp" | ||||||||
| # ) | ||||||||
|
|
||||||||
| foreach(test_file IN LISTS test_cases) | ||||||||
| # if(EXISTS "${test_file}") | ||||||||
|
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.
Suggested change
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 have uncommented these checks to make sure each file is available and emit a warning if it is not. |
||||||||
| 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() | ||||||||
|
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.
Suggested change
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 have uncommented this check. Same as above. |
||||||||
| 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); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.