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.



939
940
941
942
943
944
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
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
# File 'lib/mesa_test.rb', line 939

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
  # 2 (default) means uknown. Updated by running or loading data.
  # 1 means did diffs (not update_checksums; like each_test_run_and_diff)
  # 0 means no diffs (update_checksums; like each_test_run)
  @diff = 2

  # note: this gets overridden for new runs, so this is probably irrelevant
  @summary_text = nil

  # this overrides the submitters choice if it is non-nil
  @compiler = mesa.using_sdk ? 'SDK' : nil
  # only relevant if @compiler is SDK. Gets set during do_one
  @compiler_version = nil

  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} run failed: does not match test string",
    final_model: "#{test_name} run failed: final model #{final_model} not " \
      'made.',
    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',
    compilation: "#{test_name} compilation failed"

  }
  @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.



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

def backups
  @backups
end

#compilerObject (readonly)

Returns the value of attribute compiler.



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

def compiler
  @compiler
end

#compiler_versionObject (readonly)

Returns the value of attribute compiler_version.



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

def compiler_version
  @compiler_version
end

#data_namesObject

Returns the value of attribute data_names.



932
933
934
# File 'lib/mesa_test.rb', line 932

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.



932
933
934
# File 'lib/mesa_test.rb', line 932

def data_types=(value)
  @data_types = value
end

#diffObject (readonly)

Returns the value of attribute diff.



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

def diff
  @diff
end

#failure_msgObject (readonly)

Returns the value of attribute failure_msg.



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

def failure_msg
  @failure_msg
end

#failure_typeObject

Returns the value of attribute failure_type.



932
933
934
# File 'lib/mesa_test.rb', line 932

def failure_type
  @failure_type
end

#final_modelObject (readonly)

Returns the value of attribute final_model.



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

def final_model
  @final_model
end

#mesaObject (readonly)

Returns the value of attribute mesa.



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

def mesa
  @mesa
end

#mesa_dirObject (readonly)

Returns the value of attribute mesa_dir.



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

def mesa_dir
  @mesa_dir
end

#mesa_versionObject (readonly)

Returns the value of attribute mesa_version.



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

def mesa_version
  @mesa_version
end

#modObject (readonly)

Returns the value of attribute mod.



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

def mod
  @mod
end

#outcomeObject

Returns the value of attribute outcome.



932
933
934
# File 'lib/mesa_test.rb', line 932

def outcome
  @outcome
end

#photoObject (readonly)

Returns the value of attribute photo.



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

def photo
  @photo
end

#retriesObject (readonly)

Returns the value of attribute retries.



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

def retries
  @retries
end

#runtime_minutesObject (readonly)

Returns the value of attribute runtime_minutes.



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

def runtime_minutes
  @runtime_minutes
end

#runtime_secondsObject (readonly)

Returns the value of attribute runtime_seconds.



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

def runtime_seconds
  @runtime_seconds
end

#shellObject (readonly)

Returns the value of attribute shell.



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

def shell
  @shell
end

#stepsObject (readonly)

Returns the value of attribute steps.



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

def steps
  @steps
end

#success_msgObject (readonly)

Returns the value of attribute success_msg.



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

def success_msg
  @success_msg
end

#success_stringObject (readonly)

Returns the value of attribute success_string.



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

def success_string
  @success_string
end

#success_typeObject

Returns the value of attribute success_type.



932
933
934
# File 'lib/mesa_test.rb', line 932

def success_type
  @success_type
end

#summary_textObject (readonly)

Returns the value of attribute summary_text.



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

def summary_text
  @summary_text
end

#test_nameObject (readonly)

Returns the value of attribute test_name.



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

def test_name
  @test_name
end

#test_omp_num_threadsObject (readonly)

Returns the value of attribute test_omp_num_threads.



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

def test_omp_num_threads
  @test_omp_num_threads
end

Class Method Details

.modulesObject



935
936
937
# File 'lib/mesa_test.rb', line 935

def self.modules
  %i[star binary]
end

Instance Method Details

#add_datum(datum_name, datum_type) ⇒ Object



1030
1031
1032
1033
1034
1035
1036
1037
# File 'lib/mesa_test.rb', line 1030

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



1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
# File 'lib/mesa_test.rb', line 1044

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



1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
# File 'lib/mesa_test.rb', line 1085

def do_one
  @test_omp_num_threads = omp_num_threads
  if mesa.using_sdk
    version_bin = File.join(ENV['MESASDK_ROOT'], 'bin', 'mesasdk_version.sh')
    # can't use bash_execute because the return value of bash_execute is the
    # exit status of the commmand (true or false), whereas backticks give the
    # output (the version string) as the output
    @compiler_version = `bash -c #{version_bin}`.strip
    shell.say("Using version #{@compiler_version} of the SDK.", :blue)
  end
  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



1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
# File 'lib/mesa_test.rb', line 1134

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
  @diff = data['diff'] || @diff
  @summary_text = data['summary_text'] || @summary_text
  @compiler = data['compiler'] || @compiler

  @compiler_version = data['compiler_version'] || @compiler_version

  # 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



1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
# File 'lib/mesa_test.rb', line 1169

def load_summary_data
  begin
    out_data = parse_out
    @summary_text = get_summary_text
  rescue Errno::ENOENT
    shell.say "\nError loading data from #{out_file}. No summary data "\
              'loaded. Proceeding anyway.', :red
  else
    @runtime_minutes = out_data[:runtime_minutes]
    @retries = out_data[:retries]
    @backups = out_data[:backups]
    @steps = out_data[:steps]
  end
end

#log_resultsObject



1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
# File 'lib/mesa_test.rb', line 1105

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,
    'diff' => diff,
    'summary_text' => summary_text
  }
  if compiler == 'SDK'
    res['compiler'] = 'SDK'
    res['compiler_version'] = compiler_version
  end
  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



1039
1040
1041
# File 'lib/mesa_test.rb', line 1039

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

#parse_outObject



1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
# File 'lib/mesa_test.rb', line 1184

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)


1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
# File 'lib/mesa_test.rb', line 1011

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



1026
1027
1028
# File 'lib/mesa_test.rb', line 1026

def test_case_dir
  File.join(test_suite_dir, test_name)
end

#test_suite_dirObject



1022
1023
1024
# File 'lib/mesa_test.rb', line 1022

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