Commit b59ff71e authored by Dylan Baker's avatar Dylan Baker

generated_tests: Except error for os.makedirs

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: default avatarDylan Baker <dylanx.c.baker@intel.com>
parent c1cf7865
......@@ -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))
......
......@@ -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)
......
......@@ -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)
......
......@@ -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
......
......@@ -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)
......
......@@ -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)
......
......@@ -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))
......
......@@ -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',
......
......@@ -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 = [
......
......@@ -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'):
......
......@@ -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))
......
......@@ -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(
......
......@@ -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 []
......
......@@ -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:
......
......@@ -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
......
......@@ -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):
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment