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.



645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
# File 'lib/mesa_test.rb', line 645

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
  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

#data_namesObject

Returns the value of attribute data_names.



638
639
640
# File 'lib/mesa_test.rb', line 638

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.



638
639
640
# File 'lib/mesa_test.rb', line 638

def data_types=(value)
  @data_types = value
end

#failure_msgObject (readonly)

Returns the value of attribute failure_msg.



635
636
637
# File 'lib/mesa_test.rb', line 635

def failure_msg
  @failure_msg
end

#failure_typeObject

Returns the value of attribute failure_type.



638
639
640
# File 'lib/mesa_test.rb', line 638

def failure_type
  @failure_type
end

#final_modelObject (readonly)

Returns the value of attribute final_model.



635
636
637
# File 'lib/mesa_test.rb', line 635

def final_model
  @final_model
end

#mesaObject (readonly)

Returns the value of attribute mesa.



635
636
637
# File 'lib/mesa_test.rb', line 635

def mesa
  @mesa
end

#mesa_dirObject (readonly)

Returns the value of attribute mesa_dir.



635
636
637
# File 'lib/mesa_test.rb', line 635

def mesa_dir
  @mesa_dir
end

#mesa_versionObject (readonly)

Returns the value of attribute mesa_version.



635
636
637
# File 'lib/mesa_test.rb', line 635

def mesa_version
  @mesa_version
end

#outcomeObject

Returns the value of attribute outcome.



638
639
640
# File 'lib/mesa_test.rb', line 638

def outcome
  @outcome
end

#photoObject (readonly)

Returns the value of attribute photo.



635
636
637
# File 'lib/mesa_test.rb', line 635

def photo
  @photo
end

#runtime_secondsObject (readonly)

Returns the value of attribute runtime_seconds.



635
636
637
# File 'lib/mesa_test.rb', line 635

def runtime_seconds
  @runtime_seconds
end

#shellObject (readonly)

Returns the value of attribute shell.



635
636
637
# File 'lib/mesa_test.rb', line 635

def shell
  @shell
end

#success_msgObject (readonly)

Returns the value of attribute success_msg.



635
636
637
# File 'lib/mesa_test.rb', line 635

def success_msg
  @success_msg
end

#success_stringObject (readonly)

Returns the value of attribute success_string.



635
636
637
# File 'lib/mesa_test.rb', line 635

def success_string
  @success_string
end

#success_typeObject

Returns the value of attribute success_type.



638
639
640
# File 'lib/mesa_test.rb', line 638

def success_type
  @success_type
end

#test_nameObject (readonly)

Returns the value of attribute test_name.



635
636
637
# File 'lib/mesa_test.rb', line 635

def test_name
  @test_name
end

#test_omp_num_threadsObject (readonly)

Returns the value of attribute test_omp_num_threads.



635
636
637
# File 'lib/mesa_test.rb', line 635

def test_omp_num_threads
  @test_omp_num_threads
end

Class Method Details

.modulesObject



641
642
643
# File 'lib/mesa_test.rb', line 641

def self.modules
  i[star binary]
end

Instance Method Details

#add_datum(datum_name, datum_type) ⇒ Object



715
716
717
718
719
720
721
722
# File 'lib/mesa_test.rb', line 715

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



729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
# File 'lib/mesa_test.rb', line 729

def clean
  shell.say("cleaning #{test_name}", color = :blue)
  puts ''
  check_mesa_dir
  check_test_case
  in_dir do
    puts './clean'
    unless system('./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'
    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



769
770
771
772
773
774
775
776
777
778
779
# File 'lib/mesa_test.rb', line 769

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



799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
# File 'lib/mesa_test.rb', line 799

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']
  @mesa_version = data['mesa_version']
  @outcome = data['outcome'].to_sym
  @test_omp_num_threads = data['omp_num_threads']
  @success_type = data['success_type']
  @failure_type = data['failure_type']
  shell.say "Done loading data from #{load_file}.\n", :green
end

#log_resultsObject



781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
# File 'lib/mesa_test.rb', line 781

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,
    '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
  }
  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



724
725
726
# File 'lib/mesa_test.rb', line 724

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

#passed?Boolean

Returns:

  • (Boolean)


696
697
698
699
700
701
702
703
704
705
# File 'lib/mesa_test.rb', line 696

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



711
712
713
# File 'lib/mesa_test.rb', line 711

def test_case_dir
  File.join(test_suite_dir, test_name)
end

#test_suite_dirObject



707
708
709
# File 'lib/mesa_test.rb', line 707

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