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)
72 $sp.print("echo off \r")
73 print("DBG i: " + "echo off \r"+"\n") if $debug
74 # line = $sp.readlines()
78 $sp.print("shavs_set #{algo_select}\r")
79 print("DBG i: " + "shavs_set #{$algo_select} \r"+"\n") # if $debug
80 # line = $sp.readlines()
84 $sp.print("shavs_test1 \r")
85 print("DBG i: " + "shavs_test1 \r"+"\n") if $debug
88 end while not m=/buffer_size[\s]*=[\s]*0x([0-9A-Fa-f]*)/.match(line)
89 $buffer_size = m[1].to_i(16)
90 # line = $sp.readlines()
98 line = "" if line==nil
99 puts("DBG got: "+line) if $debug
100 end while not /[\s]*MD[\s]*=.*/.match(line)
104 def send_md(md_string)
105 for i in 0..md_string.length-1
106 $sp.print(md_string[i].chr)
107 # print("DBG s: "+ md_string[i].chr) if $debug
108 if(i%$buffer_size==$buffer_size-1)
111 end while not /\./.match(line)
116 def run_test(filename)
119 if not File.exist?(filename)
120 puts("ERROR file "+filename+" does not exist!")
124 file = File.new(filename, "r");
129 end while not (file.eof or (/[\s]*Len[\s]*=.*/.match(lb)))
130 puts("DBG sending: "+lb) if $debug
136 end while not (file.eof or (/[\s]*Msg[\s]*=.*/.match(lb)))
138 puts("DBG sending: "+lb) if $debug
143 end while not /[\s]*MD[\s]*=.*/.match(lb)
144 a = (/[\s]*MD[\s]*=[\s]*([0-9a-fA-F]*).*/.match(lb))[1];
145 b = (/[\s]*MD[\s]*=[\s]*([0-9a-fA-F]*).*/.match(avr_md))[1];
148 printf("\n%4d (%4d): ", line, (line-1)*$linewidth) if (pos%$linewidth==0 and $linewidth!=0)
149 line += 1 if (pos%$linewidth==0 and $linewidth!=0)
151 #putc((a==b)?'*':'!')
156 printf("\nshould: %s\ngot: %s\n",lb,avr_md)
165 conf = readconfigfile("/etc/testport.conf", conf)
166 conf = readconfigfile("~/.testport.conf", conf)
167 conf = readconfigfile("testport.conf", conf)
170 puts("serial port interface version: " + SerialPort::VERSION);
172 params = { "baud" => conf["PORT"]["baud"].to_i,
173 "data_bits" => conf["PORT"]["databits"].to_i,
174 "stop_bits" => conf["PORT"]["stopbits"].to_i,
175 "parity" => SerialPort::NONE }
176 params["paraty"] = SerialPort::ODD if conf["PORT"]["paraty"].downcase == "odd"
177 params["paraty"] = SerialPort::EVEN if conf["PORT"]["paraty"].downcase == "even"
178 params["paraty"] = SerialPort::MARK if conf["PORT"]["paraty"].downcase == "mark"
179 params["paraty"] = SerialPort::SPACE if conf["PORT"]["paraty"].downcase == "space"
181 puts("\nPort: "+conf["PORT"]["port"]+"@" +
182 params["baud"].to_s +
184 params["data_bits"].to_s +
185 conf["PORT"]["paraty"][0,1].upcase +
186 params["stop_bits"].to_s +
189 $sp = SerialPort.new(conf["PORT"]["port"], params)
191 $sp.read_timeout=1000; # 5 minutes
192 $sp.flow_control = SerialPort::SOFT
193 #$algo_select = ARGV[4]
200 algos.each_key do |algo|
202 puts("No test-set defined for #{algo} \r\n")
206 logfile=File.open(conf["PORT"]["testlogbase"]+algo+".txt", "a")
207 while conf[algo]["file_#{i}"] != nil
208 puts("Testing #{algo} with #{conf[algo]["file_#{i}"]}")
210 init_system(algos[algo])
211 nerrors=run_test(conf[algo]["file_#{i}"])
214 logfile.puts("[ok] "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")")
216 puts("\n[errors: "+ nerrors.to_s() +"]")
217 logfile.puts("[error] "+nerrors.to_s+" "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")")
227 for i in (5..(ARGV.size-1))
228 nerrors = run_test(ARGV[i])
232 puts("\n[errors: "+ nerrors.to_s() +"]")