3 #much copy paste such python
7 from matplotlib.pyplot import *
14 def FixedScales(binname, x0=0, y0=0, w0=1, h0=1, s=0.5, steps=100, xz = 0.5, yz = 0.5, testsvg="svg-tests/grid.svg", renderer="gpu", fps=1):
17 n = open("/dev/null", "w")
20 p = subprocess.Popen(binname + " -s stdin", bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=n, shell=True)
21 p.stdin.write("%s\n" % renderer)
22 p.stdin.write("setbounds %s %s %s %s\n" % (str(x0),str(y0),str(w0),str(h0)))
23 p.stdin.write("loadsvg %s\n" % testsvg)
24 p.stdin.write("querygpubounds original.dat\n")
25 p.stdin.write("screenshot original.bmp\n")
27 print "%s - Couldn't start - %s" % (binname, str(e))
28 return {"accuracy" : asarray(accuracy), \
29 "performance" : asarray(performance)}
31 for i in xrange(steps):
33 start_time = time.time()
34 p.stdin.write("clear\n")
35 p.stdin.write("loop 1 zoom %s %s %s\n" % (str(xz), str(yz), str(s)))
36 p.stdin.write("loadsvg %s\n" % testsvg)
37 p.stdin.write("querygpubounds step%d.dat\n" % i)
38 #while not os.path.isfile("step%d.dat" % i):
40 p.stdin.write("loop %d printspf\n" % fps) # Print an FPS count to signal it is safe to read the file
41 fpsout = p.stdout.readline().strip(" \r\n").split("\t")
43 p.stdin.write("printbounds\n")
44 bounds = p.stdout.readline().strip(" \r\n").split("\t")
46 bounds = map(float, bounds)
50 performance += [map(float, fpsout) + [time.time() - start_time]]
51 accuracy += [bounds + [gpubounds.ComputeError("original.dat", "step%d.dat" % i), \
52 gpubounds.UniqueBounds("step%d.dat" % i)]]
54 os.unlink("step%d.dat" % i) # Don't need it any more
55 #print accuracy[-1][-1]
56 if accuracy[-1][-1] <= 1:
57 print "%s - Quit early after %d steps - No precision left" % (binname, i)
59 if performance[-1][-1] > 60:
60 print "%s - Quit early after %d steps - Took too long to render frames" % (binname, i)
63 print "%s - Quit early after %d steps - Exception %s" % (binname, i, str(e))
67 p.stdin.write("screenshot final.bmp\n")
68 p.stdin.write("quit\n")
71 print "%s - Couldn't exit - %s" % (binname, str(e))
73 return {"accuracy" : asarray(accuracy),
74 "performance" : asarray(performance)}
77 def TestInvariance(binname, x0=0, y0=0, w0=1, h0=1, s=-1, steps=1000, xz = 400, yz = 300, testsvg="svg-tests/grid.svg", renderer="gpu", fps=1):
80 n = open("/dev/null", "w")
83 p = subprocess.Popen(binname + " -s stdin", bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=n, shell=True)
84 p.stdin.write("%s\n" % renderer)
85 p.stdin.write("setbounds %s %s %s %s\n" % (str(x0),str(y0),str(w0),str(h0)))
86 p.stdin.write("loadsvg %s\n" % testsvg)
87 p.stdin.write("querygpubounds original.dat\n")
88 p.stdin.write("screenshot original.bmp\n")
89 p.stdin.write("printbounds\n")
90 bounds_orig = map(float, p.stdout.readline().strip(" \r\n").split("\t"))
92 print "%s - Couldn't start - %s" % (binname, str(e))
93 return {"accuracy" : asarray(accuracy),
94 "performance" : asarray(performance)}
96 for i in xrange(1,steps,50):
98 start_time = time.time()
99 p.stdin.write("loop %d pxzoom %s %s %s\n" % (i, str(xz), str(yz), str(int(s))))
100 p.stdin.write("printbounds\n")
101 bounds = map(float, p.stdout.readline().strip(" \r\n").split("\t"))
102 p.stdin.write("loop %d pxzoom %s %s %s\n" % (i, str(xz), str(yz), str(-int(s))))
103 p.stdin.write("querygpubounds step%d.dat\n" % i)
104 while not os.path.isfile("step%d.dat" % i):
106 p.stdin.write("loop %d printspf\n" % fps) # Print an FPS count to signal it is safe to read the file
107 fpsout = p.stdout.readline().strip(" \r\n").split("\t")
111 bounds[0] = bounds[0]-bounds_orig[0]
112 bounds[1] = bounds[1]-bounds_orig[1]
113 bounds[2] = bounds[2]/bounds_orig[2]
114 bounds[3] = bounds[3]/bounds_orig[3]
115 performance += [map(float, fpsout) + [time.time() - start_time]]
116 accuracy += [bounds + [gpubounds.ComputeError("original.dat", "step%d.dat" % i), \
117 gpubounds.UniqueBounds("step%d.dat" % i)]]
119 os.unlink("step%d.dat" % i) # Don't need it any more
120 if accuracy[-1][-1] <= 10:
121 print "%s - Quit early after %d steps - No precision left" % (binname, i)
123 if performance[-1][-1] > 60:
124 print "%s - Quit early after %d steps - Took too long to render frames" % (binname, i)
127 print "%s - Quit early after %d steps - %s" % (binname, i, str(e))
130 p.stdin.write("screenshot final.bmp\n")
131 p.stdin.write("quit\n")
134 print "%s - Couldn't exit - %s" % (binname, str(e))
135 return {"accuracy" : asarray(accuracy),
136 "performance" : asarray(performance)}
138 if __name__ == "__main__":
139 results = Scaling("./single", xz=0, yz=0, fps=100)