Skip to content

Commit

Permalink
uniform way of calling tests
Browse files Browse the repository at this point in the history
  • Loading branch information
toxa81 committed Jun 25, 2024
1 parent a194382 commit 6c8328c
Show file tree
Hide file tree
Showing 29 changed files with 231 additions and 698 deletions.
3 changes: 1 addition & 2 deletions apps/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# FILE(GLOB _tests RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.cpp")
set(unit_tests "test_init;test_nan;test_ylm;test_rlm;test_sinx_cosx;test_gvec;test_fft_correctness_1;\
test_fft_correctness_2;test_fft_real_2;test_fft_real_3;test_rlm_deriv;\
test_fft_correctness_2;test_fft_correctness_3;test_rlm_deriv;\
test_spline;test_rot_ylm;test_linalg;test_wf_ortho_1;test_serialize;test_mempool;test_sim_ctx;test_roundoff;\
test_sht_lapl;test_sht;test_spheric_function;test_splindex;test_gaunt_coeff_1;test_gaunt_coeff_2;\
test_init_ctx;test_cmd_args;test_geom3d;test_any_ptr")
Expand Down
6 changes: 2 additions & 4 deletions apps/unit_tests/test_any_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using namespace sirius;

int
run_test(cmd_args const& args)
run_test()
{
void* ptr = new any_ptr(new mdarray<int, 1>({100}, get_memory_pool(memory_t::host)));
delete static_cast<any_ptr*>(ptr);
Expand All @@ -24,7 +24,5 @@ run_test(cmd_args const& args)
int
main(int argn, char** argv)
{
cmd_args args(argn, argv, {});

return sirius::call_test(argv[0], run_test, args);
return call_test(argv[0], run_test);
}
2 changes: 1 addition & 1 deletion apps/unit_tests/test_cmd_args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ main(int arg, char** argv)
{"d1=", "(double) double parameter"},
{"vi1=", "(vector<int>) vector of integers"}});

return sirius::call_test(argv[0], run_test, args);
return call_test(argv[0], run_test, args);
}
25 changes: 7 additions & 18 deletions apps/unit_tests/test_fft_correctness_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
*/

#include <sirius.hpp>
#include <testing.hpp>

/* test FFT: transform single harmonic and compare with plane wave exp(iGr) */

using namespace sirius;

template <typename T>
int
test_fft(cmd_args& args, device_t pu__)
test_fft_impl(cmd_args const& args, device_t pu__)
{
bool verbose = args.exist("verbose");

Expand Down Expand Up @@ -113,11 +114,11 @@ test_fft(cmd_args& args, device_t pu__)

template <typename T>
int
run_test(cmd_args& args)
test_fft(cmd_args const& args)
{
int result = test_fft<T>(args, device_t::CPU);
int result = test_fft_impl<T>(args, device_t::CPU);
if (acc::num_devices()) {
result += test_fft<T>(args, device_t::GPU);
result += test_fft_impl<T>(args, device_t::GPU);
}
return result;
}
Expand All @@ -131,27 +132,15 @@ main(int argn, char** argv)
{"fp32", "run in FP32 arithmetics"}});

sirius::initialize(true);
printf("running %-30s : ", argv[0]);
int result{0};
if (args.exist("fp32")) {
#if defined(SIRIUS_USE_FP32)
result = run_test<float>(args);
result = call_test(argv[0], test_fft<float>, args);
#else
RTE_THROW("not compiled with FP32 support");
#endif
} else {
result = run_test<double>(args);
}
if (result) {
printf("\x1b[31m"
"Failed"
"\x1b[0m"
"\n");
} else {
printf("\x1b[32m"
"OK"
"\x1b[0m"
"\n");
result = call_test(argv[0], test_fft<double>, args);
}
sirius::finalize();

Expand Down
30 changes: 8 additions & 22 deletions apps/unit_tests/test_fft_correctness_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include <sirius.hpp>
#include <testing.hpp>

/* test FFT: tranfrom random function to real space, transform back and compare with the original function */

Expand All @@ -15,14 +16,11 @@ using namespace mpi;

template <typename T>
int
test_fft_complex(cmd_args& args, device_t fft_pu__)
test_fft_complex_impl(cmd_args const& args, device_t fft_pu__)
{
double cutoff = args.value<double>("cutoff", 40);

double eps = 1e-12;
if (typeid(T) == typeid(float)) {
eps = 1e-6;
}
double eps = (typeid(T) == typeid(float)) ? 1e-6 : 1e-12;

r3::matrix<double> M = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};

Expand Down Expand Up @@ -68,11 +66,11 @@ test_fft_complex(cmd_args& args, device_t fft_pu__)

template <typename T>
int
run_test(cmd_args& args)
test_fft(cmd_args const& args)
{
int result = test_fft_complex<T>(args, device_t::CPU);
int result = test_fft_complex_impl<T>(args, device_t::CPU);
#ifdef SIRIUS_GPU
result += test_fft_complex<T>(args, device_t::GPU);
result += test_fft_complex_impl<T>(args, device_t::GPU);
#endif
return result;
}
Expand All @@ -85,27 +83,15 @@ main(int argn, char** argv)
{"fp32", "run in FP32 arithmetics"}});

sirius::initialize(true);
printf("running %-30s : ", argv[0]);
int result{0};
if (args.exist("fp32")) {
#if defined(SIRIUS_USE_FP32)
result = run_test<float>(args);
result = call_test(argv[0], test_fft<float>, args);
#else
RTE_THROW("not compiled with FP32 support");
#endif
} else {
result = run_test<double>(args);
}
if (result) {
printf("\x1b[31m"
"Failed"
"\x1b[0m"
"\n");
} else {
printf("\x1b[32m"
"OK"
"\x1b[0m"
"\n");
result = call_test(argv[0], test_fft<double>, args);
}
sirius::finalize();

Expand Down
85 changes: 0 additions & 85 deletions apps/unit_tests/test_fft_real_2.cpp

This file was deleted.

104 changes: 0 additions & 104 deletions apps/unit_tests/test_fft_real_3.cpp

This file was deleted.

8 changes: 2 additions & 6 deletions apps/unit_tests/test_gaunt_coeff_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using namespace sirius;

int
test1()
test_gaunt_yyy()
{
int const lmax = 3;
int const lmmax = (lmax + 1) * (lmax + 1);
Expand Down Expand Up @@ -300,9 +300,5 @@ test1()
int
main(int argn, char** argv)
{
int err{0};

err += call_test("<Ylm|Ylm|Ylm>", test1);

return std::min(err, 1);
return call_test(argv[0], test_gaunt_yyy);
}
Loading

0 comments on commit 6c8328c

Please sign in to comment.