]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - host/get_test.rb
added Whirlpool-0 and Whirlpool-T
[avr-crypto-lib.git] / host / get_test.rb
index 987a5b1f7ea1a8bb6773afd8c720eec4baa2d5a2..8b3f940c5be60f7b5c85d7ad02fb7902f038b825 100644 (file)
@@ -1,24 +1,34 @@
 #!/usr/bin/ruby 
+# get_test.rb
+=begin
+    This file is part of the AVR-Crypto-Lib.
+    Copyright (C) 2008, 2009  Daniel Otte (daniel.otte@rub.de)
 
-require 'serialport'
+    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.
 
-if ARGV.size < 5
-  STDERR.print <<EOF
-  Usage: ruby #{$0} port bps nbits stopb command [target_dir] [additional specifier]
-EOF
-  exit(1)
-end
+    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.
 
-command=ARGV[4]+" ";
-$dir=(ARGV.size>=6)?ARGV[5]:"";
-param=(ARGV.size>=7)?ARGV[6]:"";
+    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
 
-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=10;
-$sp.write(command);
+require 'rubygems'
+require 'serialport'
+
+def read_line(error_msg=true)
+  s = $sp.gets()
+  if s==nil
+    puts("ERROR: read timeout!\n") if error_msg
+       return nil
+  end  
+  s.gsub(/\006/, '');  
+end
 
 def readTestVector(param)
   fname=$dir;
@@ -27,11 +37,8 @@ def readTestVector(param)
   set=0;
   vector=0;
   begin
-    ctr=$extended_wait;
-    while((lb=$sp.gets())==nil && ctr>=0)do
-      ctr -= 1;
-    end
-    if (m=/unknown command/.match(lb) || m=/[Ee][Rr]{2}[Oo][Rr]/.match(lb))
+    lb = read_line(false)
+       if (m=/unknown command/.match(lb) || m=/[Ee][Rr]{2}[Oo][Rr]/.match(lb))
       puts("ERROR: "+lb);
       exit(2);
     end
@@ -42,10 +49,7 @@ def readTestVector(param)
   
   buffer += lb;
   begin
-    ctr=$extended_wait;
-    while((lb=$sp.gets())==nil && ctr>=0)do
-      ctr -= 1;
-    end
+    lb = read_line()
     if(lb==nil)
       return false;
     end
@@ -57,11 +61,9 @@ def readTestVector(param)
     if(m) 
       fname+=m[1]+".";
     end
+    return false if lb==nil
     buffer+=lb;
-    ctr=$extended_wait;
-    while((lb=$sp.gets())==nil && ctr>=0)do
-      ctr -= 1;
-    end
+    lb = read_line();
   end
   if(param!="")
     fname+=param+".";
@@ -83,10 +85,7 @@ def readTestVector(param)
        end
         printf(" %4u", vector);
       end
-      ctr=$extended_wait;
-      while((lb=$sp.gets())==nil && ctr>=0)do
-        ctr -= 1;
-      end
+      lb=read_line();
       if(lb==nil)
         file.close();
         return false;
@@ -98,9 +97,28 @@ def readTestVector(param)
   return true
 end
 
+
+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);
+$sp.read_timeout=1000; # 1 secound
+$extended_wait=100;
+$sp.write(command);
+
 if(readTestVector(param)==false)
   puts("ERROR: test seems not to be implemented");
-  exit(3);
+  exit(0); # 3 
 end
 
 while(readTestVector(param))