4 This file is part of the AVR-Crypto-Lib.
5 Copyright (C) 2008, 2009 Daniel Otte (daniel.otte@rub.de)
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
32 $sp.print("echo off \r")
33 print("DBG i: " + "echo off \r"+"\n") if $debug
34 # line = $sp.readlines()
38 $sp.print("shavs_set #{$algo_select}\r")
39 print("DBG i: " + "shavs_set #{$algo_select} \r"+"\n") # if $debug
40 # line = $sp.readlines()
44 $sp.print("shavs_test1 \r")
45 print("DBG i: " + "shavs_test1 \r"+"\n") if $debug
46 # line = $sp.readlines()
54 line = "" if line==nil
55 puts("DBG got: "+line) if $debug && line!=""
56 end while not /[\s]*MD[\s]*=.*/.match(line)
60 def send_md(md_string)
62 for i in 0..md_string.length-1
63 $sp.print(md_string[i].chr)
64 # print("DBG s: "+ md_string[i].chr) if $debug
71 def run_test(filename)
74 if not File.exist?(filename)
75 puts("ERROR file "+filename+" does not exist!")
78 file = File.new(filename, "r");
83 end while not (file.eof or (/[\s]*Len[\s]*=.*/.match(lb)))
84 puts("DBG sending: "+lb) if $debug
90 end while not (file.eof or (/[\s]*Msg[\s]*=.*/.match(lb)))
92 puts("DBG sending: "+lb) if $debug
97 end while not /[\s]*MD[\s]*=.*/.match(lb)
98 a = (/[\s]*MD[\s]*=[\s]*([0-9a-fA-F]*).*/.match(lb))[1];
99 b = (/[\s]*MD[\s]*=[\s]*([0-9a-fA-F]*).*/.match(avr_md))[1];
102 printf("\n%4d (%4d): ", line, (line-1)*$linewidth) if (pos%$linewidth==0 and $linewidth!=0)
103 line += 1 if (pos%$linewidth==0 and $linewidth!=0)
105 #putc((a==b)?'*':'!')
110 # printf("\nshould: %s\ngot: %s\n",lb,avr_md)
120 Usage: ruby #{$0} port bps nbits stopb algo_select testfile ...
125 puts("\nPort: "+ARGV[0]+ "@"+ARGV[1]+" "+ARGV[2]+"N"+ARGV[3]+"\n");
126 puts("serial port interface version: " + SerialPort::VERSION);
128 $params = { "baud" => ARGV[1].to_i,
129 "data_bits" => ARGV[2].to_i,
130 "stop_bits" => ARGV[3].to_i,
131 "parity" => SerialPort::NONE }
132 $sp = SerialPort.new(ARGV[0], $params)
133 #$sp = SerialPort.new(ARGV[0], ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE);
135 $sp.read_timeout=1000; # 5 minutes
136 $sp.flow_control = SerialPort::SOFT
137 $algo_select = ARGV[4]
143 for i in (5..(ARGV.size-1))
144 nerrors = run_test(ARGV[i])
148 puts("\n[errors: "+ nerrors.to_s() +"]")