예제 #1
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 );
}
예제 #2
0
void test_create() {
  char * cwd0 = util_alloc_cwd();
  char * cwd1;
  {
    ERT::TestArea ta("test/area");
    cwd1 = util_alloc_cwd();
    test_assert_string_not_equal( cwd0 , cwd1 );
    test_assert_string_equal( cwd1 , ta.getCwd().c_str());
    test_assert_string_equal( cwd0 , ta.getOriginalCwd( ).c_str() );
  }
  test_assert_false( util_is_directory(cwd1) );
  free( cwd1 );
  free( cwd0 );
}
예제 #3
0
int main(int argc , char ** argv) {
  char * cwd     = util_alloc_cwd( );
  char * path1   = argv[1];
  char * path2   = argv[2];
  {
    path_stack_type * path_stack = path_stack_alloc();

    path_stack_push_cwd( path_stack );
    
    if (path_stack_push( path_stack , "NotExist-1111"))
      test_error_exit("Pushed unexisting path\n");
    
    if (!path_stack_push( path_stack, path1 ))
      test_error_exit("Failed to push:%s \n",path1 );
    
    util_chdir( path2 );
    if (util_is_cwd( path1 ))
      test_error_exit("Failed to chdir(%s) \n",path2 );
    
    {
      if (path_stack_size( path_stack ) != 2)
        test_error_exit("Wrong stack size");
    
      if (strcmp( path1 , path_stack_peek( path_stack )) != 0)
        test_error_exit("peek error");
    }
    
    path_stack_pop( path_stack );
    printf("After pop: cwd:%s   path1:%s  \n",util_alloc_cwd() , path1);
    if (!util_is_cwd( path1 ))
      test_error_exit("path_stack_pop failed \n");

    path_stack_pop( path_stack );
    if (!util_is_cwd( cwd ))
      test_error_exit("path_stack_pop failed \n");

    if (path_stack_size( path_stack ) != 0)
      test_error_exit("Wrong stack size");
    
    if (!path_stack_push(path_stack , NULL))
      test_error_exit("Hmmm - push(NULL) failed \n");

    if (path_stack_size( path_stack ) != 1)
      test_error_exit("Wrong stack size");
    
    path_stack_pop( path_stack );
    path_stack_free( path_stack);
  }
  exit(0);
}
예제 #4
0
int main(int argc , char ** argv) {
  char * cwd = util_alloc_cwd();

  {
    config_root_path_type * root_path = config_root_path_alloc( NULL );
    
    if (!test_check_string_equal( config_root_path_get_abs_path( root_path ) , cwd ))
      test_error_exit("abs:path:%s   expeceted:%s \n",config_root_path_get_abs_path( root_path ) , cwd );

    if (!test_check_string_equal( config_root_path_get_input_path( root_path ) , NULL ))
      test_error_exit("input:path:%s   expeceted:%s \n",config_root_path_get_input_path( root_path ) , NULL );
    
    if (!test_check_string_equal( config_root_path_get_rel_path( root_path ) , NULL ))
      test_error_exit("rel:path:%s   expeceted:%s \n",config_root_path_get_rel_path( root_path ) , NULL );

    
    config_root_path_free( root_path );
  }


  {
    config_root_path_type * root_path = config_root_path_alloc( "/does/not/exist" );
    if (root_path != NULL)
      test_error_exit("Created root_path instance for not-existing input \n");
  }
  

  
  {
    const char * input_path = argv[1];
    char * cwd      = util_alloc_cwd();
    char * rel_path = util_alloc_rel_path( cwd , input_path );

    config_root_path_type * root_path1 = config_root_path_alloc( input_path );
    config_root_path_type * root_path2 = config_root_path_alloc( rel_path );

    if (!test_check_string_equal( config_root_path_get_rel_path( root_path1 ) , config_root_path_get_rel_path( root_path2 )))
      test_error_exit("Rel: %s != %s \n",config_root_path_get_rel_path( root_path1 ) , config_root_path_get_rel_path( root_path2));
    
    if (!test_check_string_equal( config_root_path_get_abs_path( root_path1 ) , config_root_path_get_abs_path( root_path2 )))
      test_error_exit("Abs: %s != %s \n",config_root_path_get_abs_path( root_path1 ) , config_root_path_get_abs_path( root_path2 ));
    
    config_root_path_free( root_path1 );
    config_root_path_free( root_path2 );
  }


  exit(0);
}
예제 #5
0
config_root_path_type * config_root_path_alloc( const char * input_path ) {
  if (input_path == NULL || util_is_directory( input_path )) {
    config_root_path_type * root_path = util_malloc( sizeof * root_path );
    {
      char * cwd = util_alloc_cwd();
      
      root_path->input_path = util_alloc_string_copy( input_path );
      if (input_path == NULL) {
        root_path->rel_path = NULL;
        root_path->abs_path = util_alloc_string_copy( cwd );
      } else {
        if (util_is_abs_path( input_path )) {
          root_path->abs_path = util_alloc_string_copy( input_path );
          root_path->rel_path = util_alloc_rel_path( cwd , root_path->abs_path);
        } else {
          root_path->rel_path = util_alloc_string_copy( input_path );
          {
            char * abs_path = util_alloc_filename( cwd , input_path , NULL );
            root_path->abs_path = util_alloc_realpath( abs_path );
            free( abs_path );
          }
        }
      }
      free( cwd );
    }
    return root_path;
  } else 
    return NULL;
}
예제 #6
0
void test_submit(lsf_driver_type * driver) {
  test_assert_true( lsf_driver_set_option(driver , LSF_DEBUG_OUTPUT , "TRUE" ) );
  test_assert_int_equal( LSF_SUBMIT_INTERNAL , lsf_driver_get_submit_method( driver ));
  {
    char * run_path = util_alloc_cwd();
    lsf_job_type * job = lsf_driver_submit_job( driver , cmd , 1 , run_path , "NAME" , 0 , NULL );
    if (job) {
      {
        int lsf_status = lsf_driver_get_job_status_lsf( driver , job );
        if (!((lsf_status == JOB_STAT_RUN) || (lsf_status == JOB_STAT_PEND))) 
          test_error_exit("Got lsf_status:%d expected: %d or %d \n",lsf_status , JOB_STAT_RUN , JOB_STAT_PEND);
      }
      
      lsf_driver_kill_job( driver , job );
      lsf_driver_set_bjobs_refresh_interval( driver , 0 );
      sleep(1);

      {
        int lsf_status = lsf_driver_get_job_status_lsf( driver , job );
        if (lsf_status != JOB_STAT_EXIT)
          test_error_exit("Got lsf_status:%d expected: %d \n",lsf_status , JOB_STAT_EXIT );
      }
    } else 
      test_error_exit("lsf_driver_submit_job() returned NULL \n");
    
    
    free( run_path );
  }
}
예제 #7
0
파일: ecl_sum.c 프로젝트: 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 );
  }
}
예제 #8
0
void test_get_original_cwd() {
   char * cwd = util_alloc_cwd();
   test_work_area_type * work_area = test_work_area_alloc( "CWD-ORG-TEST");
   test_assert_string_equal( cwd , test_work_area_get_original_cwd( work_area ));
   free( cwd );
   test_work_area_free( work_area );
}
예제 #9
0
void test_submit(lsf_driver_type * driver, const char * cmd) {
  assert( lsf_driver_set_option(driver , LSF_DEBUG_OUTPUT , "TRUE" ) );
  assert( LSF_SUBMIT_INTERNAL == lsf_driver_get_submit_method( driver ));
  {
    char * run_path = util_alloc_cwd();
    lsf_job_type * job = lsf_driver_submit_job( driver , cmd , 1 , run_path , "NAME" , 0 , NULL );
    assert( job );
    {
      {
        int lsf_status = lsf_driver_get_job_status_lsf( driver , job );
        assert( (lsf_status == JOB_STAT_RUN) || (lsf_status == JOB_STAT_PEND) );
      }

      lsf_driver_kill_job( driver , job );
      lsf_driver_set_bjobs_refresh_interval( driver , 0 );
      sleep(1);

      {
        int lsf_status = lsf_driver_get_job_status_lsf( driver , job );
        assert( lsf_status == JOB_STAT_EXIT);
      }
    }

    free( run_path );
  }
}
예제 #10
0
void test_get_cwd() {
   test_work_area_type * work_area = test_work_area_alloc( "CWD-TEST", false);
   char * cwd = util_alloc_cwd();
   test_assert_string_equal( cwd , test_work_area_get_cwd( work_area ));
   free( cwd );
   test_work_area_free( work_area );
}
예제 #11
0
void create_test_area(const char * test_name , bool store) {
  char * pre_cwd = util_alloc_cwd();
  test_work_area_type * work_area = test_work_area_alloc( test_name , store);
  char * work_path = util_alloc_string_copy( test_work_area_get_cwd( work_area ));
  
  test_assert_true( util_is_directory( work_path ));
  test_work_area_free( work_area );
  test_assert_bool_equal( store , util_entry_exists( work_path ));
  
  {
    char * post_cwd = util_alloc_cwd();
    test_assert_string_equal( pre_cwd , post_cwd );
    free( post_cwd );
  }
  free( pre_cwd );
  free( work_path );
}
예제 #12
0
파일: block_node.c 프로젝트: Ensembles/ert
void add_jobs( int chunk_size) {
  int i;
  char * cwd = util_alloc_cwd();
  for (i=0; i < chunk_size; i++) {
    block_job_type * job = block_job_alloc();
    job->lsf_job = lsf_driver_submit_job(lsf_driver , BLOCK_COMMAND , 1 , cwd , "BLOCK" , 0 , NULL );
    vector_append_ref( job_pool , job );
  }
  free( cwd );
}
예제 #13
0
void test_chdir() {
  test_work_area_type * work_area = test_work_area_alloc("test-area");
  const char * cwd = test_work_area_get_cwd( work_area );

  test_assert_false( util_chdir_file( "/file/does/not/exist"));
  test_assert_false( util_chdir_file( cwd ));
  {
    FILE * stream = util_mkdir_fopen("path/FILE","w");
    fclose( stream );
  }
  test_assert_true( util_chdir_file( "path/FILE" ));
  test_assert_string_equal( util_alloc_cwd() , util_alloc_filename( cwd, "path", NULL));
  test_work_area_free( work_area );
}
예제 #14
0
char * util_alloc_parent_path( const char * path) {
  int     path_ncomp;
  char ** path_component_list;
  char *  parent_path = NULL;

  if (path) {
    bool is_abs = util_is_abs_path( path );
    char * work_path;
    
    if (strstr(path , "..")) {
      if (is_abs) 
        work_path = util_alloc_realpath__( path );
      else {
        char * abs_path = util_alloc_realpath__( path );
        char * cwd = util_alloc_cwd();
        work_path = util_alloc_rel_path( cwd , abs_path );
        free( abs_path );
        free( cwd );
      }
    } else
      work_path = util_alloc_string_copy( path );
    
    util_path_split( work_path , &path_ncomp , &path_component_list );
    if (path_ncomp > 0) {
      int current_length = 4;
      int ip;

      parent_path = util_realloc( parent_path , current_length * sizeof * parent_path);
      parent_path[0] = '\0';
  
      for (ip=0; ip < path_ncomp - 1; ip++) {
        const char * ipath = path_component_list[ip];
        int min_length = strlen(parent_path) + strlen(ipath) + 1;
    
        if (min_length >= current_length) {
          current_length = 2 * min_length;
          parent_path = util_realloc( parent_path , current_length * sizeof * parent_path);
        }

        if (is_abs || (ip > 0))
          strcat( parent_path , UTIL_PATH_SEP_STRING );
        strcat( parent_path , ipath );
      }
    }
    util_free_stringlist( path_component_list , path_ncomp );
    free( work_path );
  }
  return parent_path;
}
예제 #15
0
파일: job_queue.c 프로젝트: agchitu/ert
int job_queue_add_job(job_queue_type * queue ,
                      const char * run_cmd ,
                      job_callback_ftype * done_callback,
                      job_callback_ftype * retry_callback,
                      job_callback_ftype * exit_callback,
                      void * callback_arg ,
                      int num_cpu ,
                      const char * run_path ,
                      const char * job_name ,
                      int argc ,
                      const char ** argv) {


  if (job_queue_accept_jobs(queue)) {
    int queue_index;
    job_queue_node_type * node = job_queue_node_alloc( job_name ,
                                                       run_path ,
                                                       run_cmd ,
                                                       argc ,
                                                       argv ,
                                                       num_cpu ,
                                                       queue->ok_file ,
                                                       queue->status_file ,
                                                       queue->exit_file,
                                                       done_callback ,
                                                       retry_callback ,
                                                       exit_callback ,
                                                       callback_arg );
    if (node) {
      job_list_get_wrlock( queue->job_list );
      {
        job_list_add_job( queue->job_list , node );
        queue_index = job_queue_node_get_queue_index(node);
        job_queue_change_node_status(queue , node , JOB_QUEUE_WAITING);
      }
      job_list_unlock( queue->job_list );
      return queue_index;   /* Handle used by the calling scope. */
    } else {
      char * cwd = util_alloc_cwd();
      util_abort("%s: failed to create job %s in path: %s cwd:%s \n",__func__ , job_name , run_path , cwd);
      return -1;
    }
  } else
    return -1;
}
예제 #16
0
qc_module_type * qc_module_alloc( ert_workflow_list_type * workflow_list , const char * qc_path ) {
  qc_module_type * qc_module = util_malloc( sizeof * qc_module );
  qc_module->qc_workflow = NULL;
  qc_module->qc_path = NULL;
  qc_module->workflow_list = workflow_list;
  qc_module->runpath_list = runpath_list_alloc();
  qc_module->runpath_list_file = NULL;
  qc_module_set_path( qc_module , qc_path );
  {
    char * cwd = util_alloc_cwd();
    char * runpath_list_file = util_alloc_filename( cwd , RUNPATH_LIST_FILE , NULL);

    qc_module_set_runpath_list_file( qc_module , runpath_list_file );

    free( runpath_list_file );
    free( cwd );
  }
  return qc_module;
}
예제 #17
0
char * util_alloc_PATH_executable(const char * executable) {
  if (util_is_abs_path(executable)) {
    if (util_is_executable(executable))
      return util_alloc_string_copy(executable);
    else
      return NULL;
  } else if (strncmp(executable , "./" , 2) == 0) {
    char * cwd = util_alloc_cwd();
    char * path = util_alloc_filename(cwd , &executable[2] , NULL);

    /* The program has been invoked as ./xxxx */
    if (!(util_is_file(path) && util_is_executable( path ))) {
      free( path );
      path = NULL;
    }
    free( cwd );

    return path;
  } else {
    char * full_path  = NULL;
    char ** path_list = util_alloc_PATH_list();
    int ipath = 0;

    while (true) {
      if (path_list[ipath] != NULL)  {
        char * current_attempt = util_alloc_filename(path_list[ipath] , executable , NULL);
      
        if ( util_is_file( current_attempt ) && util_is_executable( current_attempt )) {
          full_path = current_attempt;
          break;
        } else {
          free(current_attempt);
          ipath++;
        }
      } else
        break;
    }
    
    util_free_NULL_terminated_stringlist(path_list);
    return full_path;
  }
}
예제 #18
0
void test_submit(lsf_driver_type * driver , const char * server , const char * bsub_cmd , const char * bjobs_cmd , const char * bkill_cmd , const char * cmd) {
  lsf_driver_set_option(driver , LSF_SERVER , server );
  
  if (bsub_cmd != NULL)
    lsf_driver_set_option(driver , LSF_BSUB_CMD , server );

  if (bjobs_cmd != NULL)
    lsf_driver_set_option(driver , LSF_BJOBS_CMD , server );

  if (bkill_cmd != NULL)
    lsf_driver_set_option(driver , LSF_BKILL_CMD , server );

  {
    char * run_path = util_alloc_cwd();
    lsf_job_type * job = lsf_driver_submit_job( driver , cmd , 1 , run_path , "NAME" , 0 , NULL );
    
    if (job != NULL) {
      {
        int lsf_status = lsf_driver_get_job_status_lsf( driver , job );
        if (!((lsf_status == JOB_STAT_RUN) || (lsf_status == JOB_STAT_PEND)))
          exit(1);
      }
      
      lsf_driver_kill_job( driver , job );
      lsf_driver_set_bjobs_refresh_interval( driver , 0 );
      sleep(1);

      {
        int lsf_status = lsf_driver_get_job_status_lsf( driver , job );
        if (lsf_status != JOB_STAT_EXIT)
          exit(1);
      }
    } else
      exit(1);
    
    free( run_path );
  }
}
예제 #19
0
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);
  }
}
예제 #20
0
파일: path_stack.c 프로젝트: rolk/ert
void path_stack_push_cwd( path_stack_type * path_stack ) {
    char * cwd = util_alloc_cwd();
    stringlist_append_owned_ref( path_stack->storage , cwd);
    stringlist_append_ref( path_stack->stack , cwd );
}