]> git.cryptolib.org Git - avr-crypto-lib.git/blob - host/get_performance.rb
optimizing norx32
[avr-crypto-lib.git] / host / get_performance.rb
1 #!/usr/bin/ruby 
2 # get_performance.rb
3 =begin
4     This file is part of the AVR-Crypto-Lib.
5     Copyright (C) 2008, 2009  Daniel Otte (daniel.otte@rub.de)
6
7     This program is free software: you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation, either version 3 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 =end
20
21 $debug = false
22 require 'rubygems'
23 require 'serialport'
24 require 'getopt/std'
25 $conffile_check = Hash.new
26 $conffile_check.default = 0
27
28 ################################################################################
29 # readconfigfile                                                               #
30 ################################################################################
31
32 def readconfigfile(fname, conf)
33   return conf if $conffile_check[fname]==1
34   $conffile_check[fname]=1
35   section = "default"
36   if not File.exists?(fname)
37     return conf
38   end
39   file = File.open(fname, "r")
40   until file.eof
41     line = file.gets()
42   next if /[\s]*#/.match(line)
43   if m=/\[[\s]*([^\s]*)[\s]*\]/.match(line)
44     section=m[1]
45     conf[m[1]] = Hash.new
46     next
47   end
48   next if not /=/.match(line)
49   m=/[\s]*([^\s]*)[\s]*=[\s]*([^\s]*)/.match(line)
50   if m[1]=="include"
51     Dir.glob(m[2]){ |fn| conf = readconfigfile(fn, conf) }
52   else
53       conf[section][m[1]] = m[2]
54   end
55   end
56   file.close()
57   return conf
58 end
59
60 ################################################################################
61 # read_line                                                                    #
62 ################################################################################
63
64 def read_line(error_msg=true)
65   i=$extended_wait
66   begin
67     s = $sp.gets()
68   end until s or i==0
69   if s==nil
70     puts("ERROR: read timeout!\n") if error_msg
71         return nil
72   end   
73   s.gsub(/\006/, '');   
74 end
75
76 ################################################################################
77 # readPerformanceVector                                                        #
78 ################################################################################
79
80 def readPerformanceVector(param)
81   lb=""
82   fname=""
83   fout=0
84   begin
85     lb = read_line()
86     if lb.match(/End of performance figures/)
87       return false
88           end
89         if m=lb.match(/=== (.*) performance ===/) 
90           fout.close if fout!=0
91           fname=$dir+m[1]
92           fname+="."+param if param != ""
93           fname+=".txt"
94           fout = File.open(fname, "w+")
95           printf("> %s \n", fname)      
96           fout.write(lb)
97       else
98           if fout!=0 && lb!=""
99             fout.write(lb)
100           end   
101         end
102   end while true
103 end
104
105 ################################################################################
106 # MAIN                                                                         #
107 ################################################################################
108
109
110 opts = Getopt::Std.getopts("f:c:t:a:d")
111
112 conf = Hash.new
113 conf = readconfigfile("/etc/testport.conf", conf)
114 conf = readconfigfile("~/.testport.conf", conf)
115 conf = readconfigfile("testport.conf", conf)
116 conf = readconfigfile(opts["f"], conf) if opts["f"]
117
118 #puts conf.inspect
119
120 puts("serial port interface version: " + SerialPort::VERSION);
121 $linewidth = 64
122 params = { "baud"       => conf["PORT"]["baud"].to_i,
123             "data_bits" => conf["PORT"]["databits"].to_i,
124             "stop_bits" => conf["PORT"]["stopbits"].to_i,
125             "parity"    => SerialPort::NONE }
126 params["paraty"] = SerialPort::ODD   if conf["PORT"]["paraty"].downcase == "odd"
127 params["paraty"] = SerialPort::EVEN  if conf["PORT"]["paraty"].downcase == "even"
128 params["paraty"] = SerialPort::MARK  if conf["PORT"]["paraty"].downcase == "mark"
129 params["paraty"] = SerialPort::SPACE if conf["PORT"]["paraty"].downcase == "space"
130
131 puts("\nPort: "+conf["PORT"]["port"]+"@"    +
132                 params["baud"].to_s      +
133                 " "                      +
134                 params["data_bits"].to_s +
135                 conf["PORT"]["paraty"][0,1].upcase +
136                 params["stop_bits"].to_s +
137                 "\n")
138
139 $sp = SerialPort.new(conf["PORT"]["port"], params)
140
141 $sp.read_timeout=1000; # 5 minutes
142 $sp.flow_control = SerialPort::SOFT
143 =begin
144 if ARGV.size < 1
145   STDERR.print <<EOF
146   Usage: ruby #{$0} -c command [-t target_dir] [-a additional specifier]
147 EOF
148   exit(1)
149 end
150 =end
151
152 command=opts['c']+"\r";
153 $dir=(opts['t'])?opts['t']:"";
154 param=(opts['a'])?opts['a']:"";
155
156 $linewidth = 16
157 $extended_wait=100;
158 $sp.write(command);
159
160 while(readPerformanceVector(param))
161 end
162
163 exit(0);
164
165