X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=host%2Fshavs_test.rb;h=896377b2ea0924045e35699b934eb899ea082c13;hb=c9c11514d91b8c19f77d65ac051b998bd99048b0;hp=4c8589dc902938b5926bfb7fda3e036c5dea5a68;hpb=4f50c75ee5a6cc88bf7ea71957ed509e298e6c25;p=avr-crypto-lib.git diff --git a/host/shavs_test.rb b/host/shavs_test.rb index 4c8589d..896377b 100644 --- a/host/shavs_test.rb +++ b/host/shavs_test.rb @@ -1,4 +1,4 @@ -#!/usr/bin/ruby +#!/usr/bin/ruby # shavs_test.rb =begin This file is part of the AVR-Crypto-Lib. @@ -24,19 +24,23 @@ require 'rubygems' require 'serialport' def init_system - sleep 1 - $sp.print("echo off \r") - print("DBG i: " + "echo off \r"+"\n") if $debug +# sleep 1 + $sp.print("exit\r") + sleep 0.5 + $sp.print("exit\r") + sleep 0.5 + $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 + 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 + sleep 1 $sp.print("shavs_test1 \r") print("DBG i: " + "shavs_test1 \r"+"\n") if $debug # line = $sp.readlines() @@ -48,23 +52,24 @@ def get_md begin line = $sp.gets() line = "" if line==nil - puts("DBG g: "+line) if $debug + puts("DBG got: "+line) if $debug && line!="" end while not /[\s]*MD[\s]*=.*/.match(line) - return line + return line end def send_md(md_string) + sleep(0.15) 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 + if(i%5==4) + sleep(0.15) + end end end def run_test(filename) - errors = 0 + nerrors = 0 line=1 if not File.exist?(filename) puts("ERROR file "+filename+" does not exist!") @@ -96,17 +101,18 @@ def run_test(filename) b.upcase! printf("\n%4d (%4d): ", line, (line-1)*$linewidth) if (pos%$linewidth==0 and $linewidth!=0) line += 1 if (pos%$linewidth==0 and $linewidth!=0) + sleep(1) #putc((a==b)?'*':'!') if(a==b) putc('*') else putc('!') - # printf("\nshould: %s\ngot: %s\n",lb,avr_md) - errors += 1; - end +# printf("\nshould: %s\ngot: %s\n",lb,avr_md) + nerrors += 1 + end pos += 1 end - return errors + return nerrors.to_i end if ARGV.size < 6 @@ -119,9 +125,9 @@ end puts("\nPort: "+ARGV[0]+ "@"+ARGV[1]+" "+ARGV[2]+"N"+ARGV[3]+"\n"); puts("serial port interface version: " + SerialPort::VERSION); $linewidth = 64 -$params = { "baud" => ARGV[1].to_i, - "data_bits" => ARGV[2].to_i, - "stop_bits" => ARGV[3].to_i, +$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); @@ -133,13 +139,13 @@ $algo_select = ARGV[4] init_system() -errors = 0 +nerrors = 0 for i in (5..(ARGV.size-1)) - errors = run_test(ARGV[i]) - if errors == 0 + nerrors = run_test(ARGV[i]) + if nerrors == 0 puts("\n[ok]") else - puts("\n[errors: "+errors.to_s+"]") + puts("\n[errors: "+ nerrors.to_s() +"]") end end $sp.print("EXIT\r");