[Piglit] [PATCH] generated_tests: Except error for os.makedirs
Dylan Baker
baker.dylan.c at gmail.com
Thu Dec 11 15:39:22 PST 2014
Currently we check for the existence of a directory, and if it doesn't
exist we create it. This would be fine, except that multiple generators
can create the same directory trees. When os.makedirs tries to create a
tree that already exists it raises and OSError exception, with the errno
set to 17 (the File Exists Error). Since between the time that a check
is made and the time the os.makedirs completes a second generator can
create the directory tree we can have exceptions raised sporadically,
especially as the number of threads being used to generate goes up.
We maintain the check for existence before trying to create the
directories because os.makedirs is slow, so not even trying is better
than trying in vain.
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
generated_tests/gen_builtin_packing_tests.py | 7 ++++++-
generated_tests/gen_builtin_uniform_tests.py | 9 ++++++++-
generated_tests/gen_builtin_uniform_tests_fp64.py | 9 ++++++++-
generated_tests/gen_const_builtin_equal_tests.py | 7 ++++++-
generated_tests/gen_constant_array_size_tests.py | 9 ++++++++-
generated_tests/gen_constant_array_size_tests_fp64.py | 9 ++++++++-
generated_tests/gen_interpolation_tests.py | 9 ++++++++-
generated_tests/gen_outerproduct_invalid_params.py | 7 ++++++-
generated_tests/gen_outerproduct_tests.py | 8 ++++++--
generated_tests/gen_shader_bit_encoding_tests.py | 7 ++++++-
generated_tests/gen_shader_image_load_store_tests.py | 7 ++++++-
generated_tests/gen_texture_lod_tests.py | 7 ++++++-
generated_tests/gen_texture_query_lod_tests.py | 7 ++++++-
generated_tests/gen_uniform_initializer_tests.py | 7 ++++++-
generated_tests/genclbuiltins.py | 7 ++++++-
generated_tests/generate-cl-store-tests.py | 7 ++++++-
generated_tests/interpolation-qualifier-built-in-variable.py | 8 ++++++--
17 files changed, 112 insertions(+), 19 deletions(-)
diff --git a/generated_tests/gen_builtin_packing_tests.py b/generated_tests/gen_builtin_packing_tests.py
index 52bf1a0..5ca727a 100644
--- a/generated_tests/gen_builtin_packing_tests.py
+++ b/generated_tests/gen_builtin_packing_tests.py
@@ -1028,7 +1028,12 @@ class ShaderTest(object):
def write_file(self):
dirname = os.path.dirname(self.filename)
if not os.path.exists(dirname):
- os.makedirs(dirname)
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
with open(self.filename, "w") as f:
f.write(self.__template.render(func=self.__func_info))
diff --git a/generated_tests/gen_builtin_uniform_tests.py b/generated_tests/gen_builtin_uniform_tests.py
index d89a6f3..d3a7816 100644
--- a/generated_tests/gen_builtin_uniform_tests.py
+++ b/generated_tests/gen_builtin_uniform_tests.py
@@ -537,8 +537,15 @@ class ShaderTest(object):
shader_test += self.make_test()
filename = self.filename()
dirname = os.path.dirname(filename)
+
if not os.path.exists(dirname):
- os.makedirs(dirname)
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
+
with open(filename, 'w') as f:
f.write(shader_test)
diff --git a/generated_tests/gen_builtin_uniform_tests_fp64.py b/generated_tests/gen_builtin_uniform_tests_fp64.py
index ec12650..cf10c85 100644
--- a/generated_tests/gen_builtin_uniform_tests_fp64.py
+++ b/generated_tests/gen_builtin_uniform_tests_fp64.py
@@ -507,8 +507,15 @@ class ShaderTest(object):
shader_test += self.make_test()
filename = self.filename()
dirname = os.path.dirname(filename)
+
if not os.path.exists(dirname):
- os.makedirs(dirname)
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
+
with open(filename, 'w') as f:
f.write(shader_test)
diff --git a/generated_tests/gen_const_builtin_equal_tests.py b/generated_tests/gen_const_builtin_equal_tests.py
index eb2856c..490a591 100644
--- a/generated_tests/gen_const_builtin_equal_tests.py
+++ b/generated_tests/gen_const_builtin_equal_tests.py
@@ -74,7 +74,12 @@ def main():
dirname = os.path.join('spec', 'glsl-1.20', 'execution',
'built-in-functions')
if not os.path.exists(dirname):
- os.makedirs(dirname)
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
for test_id, x in enumerate(TEST_VECTORS, start=2):
# make equal tests
diff --git a/generated_tests/gen_constant_array_size_tests.py b/generated_tests/gen_constant_array_size_tests.py
index c395b1a..906f7c4 100644
--- a/generated_tests/gen_constant_array_size_tests.py
+++ b/generated_tests/gen_constant_array_size_tests.py
@@ -198,8 +198,15 @@ class ParserTest(object):
parser_test += self.make_shader()
filename = self.filename()
dirname = os.path.dirname(filename)
+
if not os.path.exists(dirname):
- os.makedirs(dirname)
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
+
with open(filename, 'w') as f:
f.write(parser_test)
diff --git a/generated_tests/gen_constant_array_size_tests_fp64.py b/generated_tests/gen_constant_array_size_tests_fp64.py
index a54598b..be1fe09 100644
--- a/generated_tests/gen_constant_array_size_tests_fp64.py
+++ b/generated_tests/gen_constant_array_size_tests_fp64.py
@@ -199,8 +199,15 @@ class ParserTest(object):
parser_test += self.make_shader()
filename = self.filename()
dirname = os.path.dirname(filename)
+
if not os.path.exists(dirname):
- os.makedirs(dirname)
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
+
with open(filename, 'w') as f:
f.write(parser_test)
diff --git a/generated_tests/gen_interpolation_tests.py b/generated_tests/gen_interpolation_tests.py
index 4f1428b..e839bbc 100644
--- a/generated_tests/gen_interpolation_tests.py
+++ b/generated_tests/gen_interpolation_tests.py
@@ -267,8 +267,15 @@ class Test(object):
def generate(self):
filename = self.filename()
dirname = os.path.dirname(filename)
+
if not os.path.exists(dirname):
- os.makedirs(dirname)
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
+
with open(filename, 'w') as f:
f.write(TEMPLATE.render(args=self))
diff --git a/generated_tests/gen_outerproduct_invalid_params.py b/generated_tests/gen_outerproduct_invalid_params.py
index c872e9f..77807aa 100644
--- a/generated_tests/gen_outerproduct_invalid_params.py
+++ b/generated_tests/gen_outerproduct_invalid_params.py
@@ -32,7 +32,12 @@ def main():
dirname = os.path.join('spec', 'glsl-1.20', 'compiler',
'built-in-functions')
if not os.path.exists(dirname):
- os.makedirs(dirname)
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
for type_ in ['int', 'float', 'bool', 'bvec2', 'bvec3', 'bvec4', 'mat2',
'mat2x2', 'mat2x3', 'mat2x4', 'mat3', 'mat3x2', 'mat3x3',
diff --git a/generated_tests/gen_outerproduct_tests.py b/generated_tests/gen_outerproduct_tests.py
index 80a6ad8..9a90e22 100644
--- a/generated_tests/gen_outerproduct_tests.py
+++ b/generated_tests/gen_outerproduct_tests.py
@@ -38,8 +38,12 @@ def main():
""" Generate tests """
dirname = os.path.join('spec', 'glsl-1.20', 'execution')
if not os.path.exists(dirname):
- os.makedirs(dirname)
-
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
for c, r in itertools.product(xrange(2, 5), repeat=2):
vecs = [
diff --git a/generated_tests/gen_shader_bit_encoding_tests.py b/generated_tests/gen_shader_bit_encoding_tests.py
index c879255..ded3a78 100644
--- a/generated_tests/gen_shader_bit_encoding_tests.py
+++ b/generated_tests/gen_shader_bit_encoding_tests.py
@@ -140,7 +140,12 @@ def main():
dirname = os.path.join('spec', api.lower(), 'execution',
'built-in-functions')
if not os.path.exists(dirname):
- os.makedirs(dirname)
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
for func, attrib in FUNCS.iteritems():
for execution_stage in ('vs', 'fs'):
diff --git a/generated_tests/gen_shader_image_load_store_tests.py b/generated_tests/gen_shader_image_load_store_tests.py
index b292809..6084659 100644
--- a/generated_tests/gen_shader_image_load_store_tests.py
+++ b/generated_tests/gen_shader_image_load_store_tests.py
@@ -144,7 +144,12 @@ def gen(name, src, tests):
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
- os.makedirs(dirname)
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
with open(filename, 'w') as f:
f.write(template.render(header = gen_header, **t))
diff --git a/generated_tests/gen_texture_lod_tests.py b/generated_tests/gen_texture_lod_tests.py
index a2f43fa..52f5870 100644
--- a/generated_tests/gen_texture_lod_tests.py
+++ b/generated_tests/gen_texture_lod_tests.py
@@ -76,7 +76,12 @@ def main():
"""
dirname = 'spec/arb_shader_texture_lod/compiler'
if not os.path.exists(dirname):
- os.makedirs(dirname)
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
for params in LOD_TESTS:
name = os.path.join(
diff --git a/generated_tests/gen_texture_query_lod_tests.py b/generated_tests/gen_texture_query_lod_tests.py
index 1605204..886ca60 100644
--- a/generated_tests/gen_texture_query_lod_tests.py
+++ b/generated_tests/gen_texture_query_lod_tests.py
@@ -86,7 +86,12 @@ def main():
dirname = os.path.join("spec", api.lower(), "compiler",
"built-in-functions")
if not os.path.exists(dirname):
- os.makedirs(dirname)
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
for sampler_type, coord_type in SAMPLER_TYPE_TO_COORD_TYPE.iteritems():
requirements = [requirement['extensions']] if requirement['extensions'] else []
diff --git a/generated_tests/gen_uniform_initializer_tests.py b/generated_tests/gen_uniform_initializer_tests.py
index 0a1d908..fc5e0bb 100644
--- a/generated_tests/gen_uniform_initializer_tests.py
+++ b/generated_tests/gen_uniform_initializer_tests.py
@@ -78,7 +78,12 @@ def generate_tests(type_list, base_name, major, minor):
'execution',
'uniform-initializer')
if not os.path.exists(dirname):
- os.makedirs(dirname)
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
for target in ("vs", "fs"):
for t in ALL_TEMPLATES:
diff --git a/generated_tests/genclbuiltins.py b/generated_tests/genclbuiltins.py
index 571930d..9dd371c 100644
--- a/generated_tests/genclbuiltins.py
+++ b/generated_tests/genclbuiltins.py
@@ -355,7 +355,12 @@ def print_test(f, fnName, argType, functionDef, tests, numTests, vecSize, tss):
def gen(types, minVersions, functions, testDefs, dirName):
# Create the output directory if required
if not os.path.exists(dirName):
- os.makedirs(dirName)
+ try:
+ os.makedirs(dirName)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
# Loop over all data types being tested. Create one output file per data
# type
diff --git a/generated_tests/generate-cl-store-tests.py b/generated_tests/generate-cl-store-tests.py
index 0aa7fe6..f68637e 100644
--- a/generated_tests/generate-cl-store-tests.py
+++ b/generated_tests/generate-cl-store-tests.py
@@ -31,7 +31,12 @@ VEC_SIZES = ['', '2', '4', '8', '16']
dirName = os.path.join("cl", "store")
if not os.path.exists(dirName):
- os.makedirs(dirName)
+ try:
+ os.makedirs(dirName)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
def gen_array(size):
diff --git a/generated_tests/interpolation-qualifier-built-in-variable.py b/generated_tests/interpolation-qualifier-built-in-variable.py
index 96def23..9b551e0 100644
--- a/generated_tests/interpolation-qualifier-built-in-variable.py
+++ b/generated_tests/interpolation-qualifier-built-in-variable.py
@@ -171,9 +171,13 @@ def main():
"""main function."""
dirname = os.path.join('spec', 'glsl-1.30', 'linker',
'interpolation-qualifiers')
-
if not os.path.exists(dirname):
- os.makedirs(dirname)
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno == 17: # file exists
+ pass
+ raise
for fs_mode, vs_mode in itertools.product(INTERPOLATION_MODES, repeat=2):
make_fs_vs_tests(fs_mode, vs_mode, dirname)
--
2.2.0
More information about the Piglit
mailing list