1 from multiprocessing import Process
10 def createfiles(d, n):
11 for j in xrange(1, 5):
12 print "Starting small file %s %i, %i" % (d, n, j)
17 print "ERROR %s missing" % d
20 for i in xrange(n, n+10):
21 with open(fn(i), "w") as f:
25 for i in xrange(n, n+10):
27 print "ERROR %s missing" % fn(i)
29 for i in xrange(n, n+10):
30 with open(fn(i), "r") as f:
32 print "ERROR %s doesn't have expected contents" % fn(i)
34 for i in xrange(n, n+10):
38 for i in xrange(n, n+10):
40 print "ERROR %s should have been removed" % fn(i)
47 print "ERROR %s should have been removed" % d
50 def createbigfile(d, n):
51 for j in xrange(1, 5):
52 print "Starting big file %s %i, %i" % (d, n, j)
58 print "ERROR %s missing" % d
61 with open(fn(i), "w") as f:
62 for j in xrange(0, 1000):
63 f.write((str(j) + fn(i)) * 10000)
67 print "ERROR %s missing" % fn(i)
69 with open(fn(i), "r") as f:
70 for j in xrange(0, 1000):
71 expect = (str(j) + fn(i)) * 10000
72 if f.read(len(expect)) != expect:
73 print "ERROR %s doesn't have expected contents" % fn(i)
79 print "ERROR %s should have been removed" % fn(i)
86 print "ERROR %s should have been removed" % d
89 with open("/dev/null", "w") as nul:
90 for j in xrange(1, 50):
91 subprocess.call(["ls", "-l"], stdout=nul, stderr=nul)
93 def runit(target, indir):
95 for n in xrange(0, 20):
97 p = Process(target=target, args=("dir%i" % n, n*10,))
99 p = Process(target=target, args=("", n*10,))
103 p = Process(target=do_ls, args=())
111 print "ERROR there are left over files in the directory"
114 if __name__ == '__main__':
116 print "ERROR starting directory is not empty"
119 print "Single directory small files"
120 with prof.CountTime():
121 runit(createfiles, False)
123 print "Separate directories small files"
124 with prof.CountTime():
125 runit(createfiles, True)
127 print "Single directory large files"
128 with prof.CountTime():
129 runit(createbigfile, False)
131 print "Separate directories large files"
132 with prof.CountTime():
133 runit(createbigfile, True)