require 'rubygems'
require 'serialport'
require 'getopt/std'
-require 'ftools'
+require 'fileutils'
require 'date'
$buffer_size = 0
$conffile_check = Hash.new
return conf if $conffile_check[fname]==1
$conffile_check[fname]=1
section = "default"
- if not File.exists?(fname)
+ if ! File.exists?(fname)
return conf
end
file = File.open(fname, "r")
conf[m[1]] = Hash.new
next
end
- next if not /=/.match(line)
+ next if ! /=/.match(line)
m=/[\s]*([^\s]*)[\s]*=[\s]*([^\s]*)/.match(line)
if m[1]=="include"
Dir.glob(m[2]){ |fn| conf = readconfigfile(fn, conf) }
################################################################################
def gcdext(x,y)
+ return [0, 0, 0] if(x == 0 || y == 0)
g=1
while(x&1==0 && y&1==0) do
x>>=1
def wait_for_prompt(prompt)
prompt = /[\s]*#{prompt}[\s]*/ if(prompt.class == String)
start_time = Time.now.to_i
+ acc = ''
begin
line = $sp.gets()
puts("DBG got (#{__LINE__}): "+line) if $debug && line
if (Time.now.to_i- start_time) > $max_timeout
return false
end
- end while not m=prompt.match(line)
+ acc += line
+ end while ! m=prompt.match(acc)
return m
end
puts line
return false
end
- end while not /[\s]*enter a:[\s]*/.match(line)
+ end while ! /[\s]*enter a:[\s]*/.match(line)
$sp.print(a.to_s(16)+" ")
begin
line = $sp.gets()
puts line
return false
end
- end while not /[\s]*enter b:[\s]*/.match(line)
+ end while ! /[\s]*enter b:[\s]*/.match(line)
$sp.print(b.to_s(16)+" ")
begin
line = $sp.gets()
puts line
return false
end
- end while not m=/[\s]*([-]?[0-9a-fA-F]*)[\s]+\+[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
+ end while ! m=/[\s]*([-]?[0-9a-fA-F]*)[\s]+\+[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
a_ = m[1].to_i(16)
b_ = m[2].to_i(16)
c_ = m[3].to_i(16)
puts line
return false
end
- end while not /[\s]*enter a:[\s]*/.match(line)
+ end while ! /[\s]*enter a:[\s]*/.match(line)
$sp.print(a.to_s(16)+" ")
begin
line = $sp.gets()
puts line
return false
end
- end while not /[\s]*enter b:[\s]*/.match(line)
+ end while ! /[\s]*enter b:[\s]*/.match(line)
$sp.print(b.to_s(16)+" ")
begin
line = $sp.gets()
puts line
return false
end
- end while not m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]+\*[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
+ end while ! m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]+\*[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
a_ = m[1].to_i(16)
b_ = m[2].to_i(16)
c_ = m[3].to_i(16)
puts line
return false
end
- end while not /[\s]*enter a:[\s]*/.match(line)
+ end while ! /[\s]*enter a:[\s]*/.match(line)
$sp.print(a.to_s(16)+" ")
begin
line = $sp.gets()
puts line
return false
end
- end while not m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]*\*\*2[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
+ end while ! m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]*\*\*2[\s]*=[\s]*([+-]?[0-9a-fA-F]*)/.match(line)
a_ = m[1].to_i(16)
c_ = m[2].to_i(16)
line.chomp!
puts line
return false
end
- end while not /[\s]*enter a:[\s]*/.match(line)
+ end while ! /[\s]*enter a:[\s]*/.match(line)
$sp.print(a.to_s(16)+" ")
begin
line = $sp.gets()
puts line
return false
end
- end while not /[\s]*enter b:[\s]*/.match(line)
+ end while ! /[\s]*enter b:[\s]*/.match(line)
$sp.print(b.to_s(16)+" ")
line=''
begin
puts line
return false
end
- end while not m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]+%[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]+)/.match(line)
+ end while ! m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]+%[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]+)/.match(line)
a_ = m[1].to_i(16)
b_ = m[2].to_i(16)
c_ = m[3].to_i(16)
def expmod_test(a,b,c)
begin
+ printf("[testing] expmod(%#x, %#x, %#x)\n",a,b,c) if $debug
line = $sp.gets()
line = "" if line==nil
puts("DBG got: "+line) if $debug
puts line
return false
end
- end while not /[\s]*enter a:[\s]*/.match(line)
+ end while ! /[\s]*enter a:[\s]*/.match(line)
$sp.print(a.to_s(16)+" ")
begin
line = $sp.gets()
puts line
return false
end
- end while not /[\s]*enter b:[\s]*/.match(line)
+ end while ! /[\s]*enter b:[\s]*/.match(line)
$sp.print(b.to_s(16)+" ")
begin
line = $sp.gets()
puts line
return false
end
- end while not /[\s]*enter c:[\s]*/.match(line)
+ end while ! /[\s]*enter c:[\s]*/.match(line)
$sp.print(c.to_s(16)+" ")
line=''
begin
puts line
return false
end
- end while not m=/[\s]*([+-]?[0-9a-fA-F]*)\*\*([+-]?[0-9a-fA-F]*)[\s]+%[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]+)/.match(line)
+ end while ! m=/[\s]*([+-]?[0-9a-fA-F]*)\*\*([+-]?[0-9a-fA-F]*)[\s]+%[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]+)/.match(line)
a_ = m[1].to_i(16)
b_ = m[2].to_i(16)
c_ = m[3].to_i(16)
################################################################################
def gcdext_test(a,b)
+ $logfile.printf("[testing] gcdext(%s, %s)\n", a.to_s(16), b.to_s(16))
begin
line = $sp.gets()
line = "" if line==nil
puts line
return false
end
- end while not /[\s]*enter a:[\s]*/.match(line)
+ end while ! /[\s]*enter a:[\s]*/.match(line)
$sp.print(a.to_s(16)+" ")
begin
line = $sp.gets()
puts line
return false
end
- end while not /[\s]*enter b:[\s]*/.match(line)
+ end while ! /[\s]*enter b:[\s]*/.match(line)
$sp.print(b.to_s(16)+" ")
line=''
begin
puts line
return false
end
- end while not m=/gcdext\([\s]*([+-]?[0-9a-fA-F]*)[\s]*,[\s]*([+-]?[0-9a-fA-F]*)[\s]*\)[\s]*=> a = ([+-]?[0-9a-fA-F]+); b = ([+-]?[0-9a-fA-F]+); gcd = ([+-]?[0-9a-fA-F]+)/.match(line)
+ end while ! m=/gcdext\([\s]*([+-]?[0-9a-fA-F]*)[\s]*,[\s]*([+-]?[0-9a-fA-F]*)[\s]*\)[\s]*=> a = ([+-]?[0-9a-fA-F]+); b = ([+-]?[0-9a-fA-F]+); gcd = ([+-]?[0-9a-fA-F]+)/.match(line)
a_ = m[1].to_i(16)
b_ = m[2].to_i(16)
c_ = m[3].to_i(16)
#puts conf.inspect
init_serialport(conf)
- $max_timeout = 2 * 60
+ $max_timeout = 5 * 60
if opts['d']
$debug = true
i+=1
end while(File.exists?(logfilename))
while(i>2) do
- File.move(sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',i-2,'.txt'),
- sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',i-1,'.txt'), true)
+ n1 = sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',i-2,'.txt')
+ n2 = sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',i-1,'.txt')
+ File.rename(n1, n2)
+ printf("%s -> %s\n", n1, n2)
i-=1
end
- File.move(sprintf('%s%s', conf['PORT']['testlogbase'],'bigint.txt'),
- sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',1,'.txt'), true)
+ n1 = sprintf('%s%s', conf['PORT']['testlogbase'],'bigint.txt')
+ n2 = sprintf('%s%04d%s', conf['PORT']['testlogbase']+'bigint_',1,'.txt')
+ File.rename(n1, n2)
+ printf("%s -> %s\n", n1, n2)
logfilename = conf['PORT']['testlogbase']+'bigint.txt'
end
$logfile = File.open(logfilename, 'w')
printf("logfile: %s\n", logfilename)
-
+$logfile.sync = true
$logfile.printf("bigint test from: %s\n", Time.now.to_s)
$logfile.printf("skip = %s\n", opts['s']) if opts['s']
$logfile.printf("seed = 0x%X\n", 0xdeadbeef)