Class: Mesa
- Inherits:
-
Object
- Object
- Mesa
- Defined in:
- lib/mesa_test.rb
Instance Attribute Summary collapse
-
#github_protocol ⇒ Object
readonly
Returns the value of attribute github_protocol.
-
#mesa_dir ⇒ Object
readonly
Returns the value of attribute mesa_dir.
-
#mirror_dir ⇒ Object
readonly
Returns the value of attribute mirror_dir.
-
#names_to_numbers ⇒ Object
readonly
Returns the value of attribute names_to_numbers.
-
#shell ⇒ Object
readonly
Returns the value of attribute shell.
-
#test_case_names ⇒ Object
readonly
Returns the value of attribute test_case_names.
-
#test_cases ⇒ Object
readonly
Returns the value of attribute test_cases.
Class Method Summary collapse
Instance Method Summary collapse
-
#build_log_64 ⇒ Object
base 64-encoded contents of build.log.
-
#check_installation ⇒ Object
throw an error unless it seems like it’s properly compiled.
-
#check_mod(mod) ⇒ Object
TEST SUITE METHODS.
- #checkout(new_sha: 'HEAD') ⇒ Object
- #clean ⇒ Object
-
#compiler_hash ⇒ Object
sourced from $MESA_DIR/testhub.yml, which should be created after installation.
- #downloaded? ⇒ Boolean
- #each_test_run(mod: :all) ⇒ Object
-
#find_test_case(test_case_name: nil, mod: :all) ⇒ Object
can accept a number (in string form) as a name for indexed access.
- #git_sha ⇒ Object
-
#initialize(mesa_dir: , mirror_dir: nil, github_protocol: :ssh) ⇒ Mesa
constructor
A new instance of Mesa.
- #install ⇒ Object
- #install_attempted? ⇒ Boolean
- #installed? ⇒ Boolean
-
#load_test_source_data(mod: :all) ⇒ Object
load data from the ‘do1_test_source` file that gets used in a lot of testing.
- #remove ⇒ Object
- #sha ⇒ Object
- #test_case_count(mod: :all) ⇒ Object
- #test_suite_dir(mod: nil) ⇒ Object
- #update_mirror ⇒ Object
-
#with_mesa_dir ⇒ Object
change MESA_DIR for the execution of the block and then revert to the original value.
Constructor Details
#initialize(mesa_dir: , mirror_dir: nil, github_protocol: :ssh) ⇒ Mesa
Returns a new instance of Mesa.
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
# File 'lib/mesa_test.rb', line 620 def initialize(mesa_dir: ENV['MESA_DIR'], mirror_dir: nil, github_protocol: :ssh) # absolute_path ensures that it doesn't matter where commands are executed # from @mesa_dir = File.absolute_path(mesa_dir) @mirror_dir = File.absolute_path(mirror_dir) # don't worry about validity of github protocol until it is needed in a # checkout. This way you can have garbage in there if you never really need # it. @github_protocol = if github_protocol.respond_to? :to_sym github_protocol.to_sym else github_protocol end # these get populated by calling #load_test_data @test_cases = {} @test_case_names = {} @names_to_numbers = {} # way to output colored text @shell = Thor::Shell::Color.new end |
Instance Attribute Details
#github_protocol ⇒ Object (readonly)
Returns the value of attribute github_protocol.
609 610 611 |
# File 'lib/mesa_test.rb', line 609 def github_protocol @github_protocol end |
#mesa_dir ⇒ Object (readonly)
Returns the value of attribute mesa_dir.
609 610 611 |
# File 'lib/mesa_test.rb', line 609 def mesa_dir @mesa_dir end |
#mirror_dir ⇒ Object (readonly)
Returns the value of attribute mirror_dir.
609 610 611 |
# File 'lib/mesa_test.rb', line 609 def mirror_dir @mirror_dir end |
#names_to_numbers ⇒ Object (readonly)
Returns the value of attribute names_to_numbers.
609 610 611 |
# File 'lib/mesa_test.rb', line 609 def names_to_numbers @names_to_numbers end |
#shell ⇒ Object (readonly)
Returns the value of attribute shell.
609 610 611 |
# File 'lib/mesa_test.rb', line 609 def shell @shell end |
#test_case_names ⇒ Object (readonly)
Returns the value of attribute test_case_names.
609 610 611 |
# File 'lib/mesa_test.rb', line 609 def test_case_names @test_case_names end |
#test_cases ⇒ Object (readonly)
Returns the value of attribute test_cases.
609 610 611 |
# File 'lib/mesa_test.rb', line 609 def test_cases @test_cases end |
Class Method Details
.checkout(sha: nil, work_dir: nil, mirror_dir: nil, github_protocol: :ssh) ⇒ Object
612 613 614 615 616 617 618 |
# File 'lib/mesa_test.rb', line 612 def self.checkout(sha: nil, work_dir: nil, mirror_dir: nil, github_protocol: :ssh) m = Mesa.new(mesa_dir: work_dir, mirror_dir: mirror_dir, github_protocol: github_protocol) m.checkout(new_sha: sha) m end |
Instance Method Details
#build_log_64 ⇒ Object
base 64-encoded contents of build.log
788 789 790 791 792 793 |
# File 'lib/mesa_test.rb', line 788 def build_log_64 build_log = File.join(mesa_dir, 'build.log') return '' unless File.exist?(build_log) b64_file(build_log) end |
#check_installation ⇒ Object
throw an error unless it seems like it’s properly compiled
780 781 782 783 784 785 |
# File 'lib/mesa_test.rb', line 780 def check_installation return if installed? raise MesaDirError, 'Installation check failed (build.log doesn\'t '\ 'show a successful installation).' end |
#check_mod(mod) ⇒ Object
TEST SUITE METHODS
814 815 816 817 818 819 |
# File 'lib/mesa_test.rb', line 814 def check_mod(mod) return if MesaTestCase.modules.include? mod raise TestCaseDirError, "Invalid module: #{mod}. Must be one of: " + MesaTestCase.modules.join(', ') end |
#checkout(new_sha: 'HEAD') ⇒ Object
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 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 |
# File 'lib/mesa_test.rb', line 645 def checkout(new_sha: 'HEAD') # before anything confirm that git-lfs has been installed shell.say "\nEnsuring that git-lfs is installed... ", :blue command = 'git lfs help >> /dev/null 2>&1' if bash_execute(command) shell.say "yes", :green else shell.say "no", :red raise(GitHubError, "The command #{command} returned with an error "\ 'status, indicating that git-lfs is not installed. '\ 'Make sure it is installed and try again.') end # set up mirror if it doesn't exist unless dir_or_symlink_exists?(mirror_dir) shell.say "\nCreating initial mirror at #{mirror_dir}. "\ 'This might take awhile...', :blue FileUtils.mkdir_p mirror_dir case github_protocol when :ssh command = "git clone --mirror #{GITHUB_SSH} #{mirror_dir}" shell.say command # fail loudly if this doesn't work unless bash_execute(command) # nuke the mirror directory since it is probably bogus (make this # code fire off the next time checkout is done) shell.say "Failed. Removing the [potentially corrupted] mirror.", :red command = "rm -rf #{mirror_dir}" shell.say command bash_execute(command) raise(GitHubError, 'Error while executing the following command:'\ "#{command}. Perhaps you haven't set up "\ 'ssh keys with your GitHub account?') end when :https command = "git clone --mirror #{GITHUB_HTTPS} #{mirror_dir}" shell.say command # fail loudly if this doesn't work unless bash_execute(command) # nuke the mirror directory since it is probably bogus (make this # code fire off the next time checkout is done) shell.say "Failed. Removing the [potentially corrupted] mirror.", :red command = "rm -rf #{mirror_dir}" shell.say command bash_execute(command) raise(GitHubError, 'Error while executing the following command: '\ "#{command}. Perhaps you need to configure "\ 'global GitHub account settings for https '\ 'authentication to work properly?') end else raise(GitHubError, "Invalid GitHub protocol: \"#{github_protocol}\"") end end # ensure "work" directory is removed from worktree remove update_mirror # create "work" directory with proper commit shell.say "\nSetting up worktree repo...", :blue FileUtils.mkdir_p mesa_dir command = "git -C #{mirror_dir} worktree add #{mesa_dir} #{new_sha}" shell.say command return if bash_execute(command) raise(GitHubError, 'Failed while executing the following command: '\ "\"#{command}\".") end |
#clean ⇒ Object
753 754 755 756 757 758 759 760 761 762 763 |
# File 'lib/mesa_test.rb', line 753 def clean with_mesa_dir do visit_and_check mesa_dir, MesaDirError, 'E\countered a problem in ' \ "running `clean` in #{mesa_dir}." do shell.say('MESA_DIR = ' + ENV['MESA_DIR']) shell.say './clean' bash_execute('./clean') end end self end |
#compiler_hash ⇒ Object
sourced from $MESA_DIR/testhub.yml, which should be created after installation
797 798 799 800 801 802 803 804 805 806 807 808 809 810 |
# File 'lib/mesa_test.rb', line 797 def compiler_hash data_file = File.join(mesa_dir, 'testhub.yml') res = { compiler: 'Unknown', sdk_version: 'Unknown', math_backend: 'Unknown' } if File.exist? data_file res = res.merge(YAML.safe_load(File.read(data_file)) || {}) # currently version_number is reported, but we don't need that in Git land res.delete('version_number') # returns the value, not the updated hash res end end |
#downloaded? ⇒ Boolean
889 890 891 |
# File 'lib/mesa_test.rb', line 889 def downloaded? check_mesa_dir end |
#each_test_run(mod: :all) ⇒ Object
875 876 877 878 879 880 881 882 883 884 885 886 887 |
# File 'lib/mesa_test.rb', line 875 def each_test_run(mod: :all) check_installation if mod == :all MesaTestCase.modules.each do |this_mod| each_test_run(mod: this_mod) end else visit_dir(test_suite_dir(mod: mod)) do bash_execute('./each_test_run') end end end |
#find_test_case(test_case_name: nil, mod: :all) ⇒ Object
can accept a number (in string form) as a name for indexed access
867 868 869 870 871 872 873 |
# File 'lib/mesa_test.rb', line 867 def find_test_case(test_case_name: nil, mod: :all) if /\A[0-9]+\z/ =~ test_case_name find_test_case_by_number(test_number: test_case_name.to_i, mod: mod) else find_test_case_by_name(test_case_name: test_case_name, mod: mod) end end |
#git_sha ⇒ Object
745 746 747 |
# File 'lib/mesa_test.rb', line 745 def git_sha bashticks("git -C #{mesa_dir} rev-parse HEAD") end |
#install ⇒ Object
765 766 767 768 769 770 771 772 773 774 775 776 777 |
# File 'lib/mesa_test.rb', line 765 def install with_mesa_dir do visit_and_check mesa_dir, MesaDirError, 'Encountered a problem in ' \ "running `install` in #{mesa_dir}." do shell.say('MESA_DIR = ' + ENV['MESA_DIR']) shell.say './install' bash_execute('./install') end end # this should never happen if visit_and_check works properly. check_installation self end |
#install_attempted? ⇒ Boolean
902 903 904 |
# File 'lib/mesa_test.rb', line 902 def install_attempted? File.exist? File.join(mesa_dir, 'testhub.yml') end |
#installed? ⇒ Boolean
893 894 895 896 897 898 899 900 |
# File 'lib/mesa_test.rb', line 893 def installed? # assume build log reflects installation status; does not account for # mucking with modules after the fact build_log = File.join(mesa_dir, 'build.log') downloaded? && File.exist?(build_log) && File.read(build_log).include?( 'MESA installation was successful' ) end |
#load_test_source_data(mod: :all) ⇒ Object
load data from the ‘do1_test_source` file that gets used in a lot of testing
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 |
# File 'lib/mesa_test.rb', line 828 def load_test_source_data(mod: :all) # allow for brainless loading of all module data if mod == :all MesaTestCase.modules.each do |this_mod| load_test_source_data(mod: this_mod) end else check_mod mod # convert output of +list_tests+ to a dictionary that maps # names to numbers since +each_test_run+ only knows about numbers @names_to_numbers[mod] = {} @test_case_names[mod] = [] @test_cases[mod] = {} visit_dir(test_suite_dir(mod: mod), quiet: true) do bashticks('./list_tests').split("\n").each do |line| num, tc_name = line.strip.split @names_to_numbers[mod][tc_name.strip] = num.to_i @test_case_names[mod] << tc_name.strip begin @test_cases[mod][tc_name.strip] = MesaTestCase.new( test: tc_name.strip, mod: mod, position: num.to_i, mesa: self ) rescue TestCaseDirError shell.say "No such test case #{tc_name.strip}. Skipping loading it.", :red end end end end end |
#remove ⇒ Object
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 |
# File 'lib/mesa_test.rb', line 729 def remove return unless File.exist? mesa_dir shell.say "\nRemoving work directory from worktree (clearing old data)...", :blue command = "git -C #{mirror_dir} worktree remove --force #{mesa_dir}" shell.say command return if bash_execute(command) shell.say "Failed. Simply trying to remove the directory.", :red command = "rm -rf #{mesa_dir}" shell.say command # fail loudly (the "true" tells bash_execute to raise an exception if # the command fails) bash_execute(command, true) end |
#sha ⇒ Object
749 750 751 |
# File 'lib/mesa_test.rb', line 749 def sha git_sha end |
#test_case_count(mod: :all) ⇒ Object
862 863 864 |
# File 'lib/mesa_test.rb', line 862 def test_case_count(mod: :all) all_names_ordered(mod: mod).count end |
#test_suite_dir(mod: nil) ⇒ Object
821 822 823 824 |
# File 'lib/mesa_test.rb', line 821 def test_suite_dir(mod: nil) check_mod mod File.join(mesa_dir, mod.to_s, 'test_suite') end |
#update_mirror ⇒ Object
718 719 720 721 722 723 724 725 726 727 |
# File 'lib/mesa_test.rb', line 718 def update_mirror shell.say "\nFetching MESA history...", :blue command = "git -C #{mirror_dir} fetch origin --prune" shell.say command # fail loudly return if bash_execute(command) raise(GitHubError, 'Failed while executing the following command: '\ "\"#{command}\".") end |
#with_mesa_dir ⇒ Object
change MESA_DIR for the execution of the block and then revert to the original value
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 |
# File 'lib/mesa_test.rb', line 908 def with_mesa_dir # change MESA_DIR, holding on to old value orig_mesa_dir = ENV['MESA_DIR'] ENV['MESA_DIR'] = mesa_dir shell.say "Temporarily changed MESA_DIR to #{ENV['MESA_DIR']}.", :blue # do the stuff begin yield # make sure we undo MESA_DIR change ensure ENV['MESA_DIR'] = orig_mesa_dir shell.say "Changed MESA_DIR back to #{ENV['MESA_DIR']}.", :blue end end |