Class: MesaTestCase

Inherits:
Object
  • Object
show all
Defined in:
lib/mesa_test.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test: nil, mesa: nil, success_string: '', final_model: 'final.mod', photo: nil, mod: nil) ⇒ MesaTestCase

Returns a new instance of MesaTestCase.



856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
# File 'lib/mesa_test.rb', line 856

def initialize(test: nil, mesa: nil, success_string: '',
               final_model: 'final.mod', photo: nil, mod: nil)
  @test_name = test
  @mesa_dir = mesa.mesa_dir
  @mesa = mesa
  @mesa_version = mesa.version_number
  @success_string = success_string
  @final_model = final_model
  @photo = photo
  @failure_type = nil
  @success_type = nil
  @outcome = :not_tested
  @runtime_seconds = 0
  @test_omp_num_threads = 1
  @runtime_minutes = 0
  @retries = 0
  @backups = 0
  @steps = 0
  @summary_text = ''
  unless MesaTestCase.modules.include? mod
    raise TestCaseDirError, "Invalid module: #{mod}. Must be one of: " +
                            MesaTestCase.modules.join(', ')
  end
  @mod = mod
  @failure_msg = {
    run_test_string: "#{test_name} failed: does not match test string",
    run_checksum: "#{test_name} run failed: checksum for #{final_model} " \
      'does not match after ./rn',
    run_diff: "#{test_name} run failed: diff #{final_model} " \
      'final_check.mod after ./rn',
    photo_file: "#{test_name} restart failed: #{photo} does not exist",
    photo_checksum: "#{test_name} restart failed: checksum for " \
      "#{final_model} does not match after ./re",
    photo_diff: "#{test_name} restart failed: diff #{final_model} " \
      'final_check.mod after ./re'
  }
  @success_msg = {
    run_test_string: "#{test_name} run: found test string: " \
      "'#{success_string}'",
    run_checksum: "#{test_name} run: checksum for #{final_model} matches " \
      'after ./rn',
    photo_checksum: "#{test_name} restart: checksum for #{final_model} " \
      "matches after ./re #{photo}"
  }

  # validate stuff
  check_mesa_dir
  check_test_case

  @data = {}
  @data_names = []

  # way to output colored text to shell
  @shell = Thor::Shell::Color.new
end

Instance Attribute Details

#backupsObject (readonly)

Returns the value of attribute backups.



845
846
847
# File 'lib/mesa_test.rb', line 845

def backups
  @backups
end

#data_namesObject

Returns the value of attribute data_names.



849
850
851
# File 'lib/mesa_test.rb', line 849

def data_names
  @data_names
end

#data_types=(value) ⇒ Object

Sets the attribute data_types

Parameters:

  • value

    the value to set the attribute data_types to.



849
850
851
# File 'lib/mesa_test.rb', line 849

def data_types=(value)
  @data_types = value
end

#failure_msgObject (readonly)

Returns the value of attribute failure_msg.



845
846
847
# File 'lib/mesa_test.rb', line 845

def failure_msg
  @failure_msg
end

#failure_typeObject

Returns the value of attribute failure_type.



849
850
851
# File 'lib/mesa_test.rb', line 849

def failure_type
  @failure_type
end

#final_modelObject (readonly)

Returns the value of attribute final_model.



845
846
847
# File 'lib/mesa_test.rb', line 845

def final_model
  @final_model
end

#mesaObject (readonly)

Returns the value of attribute mesa.



845
846
847
# File 'lib/mesa_test.rb', line 845

def mesa
  @mesa
end

#mesa_dirObject (readonly)

Returns the value of attribute mesa_dir.



845
846
847
# File 'lib/mesa_test.rb', line 845

def mesa_dir
  @mesa_dir
end

#mesa_versionObject (readonly)

Returns the value of attribute mesa_version.



845
846
847
# File 'lib/mesa_test.rb', line 845

def mesa_version
  @mesa_version
end

#modObject (readonly)

Returns the value of attribute mod.



845
846
847
# File 'lib/mesa_test.rb', line 845

def mod
  @mod
end

#outcomeObject

Returns the value of attribute outcome.



849
850
851
# File 'lib/mesa_test.rb', line 849

def outcome
  @outcome
end

#photoObject (readonly)

Returns the value of attribute photo.



845
846
847
# File 'lib/mesa_test.rb', line 845

def photo
  @photo
end

#retriesObject (readonly)

Returns the value of attribute retries.



845
846
847
# File 'lib/mesa_test.rb', line 845

def retries
  @retries
end

