Harden API wrapper error paths and water bindings
This commit is contained in:
@@ -58,9 +58,16 @@ int main(void)
|
||||
&min_density, &max_density) != -1) {
|
||||
return fail("null water summary mass pointer did not return -1");
|
||||
}
|
||||
if (sphlite_get_water_summary(&water_mass, NULL, &max_pressure,
|
||||
&min_density, &max_density) != -1) {
|
||||
return fail("null water summary momentum pointer did not return -1");
|
||||
}
|
||||
if (sphlite_get_water_dt_limits(NULL, &dt_accel, &dt_viscous) != -1) {
|
||||
return fail("null water dt pointer did not return -1");
|
||||
}
|
||||
if (sphlite_get_water_dt_limits(&dt_cfl, &dt_accel, NULL) != -1) {
|
||||
return fail("null water dt viscous pointer did not return -1");
|
||||
}
|
||||
|
||||
ierr = sphlite_initialize();
|
||||
if (ierr != 0) return fail("initialize failed");
|
||||
@@ -102,11 +109,17 @@ int main(void)
|
||||
x, v, a, rho, pressure, internal_energy, temperature, h, &count) != -1) {
|
||||
return fail("null particle-state array did not return -1");
|
||||
}
|
||||
if (sphlite_get_particle_state(4, ids, phase, status, material_id, section_id,
|
||||
x, v, a, rho, pressure, internal_energy, temperature, h, NULL) != -1) {
|
||||
return fail("null particle-state count did not return -1");
|
||||
}
|
||||
|
||||
ierr = sphlite_advance_explicit(1.0e-6);
|
||||
if (ierr != 0) return fail("advance explicit failed");
|
||||
ierr = sphlite_get_current_time(&time, &step);
|
||||
if (ierr != 0 || step != 1 || time <= 0.0) return fail("time query failed");
|
||||
ierr = sphlite_advance_explicit(-1.0e-6);
|
||||
if (ierr != 1) return fail("Fortran argument error was not returned to C");
|
||||
|
||||
ierr = sphlite_set_output_directory(SPHLITE_TEST_WORK_DIR);
|
||||
if (ierr != 0) return fail("set output directory failed");
|
||||
|
||||
@@ -5,30 +5,38 @@
|
||||
int main()
|
||||
{
|
||||
if (sphlite::PhaseSolid != SPHLITE_PHASE_SOLID ||
|
||||
sphlite::StatusActive != SPHLITE_STATUS_ACTIVE) {
|
||||
sphlite::PhaseWater != SPHLITE_PHASE_WATER ||
|
||||
sphlite::StatusActive != SPHLITE_STATUS_ACTIVE ||
|
||||
sphlite::StatusFailed != SPHLITE_STATUS_FAILED) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
sphlite::Session session;
|
||||
sphlite::Version version = sphlite::version();
|
||||
if (version.major != 0 || version.minor != 2 || version.patch != 1) {
|
||||
return 1;
|
||||
{
|
||||
sphlite::Session session;
|
||||
sphlite::Version version = sphlite::version();
|
||||
if (version.major != 0 || version.minor != 2 || version.patch != 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string input = std::string(SPHLITE_TEST_DATA_DIR) + "/minimal_particles_011.inp";
|
||||
sphlite::read_inp(input);
|
||||
sphlite::build_model();
|
||||
if (sphlite::particle_count() != 4) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
sphlite::ParticleState state = sphlite::particle_state();
|
||||
if (state.particle_id_ext.size() != 4 || state.phase[0] != sphlite::PhaseSolid) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
std::string input = std::string(SPHLITE_TEST_DATA_DIR) + "/minimal_particles_011.inp";
|
||||
sphlite::read_inp(input);
|
||||
sphlite::build_model();
|
||||
if (sphlite::particle_count() != 4) {
|
||||
try {
|
||||
(void)sphlite::particle_count();
|
||||
return 1;
|
||||
} catch (const sphlite::Error &) {
|
||||
}
|
||||
|
||||
sphlite::ParticleState state = sphlite::particle_state();
|
||||
if (state.particle_id_ext.size() != 4 || state.phase[0] != sphlite::PhaseSolid) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
session.close();
|
||||
|
||||
sphlite::Session water_session;
|
||||
std::string water_input = std::string(SPHLITE_TEST_DATA_DIR) + "/water_minimal_020.inp";
|
||||
sphlite::read_inp(water_input);
|
||||
|
||||
@@ -27,6 +27,7 @@ program test_solver_water
|
||||
call check_last_small_step()
|
||||
call check_no_water_dt_strategy()
|
||||
call check_bad_h_dt_error()
|
||||
call check_new_api_error_defaults()
|
||||
call check_fortran_api_paths()
|
||||
call check_fortran_api_compatibility()
|
||||
|
||||
@@ -277,6 +278,57 @@ contains
|
||||
call assert_ok(ierr, 'finalize API paths failed')
|
||||
end subroutine check_fortran_api_paths
|
||||
|
||||
subroutine check_new_api_error_defaults()
|
||||
real(rk) :: total_mass
|
||||
real(rk) :: momentum(3)
|
||||
real(rk) :: max_pressure
|
||||
real(rk) :: min_density
|
||||
real(rk) :: max_density
|
||||
real(rk) :: dt_cfl
|
||||
real(rk) :: dt_accel
|
||||
real(rk) :: dt_viscous
|
||||
|
||||
total_mass = 9.0_rk
|
||||
momentum = 9.0_rk
|
||||
max_pressure = 9.0_rk
|
||||
min_density = 9.0_rk
|
||||
max_density = 9.0_rk
|
||||
call sph_get_water_summary(total_mass, momentum, max_pressure, &
|
||||
min_density, max_density, ierr)
|
||||
if (ierr == SPH_SUCCESS) call fail('uninitialized water summary did not fail')
|
||||
if (total_mass /= 0.0_rk .or. maxval(abs(momentum)) /= 0.0_rk) then
|
||||
call fail('uninitialized water summary defaults mismatch')
|
||||
end if
|
||||
dt_cfl = 9.0_rk
|
||||
dt_accel = 9.0_rk
|
||||
dt_viscous = 9.0_rk
|
||||
call sph_get_water_dt_limits(dt_cfl, dt_accel, dt_viscous, ierr)
|
||||
if (ierr == SPH_SUCCESS) call fail('uninitialized water dt limits did not fail')
|
||||
if (dt_cfl /= 0.0_rk .or. dt_accel /= 0.0_rk .or. dt_viscous /= 0.0_rk) then
|
||||
call fail('uninitialized water dt defaults mismatch')
|
||||
end if
|
||||
call sph_initialize(ierr)
|
||||
call assert_ok(ierr, 'initialize new API errors failed')
|
||||
total_mass = 9.0_rk
|
||||
momentum = 9.0_rk
|
||||
call sph_get_water_summary(total_mass, momentum, max_pressure, &
|
||||
min_density, max_density, ierr)
|
||||
if (ierr == SPH_SUCCESS) call fail('unbuilt water summary did not fail')
|
||||
if (total_mass /= 0.0_rk .or. maxval(abs(momentum)) /= 0.0_rk) then
|
||||
call fail('unbuilt water summary defaults mismatch')
|
||||
end if
|
||||
dt_cfl = 9.0_rk
|
||||
dt_accel = 9.0_rk
|
||||
dt_viscous = 9.0_rk
|
||||
call sph_get_water_dt_limits(dt_cfl, dt_accel, dt_viscous, ierr)
|
||||
if (ierr == SPH_SUCCESS) call fail('unbuilt water dt limits did not fail')
|
||||
if (dt_cfl /= 0.0_rk .or. dt_accel /= 0.0_rk .or. dt_viscous /= 0.0_rk) then
|
||||
call fail('unbuilt water dt defaults mismatch')
|
||||
end if
|
||||
call sph_finalize(ierr)
|
||||
call assert_ok(ierr, 'finalize new API errors failed')
|
||||
end subroutine check_new_api_error_defaults
|
||||
|
||||
subroutine check_fortran_api_compatibility()
|
||||
integer :: count
|
||||
integer :: ndim
|
||||
@@ -303,6 +355,9 @@ contains
|
||||
real(rk) :: max_pressure
|
||||
real(rk) :: min_density
|
||||
real(rk) :: max_density
|
||||
real(rk) :: dt_cfl
|
||||
real(rk) :: dt_accel
|
||||
real(rk) :: dt_viscous
|
||||
character(len=256) :: message
|
||||
|
||||
call sph_initialize(ierr)
|
||||
@@ -340,6 +395,9 @@ contains
|
||||
min_density, max_density, ierr)
|
||||
call assert_ok(ierr, 'compat water summary failed')
|
||||
if (total_mass <= 0.0_rk .or. min_density <= 0.0_rk) call fail('compat summary mismatch')
|
||||
call sph_get_water_dt_limits(dt_cfl, dt_accel, dt_viscous, ierr)
|
||||
call assert_ok(ierr, 'compat water dt limits failed')
|
||||
if (dt_cfl <= 0.0_rk .or. dt_viscous <= 0.0_rk) call fail('compat dt limits mismatch')
|
||||
call sph_set_output_directory('build-codex-unix', ierr)
|
||||
call assert_ok(ierr, 'compat output directory failed')
|
||||
call sph_write_output(88, time, ierr)
|
||||
|
||||
@@ -305,29 +305,29 @@
|
||||
- [x] 确认 neighbor rebuild API 兼容 0.2.0。
|
||||
- [x] 确认 neighbor stats API 兼容 0.2.0。
|
||||
- [x] 确认 water summary API 兼容 0.2.0。
|
||||
- [ ] 确认 water dt limits API 兼容 0.2.0。
|
||||
- [ ] 加固新增 API 未初始化错误路径。
|
||||
- [ ] 加固新增 API 未 build 错误路径。
|
||||
- [ ] 确认错误返回前输出参数为安全默认值。
|
||||
- [ ] 确认 API 不暴露内部 allocatable 指针。
|
||||
- [x] 确认 water dt limits API 兼容 0.2.0。
|
||||
- [x] 加固新增 API 未初始化错误路径。
|
||||
- [x] 加固新增 API 未 build 错误路径。
|
||||
- [x] 确认错误返回前输出参数为安全默认值。
|
||||
- [x] 确认 API 不暴露内部 allocatable 指针。
|
||||
|
||||
## 阶段 O:C ABI、C++ 和 Python 加固
|
||||
|
||||
- [ ] 确认 C ABI 头文件保持 0.2.0 兼容。
|
||||
- [ ] 加固 `sphlite_get_water_summary` 空指针错误路径。
|
||||
- [ ] 加固 `sphlite_get_water_dt_limits` 空指针错误路径。
|
||||
- [ ] 加固 `sphlite_get_particle_state` 空指针错误路径。
|
||||
- [ ] 加固 `sphlite_get_particle_state` 小容量错误路径。
|
||||
- [ ] 确认 C 参数错误返回 `-1`。
|
||||
- [ ] 确认 Fortran 错误码原样返回 C 调用方。
|
||||
- [ ] 确认 C wrapper 不重新定义物理语义。
|
||||
- [ ] 确认 C++ wrapper 只做薄封装。
|
||||
- [ ] 加固 C++ water summary 测试。
|
||||
- [ ] 加固 C++ water dt limits 测试。
|
||||
- [ ] 加固 C++ 生命周期 RAII 测试。
|
||||
- [ ] 确认 Python 通过 C ABI 调用。
|
||||
- [ ] 加固 Python water summary 包装。
|
||||
- [ ] 加固 Python water dt limits 包装。
|
||||
- [x] 确认 C ABI 头文件保持 0.2.0 兼容。
|
||||
- [x] 加固 `sphlite_get_water_summary` 空指针错误路径。
|
||||
- [x] 加固 `sphlite_get_water_dt_limits` 空指针错误路径。
|
||||
- [x] 加固 `sphlite_get_particle_state` 空指针错误路径。
|
||||
- [x] 加固 `sphlite_get_particle_state` 小容量错误路径。
|
||||
- [x] 确认 C 参数错误返回 `-1`。
|
||||
- [x] 确认 Fortran 错误码原样返回 C 调用方。
|
||||
- [x] 确认 C wrapper 不重新定义物理语义。
|
||||
- [x] 确认 C++ wrapper 只做薄封装。
|
||||
- [x] 加固 C++ water summary 测试。
|
||||
- [x] 加固 C++ water dt limits 测试。
|
||||
- [x] 加固 C++ 生命周期 RAII 测试。
|
||||
- [x] 确认 Python 通过 C ABI 调用。
|
||||
- [x] 加固 Python water summary 包装。
|
||||
- [x] 加固 Python water dt limits 包装。
|
||||
- [ ] 加固 Python inspect 辅助函数。
|
||||
- [ ] 加固 Python run 辅助函数。
|
||||
- [ ] 加固 Python 缺失输入错误路径。
|
||||
|
||||
@@ -19,6 +19,8 @@ def main() -> int:
|
||||
solver = SPHLite(args.library)
|
||||
if PHASE_SOLID != 4 or STATUS_ACTIVE != 0:
|
||||
raise AssertionError("Python constants are not locked")
|
||||
if not hasattr(solver.lib, "sphlite_get_water_summary"):
|
||||
raise AssertionError("Python wrapper is not using the C ABI library")
|
||||
if solver.version() != (0, 2, 1):
|
||||
raise AssertionError("Python version mismatch")
|
||||
|
||||
@@ -53,7 +55,13 @@ def main() -> int:
|
||||
raise AssertionError("water inspect particle count mismatch")
|
||||
if water_summary["water_mass"] <= 0.0:
|
||||
raise AssertionError("water summary mass mismatch")
|
||||
if water_summary["dt_cfl"] <= 0.0 or water_summary["dt_viscous"] <= 0.0:
|
||||
if len(water_summary["water_momentum"]) != 3:
|
||||
raise AssertionError("water summary momentum shape mismatch")
|
||||
if (
|
||||
water_summary["dt_cfl"] <= 0.0
|
||||
or water_summary["dt_accel"] <= 0.0
|
||||
or water_summary["dt_viscous"] <= 0.0
|
||||
):
|
||||
raise AssertionError("water dt limits mismatch")
|
||||
water_state = water.particle_state()
|
||||
if water_state["phase"][0] != PHASE_WATER:
|
||||
|
||||
Reference in New Issue
Block a user