1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 from __future__ import print_function
6 from __future__ import absolute_import
7 from builtins import str
8 from builtins import range
9 from multiprocessing import Process
18 def createfiles(d, n):
20 print("Starting small file %s %i, %i" % (d, n, j))
25 print("ERROR %s missing" % d)
28 for i in range(n, n+10):
29 with open(fn(i), "w") as f:
33 for i in range(n, n+10):
35 print("ERROR %s missing" % fn(i))
37 for i in range(n, n+10):
38 with open(fn(i), "r") as f:
40 print("ERROR %s doesn't have expected contents" % fn(i))
42 for i in range(n, n+10):
46 for i in range(n, n+10):
48 print("ERROR %s should have been removed" % fn(i))
55 print("ERROR %s should have been removed" % d)
58 def createbigfile(d, n):
60 print("Starting big file %s %i, %i" % (d, n, j))
66 print("ERROR %s missing" % d)
69 with open(fn(i), "w") as f:
70 for j in range(0, 1000):
71 f.write((str(j) + fn(i)) * 10000)
75 print("ERROR %s missing" % fn(i))
77 with open(fn(i), "r") as f:
78 for j in range(0, 1000):
79 expect = (str(j) + fn(i)) * 10000
80 if f.read(len(expect)) != expect:
81 print("ERROR %s doesn't have expected contents" % fn(i))
87 print("ERROR %s should have been removed" % fn(i))
94 print("ERROR %s should have been removed" % d)
97 with open("/dev/null", "w") as nul:
98 for j in range(1, 50):
99 subprocess.call(["ls", "-l"], stdout=nul, stderr=nul)
101 def runit(target, indir):
103 for n in range(0, 20):
105 p = Process(target=target, args=("dir%i" % n, n*10,))
107 p = Process(target=target, args=("", n*10,))
111 p = Process(target=do_ls, args=())
119 print("ERROR there are left over files in the directory")
122 if __name__ == '__main__':
124 print("ERROR starting directory is not empty")
127 print("Single directory small files")
128 with prof.CountTime():
129 runit(createfiles, False)
131 print("Separate directories small files")
132 with prof.CountTime():
133 runit(createfiles, True)
135 print("Single directory large files")
136 with prof.CountTime():
137 runit(createbigfile, False)
139 print("Separate directories large files")
140 with prof.CountTime():
141 runit(createbigfile, True)