X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;ds=sidebyside;f=host%2Fshavs_test.rb;h=225c38133b0907b8723582865490f87885c18f1d;hb=600e82c981df8a6e446c6469e7e6be627ec027de;hp=3983b502164983a8731de00bd45ab13354dd91fb;hpb=d3db763eeb456ce00849ecf658782f95b9f5634c;p=avr-crypto-lib.git
diff --git a/host/shavs_test.rb b/host/shavs_test.rb
index 3983b50..225c381 100644
--- a/host/shavs_test.rb
+++ b/host/shavs_test.rb
@@ -18,23 +18,26 @@
along with this program. If not, see .
=end
-
-
+$debug = false
+require 'rubygems'
require 'serialport'
def init_system
sleep 1
$sp.print("echo off \r")
+ print("DBG i: " + "echo off \r"+"\n") if $debug
# line = $sp.readlines()
# print("DBG 0.0: ")
# print(line)
# sleep 1
- $sp.print("shavs_set a \r")
+ $sp.print("shavs_set #{$algo_select} \r")
+ print("DBG i: " + "shavs_set #{$algo_select} \r"+"\n") if $debug
# line = $sp.readlines()
# print("DBG 0.1: ")
# print(line)
# sleep 1
$sp.print("shavs_test1 \r")
+ print("DBG i: " + "shavs_test1 \r"+"\n") if $debug
# line = $sp.readlines()
# print("DBG 0.2: ")
# print(line)
@@ -44,12 +47,24 @@ def get_md
begin
line = $sp.gets()
line = "" if line==nil
-# puts("DBG g: "+line)
+ puts("DBG g: "+line) if $debug
end while not /[\s]*MD[\s]*=.*/.match(line)
return line
end
+def send_md(md_string)
+ for i in 0..md_string.length-1
+ $sp.print(md_string[i].chr)
+# print("DBG s: "+ md_string[i].chr) if $debug
+ if(i%20==19)
+# sleep(0.1)
+ end
+ end
+end
+
def run_test(filename)
+ errors = 0
+ line=1
if not File.exist?(filename)
puts("ERROR file "+filename+" does not exist!")
end
@@ -59,7 +74,7 @@ def run_test(filename)
begin
lb=file.gets()
end while not (file.eof or (/[\s]*Len[\s]*=.*/.match(lb)))
-# puts("DBG sending: "+lb);
+ puts("DBG sending: "+lb) if $debug
return if file.eof
$sp.print(lb.strip)
$sp.print("\r")
@@ -67,8 +82,8 @@ def run_test(filename)
lb=file.gets()
end while not (file.eof or (/[\s]*Msg[\s]*=.*/.match(lb)))
return if file.eof
-# puts("DBG sending: "+lb);
- $sp.print(lb.strip)
+ puts("DBG sending: "+lb) if $debug
+ send_md(lb.strip)
avr_md = get_md()
begin
lb=file.gets()
@@ -77,33 +92,53 @@ def run_test(filename)
b = (/[\s]*MD[\s]*=[\s]*([0-9a-fA-F]*).*/.match(avr_md))[1];
a.upcase!
b.upcase!
- puts("") if (pos%$linewidth==0 and $linewidth!=0)
- putc((a==b)?'*':'!')
+ printf("\n%4d: ", line) if (pos%$linewidth==0 and $linewidth!=0)
+ line += 1 if (pos%$linewidth==0 and $linewidth!=0)
+ #putc((a==b)?'*':'!')
+ if(a==b)
+ putc('*')
+ else
+ putc('!')
+ errors += 1;
+ end
pos += 1
end
-
+ return errors
end
-if ARGV.size < 5
+if ARGV.size < 6
STDERR.print < ARGV[1].to_i,
+ "data_bits" => ARGV[2].to_i,
+ "stop_bits" => ARGV[3].to_i,
+ "parity" => SerialPort::NONE }
+$sp = SerialPort.new(ARGV[0], $params)
+#$sp = SerialPort.new(ARGV[0], ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE);
+$sp.read_timeout=1000; # 5 minutes
+$sp.flow_control = SerialPort::SOFT
+$algo_select = ARGV[4]
#irb
init_system()
-for i in (4..(ARGV.size-1))
- run_test(ARGV[i])
- puts("")
+for i in (5..(ARGV.size-1))
+ errors = run_test(ARGV[i])
+ if errors == 0
+ puts("\n[ok]")
+ else
+ puts("\n[errors: "+errors.to_s+"]")
+ end
end
+ $sp.print("EXIT\r");
#exit(0);