X-Git-Url: https://git.cryptolib.org/?p=avr-crypto-lib.git;a=blobdiff_plain;f=host%2Fget_test.rb;h=5e8e8c3d730d1c21340041a21dac84abaf7b66ed;hp=cfc3b33a093a67e2e6382c5638132ad1003e0f2c;hb=4b5da1dc27a791b5c448274a3db09cd035b33493;hpb=d3db763eeb456ce00849ecf658782f95b9f5634c diff --git a/host/get_test.rb b/host/get_test.rb index cfc3b33..5e8e8c3 100644 --- a/host/get_test.rb +++ b/host/get_test.rb @@ -2,7 +2,7 @@ # get_test.rb =begin This file is part of the AVR-Crypto-Lib. - Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) + 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 @@ -18,15 +18,27 @@ along with this program. If not, see . =end +require 'rubygems' require 'serialport' -def read_line - s = $sp.gets() - if s==nil - puts "ERROR: read timeout!\n"; - return nil - end - s.gsub(/\006/, ''); +$debug = false +$progress_dots = false + +def read_line(error_msg=true) + begin + i = $extended_wait + begin + s = $sp.gets() + i -= 1 + end while !s && i > 0 + if s==nil + puts("ERROR: read timeout!\n") if error_msg + return nil + end + putc('.') if s.include?(6.chr) && $progress_dots + puts(s.inspect) if $debug + end while s == 6.chr + s.gsub(/\006/, '') end def readTestVector(param) @@ -36,7 +48,7 @@ def readTestVector(param) set=0; vector=0; begin - lb = read_line() + lb = read_line(false) if (m=/unknown command/.match(lb) || m=/[Ee][Rr]{2}[Oo][Rr]/.match(lb)) puts("ERROR: "+lb); exit(2); @@ -60,14 +72,16 @@ def readTestVector(param) if(m) fname+=m[1]+"."; end + return false if lb==nil buffer+=lb; - lb = read_line(); + lb = read_line(); end if(param!="") fname+=param+"."; end puts("-> "+fname+"txt"); file=File.new(fname+"txt", "w"); + file.sync = true buffer+=lb; file.write(buffer); begin @@ -110,13 +124,13 @@ param=(ARGV.size>=7)?ARGV[6]:""; puts("\nPort: "+ARGV[0]+ "@"+ARGV[1]+" "+ARGV[2]+"N"+ARGV[3]+"\n"); $linewidth = 16 $sp = SerialPort.new(ARGV[0], ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE); -$sp.read_timeout=1*60*1000; # 5 minutes -$extended_wait=100; +$sp.read_timeout=1000; # 1 second +$extended_wait=100000; $sp.write(command); if(readTestVector(param)==false) puts("ERROR: test seems not to be implemented"); - exit(3); + exit(0); # 3 end while(readTestVector(param))