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/>.
29 def readconfigfile(fname, conf)
31 if not File.exists?(fname)
34 file = File.open(fname, "r")
37 next if /[\s]*#/.match(line)
38 if m=/\[[\s]*([^\s]*)[\s]*\]/.match(line)
43 next if not /=/.match(line)
44 m=/[\s]*([^\s]*)[\s]*=[\s]*([^\s]*)/.match(line)
45 conf[section][m[1]] = m[2]
60 $sp.print("shavs_list\r")
63 return algos if /^>$/.match(line)
64 if m = /[\*\ ]([a-z]):[\s]*([a-zA-Z0-9+_-]+)/.match(line)
70 def init_system(algo_select)
71 $sp.print("echo off \r")
72 print("DBG i: " + "echo off \r"+"\n") if $debug
74 $sp.print("shavs_set #{algo_select}\r")
75 print("DBG i: " + "shavs_set #{$algo_select} \r"+"\n") # if $debug
77 $sp.print("shavs_test1 \r")
78 print("DBG i: " + "shavs_test1 \r"+"\n") if $debug
81 end while not m=/buffer_size[\s]*=[\s]*0x([0-9A-Fa-f]*)/.match(line)
82 $buffer_size = m[1].to_i(16)
88 line = "" if line==nil
89 puts("DBG got: "+line) if $debug
90 end while not /[\s]*MD[\s]*=.*/.match(line)
94 def send_md(md_string)
96 for i in 0..md_string.length-1
97 $sp.print(md_string[i].chr)
98 # print("DBG s: "+ md_string[i].chr) if $debug
99 if((i%($buffer_size*2)==0)&&(i!=0))
102 end while not /\./.match(line)
107 def run_test(filename, skip=0)
110 if not File.exist?(filename)
111 puts("ERROR file "+filename+" does not exist!")
115 file = File.new(filename, "r");
119 end while not (file.eof or (/[\s]*Len[\s]*=.*/.match(lb)))
120 len = /[\s]*Len[\s]*=[\s]*([0-9]*)/.match(lb)[1].to_i
121 puts("DBG sending: "+lb) if $debug
131 end while not (file.eof or (m=/[\s]*Msg[\s]*=[\s]*([0-9a-fA-F]*)/.match(lb)))
133 puts("DBG sending: "+lb) if $debug
138 end while not /[\s]*MD[\s]*=.*/.match(lb)
139 a = (/[\s]*MD[\s]*=[\s]*([0-9a-fA-F]*).*/.match(lb))[1];
140 b = (/[\s]*MD[\s]*=[\s]*([0-9a-fA-F]*).*/.match(avr_md))[1];
143 printf("\n%4d (%4d) [%5d]: ", line, (line-1)*$linewidth, len) if (pos%$linewidth==0 and $linewidth!=0)
144 line += 1 if (pos%$linewidth==0 and $linewidth!=0)
146 #putc((a==b)?'*':'!')
160 conf = readconfigfile("/etc/testport.conf", conf)
161 conf = readconfigfile("~/.testport.conf", conf)
162 conf = readconfigfile("testport.conf", conf)
165 puts("serial port interface version: " + SerialPort::VERSION);
167 params = { "baud" => conf["PORT"]["baud"].to_i,
168 "data_bits" => conf["PORT"]["databits"].to_i,
169 "stop_bits" => conf["PORT"]["stopbits"].to_i,
170 "parity" => SerialPort::NONE }
171 params["paraty"] = SerialPort::ODD if conf["PORT"]["paraty"].downcase == "odd"
172 params["paraty"] = SerialPort::EVEN if conf["PORT"]["paraty"].downcase == "even"
173 params["paraty"] = SerialPort::MARK if conf["PORT"]["paraty"].downcase == "mark"
174 params["paraty"] = SerialPort::SPACE if conf["PORT"]["paraty"].downcase == "space"
176 puts("\nPort: "+conf["PORT"]["port"]+"@" +
177 params["baud"].to_s +
179 params["data_bits"].to_s +
180 conf["PORT"]["paraty"][0,1].upcase +
181 params["stop_bits"].to_s +
184 $sp = SerialPort.new(conf["PORT"]["port"], params)
186 $sp.read_timeout=1000; # 5 minutes
187 $sp.flow_control = SerialPort::SOFT
193 algos.sort.each do |algoa|
196 puts("No test-set defined for #{algo} \r\n")
200 logfile=File.open(conf["PORT"]["testlogbase"]+algo+".txt", "a")
201 while conf[algo]["file_#{i}"] != nil
202 puts("Testing #{algo} with #{conf[algo]["file_#{i}"]}")
204 init_system(algoa[1])
205 nerrors=run_test(conf[algo]["file_#{i}"], 0)
208 logfile.puts("[ok] "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")")
210 puts("\n[errors: "+ nerrors.to_s() +"]")
211 logfile.puts("[error] "+nerrors.to_s+" "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")")
221 for i in (5..(ARGV.size-1))
222 nerrors = run_test(ARGV[i])
226 puts("\n[errors: "+ nerrors.to_s() +"]")