#runtime_minutesObject (readonly)

Returns the value of attribute runtime_minutes.



845
846
847
# File 'lib/mesa_test.rb', line 845

def runtime_minutes
  @runtime_minutes
end

#runtime_secondsObject (readonly)

Returns the value of attribute runtime_seconds.



845
846
847
# File 'lib/mesa_test.rb', line 845

def runtime_seconds
  @runtime_seconds
end

#shellObject (readonly)

Returns the value of attribute shell.



845
846
847
# File 'lib/mesa_test.rb', line 845

def shell
  @shell
end

#stepsObject (readonly)

Returns the value of attribute steps.



845
846
847
# File 'lib/mesa_test.rb', line 845

def steps
  @steps
end

#success_msgObject (readonly)

Returns the value of attribute success_msg.



845
846
847
# File 'lib/mesa_test.rb', line 845

def success_msg
  @success_msg
end

#success_stringObject (readonly)

Returns the value of attribute success_string.



845
846
847
# File 'lib/mesa_test.rb', line 845

def success_string
  @success_string
end

#success_typeObject

Returns the value of attribute success_type.



849
850
851
# File 'lib/mesa_test.rb', line 849

def success_type
  @success_type
end

#summary_textObject (readonly)

Returns the value of attribute summary_text.



845
846
847
# File 'lib/mesa_test.rb', line 845

def summary_text
  @summary_text
end

#test_nameObject (readonly)

Returns the value of attribute test_name.



845
846
847
# File 'lib/mesa_test.rb', line 845

def test_name
  @test_name
end

#test_omp_num_threadsObject (readonly)

Returns the value of attribute test_omp_num_threads.



845
846
847
# File 'lib/mesa_test.rb', line 845

def test_omp_num_threads
  @test_omp_num_threads
end

Class Method Details

.modulesObject



852
853
854
# File 'lib/mesa_test.rb', line 852

def self.modules
  %i[star binary]
end

Instance Method Details

#add_datum(datum_name, datum_type) ⇒ Object



931
932
933
934
935
936
937
938
# File 'lib/mesa_test.rb', line 931

def add_datum(datum_name, datum_type)
  unless data_types.include? datum_type.to_sym
    raise InvalidDataType, "Invalid data type: #{datum_type}. Must be one "\
      'of ' + data_types.join(', ') + '.'
  end
  @data[datum_name] = datum_type
  @data_names << datum_name
end

#cleanObject

based on $MESA_DIR/star/test_suite/each_test_clean, revision 10000



945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
# File 'lib/mesa_test.rb', line 945

def clean
  shell.say("cleaning #{test_name}", color = :blue)
  puts ''
  check_mesa_dir
  check_test_case
  in_dir do
    puts './clean'
    unless bash_execute('./clean')
      raise TestCaseDirError, 'Encountered an error while running ./clean ' \
      "in #{Dir.getwd}."
    end
    shell.say 'Removing all files from LOGS, LOGS1, LOGS2, photos, ' \
      'photos1, and photos2', color = :blue
    FileUtils.rm_f Dir.glob('LOGS/*')
    FileUtils.rm_f Dir.glob('LOGS1/*')
    FileUtils.rm_f Dir.glob('LOGS2/*')
    FileUtils.rm_f Dir.glob('photos/*')
    FileUtils.rm_f Dir.glob('photos1/*')
    FileUtils.rm_f Dir.glob('photos2/*')

    shell.say 'Removing files binary_history.data, out.txt, and ' \
      'test_results.yml', color = :blue
    FileUtils.rm_f 'binary_history.data'
    FileUtils.rm_f 'out.txt'
    FileUtils.rm_f 'test_results.yml'
    if File.directory? File.join('star_history', 'history_out')
      shell.say 'Removing all files of the form history_out* from ' \
        'star_history', :blue
      FileUtils.rm_f Dir.glob(File.join('star_history', 'history_out', '*'))
    end
    if File.directory? File.join('star_profile', 'profiles_out')
      shell.say 'Removing all files of the form profiles_out* from ' \
        'star_profile', color = :blue
      FileUtils.rm_f Dir.glob(File.join('star_profile', 'profiles_out', '*'))
    end
    shell.say 'Removing .running', color = :blue
    FileUtils.rm_f '.running'
  end
end

#do_oneObject

based on $MESA_DIR/star/test_suite/each_test_run_and_diff, revision 10000



986
987
988
989
990
991
992
993
994
995
996
# File 'lib/mesa_test.rb', line 986

