Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #132 from joakim-hove/test-context-dict-init
Browse files Browse the repository at this point in the history
Test context dict init
  • Loading branch information
joakim-hove authored Oct 5, 2017
2 parents 355f9c4 + 5c43b0e commit 8e61c94
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 140 deletions.
4 changes: 3 additions & 1 deletion libenkf/include/ert/enkf/ert_test_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include <stdbool.h>

#include <ert/util/type_macros.h>
#include <ert/util/test_work_area.h>

#include <ert/enkf/res_config.h>
#include <ert/enkf/enkf_main.h>

#ifdef __cplusplus
Expand All @@ -34,7 +36,7 @@ typedef struct ert_test_context_struct ert_test_context_type;

void ert_test_context_set_store( ert_test_context_type * test_context , bool store);
ert_test_context_type * ert_test_context_alloc( const char * test_name , const char * model_config);
ert_test_context_type * ert_test_context_alloc_python( const char * test_name , const char * model_config);
ert_test_context_type * ert_test_context_alloc_python( test_work_area_type * work_area, res_config_type * res_config);
void ert_test_context_free( ert_test_context_type * test_context );
enkf_main_type * ert_test_context_get_main( ert_test_context_type * test_context );
bool ert_test_context_install_workflow_job( ert_test_context_type * test_context , const char * job_name , const char * job_file);
Expand Down
25 changes: 16 additions & 9 deletions libenkf/src/ecl_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,22 +587,29 @@ void ecl_config_init(ecl_config_type * ecl_config, const config_content_type * c
}

