Пример #1
0
void simple_test() {
  time_map_type * time_map = time_map_alloc( );
  test_work_area_type * work_area = test_work_area_alloc("enkf_time_map" , true);
  const char * mapfile = "map";
  
  test_assert_true( time_map_update( time_map , 0 , 100 )   );
  test_assert_true( time_map_update( time_map , 1 , 200 )   );
  test_assert_true( time_map_update( time_map , 1 , 200 )   );
  test_assert_false( time_map_update( time_map , 1 , 250 )  );

  test_assert_true( time_map_equal( time_map , time_map ) );
  time_map_fwrite( time_map , mapfile);
  {
    time_map_type * time_map2 = time_map_alloc( );

    test_assert_false( time_map_equal( time_map , time_map2 ) );
    time_map_fread( time_map2 , mapfile );
    test_assert_true( time_map_equal( time_map , time_map2 )  );
    time_map_free( time_map2 );
  }
  {
    time_t mtime1 = util_file_mtime( mapfile );
    sleep(2);
    time_map_fwrite( time_map , mapfile);
    
    test_assert_time_t_equal( mtime1 , util_file_mtime( mapfile ) );
    time_map_update( time_map , 2 , 300 );
    time_map_fwrite( time_map , mapfile);
    test_assert_time_t_not_equal( mtime1 , util_file_mtime( mapfile ) );
  }
  test_work_area_free( work_area );
}
Пример #2
0
bool workflow_try_compile( workflow_type * script , const subst_list_type * context) {
  if (util_file_exists( script->src_file )) {
    const char * src_file = script->src_file;
    char * tmp_file = NULL;
    bool   update = false;
    if (context != NULL) {
      tmp_file = util_alloc_tmp_file("/tmp" , "ert-workflow" , false );
      update = subst_list_filter_file( context , script->src_file , tmp_file );
      if (update) {
        script->compiled = false;
        src_file = tmp_file;
      } else {
        remove( tmp_file );
        free( tmp_file );
        tmp_file = NULL;
      }
    }

    {
      time_t src_mtime = util_file_mtime( script->src_file );
      if (script->compiled) {
        if (util_difftime_seconds( src_mtime , script->compile_time ) > 0 )
          return true;
        else {
          // Script has been compiled succesfully, but then changed afterwards.
          // We try to recompile; if that fails we are left with 'nothing'.
        }
      }
    }

    {
      // Try to compile
      config_parser_type * config_compiler = workflow_joblist_get_compiler( script->joblist );
      script->compiled = false;
      workflow_clear( script );
      {
        config_content_type * content = config_parse( config_compiler , src_file , WORKFLOW_COMMENT_STRING , WORKFLOW_INCLUDE , NULL , CONFIG_UNRECOGNIZED_ERROR , true );

        if (config_content_is_valid( content )) {
          int cmd_line;
          for (cmd_line = 0; cmd_line < config_content_get_size(content); cmd_line++) {
            const config_content_node_type * node = config_content_iget_node( content , cmd_line );
            const char * jobname = config_content_node_get_kw( node );
            const workflow_job_type * job = workflow_joblist_get_job( script->joblist , jobname );
            cmd_type * cmd = cmd_alloc( job , config_content_node_get_stringlist( node ));

            workflow_add_cmd( script , cmd );
          }
          script->compiled = true;
        } else
          workflow_store_error( script , config_content_get_errors( content ));

        config_content_free( content );
      }
    }

    if (tmp_file != NULL) {
      if (script->compiled)
        remove( tmp_file );
      free( tmp_file );
    }
  }

  // It is legal to remove the script after successfull compilation but
  // then the context will not be applied at subsequent invocations.
  return script->compiled;
}