X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=host%2Fshavs_test.rb;h=99553ff47bb3e49047188b58b6a5c6a0c83bb6bd;hb=402f8b98e8bd4ca12bbac8fe6ccd07e594015a63;hp=767054339d3605b5acf27da3645d75e9794fbafa;hpb=92725df162cf1ce83c4bd002fdaff69707e5f310;p=avr-crypto-lib.git diff --git a/host/shavs_test.rb b/host/shavs_test.rb index 7670543..99553ff 100644 --- a/host/shavs_test.rb +++ b/host/shavs_test.rb @@ -19,22 +19,25 @@ =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 #{$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) @@ -49,7 +52,19 @@ def get_md 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.015) + end + end +end + def run_test(filename) + errors = 0 + line=1 if not File.exist?(filename) puts("ERROR file "+filename+" does not exist!") end @@ -68,7 +83,7 @@ def run_test(filename) end while not (file.eof or (/[\s]*Msg[\s]*=.*/.match(lb))) return if file.eof puts("DBG sending: "+lb) if $debug - $sp.print(lb.strip) + send_md(lb.strip) avr_md = get_md() begin lb=file.gets() @@ -77,11 +92,19 @@ 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 (%4d): ", line, (line-1)*$linewidth) 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('!') + # printf("\nshould: %s\ngot: %s\n",lb,avr_md) + errors += 1; + end pos += 1 end - + return errors end if ARGV.size < 6 @@ -92,17 +115,29 @@ EOF end puts("\nPort: "+ARGV[0]+ "@"+ARGV[1]+" "+ARGV[2]+"N"+ARGV[3]+"\n"); +puts("serial port interface version: " + SerialPort::VERSION); $linewidth = 64 -$sp = SerialPort.new(ARGV[0], ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE); +$params = { "baud" => 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 (5..(ARGV.size-1)) - run_test(ARGV[i]) - puts("") + errors = run_test(ARGV[i]) + if errors == 0 + puts("\n[ok]") + else + puts("\n[errors: "+errors.to_s+"]") + end end $sp.print("EXIT\r");