X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=host%2Fshavs_test.rb;h=cba4dd4617fc4c05917c4ea1f4d12c45047a67c1;hb=83398013d7fefe3600b771be65317a330a140ffb;hp=225c38133b0907b8723582865490f87885c18f1d;hpb=600e82c981df8a6e446c6469e7e6be627ec027de;p=avr-crypto-lib.git diff --git a/host/shavs_test.rb b/host/shavs_test.rb index 225c381..cba4dd4 100644 --- a/host/shavs_test.rb +++ b/host/shavs_test.rb @@ -1,8 +1,8 @@ -#!/usr/bin/ruby +#!/usr/bin/ruby # shavs_test.rb =begin This file is part of the AVR-Crypto-Lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + Copyright (C) 2008, 2009 Daniel Otte (daniel.otte@rub.de) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,7 +18,8 @@ along with this program. If not, see . =end -$debug = false +$debug = true; +$debug = false; require 'rubygems' require 'serialport' @@ -49,7 +50,7 @@ def get_md line = "" if line==nil puts("DBG g: "+line) if $debug end while not /[\s]*MD[\s]*=.*/.match(line) - return line + return line end def send_md(md_string) @@ -57,13 +58,13 @@ def send_md(md_string) $sp.print(md_string[i].chr) # print("DBG s: "+ md_string[i].chr) if $debug if(i%20==19) -# sleep(0.1) - end + sleep(0.1) + 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!") @@ -71,6 +72,7 @@ def run_test(filename) pos = 0 file = File.new(filename, "r"); until file.eof + sleep(0.5) begin lb=file.gets() end while not (file.eof or (/[\s]*Len[\s]*=.*/.match(lb))) @@ -92,18 +94,19 @@ def run_test(filename) b = (/[\s]*MD[\s]*=[\s]*([0-9a-fA-F]*).*/.match(avr_md))[1]; a.upcase! b.upcase! - printf("\n%4d: ", line) if (pos%$linewidth==0 and $linewidth!=0) + 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('!') - 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 @@ -116,9 +119,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); @@ -130,12 +133,13 @@ $algo_select = ARGV[4] init_system() +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");