Пример #1
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;
}
Пример #2
0
int main( int argc , char ** argv) {
  const char * exjob_file = "job";
  const char * bin_path = argv[1];
  const char * internal_workflow = argv[2];
  test_work_area_type * work_area = test_work_area_alloc( "job_workflow_test" );

  signal(SIGSEGV , util_abort_signal);    
  create_exjob( exjob_file , bin_path );
  {
    
    int int_value = rand();
    int read_value = 100;
    workflow_joblist_type * joblist = workflow_joblist_alloc();
    
    if (!workflow_joblist_add_job_from_file( joblist , "CREATE_FILE" , exjob_file)) {
      remove( exjob_file );
      {
        config_type * job_config = workflow_joblist_get_job_config( joblist );
        config_fprintf_errors( job_config , true , stdout );
      }
      test_error_exit("Loading job CREATE_FILE failed\n");
    } else
      remove( exjob_file );
    
    if (!workflow_joblist_add_job_from_file( joblist , "READ_FILE"   , internal_workflow))
      test_error_exit("Loading job READ_FILE failed\n");
    
    {
      config_type * workflow_compiler = workflow_joblist_get_compiler( joblist );
      if (config_get_schema_size( workflow_compiler ) != 2)
        test_error_exit("Config compiler - wrong size \n");
    }
    
    
    {
      const char * workflow_file = "workflow";
      const char * tmp_file = "fileX";
      workflow_type * workflow;
      
      create_workflow( workflow_file , tmp_file , int_value );
      workflow = workflow_alloc(workflow_file , joblist );
      unlink( workflow_file );
      
      {
        bool runOK;
        runOK = workflow_run( workflow , &read_value , false , NULL);
        if (runOK) {
          if (int_value != read_value)
            test_error_exit("Wrong numeric value read back \n");

          test_assert_int_equal( workflow_get_stack_size( workflow ) , 2 );
          test_assert_not_NULL( workflow_iget_stack_ptr( workflow , 0 ) );
          test_assert_NULL( workflow_iget_stack_ptr( workflow , 1 ) );
          
          {
            void * return_value = workflow_iget_stack_ptr( workflow , 0 );
            int return_int = *((int *) return_value);
            if (int_value != return_int)
              test_error_exit("Wrong numeric value read back \n");
            
            test_assert_not_NULL( workflow_pop_stack( workflow ));
            test_assert_NULL( workflow_pop_stack( workflow ));
            test_assert_int_equal( workflow_get_stack_size( workflow ) , 0 );
            
            free( return_value );
          }

          
          
        } else {
          config_type * workflow_compiler = workflow_joblist_get_compiler( joblist );
          config_fprintf_errors( workflow_compiler , true ,stdout);
          unlink( tmp_file );
          test_error_exit("Workflow did not run\n");
        }
        unlink( tmp_file );
      }
    }
    workflow_joblist_free( joblist );
    
  }
  {
    workflow_joblist_type * joblist = workflow_joblist_alloc();
    const char * workflow_file = "workflow";
    const char * tmp_file = "fileX";
    int read_value;
    int int_value = 100;
    workflow_type * workflow;
    
    create_workflow( workflow_file , tmp_file , int_value );
    workflow = workflow_alloc(workflow_file , joblist );
    unlink( workflow_file );

    test_assert_false( workflow_run( workflow , &read_value , false , NULL) );
    test_assert_int_equal( workflow_get_stack_size( workflow ) , 0 );
  }
  test_work_area_free( work_area );
  exit(0);
}