def do_one
  @test_omp_num_threads = omp_num_threads
  in_dir do
    FileUtils.touch '.running'
    shell.say("building and running #{test_name}", :blue)
    puts ''
    build_and_run
    FileUtils.rm '.running'
    puts ''
  end
end

#load_resultsObject



1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
# File 'lib/mesa_test.rb', line 1022

def load_results
  # loads all parameters from a previous test run, likely for submission
  # purposes
  load_file = File.join(test_case_dir, 'test_results.yml')
  shell.say "Loading data from #{load_file}...", :blue
  unless File.exist? load_file
    shell.say "No such file: #{load_file}. No data loaded.", :red
    return
  end
  data = YAML.safe_load(File.read(load_file), [Symbol])
  @runtime_seconds = data['runtime_seconds'] || @runtime_seconds
  @mod = data['module'] || @mod
  @mesa_version = data['mesa_version'] || @mesa_version
  @outcome = data['outcome'] || @outcome
  @test_omp_num_threads = data['omp_num_threads'] || @test_omp_num_threads
  @success_type = data['success_type'] || @success_type
  @failure_type = data['failure_type'] || @failure_type
  @runtime_minutes = data['runtime_minutes'] || @runtime_minutes
  @retries = data['retries'] || @retries
  @backups = data['backups'] || @backups
  @steps = data['steps'] || @steps
  @summary_text = data['summary_text'] || @summary_text

  # convert select data to symbols since that is how they are used
  @outcome = @outcome.to_sym if @outcome
  @success_type = @success_type.to_sym if @success_type
  @failure_type = @failure_type.to_sym if @failure_type

  shell.say "Done loading data from #{load_file}.\n", :green
end

#load_summary_dataObject



1053
1054
1055
1056
1057
1058
1059
1060
# File 'lib/mesa_test.rb', line 1053

def load_summary_data
  out_data = parse_out
  @runtime_minutes = out_data[:runtime_minutes]
  @retries = out_data[:retries]
  @backups = out_data[:backups]
  @steps = out_data[:steps]
  @summary_text = get_summary_text
end

#log_resultsObject



998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
# File 'lib/mesa_test.rb', line 998

def log_results
  # gets all parameters that would be submitted as well as computer
  # information and dumps to a yml file in the test case directory
  save_file = File.join(test_case_dir, 'test_results.yml')
  shell.say "Logging test results to #{save_file}...", :blue
  res = {
    'test_case' => test_name,
    'module' => mod,
    'runtime_seconds' => runtime_seconds,
    'mesa_version' => mesa_version,
    'outcome' => outcome,
    'omp_num_threads' => test_omp_num_threads,
    'success_type' => success_type,
    'failure_type' => failure_type,
    'runtime_minutes' => runtime_minutes,
    'retries' => retries,
    'backups' => backups,
    'steps' => steps,
    'summary_text' => summary_text
  }
  File.open(save_file, 'w') { |f| f.write(YAML.dump(res)) }
  shell.say "Successfully saved results to file #{save_file}.\n", :green
end

#omp_num_threadsObject



940
941
942
# File 'lib/mesa_test.rb', line 940

def omp_num_threads
  ENV['OMP_NUM_THREADS'].to_i || 1
end

#parse_outObject



1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
# File 'lib/mesa_test.rb', line 1062

def parse_out
  runtime_minutes = 0
  retries = 0
  backups = 0
  steps = 0
  run_summaries.each do |summary|
    summary =~ /^\s*runtime\s*\(minutes\),\s+retries,\s+backups,\ssteps\s+(\d+\.?\d*)\s+(\d+)\s+(\d+)\s+(\d+)\s*$/
    runtime_minutes += $1.to_f
    retries += $2.to_i
    backups += $3.to_i
    steps += $4.to_i
  end
  {runtime_minutes: runtime_minutes, retries: retries, backups: backups,
   steps: steps}
end

#passed?Boolean

Returns:

  • (Boolean)


912
913
914
915
916
917
918
919
920
921
# File 'lib/mesa_test.rb', line 912

def passed?
  if @outcome == :pass
    true
  elsif @outcome == :fail
    false
  else
    raise TestCaseDirError, 'Cannot determine pass/fail status of ' \
    "#{test_name} yet."
  end
end

#test_case_dirObject



927
928
929
# File 'lib/mesa_test.rb', line 927

def test_case_dir
  File.join(test_suite_dir, test_name)
end

#test_suite_dirObject



923
924
925
# File 'lib/mesa_test.rb', line 923

def test_suite_dir
  mesa.test_suite_dir(mod: @mod)
end