Skip to content

Commit 05c5e13

Browse files
committed
fix(test): updated test and cma_case
1 parent ea3f0e4 commit 05c5e13

File tree

7 files changed

+52
-39
lines changed

7 files changed

+52
-39
lines changed

apps/api/tests/data/0d/cma_case

1 Byte
Binary file not shown.

apps/api/tests/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
cma_path = meson.current_source_dir() + '/data/0d/'
22

3-
43
test_api = executable('test_api', 'test_api.cpp',dependencies:[lib_api_shared_dep])
54
test_api_bad_alloc = executable('test_api_bad_alloc', 'test_api_throw.cpp',dependencies:[lib_api_shared_dep])
65
if build_c_api

apps/api/tests/test_api.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22
#include <optional>
33

44
#include "common_test.hpp"
5+
#include "core/simulation_parameters.hpp"
56

67
#define INIT Api::SimulationInstance::init(argc, argv);
78

89
Core::UserControlParameters gparams(std::string_view path)
910
{
10-
bool serde = false;
11-
return {.biomass_initial_concentration = cx,
12-
.final_time = ft,
13-
.delta_time = dt,
14-
.number_particle = np,
15-
.n_thread = nt,
16-
.number_exported_result = nex,
17-
.recursive = false,
18-
.force_override = true,
19-
.load_serde = serde,
20-
.initialiser_path = "",
21-
.model_name = "None",
22-
.results_file_name = tmp_dir,
23-
.cma_case_path = std::string(path),
24-
.serde_file = std::nullopt};
11+
auto p = Core::UserControlParameters::m_default();
12+
13+
p.biomass_initial_concentration = cx;
14+
p.final_time = ft;
15+
p.delta_time = dt;
16+
p.number_particle = np;
17+
p.n_thread = nt;
18+
p.number_exported_result = nex;
19+
p.force_override = true;
20+
p.load_serde = false;
21+
p.results_file_name = tmp_dir;
22+
p.cma_case_path = std::string(path);
23+
24+
return p;
2525
}
2626

2727
void test_exec(std::string_view path)
@@ -57,10 +57,11 @@ void test_register_parameters(int argc, char** argv, std::string_view path)
5757
auto handle = *INIT;
5858
assert(handle->register_parameters(gparams(path)));
5959
}
60-
60+
#include <iostream>
6161
int main(int argc, char** argv)
6262
{
6363
std::string cma_path = get_cma_path(argc, argv);
64+
std::cout << cma_path << std::endl;
6465
test_init(argc, argv);
6566
test_apply_err(argc, argv);
6667
test_exec_err(argc, argv);

apps/api/tests/test_api_raw.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ void test_exec(int argc, char** argv, std::string_view path)
4646

4747
void test_apply(int argc, char** argv, std::string_view path)
4848
{
49-
Handle handle = INIT mock_prepre_apply(path, handle);
49+
Handle handle = INIT;
50+
mock_prepre_apply(path, handle);
5051
CHECK(apply(handle, 0));
5152
delete_handle(&handle);
5253
}
@@ -83,13 +84,13 @@ void test_register_initializer_path(int argc, char** argv)
8384
}
8485
void test_make_params(int argc, char** argv)
8586
{
86-
Param params = PARAM assert(params.biomass_initial_concentration == cx);
87+
Param params = PARAM;
88+
assert(params.biomass_initial_concentration == cx);
8789
assert(params.final_time == ft);
8890
assert(params.delta_time == dt);
8991
assert(params.number_particle == np);
9092
assert(params.n_thread == 1); // Default value
9193
assert(params.number_exported_result == nex);
92-
assert(params.recursive == 0); // Default value
9394
assert(params.force_override == 0); // Default value
9495
assert(params.load_serde == 0); // Default value
9596
}
@@ -105,8 +106,7 @@ void test_register_parameters(int argc, char** argv)
105106
// need existing directory
106107
void test_register_cma_path_recursive(int argc, char** argv)
107108
{
108-
Handle handle = INIT int result =
109-
register_cma_path_recursive(handle, "./tools");
109+
Handle handle = INIT int result = register_cma_path(handle, "./tools");
110110
assert(result == 0);
111111
delete_handle(&handle);
112112
}
@@ -159,10 +159,6 @@ void test_branch_null(int argc, char** argv)
159159
CHECK_FALSE(register_result_path(handle, NULL));
160160
CHECK_FALSE(register_result_path(NULL, NULL));
161161

