Simplified testing of exit status

This commit is contained in:
Joakim Hove
2020-04-15 21:04:26 +02:00
parent 133ff18ee3
commit 43e2fced7d
4 changed files with 30 additions and 52 deletions

View File

@@ -161,22 +161,18 @@ if (ENABLE_MOCKSIM)
target_link_libraries(mocksim opmcommon)
target_include_directories(mocksim PUBLIC msim/include)
add_executable(msim examples/msim.cpp)
add_executable(msim_exit_status tests/msim/msim_exit_status.cpp)
target_link_libraries(msim mocksim)
target_link_libraries(msim_exit_status mocksim)
if (Boost_UNIT_TEST_FRAMEWORK_FOUND)
set(_libs mocksim opmcommon
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
foreach( test test_msim test_msim_ACTIONX)
foreach( test test_msim test_msim_ACTIONX test_msim_EXIT)
opm_add_test(${test} SOURCES tests/msim/${test}.cpp
LIBRARIES ${_libs}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/tests
CONDITION ${HAVE_ECL_INPUT})
endforeach()
add_test( NAME exit_test
COMMAND ${PROJECT_SOURCE_DIR}/tests/test_exit_status.sh ${PROJECT_SOURCE_DIR}/tests/EXIT_TEST.DATA ${PROJECT_BINARY_DIR}/bin/msim_exit_status 99 )
endif()
endif()

View File

@@ -56,7 +56,7 @@ void msim::run(Schedule& schedule, EclipseIO& io, bool report_only) {
post_step(schedule, st, sol, well_data, report_step);
const auto& exit_status = schedule.exitStatus();
if (exit_status.has_value())
std::exit( exit_status.value() );
return;
}
}

View File

@@ -17,6 +17,11 @@
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#define BOOST_TEST_MODULE ACTIONX_SIM
#include <boost/test/unit_test.hpp>
#include <stdexcept>
#include <opm/output/eclipse/EclipseIO.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
@@ -28,6 +33,7 @@
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
#include <tests/WorkArea.cpp>
#include <opm/msim/msim.hpp>
namespace Opm {
@@ -70,33 +76,32 @@ double prod_wpr_P4(const EclipseState& es, const Schedule& /* sched */, const S
}
}
int main(int , char **argv) {
std::string deck_file = argv[1];
BOOST_AUTO_TEST_CASE(MSIM_EXIT_TEST) {
std::string deck_file = "EXIT_TEST.DATA";
Opm::Parser parser;
Opm::ParseContext parse_context;
Opm::ErrorGuard error_guard;
auto python = std::make_shared<Opm::Python>();
Opm::Deck deck = parser.parseFile(deck_file, parse_context, error_guard);
Opm::Deck deck = parser.parseFile(deck_file);
Opm::EclipseState state(deck);
Opm::Schedule schedule(deck, state, parse_context, error_guard, python);
Opm::SummaryConfig summary_config(deck, schedule, state.getTableManager(), parse_context, error_guard);
Opm::Schedule schedule(deck, state, python);
Opm::SummaryConfig summary_config(deck, schedule, state.getTableManager());
if (error_guard) {
error_guard.dump();
error_guard.terminate();
{
WorkArea work_area("test_msim");
Opm::msim msim(state);
Opm::EclipseIO io(state, state.getInputGrid(), schedule, summary_config);
msim.well_rate("P1", Opm::data::Rates::opt::oil, Opm::prod_opr);
msim.well_rate("P2", Opm::data::Rates::opt::oil, Opm::prod_opr);
msim.well_rate("P3", Opm::data::Rates::opt::oil, Opm::prod_opr);
msim.well_rate("P4", Opm::data::Rates::opt::oil, Opm::prod_opr);
msim.well_rate("P1", Opm::data::Rates::opt::wat, Opm::prod_wpr_P1);
msim.well_rate("P2", Opm::data::Rates::opt::wat, Opm::prod_wpr_P2);
msim.well_rate("P3", Opm::data::Rates::opt::wat, Opm::prod_wpr_P3);
msim.well_rate("P4", Opm::data::Rates::opt::wat, Opm::prod_wpr_P4);
msim.run(schedule, io, false);
}
Opm::msim msim(state);
Opm::EclipseIO io(state, state.getInputGrid(), schedule, summary_config);
msim.well_rate("P1", Opm::data::Rates::opt::oil, Opm::prod_opr);
msim.well_rate("P2", Opm::data::Rates::opt::oil, Opm::prod_opr);
msim.well_rate("P3", Opm::data::Rates::opt::oil, Opm::prod_opr);
msim.well_rate("P4", Opm::data::Rates::opt::oil, Opm::prod_opr);
msim.well_rate("P1", Opm::data::Rates::opt::wat, Opm::prod_wpr_P1);
msim.well_rate("P2", Opm::data::Rates::opt::wat, Opm::prod_wpr_P2);
msim.well_rate("P3", Opm::data::Rates::opt::wat, Opm::prod_wpr_P3);
msim.well_rate("P4", Opm::data::Rates::opt::wat, Opm::prod_wpr_P4);
msim.run(schedule, io, false);
auto exit_status = schedule.exitStatus();
BOOST_CHECK( exit_status.has_value() );
BOOST_CHECK_EQUAL(exit_status.value(), 99);
}

View File

@@ -1,23 +0,0 @@
#!/bin/bash
INPUT_CASE="$1"
SIMULATOR="$2"
EXIT_STATUS="$3"
work_dir=$(mktemp -d)
cp "${INPUT_CASE}" ${work_dir}
pushd ${work_dir}
ecode=0
${SIMULATOR} $(basename "${INPUT_CASE}")
sim_status=$?
if [ ${sim_status} -ne ${EXIT_STATUS} ]
then
ecode=1
echo "Test of exit status failed - expected: ${EXIT_STATUS} got ${sim_status}"
fi
popd
rm -rf ${work_dir}
exit $ecode