#!/usr/bin/python import subprocess import random import math def kernel_scale (rtime, total, stime): p = subprocess.Popen("./scale_stime " + str(rtime) + " " + str(total) + " " + str(stime) , shell=True, stdout=subprocess.PIPE) return int(p.stdout.read()) def python_scale (rtime, total, stime): return (stime * rtime) / total max_rtime = 10*4096*364*24*60*60*1000; # 10 years for 4096 threads fail=False K=1000 for i in range(0, K): rtime = random.randrange(max_rtime) total = int(random.uniform(0.1, 1.9) * rtime) for n in range(1, 100): stime = (n * total / 100) r1 = kernel_scale(rtime, total, stime) r2 = python_scale(rtime, total, stime) if (float(abs(r1 - r2)) / float(r2)) > 0.0005: print "FAIL!" print "rtime: " + str(rtime) print "total: " + str(total) print "stime: " + str(stime) print "kernel: " + str(r1) print "python: " + str(r2) fail=True break if fail: break; if (i % 100) == 99: print str(i/100) + "/" + str(K/100) + " OK"