mips_tester 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +3 -0
- data/Gemfile.lock +24 -0
- data/LICENSE +20 -0
- data/README.md +32 -0
- data/Rakefile +18 -0
- data/lib/mips_tester.rb +97 -0
- data/mips_tester.gemspec +22 -0
- data/spec/fixtures/empty.asm +0 -0
- data/spec/mips_spec.rb +16 -0
- data/spec/spec_helper.rb +8 -0
- metadata +79 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mips_tester (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.2)
|
10
|
+
rspec (2.5.0)
|
11
|
+
rspec-core (~> 2.5.0)
|
12
|
+
rspec-expectations (~> 2.5.0)
|
13
|
+
rspec-mocks (~> 2.5.0)
|
14
|
+
rspec-core (2.5.1)
|
15
|
+
rspec-expectations (2.5.0)
|
16
|
+
diff-lcs (~> 1.1.2)
|
17
|
+
rspec-mocks (2.5.0)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
mips_tester!
|
24
|
+
rspec (> 2.0)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Federico Ravasio
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# MIPS Tester
|
2
|
+
MIPS Tester is a simple class that provides the ability to mass test MIPS assemblies.
|
3
|
+
It relies on MARS (it's ugly I know, but SPIM's cli doesn't work with automated inputs).
|
4
|
+
|
5
|
+
## Installation & Prerequisites
|
6
|
+
|
7
|
+
* Install MIPS Tester:
|
8
|
+
|
9
|
+
$> gem install mips_tester
|
10
|
+
|
11
|
+
* Install the Java Runtime
|
12
|
+
|
13
|
+
* Download [MARS](http://courses.missouristate.edu/KenVollmar/MARS/)
|
14
|
+
Put it somewhere handy, the path will be requested at runtime!
|
15
|
+
|
16
|
+
## Getting Started: Test an empty program
|
17
|
+
|
18
|
+
$> touch test.asm
|
19
|
+
$> irb
|
20
|
+
$irb :001> require 'mips_tester'
|
21
|
+
$irb :002> tester = MIPSTester::MIPS.new :mars_path => "/Applications/MARS_4_1.jar"
|
22
|
+
$irb :003> tester.run "test.asm" do
|
23
|
+
$irb :004> register :s0 => 0x01
|
24
|
+
$irb :005> register :s1 => 0x45
|
25
|
+
$irb :006> expected :s0 => 0x01, :s1 => 0x45
|
26
|
+
$irb :007> verbose! # Optional verbosity!
|
27
|
+
$irb :008> end
|
28
|
+
=> true
|
29
|
+
|
30
|
+
## TO-DOs
|
31
|
+
* Ability to input memory address and expect their results
|
32
|
+
* Better failing messages
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'yard'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
|
7
|
+
task :default => [:spec]
|
8
|
+
|
9
|
+
desc "run spec tests"
|
10
|
+
RSpec::Core::RakeTask.new('spec') do |t|
|
11
|
+
t.pattern = 'spec/*_spec.rb'
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Generate documentation'
|
15
|
+
YARD::Rake::YardocTask.new do |t|
|
16
|
+
t.files = ['lib/*.rb', '-', 'LICENSE']
|
17
|
+
t.options = ['--main', 'README.md', '--no-private']
|
18
|
+
end
|
data/lib/mips_tester.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'tempfile' unless defined? Tempfile
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
module MIPSTester
|
5
|
+
VERSION = "0.0.1"
|
6
|
+
|
7
|
+
class MIPS
|
8
|
+
REGISTER = /^(at|v[01]|a[0-3]|s[0-7]|t\d|[2-9]|1[0-9]|2[0-5])$/
|
9
|
+
ADDRESS = /^(\d{1,10}|0x[\da-f]{1,8}|0b[01]{1,32})$/
|
10
|
+
|
11
|
+
def initialize(params = {})
|
12
|
+
@mars_path = params.delete(:mars_path)
|
13
|
+
raise Exception.new("Provide valid Mars jar!") if not @mars_path or not File.exists? @mars_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def run(file, &block)
|
17
|
+
raise Exception.new("Provide valid file!") if not file or not File.exists? file
|
18
|
+
raise Exception.new("Provide block!") if not block
|
19
|
+
|
20
|
+
reset!
|
21
|
+
|
22
|
+
instance_eval(&block)
|
23
|
+
|
24
|
+
asm = Tempfile.new "temp.asm"
|
25
|
+
asm.write prep_registers(@regs)
|
26
|
+
asm.write File.read(file)
|
27
|
+
asm.close
|
28
|
+
|
29
|
+
cli = `#{["java -jar", @mars_path, @regs.keys.join(" "), "nc dec", asm.path].join(" ")}`
|
30
|
+
|
31
|
+
begin
|
32
|
+
results = parse_results cli
|
33
|
+
|
34
|
+
if @verbose
|
35
|
+
puts "\nExpected:"
|
36
|
+
pp @exp
|
37
|
+
puts "\nResults:"
|
38
|
+
pp results
|
39
|
+
end
|
40
|
+
|
41
|
+
return compare_hashes(@exp, results)
|
42
|
+
rescue Exception => ex
|
43
|
+
puts ex.message
|
44
|
+
return nil
|
45
|
+
ensure
|
46
|
+
asm.unlink
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def verbose!; @verbose = true; end
|
53
|
+
def register hash; @regs.merge! hash; end
|
54
|
+
def expected hash; @exp.merge! hash; end
|
55
|
+
|
56
|
+
def reset!
|
57
|
+
@regs = {}; @exp = {}; @verbose = false
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse_results(results)
|
61
|
+
if results =~ /^Error/
|
62
|
+
throw Exception.new "Error in file\nReason: #{results}\n\n"
|
63
|
+
end
|
64
|
+
|
65
|
+
out = {}
|
66
|
+
|
67
|
+
results.split("\n")[1..-1].map do |reg|
|
68
|
+
g = reg.strip.split("\t")
|
69
|
+
out.merge! g[0].gsub("$", "") => g[1].to_i
|
70
|
+
end
|
71
|
+
|
72
|
+
out
|
73
|
+
end
|
74
|
+
|
75
|
+
def prep_registers(regs)
|
76
|
+
out = ""
|
77
|
+
regs.each_pair do |key, value|
|
78
|
+
if key =~ REGISTER
|
79
|
+
out << "li\t\t$#{key}, #{value}\n"
|
80
|
+
elsif key =~ ADDRESS
|
81
|
+
out << "li\t\t$t0, #{key}\n"
|
82
|
+
out << "li\t\t$t1, 0x#{value.to_s(16)}\n"
|
83
|
+
out << "sb\t\t$t1, ($t0)\n"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
out
|
87
|
+
end
|
88
|
+
|
89
|
+
def compare_hashes(first, second)
|
90
|
+
first.each_pair do |key, value|
|
91
|
+
return false unless second[key.to_s] == value
|
92
|
+
end
|
93
|
+
|
94
|
+
true
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/mips_tester.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'mips_tester'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'mips_tester'
|
7
|
+
s.version = MIPSTester::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Federico Ravasio']
|
10
|
+
s.email = ['ravasio.federico@gmail.com']
|
11
|
+
s.summary = 'Class to test MIPS asm files'
|
12
|
+
s.homepage = 'http://github.com/razielgn/mips_tester'
|
13
|
+
s.description = s.summary + ". It relies on MARS\' cli, so be sure to download its JAR first."
|
14
|
+
|
15
|
+
s.required_ruby_version = '>=1.9.2'
|
16
|
+
|
17
|
+
s.add_development_dependency 'rspec', '>2.0'
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
21
|
+
s.require_paths = ['lib']
|
22
|
+
end
|
File without changes
|
data/spec/mips_spec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MIPSTester::MIPS do
|
4
|
+
let :mips do
|
5
|
+
MIPSTester::MIPS.new :mars_path => "/Applications/MARS_4_1.jar"
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should work properly with an empty file' do
|
9
|
+
mips.run fixture_path("empty.asm") do
|
10
|
+
register :s0 => 0x0C, :s1 => 0x3F
|
11
|
+
register :s2 => 0x34
|
12
|
+
expected :s0 => 0x0C, :s1 => 0x3F
|
13
|
+
expected :s2 => 0x34
|
14
|
+
end.should be_true
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mips_tester
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Federico Ravasio
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-17 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rspec
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "2.0"
|
25
|
+
type: :development
|
26
|
+
version_requirements: *id001
|
27
|
+
description: Class to test MIPS asm files. It relies on MARS' cli, so be sure to download its JAR first.
|
28
|
+
email:
|
29
|
+
- ravasio.federico@gmail.com
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files: []
|
35
|
+
|
36
|
+
files:
|
37
|
+
- Gemfile
|
38
|
+
- Gemfile.lock
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/mips_tester.rb
|
43
|
+
- mips_tester-0.0.1.gem
|
44
|
+
- mips_tester.gemspec
|
45
|
+
- spec/fixtures/empty.asm
|
46
|
+
- spec/mips_spec.rb
|
47
|
+
- spec/spec_helper.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/razielgn/mips_tester
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.9.2
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.6.2
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Class to test MIPS asm files
|
76
|
+
test_files:
|
77
|
+
- spec/fixtures/empty.asm
|
78
|
+
- spec/mips_spec.rb
|
79
|
+
- spec/spec_helper.rb
|