162-
CHECK_FALSE(register_cma_path_recursive(NULL, "valid"));
163-
CHECK_FALSE(register_cma_path_recursive(handle, NULL));
164-
CHECK_FALSE(register_cma_path_recursive(NULL, NULL));
165-
166162
CHECK_FALSE(register_serde(NULL, "valid"));
167163
CHECK_FALSE(register_serde(handle, NULL));
168164
CHECK_FALSE(register_serde(NULL, NULL));

apps/core/src/global_initaliser.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <cstddef>
99
#include <cstdio>
1010
#include <dataexporter/data_exporter.hpp>
11+
#include <exception>
1112
#include <load_balancing/iload_balancer.hpp>
1213
#include <load_balancing/impl_lb.hpp>
1314
#include <mc/mcinit.hpp>
@@ -206,13 +207,24 @@ namespace Core
206207
std::optional<CmaUtils::TransitionnerPtrType>
207208
GlobalInitialiser::init_transitionner()
208209
{
209-
210-
auto d_transition = (is_host)
211-
? get_dtransitioner(user_params.cma_case_path)
212-
: CmaUtils::TransitionnerPtrType::from_raw(nullptr);
210+
auto d_transition = CmaUtils::TransitionnerPtrType::from_raw(nullptr);
213211

214212
if (is_host)
215213
{
214+
try
215+
{
216+
d_transition = (is_host)
217+
? get_dtransitioner(user_params.cma_case_path)
218+
: CmaUtils::TransitionnerPtrType::from_raw(nullptr);
219+
}
220+
catch (std::exception& e)
221+
{
222+
if (logger)
223+
{
224+
logger->error(e.what());
225+
}
226+
return std::nullopt;
227+
}
216228
f_init_gas_flow = info.current_rank == 0 && params.is_two_phase_flow;
217229
const auto state = d_transition->get_current();
218230
if (logger)

apps/libs/mpi_w/public/mpi_w/iteration_payload.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ namespace WrapMPI
7474
[[nodiscard]] bool sendAll(std::size_t n_rank) noexcept;
7575

7676
void wait() noexcept;
77-
77+
#ifdef NDEBUG // FIXME Needed for unite test
7878
private:
79+
#endif
7980
std::span<const double> liquid_volumes;
8081
std::span<const std::size_t> liquid_neighbors_flat;
8182
std::span<const double> proba_leaving_flat;

apps/libs/mpi_w/tests/test_iteration_payload.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include <cassert>
22
#include <iostream>
3+
#ifdef NDEBUG
4+
# undef NDEBUG
5+
#endif
36
#include <mpi_w/iteration_payload.hpp>
47

58
int main(int argc, char** argv)
@@ -17,31 +20,32 @@ int main(int argc, char** argv)
1720
std::vector<double> gases = {7.7, 8.8, 9.9};
1821

1922
std::vector<size_t> raw_neighbors = {1, 2, 3, 1, 2, 3, 1, 2, 3};
23+
std::vector<double> flat_proba = {0, 0.5, 1, 0, 0.5, 1, 0, 0.5, 1};
2024

21-
CmaRead::L2DView<const size_t> n_view(raw_neighbors, 3);
2225
if (size != 1)
2326
{
2427

2528
MPI_Status status;
2629
if (rank == 0)
30+
2731
{ // Sender
2832

2933
WrapMPI::HostIterationPayload host_payload;
30-
host_payload.liquid_flows = flows;
34+
host_payload.liquid_out_flows = flows;
3135
host_payload.liquid_volumes = volumes;
32-
host_payload.gas_volumes = gases;
33-
host_payload.neighbors = n_view;
36+
host_payload.liquid_neighbors_flat = raw_neighbors;
37+
host_payload.proba_leaving_flat = flat_proba;
3438
auto _ = host_payload.sendAll(size);
3539
}
3640
else if (rank == 1)
3741
{
38-
WrapMPI::IterationPayload payload(3, 3);
42+
WrapMPI::IterationPayload payload(3);
3943
payload.recv(0, &status);
4044

41-
assert(payload.liquid_flows == flows);
45+
assert(payload.liquid_out_flows == flows);
4246
assert(payload.liquid_volumes == volumes);
43-
assert(payload.gas_volumes == gases);
44-
assert(raw_neighbors == payload.raw_neighbors);
47+
assert(payload.liquid_neighbors_flat == raw_neighbors);
48+
assert(payload.proba_leaving_flat == payload.proba_leaving_flat);
4549
}
4650
}
4751
std::cout << "OK" << std::endl;

0 commit comments

Comments
 (0)