if (config_content_has_item(config, SCHEDULE_FILE_KEY)) {
const char * schedule_target_file = config_content_safe_iget(config, SCHEDULE_FILE_KEY, 0, 1);
if (schedule_target_file) {
const config_content_item_type * schedule_item = config_content_get_item( config, SCHEDULE_FILE_KEY);
config_content_node_type * schedule_node = config_content_item_get_last_node( schedule_item );
char * schedule_target_file = NULL;

if (config_content_node_get_size( schedule_node ) > 1) {
schedule_target_file = config_content_node_iget_as_abspath( schedule_node, 1 );
ui_return_type * ui_return_sched_target_file = ecl_config_validate_schedule_file(ecl_config, schedule_target_file);
if (!ui_return_get_status(ui_return_sched_target_file) == UI_RETURN_OK) {
util_abort("%s: failed to set target schedule file. Error:%s\n",__func__ , ui_return_get_last_error(ui_return_sched_target_file));
util_abort("%s: failed to set target schedule file. Error:%s\n",__func__ , ui_return_get_last_error(ui_return_sched_target_file));
}
ui_return_free(ui_return_sched_target_file);
}

ui_return_type * ui_return = ecl_config_validate_schedule_file(ecl_config, config_content_iget(config, SCHEDULE_FILE_KEY, 0, 0));
if (ui_return_get_status(ui_return) == UI_RETURN_OK)
ecl_config_set_schedule_file(ecl_config, config_content_iget(config, SCHEDULE_FILE_KEY, 0, 0), schedule_target_file);
else
util_abort("%s: failed to set schedule file. Error:%s\n",__func__ , ui_return_get_last_error(ui_return));

ui_return_free(ui_return);
{
const char * schedule_src_file = config_content_node_iget_as_abspath( schedule_node, 0 );
ui_return_type * ui_return = ecl_config_validate_schedule_file(ecl_config, schedule_src_file);
if (ui_return_get_status(ui_return) == UI_RETURN_OK)
ecl_config_set_schedule_file(ecl_config, schedule_src_file, schedule_target_file);
else
util_abort("%s: failed to set schedule file. Error:%s\n",__func__ , ui_return_get_last_error(ui_return));
ui_return_free(ui_return);
}
}

if (config_content_has_item(config, GRID_KEY)) {
Expand Down
52 changes: 24 additions & 28 deletions libenkf/src/ert_test_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,47 +43,43 @@ struct ert_test_context_struct {

UTIL_IS_INSTANCE_FUNCTION( ert_test_context , ERT_TEST_CONTEXT_TYPE_ID )

static ert_test_context_type * ert_test_context_alloc__( const char * test_name , const char * model_config , bool python_mode) {

static ert_test_context_type * ert_test_context_alloc__( test_work_area_type * work_area, res_config_type * res_config, const char * ui_mode) {
ert_test_context_type * test_context = util_malloc( sizeof * test_context );
UTIL_TYPE_ID_INIT( test_context , ERT_TEST_CONTEXT_TYPE_ID );

/*
This environment variable is set to ensure that test context will
parse the correct files when loading site config.
parse the correct files when loading site config. The ui_mode
string should be "tui" or "gui".
*/
if (python_mode)
setenv("ERT_UI_MODE" , "gui" , 1);
else
setenv("ERT_UI_MODE" , "tui" , 1);


if (util_file_exists(model_config)) {
test_context->work_area = test_work_area_alloc(test_name);
test_work_area_set_store( test_context->work_area , false );
test_work_area_copy_parent_content(test_context->work_area , model_config );
{
char * config_file = util_split_alloc_filename( model_config );
test_context->res_config = res_config_alloc_load(config_file);
test_context->enkf_main = enkf_main_alloc(test_context->res_config, true, false);
free( config_file );
}
test_context->rng = rng_alloc( MZRAN , INIT_DEV_URANDOM );
} else {
test_context->enkf_main = NULL;
test_context->work_area = NULL;
test_context->rng = NULL;
test_context->res_config = NULL;
}
setenv("ERT_UI_MODE" , ui_mode , 1);
test_context->res_config = res_config;
test_context->work_area = work_area;
test_context->enkf_main = enkf_main_alloc(test_context->res_config, true, false);
test_context->rng = rng_alloc( MZRAN , INIT_DEV_URANDOM );
return test_context;
}


ert_test_context_type * ert_test_context_alloc( const char * test_name , const char * model_config) {
return ert_test_context_alloc__( test_name , model_config , false );
if (!util_file_exists(model_config))
return NULL;

test_work_area_type * work_area = test_work_area_alloc(test_name);
test_work_area_set_store( work_area , false );
test_work_area_copy_parent_content(work_area , model_config );

char * config_file = util_split_alloc_filename( model_config );
res_config_type * res_config = res_config_alloc_load(config_file);
free( config_file );

return ert_test_context_alloc__( work_area, res_config, "tui");
}


ert_test_context_type * ert_test_context_alloc_python( const char * test_name , const char * model_config) {
return ert_test_context_alloc__( test_name , model_config , true );
ert_test_context_type * ert_test_context_alloc_python( test_work_area_type * work_area, res_config_type * res_config) {
return ert_test_context_alloc__( work_area, res_config , "gui");
}


Expand Down
2 changes: 2 additions & 0 deletions libenkf/src/res_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,5 @@ const char * res_config_get_user_config_file(const res_config_type * res_config)
const char * res_config_get_site_config_file(const res_config_type * res_config) {
return site_config_get_config_file(res_config->site_config);
}


51 changes: 21 additions & 30 deletions libenkf/tests/enkf_ert_test_context.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
Copyright (C) 2014 Statoil ASA, Norway.
Copyright (C) 2014 Statoil ASA, Norway.
The file 'enkf_ert_test_context.c' is part of ERT - Ensemble based
Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/


Expand All @@ -27,17 +27,8 @@


void test_create_invalid(const char * config_file) {
char * cwd0 = util_alloc_cwd();
ert_test_context_type * test_context = ert_test_context_alloc("CREATE_CONTEXT" , config_file );
test_assert_true( ert_test_context_is_instance( test_context ));
test_assert_NULL( ert_test_context_get_main( test_context ));
{
char * cwd1 = util_alloc_cwd();
test_assert_string_equal(cwd1 , cwd0);
free( cwd1 );
}
free( cwd0 );
ert_test_context_free( test_context );
test_assert_NULL( test_context );
}


Expand All @@ -64,7 +55,7 @@ void test_install_job( const char * config_file, const char * job_file_OK , cons
test_assert_false( ert_test_context_install_workflow_job( test_context , "JOB" , "File/does/not/exist"));
test_assert_false( ert_test_context_install_workflow_job( test_context , "ERROR" , job_file_ERROR));
test_assert_true( ert_test_context_install_workflow_job( test_context , "OK" , job_file_OK));

ert_test_context_free( test_context );
}

Expand All @@ -78,10 +69,10 @@ void test_run_workflow_job( const char * config_file , const char * job_file ) {
stringlist_append_ref( args1 , "NewCase");
test_assert_false( ert_test_context_run_worklow_job( test_context , "NO-this-does-not-exist" , args1));
ert_test_context_install_workflow_job( test_context , "JOB" , job_file );

test_assert_false( ert_test_context_run_worklow_job( test_context , "JOB" , args0));
test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args1));

stringlist_free( args0 );
stringlist_free( args1 );
ert_test_context_free( test_context );
Expand Down Expand Up @@ -109,7 +100,7 @@ void test_install_workflow( const char * config_file , const char * job_file ) {
void test_run_workflow(const char * config_file , const char * job_file) {
ert_test_context_type * test_context = ert_test_context_alloc("INSTALL_WORKFLOW" , config_file );
test_assert_false( ert_test_context_run_worklow( test_context , "No-does.not.exist"));

ert_test_context_install_workflow_job( test_context , "JOB" , job_file );
{
FILE * stream1 = util_fopen( "WFLOW1", "w");
Expand All @@ -118,14 +109,14 @@ void test_run_workflow(const char * config_file , const char * job_file) {
ert_test_context_fwrite_workflow_job( stream1 , "JOB" , args);
stringlist_append_ref( args , "NewCase");
ert_test_context_fwrite_workflow_job( stream2 , "JOB" , args);

stringlist_free( args );
fclose( stream1 );
fclose( stream2 );
}
test_assert_true( ert_test_context_install_workflow( test_context , "WFLOW1" , "WFLOW1"));
test_assert_true( ert_test_context_install_workflow( test_context , "WFLOW2" , "WFLOW2"));

test_assert_true( ert_test_context_run_worklow( test_context , "WFLOW2"));
test_assert_false( ert_test_context_run_worklow( test_context , "WFLOW1"));

Expand Down
56 changes: 28 additions & 28 deletions libenkf/tests/enkf_export_field_test.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
Copyright (C) 2013 Statoil ASA, Norway.
The file 'enkf_export_field_test.c' is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
Copyright (C) 2013 Statoil ASA, Norway.
The file 'enkf_export_field_test.c' is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <stdlib.h>
#include <stdbool.h>
Expand All @@ -34,13 +34,13 @@ void test_export_field(ert_test_context_type * test_context , const char * job_n
test_assert_true( ert_test_context_install_workflow_job( test_context , job_name , job_file ));
{
stringlist_type * args = stringlist_alloc_new();

stringlist_append_copy(args, "PERMZ");
stringlist_append_copy(args, "TEST_EXPORT/test_export_field/PermZ%d.grdecl");
stringlist_append_copy(args, "0");
stringlist_append_copy(args, "FORECAST");
stringlist_append_copy(args, "0, 2");

test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );
stringlist_free( args );
}
Expand All @@ -53,29 +53,29 @@ void job_file_export_field_ecl_grdecl(ert_test_context_type * test_context , con
ert_test_context_install_workflow_job( test_context , job_name , job_file );
{
stringlist_type * args = stringlist_alloc_new();

stringlist_append_copy(args, "PERMX");
stringlist_append_copy(args, "TEST_EXPORT/test_export_field_ecl_grdecl/PermX%d.grdecl");
stringlist_append_copy(args, "0");
stringlist_append_copy(args, "ANALYZED");
test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

stringlist_clear(args);
stringlist_append_copy(args, "PERMZ");
stringlist_append_copy(args, "TEST_EXPORT/test_export_field_ecl_grdecl/PermZ%d");
stringlist_append_copy(args, "0");
stringlist_append_copy(args, "FORECAST");
stringlist_append_copy(args, "0-1");
test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );


test_assert_true(util_file_exists("TEST_EXPORT/test_export_field_ecl_grdecl/PermX0.grdecl"));
test_assert_true(util_file_exists("TEST_EXPORT/test_export_field_ecl_grdecl/PermX1.grdecl"));
test_assert_true(util_file_exists("TEST_EXPORT/test_export_field_ecl_grdecl/PermX2.grdecl"));

test_assert_true(util_file_exists("TEST_EXPORT/test_export_field_ecl_grdecl/PermZ0"));
test_assert_true(util_file_exists("TEST_EXPORT/test_export_field_ecl_grdecl/PermZ1"));

stringlist_free( args );
}
}
Expand All @@ -85,28 +85,28 @@ void job_file_export_field_rms_roff(ert_test_context_type * test_context , const
test_assert_true( ert_test_context_install_workflow_job( test_context , job_name , job_file ) );
{
stringlist_type * args = stringlist_alloc_new();

stringlist_append_copy(args, "PERMZ");
stringlist_append_copy(args, "TEST_EXPORT/test_export_field_rms_roff/PermZ%d");
stringlist_append_copy(args, "0");
stringlist_append_copy(args, "ANALYZED");
test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

stringlist_clear(args);
stringlist_append_copy(args, "PERMX");
stringlist_append_copy(args, "TEST_EXPORT/test_export_field_rms_roff/PermX%d.roff");
stringlist_append_copy(args, "0");
stringlist_append_copy(args, "FORECAST");
test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) );

test_assert_true(util_file_exists("TEST_EXPORT/test_export_field_rms_roff/PermZ0"));
test_assert_true(util_file_exists("TEST_EXPORT/test_export_field_rms_roff/PermZ1"));
test_assert_true(util_file_exists("TEST_EXPORT/test_export_field_rms_roff/PermZ2"));

test_assert_true(util_file_exists("TEST_EXPORT/test_export_field_rms_roff/PermX0.roff"));
test_assert_true(util_file_exists("TEST_EXPORT/test_export_field_rms_roff/PermX1.roff"));
test_assert_true(util_file_exists("TEST_EXPORT/test_export_field_rms_roff/PermX2.roff"));

stringlist_free( args );
}
}
Expand Down
28 changes: 14 additions & 14 deletions libenkf/tests/enkf_plot_gendata_fs.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
Copyright (C) 2014 Statoil ASA, Norway.
Copyright (C) 2014 Statoil ASA, Norway.
The file 'enkf_plot_gendata_fs.c' is part of ERT - Ensemble based Reservoir Tool.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
ERT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ERT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
for more details.
*/
#include <stdlib.h>

Expand Down
Loading

0 comments on commit 8e61c94

Please sign in to comment.