adds arm testing of same files
This commit is contained in:
parent
ae976c8fb9
commit
c8a903cd83
@ -1,5 +1,18 @@
|
|||||||
# Method testing
|
# Mains testing
|
||||||
|
|
||||||
Test Whole methods by their output. Using the main method (implicitly)
|
Test methods by their output and exit codes (return, since it is the main).
|
||||||
|
|
||||||
Through Interpreter
|
There are only two tests here, one for interpreter, one for arm.
|
||||||
|
Both run the same tests. The actual ruby code that is run is in the source dir.
|
||||||
|
Test methods are generated, one for each source file.
|
||||||
|
|
||||||
|
File names follow [name,stdout,exitcode] joined by _ pattern. Stdout may be left blank,
|
||||||
|
but exit code must be supplied.
|
||||||
|
|
||||||
|
Obviously the arm tests need an arm platform. This may be defined by ARM_HOST,
|
||||||
|
eg for simulated ARM_HOST=localhost
|
||||||
|
|
||||||
|
Also port and user may be specified with ARM_PORT and ARM_USER , they default to
|
||||||
|
2222 and pi if left blank.
|
||||||
|
SSH keys must be set up so no passwords are required (and the users private key may
|
||||||
|
not be password protected)
|
||||||
|
@ -1,14 +1,4 @@
|
|||||||
require_relative '../helper'
|
require_relative '../helper'
|
||||||
|
|
||||||
module Mains
|
module Mains
|
||||||
class MainsTest < MiniTest::Test
|
|
||||||
include Risc::Ticker
|
|
||||||
def setup;end
|
|
||||||
|
|
||||||
def run_main_check(input , stdout , exit_code)
|
|
||||||
run_main(input)
|
|
||||||
assert_equal stdout , @interpreter.stdout , "Wrong stdout"
|
|
||||||
assert_equal exit_code , get_return.to_s , "Wrong exit code"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
1
test/mains/source/add__4.rb
Normal file
1
test/mains/source/add__4.rb
Normal file
@ -0,0 +1 @@
|
|||||||
|
return 2 +2
|
88
test/mains/test_arm.rb
Normal file
88
test/mains/test_arm.rb
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
require_relative 'helper'
|
||||||
|
require 'net/ssh'
|
||||||
|
require 'net/scp'
|
||||||
|
|
||||||
|
module Mains
|
||||||
|
class TestArm < MiniTest::Test
|
||||||
|
|
||||||
|
# runnable_methods is called by minitest to determine which tests to run
|
||||||
|
def self.runnable_methods
|
||||||
|
all = Dir["test/mains/source/*.rb"]
|
||||||
|
tests =[]
|
||||||
|
all.each do |file_name|
|
||||||
|
fullname = file_name.split("/").last.split(".").first
|
||||||
|
name , stdout , exit_code = fullname.split("_")
|
||||||
|
method_name = "test_#{name}"
|
||||||
|
tests << method_name
|
||||||
|
input = File.read(file_name)
|
||||||
|
self.send(:define_method, method_name ) do
|
||||||
|
out , code = run_main(input , name)
|
||||||
|
assert_equal stdout , out , "Wrong stdout #{name}"
|
||||||
|
assert_equal exit_code , code.to_s , "Wrong exit code #{name}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tests
|
||||||
|
end
|
||||||
|
|
||||||
|
DEBUG = true
|
||||||
|
|
||||||
|
def setup
|
||||||
|
Risc.machine.boot
|
||||||
|
end
|
||||||
|
|
||||||
|
def run_main(input , file)
|
||||||
|
Vool::VoolCompiler.ruby_to_binary( "class Space;def main(arg);#{input};end;end" )
|
||||||
|
writer = Elf::ObjectWriter.new(Risc.machine)
|
||||||
|
writer.save "test/#{file}.o"
|
||||||
|
run_ssh(file)
|
||||||
|
end
|
||||||
|
|
||||||
|
def run_ssh( file )
|
||||||
|
host = ENV["ARM_HOST"]
|
||||||
|
return unless host
|
||||||
|
port = (ENV["ARM_PORT"] || 2222)
|
||||||
|
user = (ENV["ARM_USER"] || "pi")
|
||||||
|
binary_file = "/tmp/#{file}"
|
||||||
|
object_file = binary_file + ".o"
|
||||||
|
Net::SCP.start(host, user , port: port ) do |scp|
|
||||||
|
puts "Copying test/#{file}.o to #{object_file}" if DEBUG
|
||||||
|
scp.upload! "test/#{file}.o", object_file
|
||||||
|
end
|
||||||
|
Net::SSH.start(host, user , port: port ) do |ssh|
|
||||||
|
puts "Linking #{object_file}" if DEBUG
|
||||||
|
stdout , exit_code = ssh_exec!(ssh , "ld -N -o #{binary_file} #{object_file}")
|
||||||
|
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
|
||||||
|
|
||||||
|
def ssh_exec!(ssh, command)
|
||||||
|
stdout_data = ""
|
||||||
|
exit_code = nil
|
||||||
|
ssh.open_channel do |channel|
|
||||||
|
channel.exec(command) do |ch, success|
|
||||||
|
unless success
|
||||||
|
raise "FAILED: couldn't execute command (ssh.channel.exec)"
|
||||||
|
end
|
||||||
|
channel.on_data do |c,data|
|
||||||
|
stdout_data+=data
|
||||||
|
end
|
||||||
|
channel.on_extended_data do |c,type,data|
|
||||||
|
raise "#{ssh} received stderr #{data}"
|
||||||
|
end
|
||||||
|
channel.on_request("exit-status") do |c,data|
|
||||||
|
exit_code = data.read_long
|
||||||
|
end
|
||||||
|
channel.on_request("exit-signal") do |c, data|
|
||||||
|
raise "#{ssh} received signal #{data.read_long}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
ssh.loop
|
||||||
|
[stdout_data, exit_code]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,11 +0,0 @@
|
|||||||
require_relative 'helper'
|
|
||||||
|
|
||||||
module Mains
|
|
||||||
class TestPuts < MainsTest
|
|
||||||
|
|
||||||
def test_ruby_puts
|
|
||||||
run_main_file "puts"
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user