reusing ssh instance for arm
some speedup , but hoped for more
This commit is contained in:
parent
c8a903cd83
commit
f83f52faa0
@ -5,18 +5,30 @@ require 'net/scp'
|
|||||||
module Mains
|
module Mains
|
||||||
class TestArm < MiniTest::Test
|
class TestArm < MiniTest::Test
|
||||||
|
|
||||||
|
DEBUG = true
|
||||||
|
def self.user
|
||||||
|
ENV["ARM_USER"] || "pi"
|
||||||
|
end
|
||||||
|
def self.port
|
||||||
|
ENV["ARM_PORT"] || 2222
|
||||||
|
end
|
||||||
|
|
||||||
# runnable_methods is called by minitest to determine which tests to run
|
# runnable_methods is called by minitest to determine which tests to run
|
||||||
def self.runnable_methods
|
def self.runnable_methods
|
||||||
all = Dir["test/mains/source/*.rb"]
|
all = Dir["test/mains/source/*_*.rb"]
|
||||||
tests =[]
|
tests =[]
|
||||||
|
host = ENV["ARM_HOST"]
|
||||||
|
return tests unless host
|
||||||
|
ssh = Net::SSH.start(host, user , port: port )
|
||||||
all.each do |file_name|
|
all.each do |file_name|
|
||||||
fullname = file_name.split("/").last.split(".").first
|
fullname = file_name.split("/").last.split(".").first
|
||||||
name , stdout , exit_code = fullname.split("_")
|
name , stdout , exit_code = fullname.split("_")
|
||||||
method_name = "test_#{name}"
|
method_name = "test_#{name}"
|
||||||
tests << method_name
|
|
||||||
input = File.read(file_name)
|
input = File.read(file_name)
|
||||||
|
tests << method_name
|
||||||
self.send(:define_method, method_name ) do
|
self.send(:define_method, method_name ) do
|
||||||
out , code = run_main(input , name)
|
compile( input , name , ssh.scp)
|
||||||
|
out , code = run_ssh(name , ssh)
|
||||||
assert_equal stdout , out , "Wrong stdout #{name}"
|
assert_equal stdout , out , "Wrong stdout #{name}"
|
||||||
assert_equal exit_code , code.to_s , "Wrong exit code #{name}"
|
assert_equal exit_code , code.to_s , "Wrong exit code #{name}"
|
||||||
end
|
end
|
||||||
@ -24,39 +36,27 @@ module Mains
|
|||||||
tests
|
tests
|
||||||
end
|
end
|
||||||
|
|
||||||
DEBUG = true
|
def compile(input , file , scp)
|
||||||
|
|
||||||
def setup
|
|
||||||
Risc.machine.boot
|
Risc.machine.boot
|
||||||
end
|
puts "Compiling test/#{file}.o" if DEBUG
|
||||||
|
|
||||||
def run_main(input , file)
|
|
||||||
Vool::VoolCompiler.ruby_to_binary( "class Space;def main(arg);#{input};end;end" )
|
Vool::VoolCompiler.ruby_to_binary( "class Space;def main(arg);#{input};end;end" )
|
||||||
writer = Elf::ObjectWriter.new(Risc.machine)
|
writer = Elf::ObjectWriter.new(Risc.machine)
|
||||||
writer.save "test/#{file}.o"
|
writer.save "test/#{file}.o"
|
||||||
run_ssh(file)
|
object_file = "/tmp/#{file}.o"
|
||||||
|
puts "Copying test/#{file}.o to #{object_file}" if DEBUG
|
||||||
|
scp.upload! "test/#{file}.o", object_file
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_ssh( file )
|
def run_ssh( file , ssh)
|
||||||
host = ENV["ARM_HOST"]
|
|
||||||
return unless host
|
|
||||||
port = (ENV["ARM_PORT"] || 2222)
|
|
||||||
user = (ENV["ARM_USER"] || "pi")
|
|
||||||
binary_file = "/tmp/#{file}"
|
binary_file = "/tmp/#{file}"
|
||||||
object_file = binary_file + ".o"
|
object_file = binary_file + ".o"
|
||||||
Net::SCP.start(host, user , port: port ) do |scp|
|
puts "Linking #{object_file}" if DEBUG
|
||||||
puts "Copying test/#{file}.o to #{object_file}" if DEBUG
|
stdout , exit_code = ssh_exec!(ssh , "ld -N -o #{binary_file} #{object_file}")
|
||||||
scp.upload! "test/#{file}.o", object_file
|
assert_equal 0 , exit_code , "Linking #{binary_file} failed"
|
||||||
end
|
puts "Running #{binary_file}" if DEBUG
|
||||||
Net::SSH.start(host, user , port: port ) do |ssh|
|
stdout , exit_code = ssh_exec!(ssh , binary_file)
|
||||||
puts "Linking #{object_file}" if DEBUG
|
puts "Result #{stdout} #{exit_code}" if DEBUG
|
||||||
stdout , exit_code = ssh_exec!(ssh , "ld -N -o #{binary_file} #{object_file}")
|
return stdout , exit_code
|
||||||
assert_equal 0 , exit_code , "Linking #{binary_file} failed"
|
|
||||||
puts "Running #{binary_file}" if DEBUG
|
|
||||||
stdout , exit_code = ssh_exec!(ssh , binary_file)
|
|
||||||
puts "Result #{stdout} #{exit_code}" if DEBUG
|
|
||||||
return stdout , exit_code
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def ssh_exec!(ssh, command)
|
def ssh_exec!(ssh, command)
|
||||||
|
Loading…
Reference in New Issue
Block a user