2008-07-18 20:51:00 +00:00
|
|
|
#!/usr/bin/ruby
|
2009-02-06 10:39:33 +00:00
|
|
|
# get_test.rb
|
|
|
|
=begin
|
|
|
|
This file is part of the AVR-Crypto-Lib.
|
2009-05-14 00:31:18 +00:00
|
|
|
Copyright (C) 2008, 2009 Daniel Otte (daniel.otte@rub.de)
|
2009-02-06 10:39:33 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
=end
|
2008-07-18 20:51:00 +00:00
|
|
|
|
2010-12-18 23:47:24 +00:00
|
|
|
require 'rubygems'
|
2008-12-10 23:59:43 +00:00
|
|
|
require 'serialport'
|
2008-07-18 20:51:00 +00:00
|
|
|
|
2009-02-25 20:22:32 +00:00
|
|
|
def read_line(error_msg=true)
|
2009-02-04 13:50:15 +00:00
|
|
|
s = $sp.gets()
|
|
|
|
if s==nil
|
2009-02-25 20:22:32 +00:00
|
|
|
puts("ERROR: read timeout!\n") if error_msg
|
2009-02-04 13:50:15 +00:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
s.gsub(/\006/, '');
|
|
|
|
end
|
|
|
|
|
2008-07-18 20:51:00 +00:00
|
|
|
def readTestVector(param)
|
|
|
|
fname=$dir;
|
|
|
|
lb="";
|
|
|
|
buffer="";
|
|
|
|
set=0;
|
|
|
|
vector=0;
|
|
|
|
begin
|
2009-02-25 20:22:32 +00:00
|
|
|
lb = read_line(false)
|
2009-02-04 13:50:15 +00:00
|
|
|
if (m=/unknown command/.match(lb) || m=/[Ee][Rr]{2}[Oo][Rr]/.match(lb))
|
2008-07-18 20:51:00 +00:00
|
|
|
puts("ERROR: "+lb);
|
|
|
|
exit(2);
|
|
|
|
end
|
|
|
|
if(lb==nil)
|
|
|
|
return false;
|
|
|
|
end
|
|
|
|
end while(m=/\*+/.match(lb));
|
|
|
|
|
|
|
|
buffer += lb;
|
|
|
|
begin
|
2009-02-04 13:50:15 +00:00
|
|
|
lb = read_line()
|
2008-07-18 20:51:00 +00:00
|
|
|
if(lb==nil)
|
|
|
|
return false;
|
|
|
|
end
|
|
|
|
buffer+=lb;
|
|
|
|
end while(m=/\*.*/.match(lb));
|
|
|
|
|
|
|
|
while(!(m=/Test vectors/.match(lb)))
|
|
|
|
m=/[^:]*:[\s]([A-Za-z0-9_-]*)/.match(lb);
|
|
|
|
if(m)
|
|
|
|
fname+=m[1]+".";
|
|
|
|
end
|
2009-02-10 00:37:51 +00:00
|
|
|
return false if lb==nil
|
2008-07-18 20:51:00 +00:00
|
|
|
buffer+=lb;
|
2009-02-10 00:37:51 +00:00
|
|
|
lb = read_line();
|
2008-07-18 20:51:00 +00:00
|
|
|
end
|
|
|
|
if(param!="")
|
|
|
|
fname+=param+".";
|
|
|
|
end
|
|
|
|
puts("-> "+fname+"txt");
|
|
|
|
file=File.new(fname+"txt", "w");
|
|
|
|
buffer+=lb;
|
|
|
|
file.write(buffer);
|
|
|
|
begin
|
|
|
|
if (m=/Test\ vectors\ \-\-\ set[\s]+([0-9]+)/.match(lb))
|
|
|
|
set=m[1].to_i;
|
|
|
|
print("\nSet "+m[1]+":");
|
|
|
|
end
|
|
|
|
if (m=/Set [0-9]*, vector#[\s]*([0-9]+):/.match(lb))
|
|
|
|
vector=m[1].to_i;
|
|
|
|
#print(" "+m[1]);
|
|
|
|
if(vector!=0 && vector % $linewidth==0)
|
|
|
|
print("\n ")
|
|
|
|
end
|
2008-12-10 23:59:43 +00:00
|
|
|
printf(" %4u", vector);
|
|
|
|
end
|
2009-02-04 13:50:15 +00:00
|
|
|
lb=read_line();
|
2008-07-18 20:51:00 +00:00
|
|
|
if(lb==nil)
|
|
|
|
file.close();
|
|
|
|
return false;
|
|
|
|
end
|
|
|
|
file.write(lb);
|
|
|
|
end while(!m=/End of test vectors/.match(lb));
|
|
|
|
puts("\n");
|
|
|
|
file.close();
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2009-02-02 23:05:19 +00:00
|
|
|
|
|
|
|
if ARGV.size < 5
|
|
|
|
STDERR.print <<EOF
|
|
|
|
Usage: ruby #{$0} port bps nbits stopb command [target_dir] [additional specifier]
|
|
|
|
EOF
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
command=ARGV[4]+"\r";
|
|
|
|
$dir=(ARGV.size>=6)?ARGV[5]:"";
|
|
|
|
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);
|
2009-02-16 14:18:19 +00:00
|
|
|
$sp.read_timeout=1000; # 1 secound
|
2009-02-02 23:05:19 +00:00
|
|
|
$extended_wait=100;
|
|
|
|
$sp.write(command);
|
|
|
|
|
2008-07-18 20:51:00 +00:00
|
|
|
if(readTestVector(param)==false)
|
2008-12-10 23:59:43 +00:00
|
|
|
puts("ERROR: test seems not to be implemented");
|
2011-01-05 09:32:41 +00:00
|
|
|
exit(0); # 3
|
2008-07-18 20:51:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
while(readTestVector(param))
|
|
|
|
end
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
|