X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;ds=sidebyside;f=host%2Fshavs_test2.rb;h=863fb845ca164829f15fe6ed227379aac5927581;hb=bcf30b86c5b63415da79f7cd41e595ae2c510163;hp=f6e4af1d5873c79fbd32f98a3322bc739cfbc089;hpb=42251bae9cc25d0cce904fb46dd40bb051878da4;p=avr-crypto-lib.git diff --git a/host/shavs_test2.rb b/host/shavs_test2.rb index f6e4af1..863fb84 100644 --- a/host/shavs_test2.rb +++ b/host/shavs_test2.rb @@ -25,8 +25,12 @@ require 'serialport' require 'getopt/std' $buffer_size = 0 +$conffile_check = Hash.new +$conffile_check.default = 0 def readconfigfile(fname, conf) + return conf if $conffile_check[fname]==1 + $conffile_check[fname]=1 section = "default" if not File.exists?(fname) return conf @@ -42,7 +46,11 @@ def readconfigfile(fname, conf) end next if not /=/.match(line) m=/[\s]*([^\s]*)[\s]*=[\s]*([^\s]*)/.match(line) - conf[section][m[1]] = m[2] + if m[1]=="include" + Dir.glob(m[2]){ |fn| conf = readconfigfile(fn, conf) } + else + conf[section][m[1]] = m[2] + end end file.close() return conf @@ -68,18 +76,11 @@ def scan_system end def init_system(algo_select) -# sleep 1 $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 + 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 $sp.print("shavs_test1 \r") print("DBG i: " + "shavs_test1 \r"+"\n") if $debug @@ -87,9 +88,6 @@ def init_system(algo_select) line=$sp.gets() end while not m=/buffer_size[\s]*=[\s]*0x([0-9A-Fa-f]*)/.match(line) $buffer_size = m[1].to_i(16) -# line = $sp.readlines() -# print("DBG 0.2: ") -# print(line) end def get_md @@ -102,18 +100,20 @@ def get_md end def send_md(md_string) + $sp.print("Msg = ") 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%$buffer_size==$buffer_size-1) - begin - line=$sp.gets() - end while not /\./.match(line) + sleep(0.01) + if((i%($buffer_size*2)==0)&&(i!=0)) + begin + line=$sp.gets() + end while not /\./.match(line) end end end -def run_test(filename) +def run_test(filename, skip=0) nerrors = 0 line=1 if not File.exist?(filename) @@ -123,20 +123,24 @@ 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))) + len = /[\s]*Len[\s]*=[\s]*([0-9]*)/.match(lb)[1].to_i puts("DBG sending: "+lb) if $debug return if file.eof + if(skip>0) + skip -= 1 + redo + end $sp.print(lb.strip) $sp.print("\r") begin lb=file.gets() - end while not (file.eof or (/[\s]*Msg[\s]*=.*/.match(lb))) + end while not (file.eof or (m=/[\s]*Msg[\s]*=[\s]*([0-9a-fA-F]*)/.match(lb))) return if file.eof puts("DBG sending: "+lb) if $debug - send_md(lb.strip) + send_md(m[1]) avr_md = get_md() begin lb=file.gets() @@ -145,15 +149,16 @@ def run_test(filename) b = (/[\s]*MD[\s]*=[\s]*([0-9a-fA-F]*).*/.match(avr_md))[1]; a.upcase! b.upcase! - printf("\n%4d (%4d): ", line, (line-1)*$linewidth) if (pos%$linewidth==0 and $linewidth!=0) + printf("\n%4d (%4d) [%5d]: ", line, (line-1)*$linewidth, len) if (pos%$linewidth==0 and $linewidth!=0) line += 1 if (pos%$linewidth==0 and $linewidth!=0) - sleep(1) + #sleep(1) #putc((a==b)?'*':'!') if(a==b) putc('*') else putc('!') - printf("\nshould: %s\ngot: %s\n",lb,avr_md) + # printf("<%d>",len) + printf("\nError @%05d: %s \n != %s - ",len, a, b) nerrors += 1 end pos += 1 @@ -161,11 +166,15 @@ def run_test(filename) return nerrors.to_i end +opts = Getopt::Std.getopts("s:f:i:hdca") + conf = Hash.new conf = readconfigfile("/etc/testport.conf", conf) conf = readconfigfile("~/.testport.conf", conf) conf = readconfigfile("testport.conf", conf) -puts conf.inspect +conf = readconfigfile(opts["f"], conf) if opts["f"] + +#puts conf.inspect puts("serial port interface version: " + SerialPort::VERSION); $linewidth = 64 @@ -190,14 +199,25 @@ $sp = SerialPort.new(conf["PORT"]["port"], params) $sp.read_timeout=1000; # 5 minutes $sp.flow_control = SerialPort::SOFT -#$algo_select = ARGV[4] -#irb reset_system() algos=scan_system() -puts algos.inspect +#puts algos.inspect + +if opts["s"] + algos_rev = algos.invert + algo_tasks = Array.new + opts["s"].each_byte{ |x| + if algos_rev[x.chr] + algo_tasks << [algos_rev[x.chr],x.chr] + end + } +else + algo_tasks=algos.sort +end -algos.each_key do |algo| +algo_tasks.each do |algoa| + algo = algoa[0] if conf[algo]==nil puts("No test-set defined for #{algo} \r\n") next @@ -207,8 +227,10 @@ algos.each_key do |algo| while conf[algo]["file_#{i}"] != nil puts("Testing #{algo} with #{conf[algo]["file_#{i}"]}") reset_system() - init_system(algos[algo]) - nerrors=run_test(conf[algo]["file_#{i}"]) + init_system(algoa[1]) + skip=0 + skip=opts["i"].to_i if opts["i"] + nerrors=run_test(conf[algo]["file_#{i}"], skip) if nerrors == 0 puts("\n[ok]") logfile.puts("[ok] "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")")