Example #1
0
void test_copy_parent_content( const char * path ) {
  char * full_path = util_alloc_abs_path( path );
  char * parent_path = util_alloc_parent_path( full_path );
  test_work_area_type * work_area = test_work_area_alloc( "copy-parent-content" );

  test_assert_false( test_work_area_copy_parent_content( work_area , "Does/not/exist") );
  test_assert_true( test_work_area_copy_parent_content( work_area , path ) );

  {

    struct dirent ** src_namelist;
    struct dirent ** target_namelist;
    int src_size    = scandir( parent_path                         , &src_namelist    , NULL , alphasort);
    int target_size = scandir( test_work_area_get_cwd( work_area ) , &target_namelist , NULL , alphasort);

    test_assert_int_equal( src_size , target_size );
    for (int i=0; i < src_size; i++) {
      test_assert_string_equal( src_namelist[i]->d_name , target_namelist[i]->d_name);

      free( src_namelist[i] );
      free( target_namelist[i] );
    }

    free( src_namelist );
    free( target_namelist );
  }
  free( parent_path );
  free( full_path );

  test_work_area_free( work_area );
}
Example #2
0
File: ecl_sum.c Project: flikka/ert
void ecl_sum_set_case( ecl_sum_type * ecl_sum , const char * ecl_case) {
  util_safe_free( ecl_sum->ecl_case );
  util_safe_free( ecl_sum->path );
  util_safe_free( ecl_sum->abs_path );
  util_safe_free( ecl_sum->base );
  util_safe_free( ecl_sum->ext );
  {
    char  *path , *base, *ext;

    util_alloc_file_components( ecl_case , &path , &base , &ext);

    ecl_sum->ecl_case = util_alloc_string_copy( ecl_case );
    ecl_sum->path     = util_alloc_string_copy( path );
    ecl_sum->base     = util_alloc_string_copy( base );
    ecl_sum->ext      = util_alloc_string_copy( ext );
    if (path != NULL)
      ecl_sum->abs_path = util_alloc_abs_path( path );
    else
      ecl_sum->abs_path = util_alloc_cwd();

    util_safe_free( base );
    util_safe_free( path );
    util_safe_free( ext );
  }
}
Example #3
0
void hook_manager_set_runpath_list_file( hook_manager_type * hook_manager , const char * basepath, const char * filename) {

  if (filename && util_is_abs_path( filename ))
    hook_manager_set_runpath_list_file__( hook_manager , filename );
  else {
    const char * file = RUNPATH_LIST_FILE;

    if (filename != NULL)
      file = filename;

    char * file_with_path_prefix = NULL;
    if (basepath != NULL) {
      file_with_path_prefix = util_alloc_filename(basepath, file, NULL);
    }
    else
      file_with_path_prefix = util_alloc_string_copy(file);

    {
      char * absolute_path = util_alloc_abs_path(file_with_path_prefix);
      hook_manager_set_runpath_list_file__( hook_manager , absolute_path );
      free( absolute_path );
    }

    free(file_with_path_prefix);
  }
}
Example #4
0
void test_install_file_exists(const char * filename ) {
  char * abs_input_path = util_alloc_abs_path( filename );
  test_work_area_type * work_area = test_work_area_alloc( "FILE-TEST" );

  test_work_area_install_file( work_area , filename );
  test_assert_true( util_files_equal( abs_input_path , filename ));
  test_work_area_free( work_area );
  free( abs_input_path );
}
void test_predicate_matching() {
  test_work_area_type * work_area = test_work_area_alloc("predicate_test");
  stringlist_type * s = stringlist_alloc_new();
  stringlist_append_copy(s, "s");
  stringlist_select_files(s, "does/not/exist", NULL, NULL);
  test_assert_int_equal(stringlist_get_size(s), 0);


  {
    FILE * f = util_fopen("FILE.txt", "w");
    fclose(f);
  }
  stringlist_select_files(s , test_work_area_get_cwd(work_area), NULL, NULL);
  test_assert_int_equal(1, stringlist_get_size(s));
  {
    char * exp = util_alloc_abs_path("FILE.txt");
    test_assert_string_equal( exp, stringlist_iget(s, 0));
    free(exp);
  }

  stringlist_select_files(s , NULL, NULL, NULL);
  test_assert_int_equal(1, stringlist_get_size(s));
  test_assert_string_equal( "FILE.txt", stringlist_iget(s, 0));

  stringlist_select_files(s , test_work_area_get_cwd(work_area), FILE_predicate, NULL);
  test_assert_int_equal(1, stringlist_get_size(s));
  {
    char * exp = util_alloc_abs_path("FILE.txt");
    test_assert_string_equal( exp, stringlist_iget(s, 0));
    free(exp);
  }

  stringlist_select_files(s , test_work_area_get_cwd(work_area), not_FILE_predicate, NULL);
  test_assert_int_equal(0, stringlist_get_size(s));

  stringlist_free(s);
  test_work_area_free(work_area);
}
int main(int argc , char ** argv) {
  const int queue_timeout =  180;
  const int submit_timeout = 180;
  const int status_timeout = 180;
  const int number_of_jobs = 250;
  const int submit_threads = number_of_jobs / 10 ;
  const int status_threads = number_of_jobs + 1;
  const char * job = util_alloc_abs_path(argv[1]);
  rng_type * rng = rng_alloc( MZRAN , INIT_CLOCK );
  test_work_area_type * work_area = test_work_area_alloc("job_queue");
  job_type **jobs = alloc_jobs( rng , number_of_jobs , job);

  job_queue_type * queue = job_queue_alloc(number_of_jobs, "OK", "ERROR");
  queue_driver_type * driver = queue_driver_alloc_local();
  job_queue_manager_type * queue_manager = job_queue_manager_alloc( queue );

  job_queue_set_driver(queue, driver);
  job_queue_manager_start_queue(queue_manager, 0, false , true);

  {
    thread_pool_type * status_pool = thread_pool_alloc( status_threads , true );
    thread_pool_type * submit_pool = thread_pool_alloc( submit_threads , true );

    submit_jobs( queue , number_of_jobs , jobs , submit_pool );
    status_jobs( queue , number_of_jobs , jobs , status_pool );

    if (!thread_pool_try_join( submit_pool , submit_timeout ))
      util_exit("Joining submit pool failed \n");
    thread_pool_free( submit_pool );

    job_queue_submit_complete(queue);

    if (!thread_pool_try_join( status_pool , status_timeout))
      util_exit("Joining status pool failed \n");
    thread_pool_free( status_pool );
  }

  if (!job_queue_manager_try_wait(queue_manager , queue_timeout))
    util_exit("job_queue never completed \n");

  job_queue_manager_free(queue_manager);
  job_queue_free(queue);
  queue_driver_free(driver);
  check_jobs( number_of_jobs , jobs );
  test_work_area_free(work_area);
  rng_free( rng );
}
Example #7
0
void test_copy_parent_directory( const char * path ) {
  test_work_area_type * work_area = test_work_area_alloc( "copy-parent-directory" );
  char * parent_path;

  {
    char * full_path = util_alloc_abs_path( path );
    util_alloc_file_components( path , &parent_path , NULL , NULL);
    free( full_path );
  }

  test_assert_false( test_work_area_copy_parent_directory( work_area , "Does/not/exist") );
  test_assert_true( test_work_area_copy_parent_directory( work_area , path ) );

  test_assert_true( util_entry_exists( parent_path ));
  test_assert_true( util_is_directory( parent_path ));

  test_work_area_free( work_area );
  free( parent_path );
}
Example #8
0
File: run_arg.c Project: akva2/ert
static run_arg_type * run_arg_alloc(enkf_fs_type * init_fs ,
                                    enkf_fs_type * result_fs ,
                                    enkf_fs_type * update_target_fs ,
                                    int iens ,
                                    run_mode_type run_mode          ,
                                    int init_step_parameters        ,
                                    state_enum init_state_parameter ,
                                    state_enum init_state_dynamic   ,
                                    int step1                       ,
                                    int step2                       ,
                                    int iter                        ,
                                    const char * runpath) {

  run_arg_type * run_arg = util_malloc(sizeof * run_arg );
  UTIL_TYPE_ID_INIT(run_arg , RUN_ARG_TYPE_ID);

  run_arg->init_fs = init_fs;
  run_arg->result_fs = result_fs;
  run_arg->update_target_fs = update_target_fs;

  run_arg->iens = iens;
  run_arg->run_mode = run_mode;
  run_arg->init_step_parameters = init_step_parameters;
  run_arg->init_state_parameter = init_state_parameter;
  run_arg->init_state_dynamic = init_state_dynamic;
  run_arg->step1 = step1;
  run_arg->step2 = step2;
  run_arg->iter = iter;
  run_arg->run_path = util_alloc_abs_path( runpath );
  run_arg->num_internal_submit = 0;
  run_arg->queue_index = INVALID_QUEUE_INDEX;
  run_arg->run_status = JOB_NOT_STARTED;

  if (step1 == 0)
    run_arg->load_start = 1;
  else
    run_arg->load_start = step1;

  return run_arg;
}
Example #9
0
void config_content_set_config_file( config_content_type * content , const char * config_file ) {
  content->config_file = util_realloc_string_copy( content->config_file , config_file );

  util_safe_free(content->abs_path);
  content->abs_path = util_alloc_abs_path( config_file );
}