int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); const char * config_file = argv[1]; ert_test_context_type * test_context = ert_test_context_alloc("VerifyJobsFileTest" , config_file); enkf_main_type * enkf_main = ert_test_context_get_main(test_context); { const int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc(0, false); bool_vector_iset( iactive , ens_size - 1 , true ); enkf_main_create_run_path(enkf_main , iactive , 0); bool_vector_free(iactive); } const char * filename = util_alloc_filename(ert_test_context_get_cwd(test_context), "simulations/run0/jobs.py", NULL); const char * jobs_file_content = util_fread_alloc_file_content(filename, NULL); test_assert_true (strstr(jobs_file_content, "umask = 0022") != NULL); test_assert_false (strstr(jobs_file_content, "umask = 0023") != NULL); test_assert_false (strstr(jobs_file_content, "umask = 0032") != NULL); test_assert_false (strstr(jobs_file_content, "umask = 0122") != NULL); test_assert_false (strstr(jobs_file_content, "umask = 1022") != NULL); ert_test_context_free(test_context); exit(0); }
void test_measure( ert_test_context_type * test_context ) { enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); enkf_fs_type * fs = enkf_main_get_fs( enkf_main ); enkf_obs_type * enkf_obs = enkf_main_get_obs( enkf_main ); obs_vector_type * rft_obs = enkf_obs_get_vector( enkf_obs , "RFT_TEST"); int_vector_type * ens_active_list = int_vector_alloc(0,0); active_list_type * active_list = active_list_alloc( ); meas_data_type * meas_data_RFT; for (int i=0; i < enkf_main_get_ensemble_size( enkf_main ); i++) int_vector_append( ens_active_list , i ); { bool_vector_type * ens_mask; ens_mask = int_vector_alloc_mask( ens_active_list ); meas_data_RFT = meas_data_alloc( ens_mask ); bool_vector_free( ens_mask ); } obs_vector_measure( rft_obs , fs , 20 , ens_active_list , meas_data_RFT , active_list ); int_vector_free( ens_active_list ); active_list_free( active_list ); meas_data_free( meas_data_RFT ); }
bool ert_test_context_run_worklow( ert_test_context_type * test_context , const char * workflow_name) { enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); ert_workflow_list_type * workflow_list = enkf_main_get_workflow_list( enkf_main ); if (ert_workflow_list_has_workflow( workflow_list , workflow_name )) return ert_workflow_list_run_workflow( workflow_list , workflow_name , enkf_main ); else return false; }
bool ert_test_context_install_workflow( ert_test_context_type * test_context , const char * workflow_name , const char * workflow_file) { if (util_file_exists( workflow_file )) { enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); ert_workflow_list_type * workflow_list = enkf_main_get_workflow_list( enkf_main ); ert_workflow_list_add_workflow( workflow_list , workflow_file , workflow_name ); return ert_workflow_list_has_workflow( workflow_list , workflow_name); } else return false; }
void test_container( ert_test_context_type * test_context ) { enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); enkf_obs_type * enkf_obs = enkf_main_get_obs( enkf_main ); obs_vector_type * rft_obs = enkf_obs_get_vector( enkf_obs , "RFT_TEST"); enkf_fs_type * fs = enkf_main_get_fs( enkf_main ); bool_vector_type * active_mask = bool_vector_alloc( enkf_main_get_ensemble_size( enkf_main ) , true ); test_assert_true( obs_vector_has_data( rft_obs , active_mask , fs )); bool_vector_free( active_mask ); }
int main( int argc , char ** argv) { const char * config_file = argv[1]; util_install_signals(); ert_test_context_type * test_context = ert_test_context_alloc("GENDATA" , config_file , NULL ); enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); test_gendata( enkf_main , "GEN_TIMESHIFT" , 60); ert_test_context_free( test_context ); exit(0); }
void test_iget(ert_test_context_type * test_context) { enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); enkf_obs_type * enkf_obs = enkf_main_get_obs( enkf_main ); test_assert_int_equal( 32 , enkf_obs_get_size( enkf_obs ) ); for (int iobs = 0; iobs < enkf_obs_get_size( enkf_obs ); iobs++) { obs_vector_type * vec1 = enkf_obs_iget_vector( enkf_obs , iobs ); obs_vector_type * vec2 = enkf_obs_get_vector( enkf_obs , obs_vector_get_key( vec1 )); test_assert_ptr_equal( vec1 , vec2 ); } }
int main(int argc , char ** argv) { const char * config_file = argv[1]; ert_test_context_type * test_context = ert_test_context_alloc("gen_kw_test" , config_file , NULL); enkf_main_type * enkf_main = ert_test_context_get_main(test_context); test_assert_not_NULL(enkf_main); test_write_gen_kw_export_file(enkf_main); test_assert_util_abort("gen_kw_ecl_write", test_send_fortio_to_gen_kw_ecl_write, enkf_main); ert_test_context_free( test_context ); exit(0); }
void test_create_valid( const char * config_file ) { char * cwd0 = util_alloc_cwd(); ert_test_context_type * test_context = ert_test_context_alloc("CREATE_CONTEXT" , config_file , NULL ); test_assert_true( ert_test_context_is_instance( test_context )); test_assert_true( enkf_main_is_instance( ert_test_context_get_main( test_context ))); { char * cwd1 = util_alloc_cwd(); test_assert_string_not_equal(cwd1 , cwd0); free( cwd1 ); } free( cwd0 ); ert_test_context_free( test_context ); }
int main(int argc , char ** argv) { const char * config_file = argv[1]; ert_test_context_type * context = ert_test_context_alloc( "OBS_VECTOR_FS" , config_file); enkf_main_type * enkf_main = ert_test_context_get_main( context ); { test_valid_obs_vector( enkf_main , "WWCT:OP_3"); test_container( context ); test_measure( context ); test_invalid_obs_vector( enkf_main , "GOPT:OP"); } ert_test_context_free( context ); }
void test_init_case_job(ert_test_context_type * test_context, const char * job_name , const char * job_file) { stringlist_type * args = stringlist_alloc_new(); enkf_main_type * enkf_main = ert_test_context_get_main(test_context); test_assert_true( ert_test_context_install_workflow_job( test_context , "JOB" , job_file ) ); //Test init current case from existing { enkf_fs_type * cur_fs = enkf_main_mount_alt_fs( enkf_main , "new_current_case" , true ); enkf_main_select_fs(enkf_main, "new_current_case"); test_assert_ptr_not_equal(cur_fs , enkf_main_get_fs( enkf_main )); stringlist_append_copy( args, "default"); //case to init from test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args) ); enkf_fs_decref(cur_fs); } { const char * current_case = enkf_main_get_current_fs( enkf_main ); test_assert_string_equal(current_case, "new_current_case"); test_assert_true(enkf_fs_has_node(enkf_main_get_fs(enkf_main), "PERMZ", PARAMETER, 0, 0, ANALYZED)); enkf_fs_type * default_fs = enkf_main_mount_alt_fs( enkf_main , "default" , true ); state_map_type * default_state_map = enkf_fs_get_state_map(default_fs); state_map_type * current_state_map = enkf_fs_get_state_map(enkf_main_get_fs(enkf_main)); test_assert_int_equal(state_map_get_size(default_state_map), state_map_get_size(current_state_map)); enkf_fs_decref(default_fs); } //Test init case from existing case: stringlist_clear(args); stringlist_append_copy(args, "default"); //case to init from stringlist_append_copy(args, "new_not_current_case"); test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args) ); { enkf_fs_type * fs = enkf_main_mount_alt_fs(enkf_main, "new_not_current_case", true); test_assert_not_NULL( fs ); test_assert_true( enkf_fs_has_node(fs, "PERMZ", PARAMETER, 0, 0, ANALYZED )); enkf_fs_type * default_fs = enkf_main_mount_alt_fs( enkf_main , "default" , true ); state_map_type * default_state_map = enkf_fs_get_state_map(default_fs); state_map_type * new_state_map = enkf_fs_get_state_map(fs); test_assert_int_equal(state_map_get_size(default_state_map), state_map_get_size(new_state_map)); enkf_fs_decref(fs); } stringlist_free( args ); }
void test_config( const char * config_file ) { ert_test_context_type * test_context = ert_test_context_alloc( "RUNPATH_FILE" , config_file , NULL ); enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); qc_module_type * qc_module = enkf_main_get_qc_module( enkf_main ); ert_test_context_run_worklow( test_context , "ARGECHO_WF"); { FILE * stream = util_fopen("runpath_list.txt" , "r"); char runpath_file[256]; fscanf(stream , "%s" , runpath_file ); fclose( stream ); test_assert_string_equal( runpath_file , qc_module_get_runpath_list_file( qc_module )); } ert_test_context_free( test_context ); }
void test_init_misfit_table(ert_test_context_type * test_context , const char * job_name , const char * job_file) { stringlist_type * args = stringlist_alloc_new(); ert_test_context_install_workflow_job( test_context , job_name , job_file ); enkf_main_type * enkf_main = ert_test_context_get_main(test_context); enkf_fs_type * fs = enkf_main_get_fs(enkf_main); misfit_ensemble_type * misfit_ensemble = enkf_fs_get_misfit_ensemble( fs ); test_assert_false(misfit_ensemble_initialized(misfit_ensemble)); test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) ); test_assert_true(misfit_ensemble_initialized(misfit_ensemble)); stringlist_free( args ); }
void test_magic_strings( ert_test_context_type * test_context ) { enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); test_assert_true( ert_test_context_run_worklow( test_context , "MAGIC_PRINT") ); test_assert_true( util_file_exists( "magic-list.txt") ); { FILE * stream = util_fopen("magic-list.txt" , "r"); char string[128]; fscanf( stream , "%s" , string); test_assert_string_equal( string , enkf_fs_get_case_name( enkf_main_get_fs( enkf_main ))); fscanf( stream , "%s" , string); test_assert_string_equal( string , "MagicAllTheWayToWorkFlow"); fclose( stream ); } }
int main( int argc , char ** argv) { const char * model_config = argv[1]; const char * site_config = NULL; ert_test_context_type * test_context = ert_test_context_alloc( "MAGIC-STRINGS" , model_config , site_config); enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); { test_has_job( test_context ); enkf_main_select_fs(enkf_main , "default"); test_assert_string_equal( "default" , enkf_fs_get_case_name( enkf_main_get_fs( enkf_main ))); test_magic_strings( test_context ); enkf_main_select_fs(enkf_main , "extraCase"); test_assert_string_equal( "extraCase" , enkf_fs_get_case_name( enkf_main_get_fs( enkf_main ))); test_magic_strings( test_context ); } ert_test_context_free( test_context ); }
bool ert_test_context_run_worklow_job( ert_test_context_type * test_context , const char * job_name, const stringlist_type * args) { enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); ert_workflow_list_type * workflow_list = enkf_main_get_workflow_list( enkf_main ); if (ert_workflow_list_has_job( workflow_list , job_name )) { bool status; { char * workflow = util_alloc_sprintf("WORKFLOW-%06d" , rng_get_int( test_context->rng , 1000000)); { FILE * stream = util_fopen( workflow , "w"); ert_test_context_fwrite_workflow_job( stream , job_name , args ); fclose(stream); } ert_test_context_install_workflow( test_context , workflow , workflow); status = ert_test_context_run_worklow( test_context , workflow ); free(workflow); } return status; } else return false; }
void testS( ert_test_context_type * test_context ) { { enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); enkf_obs_type * enkf_obs = enkf_main_get_obs( enkf_main ); enkf_fs_type * fs = enkf_main_get_fs( enkf_main ); int_vector_type * active_list = int_vector_alloc(0,0); obs_data_type * obs_data = obs_data_alloc(1.0); local_obsdata_type * obs_set = local_obsdata_alloc( "KEY" ); bool_vector_type * ens_mask; meas_data_type * meas_data; for (int i= 0; i < enkf_main_get_ensemble_size( enkf_main); i++) int_vector_append( active_list , i ); ens_mask = int_vector_alloc_mask( active_list); obs_data = obs_data_alloc(1.0); meas_data = meas_data_alloc( ens_mask ); enkf_obs_add_local_nodes_with_data( enkf_obs , obs_set , fs , ens_mask ); enkf_obs_get_obs_and_measure_data( enkf_obs , fs , obs_set, FORECAST , active_list , meas_data , obs_data); { FILE * stream = util_fopen("analysis/Smatrix" , "r"); matrix_type * S = meas_data_allocS( meas_data ); matrix_type * S0 = matrix_fread_alloc( stream ); test_assert_true( matrix_equal( S0 , S )); matrix_free( S ); matrix_free( S0 ); fclose( stream ); } int_vector_free( active_list ); meas_data_free( meas_data ); obs_data_free( obs_data ); local_obsdata_free( obs_set ); bool_vector_free( ens_mask ); } }
int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); const char * config_file = argv[1]; const char * init_file = argv[2]; const char * key = "PORO"; int iens = 0; ert_test_context_type * test_context = ert_test_context_alloc("ExportInactiveCellsTest" , config_file); enkf_main_type * enkf_main = ert_test_context_get_main(test_context); enkf_fs_type * fs = enkf_main_get_fs(enkf_main); const ensemble_config_type * ensemble_config = enkf_main_get_ensemble_config(enkf_main); const enkf_config_node_type * config_node = ensemble_config_get_node(ensemble_config , key); const field_config_type * field_config = enkf_config_node_get_ref( config_node ); enkf_state_type * state = enkf_main_iget_state( enkf_main , iens ); enkf_node_type * field_node = enkf_state_get_node( state , key ); field_type * field = enkf_node_value_ptr(field_node); { forward_initialize_node(enkf_main, init_file, field_node); node_id_type node_id = {.report_step = 0 , .iens = iens , .state = BOTH }; test_assert_true(enkf_node_try_load(field_node , fs , node_id)); field_scale(field, 3.0); } int nx,ny,nz; field_config_get_dims(field_config , &nx , &ny , &nz); const char * export_file_grdecl = "my_test_dir/exported_field_test_file_grdecl"; const char * export_file_roff = "my_test_dir/exported_field_test_file_roff"; field_file_format_type file_type; char * found_init_file = enkf_main_alloc_abs_path_to_init_file(enkf_main, config_node); { file_type = ECL_GRDECL_FILE; field_export(field, export_file_grdecl, NULL, file_type, false, found_init_file); check_exported_data(export_file_grdecl, init_file, file_type, field_config, field, nx, ny, nz); } { file_type = RMS_ROFF_FILE; field_export(field, export_file_roff, NULL, file_type, false, found_init_file); check_exported_data(export_file_roff, init_file, file_type, field_config, field, nx, ny, nz); } free(found_init_file); found_init_file = NULL; { file_type = ECL_GRDECL_FILE; field_export(field, export_file_grdecl, NULL, file_type, false, found_init_file); check_exported_data(export_file_grdecl, found_init_file, file_type, field_config, field, nx, ny, nz); } { file_type = RMS_ROFF_FILE; field_export(field, export_file_roff, NULL, file_type, false, found_init_file); check_exported_data(export_file_roff, found_init_file, file_type, field_config, field, nx, ny, nz); } ert_test_context_free(test_context); exit(0); }
void test_has_job(ert_test_context_type * test_context ) { enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); ert_workflow_list_type * workflows = enkf_main_get_workflow_list( enkf_main ); test_assert_true( ert_workflow_list_has_job( workflows , "MAGIC_PRINT" )); }
static void test_export_runpath_file(ert_test_context_type * test_context, const char * job_name, const char * job_file, stringlist_type * args, int_vector_type * iens_values, int_vector_type * iter_values) { ert_test_context_install_workflow_job( test_context , job_name , job_file ); test_assert_true( ert_test_context_run_worklow_job( test_context , job_name , args) ); { const enkf_main_type * enkf_main = ert_test_context_get_main(test_context); qc_module_type * qc_module = enkf_main_get_qc_module( enkf_main ); const char * runpath_file_name = qc_module_get_runpath_list_file(qc_module); ecl_config_type * ecl_config = enkf_main_get_ecl_config(enkf_main); const model_config_type * model_config = enkf_main_get_model_config(enkf_main); const char * base_fmt = ecl_config_get_eclbase(ecl_config); const char * runpath_fmt = model_config_get_runpath_as_char(model_config); test_assert_true(util_file_exists(runpath_file_name)); FILE * file = util_fopen(runpath_file_name, "r"); int file_iens = 0; char file_path[256]; char file_base[256]; int file_iter = 0; char * cwd = util_alloc_cwd(); int counter = 0; int iens_index = 0; int iter_index = 0; while (4 == fscanf( file , "%d %s %s %d" , &file_iens , file_path , file_base, &file_iter)) { ++ counter; test_assert_true(int_vector_size(iens_values) >= iens_index+1); test_assert_true(int_vector_size(iter_values) >= iter_index+1); int iens = int_vector_iget(iens_values, iens_index); int iter = int_vector_iget(iter_values, iter_index); test_assert_int_equal(file_iens, iens); test_assert_int_equal(file_iter, iter); char * base = util_alloc_sprintf("--%d", iens); if (base_fmt && (util_int_format_count(base_fmt) == 1)) base = util_alloc_sprintf(base_fmt, iens); test_assert_string_equal(base, file_base); char * runpath = ""; if (util_int_format_count(runpath_fmt) == 1) runpath = util_alloc_sprintf(runpath_fmt, iens); else if (util_int_format_count(runpath_fmt) == 2) runpath = util_alloc_sprintf(runpath_fmt, iens,iter); test_assert_string_equal(runpath, file_path); if (iens_index+1 < int_vector_size(iens_values)) ++iens_index; else if ((iens_index+1 == int_vector_size(iens_values))) { ++iter_index; iens_index = 0; } free(base); free(runpath); } int linecount = int_vector_size(iens_values) * int_vector_size(iter_values); test_assert_int_equal(linecount, counter); free(cwd); fclose(file); } }