X-Git-Url: https://git.cryptolib.org/?p=avr-crypto-lib.git;a=blobdiff_plain;f=host%2Fshavs_test2.rb;h=058d060bd1c6d1d8c7309bc66e66189bcb123159;hp=ad242f4445b81a671b190666e573a89c51248085;hb=4b5da1dc27a791b5c448274a3db09cd035b33493;hpb=01166b227940a23b4b666d2bda5964bfd2fbc9da diff --git a/host/shavs_test2.rb b/host/shavs_test2.rb index ad242f4..058d060 100644 --- a/host/shavs_test2.rb +++ b/host/shavs_test2.rb @@ -1,8 +1,8 @@ #!/usr/bin/ruby # shavs_test.rb =begin - This file is part of the AVR-Crypto-Lib. - Copyright (C) 2008, 2009 Daniel Otte (daniel.otte@rub.de) + This file is part of the ARM-Crypto-Lib. + Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) 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 @@ -24,9 +24,17 @@ require 'rubygems' require 'serialport' require 'getopt/std' -$buffer_size = 0 +$buffer_size = 0 # set automatically in init_system +$conffile_check = Hash.new +$conffile_check.default = 0 + +################################################################################ +# readconfigfile # +################################################################################ def readconfigfile(fname, conf) + return conf if $conffile_check[fname]==1 + $conffile_check[fname]=1 section = "default" if not File.exists?(fname) return conf @@ -40,14 +48,22 @@ def readconfigfile(fname, conf) conf[m[1]] = Hash.new next end - next if not /=/.match(line) + next if ! /=/.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 end +################################################################################ +# reset_system # +################################################################################ + def reset_system $sp.print("exit\r") sleep 0.1 @@ -55,6 +71,10 @@ def reset_system sleep 0.1 end +################################################################################ +# scan_system # +################################################################################ + def scan_system algos = Hash.new $sp.print("shavs_list\r") @@ -67,43 +87,89 @@ def scan_system end end +################################################################################ +# init_system # +################################################################################ + def init_system(algo_select) $sp.print("echo off \r") print("DBG i: " + "echo off \r"+"\n") if $debug - sleep 1 + sleep 0.1 $sp.print("shavs_set #{algo_select}\r") - print("DBG i: " + "shavs_set #{$algo_select} \r"+"\n") # if $debug - sleep 1 + print("DBG i: " + "shavs_set #{$algo_select} \r"+"\n") if $debug + sleep 0.1 $sp.print("shavs_test1 \r") print("DBG i: " + "shavs_test1 \r"+"\n") if $debug begin 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) + printf("buffer_size = %d\n", $buffer_size) end +################################################################################ +# get_md # +################################################################################ + def get_md begin line = $sp.gets() + puts("DBG got: " + line.inspect) if $debug line = "" if line==nil - puts("DBG got: "+line) if $debug + # puts("DBG got: "+line) if $debug end while not /[\s]*MD[\s]*=.*/.match(line) return line end +################################################################################ +# send_md # +################################################################################ +=begin 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*2)==0)&&(i!=0)) - begin - line=$sp.gets() - end while not /\./.match(line) - end + if((i%($buffer_size*2)==0)&&(i!=0)) + begin + line=$sp.gets() + end while not /\./.match(line) + end + end +end +=end +def send_md(md_string) +# puts 'DBG: send_md; md_string.length = '+md_string.length.to_s+'; buffer_size = '+$buffer_size.to_s + bs = $buffer_size*2 + $sp.print("Msg = ") + $sp.print(md_string[0]) + md_string = md_string[1..-1] + for i in 0..((md_string.length)/bs) +# puts 'DBG bulk send' + if(md_string.length-i*bs<=bs) + # puts "DBG: i="+i.to_s() + t = md_string[(i*bs)..-1] + printf("sending final %d chars: %s\n", t.length, t[-10..-1]) if $debug + $sp.print(t) + return + end + t = md_string[(i*bs)..((i+1)*bs-1)] + printf("sending %d chars: %s\n", t.length, t[-10..-1]) if $debug + $sp.print(t) + sleep(0.1) + print("going to wait ... : ") if $debug + begin + line=$sp.gets() + puts(line.inspect) if $debug + line='' if !line + end while ! /\./.match(line) end end + +################################################################################ +# run_test # +################################################################################ + def run_test(filename, skip=0) nerrors = 0 line=1 @@ -116,25 +182,32 @@ def run_test(filename, skip=0) until file.eof 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 +# printf("DBG info: file read: %s", lb) + end while not (file.eof or (/[\s]*Len[\s]*=/.match(lb))) +# puts("got ya") + if file.eof + file.close() + return nerrors + end + len = /[\s]*Len[\s]*=[\s]*([0-9]*)/.match(lb)[1].to_i if(skip>0) skip -= 1 redo end + puts("DBG sending: "+lb) if $debug $sp.print(lb.strip) $sp.print("\r") begin - lb=file.gets() + lb=file.gets() 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(m[1]) + puts("DBG sending [done] getting...") if $debug avr_md = get_md() + puts("DBG getting [done]") if $debug begin - lb=file.gets() + lb=file.gets() end while not /[\s]*MD[\s]*=.*/.match(lb) a = (/[\s]*MD[\s]*=[\s]*([0-9a-fA-F]*).*/.match(lb))[1]; b = (/[\s]*MD[\s]*=[\s]*([0-9a-fA-F]*).*/.match(avr_md))[1]; @@ -148,18 +221,40 @@ def run_test(filename, skip=0) putc('*') else putc('!') - printf("<%d>",len) + # printf("<%d>",len) + printf("\nError @%05d: %s [should]\n != %s [is]- ",len, a, b) nerrors += 1 end pos += 1 end - return nerrors.to_i + file.close() + return nerrors end + +################################################################################ +# MAIN # +################################################################################ +# +# Options: +# -s {algo_letter} run only specified algos +# -f also read config from +# -i skip until test nr. +# -j start with testfile +# -o use just one testfile +# -h ??? +# -d enable debug mode +# -c ??? +# -a ??? + +opts = Getopt::Std.getopts("s:f:i:j:hdcao") + conf = Hash.new conf = readconfigfile("/etc/testport.conf", conf) conf = readconfigfile("~/.testport.conf", conf) conf = readconfigfile("testport.conf", conf) +conf = readconfigfile(opts["f"], conf) if opts["f"] + #puts conf.inspect puts("serial port interface version: " + SerialPort::VERSION); @@ -190,19 +285,38 @@ reset_system() algos=scan_system() #puts algos.inspect -algos.sort.each do |algoa| +if opts["d"] + $debug = true +end + +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 + +algo_tasks.each do |algoa| algo = algoa[0] if conf[algo]==nil puts("No test-set defined for #{algo} \r\n") next else - i=0 - logfile=File.open(conf["PORT"]["testlogbase"]+algo+".txt", "a") - while conf[algo]["file_#{i}"] != nil - puts("Testing #{algo} with #{conf[algo]["file_#{i}"]}") - reset_system() - init_system(algoa[1]) - nerrors=run_test(conf[algo]["file_#{i}"], 0) + i=0 + i = opts["j"].to_i if opts["j"] + logfile=File.open(conf["PORT"]["testlogbase"]+algo+".txt", "a") + while conf[algo]["file_#{i}"] != nil + puts("Testing #{algo} with #{conf[algo]["file_#{i}"]}") + reset_system() + 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()+")") @@ -210,7 +324,8 @@ algos.sort.each do |algoa| puts("\n[errors: "+ nerrors.to_s() +"]") logfile.puts("[error] "+nerrors.to_s+" "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")") end - i += 1 + i = i+1 + break if opts["o"] end logfile.close() end