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.
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/mesa_test.rb', line 532 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.
521 522 523 |
# File 'lib/mesa_test.rb', line 521 def github_protocol @github_protocol end |
#mesa_dir ⇒ Object (readonly)
Returns the value of attribute mesa_dir.
521 522 523 |
# File 'lib/mesa_test.rb', line 521 def mesa_dir @mesa_dir end |
#mirror_dir ⇒ Object (readonly)
Returns the value of attribute mirror_dir.
521 522 523 |
# File 'lib/mesa_test.rb', line 521 def mirror_dir @mirror_dir end |
#names_to_numbers ⇒ Object (readonly)
Returns the value of attribute names_to_numbers.
521 522 523 |
# File 'lib/mesa_test.rb', line 521 def names_to_numbers @names_to_numbers end |
#shell ⇒ Object (readonly)
Returns the value of attribute shell.
521 522 523 |
# File 'lib/mesa_test.rb', line 521 def shell @shell end |
#test_case_names ⇒ Object (readonly)
Returns the value of attribute test_case_names.
521 522 523 |
# File 'lib/mesa_test.rb', line 521 def test_case_names @test_case_names end |
#test_cases ⇒ Object (readonly)
Returns the value of attribute test_cases.
521 522 523 |
# File 'lib/mesa_test.rb', line 521 def test_cases @test_cases end |
Class Method Details
.checkout(sha: nil, work_dir: nil, mirror_dir: nil, github_protocol: :ssh) ⇒ Object
524 525 526 527 528 529 530 |
# File 'lib/mesa_test.rb', line 524 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
700 701 702 703 704 705 |
# File 'lib/mesa_test.rb', line 700 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
692 693 694 695 696 697 |
# File 'lib/mesa_test.rb', line 692 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
726 727 728 729 730 731 |
# File 'lib/mesa_test.rb', line 726 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
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'lib/mesa_test.rb', line 557 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
665 666 667 668 669 670 671 672 673 674 675 |
# File 'lib/mesa_test.rb', line 665 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
709 710 711 712 713 714 715 716 717 718 719 720 721 722 |
# File 'lib/mesa_test.rb', line 709 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
801 802 803 |
# File 'lib/mesa_test.rb', line 801 def downloaded? check_mesa_dir end |
#each_test_run(mod: :all) ⇒ Object
787 788 789 790 791 792 793 794 795 796 797 798 799 |
# File 'lib/mesa_test.rb', line 787 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
779 780 781 782 783 784 785 |
# File 'lib/mesa_test.rb', line 779 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
657 658 659 |
# File 'lib/mesa_test.rb', line 657 def git_sha bashticks("git -C #{mesa_dir} rev-parse HEAD") end |
#install ⇒ Object
677 678 679 680 681 682 683 684 685 686 687 688 689 |
# File 'lib/mesa_test.rb', line 677 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
814 815 816 |
# File 'lib/mesa_test.rb', line 814 def install_attempted? File.exist? File.join(mesa_dir, 'testhub.yml') end |
#installed? ⇒ Boolean
805 806 807 808 809 810 811 812 |
# File 'lib/mesa_test.rb', line 805 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
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 767 768 769 770 771 772 |
# File 'lib/mesa_test.rb', line 740 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
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'lib/mesa_test.rb', line 641 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
661 662 663 |
# File 'lib/mesa_test.rb', line 661 def sha git_sha end |
#test_case_count(mod: :all) ⇒ Object
774 775 776 |
# File 'lib/mesa_test.rb', line 774 def test_case_count(mod: :all) all_names_ordered(mod: mod).count end |
#test_suite_dir(mod: nil) ⇒ Object
733 734 735 736 |
# File 'lib/mesa_test.rb', line 733 def test_suite_dir(mod: nil) check_mod mod File.join(mesa_dir, mod.to_s, 'test_suite') end |
#update_mirror ⇒ Object
630 631 632 633 634 635 636 637 638 639 |
# File 'lib/mesa_test.rb', line 630 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
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 |
# File 'lib/mesa_test.rb', line 820 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 |