Ejemplo n.º 1
0
void test_readonly() {
  {
    state_map_type * map1 = state_map_fread_alloc_readonly("FileDoesNotExist");
    
    test_assert_true(state_map_is_instance(map1));
    test_assert_int_equal(0 , state_map_get_size( map1 ));
    test_assert_true( state_map_is_readonly( map1 ));
    state_map_free(map1);
  }
  {
    test_work_area_type * work_area = test_work_area_alloc("state-map");
    state_map_type * map1 = state_map_alloc();
    
    state_map_iset(map1 , 5 , STATE_INITIALIZED);
    state_map_iset(map1 , 9 , STATE_INITIALIZED);

    state_map_fwrite(map1 , "map1");
    {
      state_map_type * map2 = state_map_fread_alloc_readonly("map1");
      
      test_assert_true(state_map_equal(map1 , map2));
      state_map_free(map2);
    }
    test_work_area_free( work_area );
    state_map_free(map1);
  }
}
Ejemplo n.º 2
0
void test_copy() {
  state_map_type * state_map = state_map_alloc();
  state_map_iset( state_map , 0 , STATE_INITIALIZED );
  state_map_iset( state_map , 100 , STATE_INITIALIZED );
  {
    state_map_type * copy = state_map_alloc_copy( state_map );
    test_assert_true( state_map_equal( copy , state_map ));

    state_map_iset( state_map , 10 , STATE_INITIALIZED );
    test_assert_false( state_map_equal( copy , state_map ));                      
    
    state_map_free( copy );
  }
  state_map_free( state_map );
}
Ejemplo n.º 3
0
void create_test() {
  state_map_type * state_map = state_map_alloc();
  test_assert_true( state_map_is_instance( state_map ));
  test_assert_int_equal( 0 , state_map_get_size( state_map ));
  test_assert_false( state_map_is_readonly( state_map ));
  state_map_free( state_map );
}
Ejemplo n.º 4
0
void test_deselect_matching( ) {
  state_map_type * map = state_map_alloc( );
  bool_vector_type * mask1 = bool_vector_alloc(0 , false);
  bool_vector_type * mask2 = bool_vector_alloc(1000 , true);

  state_map_iset( map , 10 , STATE_INITIALIZED );
  state_map_iset( map , 10 , STATE_HAS_DATA );
  state_map_iset( map , 20 , STATE_INITIALIZED );
  state_map_deselect_matching( map , mask1 , STATE_HAS_DATA | STATE_INITIALIZED );
  state_map_deselect_matching( map , mask2 , STATE_HAS_DATA | STATE_INITIALIZED );
  
  test_assert_int_equal( state_map_get_size( map ) , bool_vector_size( mask1 ));
  
  for (int i=0; i < bool_vector_size( mask1 ); i++) {
    if (i==10)
      test_assert_false( bool_vector_iget( mask1 , i ));
    else if (i== 20)
      test_assert_false( bool_vector_iget( mask2 , i ));
    else {
      test_assert_false( bool_vector_iget( mask1 , i ));
      test_assert_true( bool_vector_iget( mask2 , i ));
    }
  }
    
  bool_vector_free( mask1 );
  bool_vector_free( mask2 );
  state_map_free( map );
}
Ejemplo n.º 5
0
void set_test( ) {
  state_map_type * state_map = state_map_alloc();
  state_map_iset( state_map , 0 , STATE_INITIALIZED );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( state_map , 0 ));

  state_map_iset( state_map , 100 , STATE_INITIALIZED );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( state_map , 100 ));

  test_assert_int_equal( STATE_UNDEFINED , state_map_iget( state_map , 50 ));
  test_assert_int_equal( 101 , state_map_get_size( state_map ));
  state_map_free( state_map );
}
Ejemplo n.º 6
0
void test_update_undefined( ) {
  state_map_type * map = state_map_alloc( );
  
  state_map_iset( map , 10 , STATE_INITIALIZED );
  test_assert_int_equal( STATE_UNDEFINED , state_map_iget( map , 5 ) );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 10 ) );

  state_map_update_undefined( map , 5 , STATE_INITIALIZED );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 5 ) );
  
  state_map_update_undefined( map , 10 , STATE_INITIALIZED );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 10 ) );
  
  state_map_free( map );
}
Ejemplo n.º 7
0
void test_count_matching() {
  state_map_type * map1 = state_map_alloc();
  state_map_iset(map1 , 10 , STATE_INITIALIZED );

  state_map_iset(map1 , 15 , STATE_INITIALIZED );
  state_map_iset(map1 , 15 , STATE_HAS_DATA );

  state_map_iset(map1 , 16 , STATE_INITIALIZED );
  state_map_iset(map1 , 16 , STATE_HAS_DATA );
  state_map_iset(map1 , 16 , STATE_LOAD_FAILURE );
  
  test_assert_int_equal( 1 , state_map_count_matching( map1 , STATE_HAS_DATA));
  test_assert_int_equal( 2 , state_map_count_matching( map1 , STATE_HAS_DATA | STATE_LOAD_FAILURE));
  test_assert_int_equal( 3 , state_map_count_matching( map1 , STATE_HAS_DATA | STATE_LOAD_FAILURE | STATE_INITIALIZED));

  state_map_free( map1 );
}
Ejemplo n.º 8
0
void test_update_matching( ) {
  state_map_type * map = state_map_alloc( );
  
  state_map_iset( map , 10 , STATE_INITIALIZED );
  state_map_iset( map , 3 , STATE_PARENT_FAILURE );
  test_assert_int_equal( STATE_UNDEFINED , state_map_iget( map , 5 ) );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 10 ) );

  state_map_update_matching( map , 5 , STATE_UNDEFINED | STATE_LOAD_FAILURE , STATE_INITIALIZED );
  state_map_update_matching( map , 10 , STATE_UNDEFINED | STATE_LOAD_FAILURE , STATE_INITIALIZED );
  state_map_update_matching( map , 3 , STATE_UNDEFINED | STATE_LOAD_FAILURE , STATE_INITIALIZED );
  
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 5 ) );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 10 ) );
  test_assert_int_equal( STATE_PARENT_FAILURE , state_map_iget( map , 3 ) );
  
  state_map_update_undefined( map , 10 , STATE_INITIALIZED );
  test_assert_int_equal( STATE_INITIALIZED , state_map_iget( map , 10 ) );
  
  state_map_free( map );
}
Ejemplo n.º 9
0
Archivo: enkf_fs.c Proyecto: shulNN/ert
static void enkf_fs_umount( enkf_fs_type * fs ) {
  if (!fs->read_only) {
    enkf_fs_fsync( fs );
    enkf_fs_fwrite_misfit( fs );
  }

  if (fs->lock_fd > 0) {
    close( fs->lock_fd );  // Closing the lock_file file descriptor - and releasing the lock.
    util_unlink_existing( fs->lock_file );
  }

  
  {
    int refcount = fs->refcount;
    if (refcount == 0) {
      enkf_fs_free_driver( fs->dynamic_forecast );
      enkf_fs_free_driver( fs->dynamic_analyzed );
      enkf_fs_free_driver( fs->parameter );
      enkf_fs_free_driver( fs->eclipse_static );
      enkf_fs_free_driver( fs->index );
      
      util_safe_free( fs->case_name );
      util_safe_free( fs->root_path );
      util_safe_free(fs->lock_file);
      util_safe_free( fs->mount_point );
      path_fmt_free( fs->case_fmt );
      path_fmt_free( fs->case_member_fmt );
      path_fmt_free( fs->case_tstep_fmt );
      path_fmt_free( fs->case_tstep_member_fmt );
      
      state_map_free( fs->state_map );
      time_map_free( fs->time_map );
      cases_config_free( fs->cases_config );
      free( fs );
    } else
      util_abort("%s: internal fuckup - tried to umount a filesystem with refcount:%d\n",__func__ , refcount);
  }
}
Ejemplo n.º 10
0
void load_empty_test() {
  state_map_type * state_map = state_map_fread_alloc( "File/does/not/exists" );
  test_assert_true( state_map_is_instance( state_map ));
  test_assert_int_equal( 0 , state_map_get_size( state_map ));
  state_map_free( state_map );
}
Ejemplo n.º 11
0
void get_test( ) {
  state_map_type * state_map = state_map_alloc();
  test_assert_int_equal( STATE_UNDEFINED , state_map_iget( state_map , 0 ));
  test_assert_int_equal( STATE_UNDEFINED , state_map_iget( state_map , 100 ));
  state_map_free( state_map );
}
Ejemplo n.º 12
0
int main(int argc, char ** argv) {
  const char * config_file = argv[1];
  test_work_area_type * work_area = test_work_area_alloc( "enkf_main_fs" );
  char * model_config;
  util_alloc_file_components( config_file , NULL , &model_config , NULL);
  test_work_area_copy_parent_content( work_area , config_file );
  {
    const char * site_config = "/project/res/etc/ERT/site-config";
    enkf_main_type * enkf_main = enkf_main_bootstrap( site_config , model_config , false , false );

    enkf_main_select_fs( enkf_main , "enkf");
    test_assert_true( enkf_main_case_is_current( enkf_main , "enkf"));
    test_assert_false( enkf_main_case_is_current( enkf_main , "default_fs"));
    test_assert_false( enkf_main_case_is_current( enkf_main , "does_not_exist"));

    test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    {
      enkf_fs_type * fs_ref = enkf_main_get_fs_ref( enkf_main );
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      enkf_fs_decref( fs_ref );
      test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    }

    {
      state_map_type * map1 = enkf_fs_get_state_map( enkf_main_get_fs( enkf_main ));
      state_map_type * map2 = enkf_main_alloc_readonly_state_map(enkf_main , "enkf");
      test_assert_true(state_map_equal( map1 , map2 ));
      state_map_free( map2 );
    }
    {
      enkf_fs_type * fs1 = enkf_main_mount_alt_fs( enkf_main , "default" , false );
      enkf_fs_type * fs2 = enkf_main_mount_alt_fs( enkf_main , "enkf" , false );
      
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      test_assert_int_equal( 2 , enkf_fs_get_refcount( fs2 ));
      test_assert_int_equal( 1 , enkf_fs_get_refcount( fs1 ));

      enkf_fs_decref( fs1 );
      enkf_fs_decref( fs2 );
    }

    {
      enkf_fs_type * enkf_fs = enkf_main_mount_alt_fs( enkf_main , "enkf" , false  );
      
      enkf_main_select_fs( enkf_main , "default");
      test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      enkf_fs_decref( enkf_fs );
    }

    {
      enkf_fs_type * default_fs = enkf_main_mount_alt_fs( enkf_main , "default" , false );
      
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      enkf_main_select_fs( enkf_main , "default");
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      enkf_fs_decref( default_fs );
      test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    }
    /*****************************************************************/
    {
      enkf_fs_type * fs = enkf_main_mount_alt_fs( enkf_main , "default" , false  );
      test_assert_int_equal( 2 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
      
      enkf_main_set_fs( enkf_main , fs , NULL );
      enkf_fs_decref( fs );
      test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    }
    {
      enkf_fs_type * fs = enkf_main_mount_alt_fs( enkf_main , "enkf" , false );
      enkf_fs_type * current = enkf_main_mount_alt_fs( enkf_main , "default" , false );
      
      test_assert_int_equal( 2 , enkf_fs_get_refcount( current ));
      test_assert_int_equal( 1 , enkf_fs_get_refcount( fs));
      enkf_main_set_fs( enkf_main , fs , NULL);
      test_assert_int_equal( 2 , enkf_fs_get_refcount( fs));
      test_assert_int_equal( 1 , enkf_fs_get_refcount( current ));

      enkf_fs_decref( current );
      enkf_fs_decref( fs);
    }

    
    

    test_assert_int_equal( 1 , enkf_fs_get_refcount( enkf_main_get_fs( enkf_main )));
    enkf_main_free( enkf_main );
  }
  test_work_area_free( work_area );
  exit(0);
}