mips_tester 0.1.3 → 0.1.4
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/lib/mips_tester.rb +24 -12
- data/spec/fixtures/memory.asm +3 -0
- data/spec/mips_spec.rb +11 -2
- metadata +4 -2
data/lib/mips_tester.rb
CHANGED
@@ -3,7 +3,7 @@ require 'tempfile' unless defined? Tempfile
|
|
3
3
|
# Main MIPSTester module
|
4
4
|
module MIPSTester
|
5
5
|
# Library version
|
6
|
-
VERSION = "0.1.
|
6
|
+
VERSION = "0.1.4"
|
7
7
|
|
8
8
|
# MIPSFileError Exception, raised when test file is not valid or non-existent
|
9
9
|
class MIPSFileError < Exception; end
|
@@ -70,17 +70,17 @@ module MIPSTester
|
|
70
70
|
|
71
71
|
cli = `#{["java -jar",
|
72
72
|
@mars_path,
|
73
|
-
@
|
74
|
-
@
|
75
|
-
"nc dec",
|
73
|
+
@exp_regs.empty? ? "" : @exp_regs.keys.join(" "),
|
74
|
+
@exp_addresses.empty? ? "" : @exp_addresses.map{|addr| "#{addr[0]}-#{addr[0].to_i 16}"}.join(" "),
|
75
|
+
" nc dec",
|
76
76
|
asm.path].join(" ")}`
|
77
77
|
|
78
78
|
begin
|
79
79
|
results = parse_results cli
|
80
80
|
|
81
|
-
puts "Expected:\n#{@
|
81
|
+
puts "Expected:\n#{@exp_regs.dup.merge @exp_addresses}\nResults:\n#{results}" if @verbose
|
82
82
|
|
83
|
-
return compare_hashes(@
|
83
|
+
return compare_hashes(@exp_regs.dup.merge(@exp_addresses), results)
|
84
84
|
rescue Exception => ex
|
85
85
|
raise MIPSFileError.new ex.message.gsub(asm.path, File.basename(file)).split("\n")[0..1].join("\n")
|
86
86
|
ensure
|
@@ -95,17 +95,29 @@ module MIPSTester
|
|
95
95
|
def set hash
|
96
96
|
hash.each_pair do |key, value|
|
97
97
|
case key.to_s
|
98
|
-
when REGISTER_REGEX then @
|
99
|
-
when ADDRESS_REGEX then @
|
98
|
+
when REGISTER_REGEX then @set_regs.merge! key => value
|
99
|
+
when ADDRESS_REGEX then @set_addresses.merge! key => value
|
100
100
|
else puts "Warning: #{key.inspect} not recognized as register or memory address. Discarded."
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
def expect hash
|
105
|
+
def expect hash
|
106
|
+
hash.each_pair do |key, value|
|
107
|
+
case key.to_s
|
108
|
+
when REGISTER_REGEX then @exp_regs.merge! key => value
|
109
|
+
when ADDRESS_REGEX then @exp_addresses.merge! key => value
|
110
|
+
else puts "Warning: #{key.inspect} not recognized as register or memory address. Discarded."
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
106
114
|
|
107
115
|
def reset!
|
108
|
-
@
|
116
|
+
@set_regs = {}
|
117
|
+
@set_addresses = {}
|
118
|
+
@exp_regs = {}
|
119
|
+
@exp_addresses = {}
|
120
|
+
@verbose = false
|
109
121
|
end
|
110
122
|
|
111
123
|
def parse_results(results)
|
@@ -128,8 +140,8 @@ module MIPSTester
|
|
128
140
|
|
129
141
|
def prep_params
|
130
142
|
out = ""
|
131
|
-
@
|
132
|
-
@
|
143
|
+
@set_regs.each_pair {|key, value| out << "li\t\t$#{key}, #{value}\n" }
|
144
|
+
@set_addresses.each_pair do |key, value|
|
133
145
|
out << "li\t\t$t0, #{key}\n"
|
134
146
|
out << "li\t\t$t1, 0x#{value.to_s(16)}\n"
|
135
147
|
out << "sb\t\t$t1, ($t0)\n"
|
data/spec/mips_spec.rb
CHANGED
@@ -53,8 +53,8 @@ describe MIPS do
|
|
53
53
|
|
54
54
|
it 'should expect given memory address values' do
|
55
55
|
mips.test fixture_path("empty.asm") do
|
56
|
-
set '
|
57
|
-
expect '
|
56
|
+
set '0x10010010' => 45, '0x10010020' => 32, '0x10010030' => 0xFF
|
57
|
+
expect '0x10010010' => 45, '0x10010020' => 32, '0x10010030' => 0xFF
|
58
58
|
end.should be_true
|
59
59
|
end
|
60
60
|
|
@@ -81,4 +81,13 @@ describe MIPS do
|
|
81
81
|
end.should be_true
|
82
82
|
end
|
83
83
|
end
|
84
|
+
|
85
|
+
context 'memory.asm' do
|
86
|
+
it 'should get the value given to s0 in memory address 0x10010060' do
|
87
|
+
mips.test fixture_path("memory.asm") do
|
88
|
+
set :s0 => 78
|
89
|
+
expect "0x10010060" => 78, :s0 => 78
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
84
93
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: mips_tester
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Federico Ravasio
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-19 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- spec/fixtures/add.asm
|
45
45
|
- spec/fixtures/empty.asm
|
46
46
|
- spec/fixtures/invalid_syntax.asm
|
47
|
+
- spec/fixtures/memory.asm
|
47
48
|
- spec/mips_spec.rb
|
48
49
|
- spec/spec_helper.rb
|
49
50
|
homepage: http://github.com/razielgn/mips_tester
|
@@ -77,6 +78,7 @@ test_files:
|
|
77
78
|
- spec/fixtures/add.asm
|
78
79
|
- spec/fixtures/empty.asm
|
79
80
|
- spec/fixtures/invalid_syntax.asm
|
81
|
+
- spec/fixtures/memory.asm
|
80
82
|
- spec/mips_spec.rb
|
81
83
|
- spec/spec_helper.rb
|
82
84
|
has_rdoc:
|