Commit 68829470 authored by Dylan Baker's avatar Dylan Baker

generated_tests: Actually catch exception in os.makedirs

Patch b59ff71e was supposed to fix os.makedirs exceptions, but falls
short because of a missing else statement that causes all of the caught
exceptions to fall back to raise.

This corrects, it also pulls the duplicate functions out into a shared
module.

v2: - remove accidentally included hunk (Mark)
v3: - Actually include the modules directory in the commit (Mark)
Signed-off-by: default avatarDylan Baker <dylanx.c.baker@intel.com>
Reviewed-by: Mark Janes's avatarMark Janes <mark.a.janes@intel.com>
parent 828f610a
......@@ -43,6 +43,7 @@ from math import copysign, fabs, fmod, frexp, isinf, isnan, modf
from numpy import int8, int16, uint8, uint16, uint32, float32
from templates import template_dir
from modules import utils
TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
......@@ -1027,13 +1028,7 @@ class ShaderTest(object):
def write_file(self):
dirname = os.path.dirname(self.filename)
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
with open(self.filename, "w") as f:
f.write(self.__template.render(func=self.__func_info))
......
......@@ -52,6 +52,8 @@ import os
import os.path
import sys
from modules import utils
def compute_offset_and_scale(test_vectors):
"""Compute scale and offset values such that for each result in
......@@ -537,15 +539,7 @@ class ShaderTest(object):
shader_test += self.make_test()
filename = self.filename()
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
with open(filename, 'w') as f:
f.write(shader_test)
......
......@@ -52,6 +52,8 @@ import os
import os.path
import sys
from modules import utils
def compute_offset_and_scale(test_vectors):
"""Compute scale and offset values such that for each result in
......@@ -507,15 +509,7 @@ class ShaderTest(object):
shader_test += self.make_test()
filename = self.filename()
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
with open(filename, 'w') as f:
f.write(shader_test)
......
......@@ -25,6 +25,7 @@ import re
import os
from templates import template_file
from modules import utils
TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]),
'template.shader_test.mako')
......@@ -73,13 +74,7 @@ def main():
""" Main function """
dirname = os.path.join('spec', 'glsl-1.20', 'execution',
'built-in-functions')
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
for test_id, x in enumerate(TEST_VECTORS, start=2):
# make equal tests
......
......@@ -40,6 +40,7 @@ import optparse
import os
import os.path
from modules import utils
class ParserTest(object):
"""Class used to build a test of a single built-in. This is an
......@@ -198,15 +199,7 @@ class ParserTest(object):
parser_test += self.make_shader()
filename = self.filename()
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
with open(filename, 'w') as f:
f.write(parser_test)
......
......@@ -40,6 +40,7 @@ import optparse
import os
import os.path
from modules import utils
class ParserTest(object):
"""Class used to build a test of a single built-in. This is an
......@@ -199,15 +200,7 @@ class ParserTest(object):
parser_test += self.make_shader()
filename = self.filename()
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
with open(filename, 'w') as f:
f.write(parser_test)
......
......@@ -71,6 +71,7 @@ from __future__ import print_function
import os
from templates import template_file
from modules import utils
TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]),
'template.shader_test.mako')
......@@ -267,15 +268,7 @@ class Test(object):
def generate(self):
filename = self.filename()
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
with open(filename, 'w') as f:
f.write(TEMPLATE.render(args=self))
......
......@@ -26,6 +26,7 @@ import os
import itertools
from templates import template_dir
from modules import utils
TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
......@@ -89,8 +90,7 @@ def all_tests():
def main():
dirname = os.path.join('spec', 'glsl-1.10', 'compiler', 'expressions')
if not os.path.exists(dirname):
os.makedirs(dirname)
utils.safe_makedirs(dirname)
for args in all_tests():
generate(dirname, *args)
......
......@@ -22,6 +22,7 @@ from __future__ import print_function
import os
from templates import template_file
from modules import utils
TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]),
'template.vert.mako')
......@@ -31,13 +32,7 @@ def main():
""" Generate tests """
dirname = os.path.join('spec', 'glsl-1.20', 'compiler',
'built-in-functions')
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
for type_ in ['int', 'float', 'bool', 'bvec2', 'bvec3', 'bvec4', 'mat2',
'mat2x2', 'mat2x3', 'mat2x4', 'mat3', 'mat3x2', 'mat3x3',
......
......@@ -26,6 +26,7 @@ import itertools
import collections
from templates import template_file
from modules import utils
TEMPLATE = template_file(os.path.splitext(os.path.basename(__file__))[0],
'template.shader_test.mako')
......@@ -37,13 +38,8 @@ Parameters = collections.namedtuple(
def main():
""" Generate tests """
dirname = os.path.join('spec', 'glsl-1.20', 'execution')
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
for c, r in itertools.product(xrange(2, 5), repeat=2):
vecs = [
......
......@@ -27,6 +27,7 @@ import os
from operator import neg
from templates import template_file
from modules import utils
TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]),
'template.shader_test.mako')
......@@ -139,13 +140,7 @@ def main():
dirname = os.path.join('spec', api.lower(), 'execution',
'built-in-functions')
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
for func, attrib in FUNCS.iteritems():
for execution_stage in ('vs', 'fs'):
......
......@@ -26,6 +26,8 @@ import os.path
from mako.template import Template
from textwrap import dedent
from modules import utils
def gen_header(status):
"""
......@@ -143,13 +145,7 @@ def gen(name, src, tests):
print(filename)
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
with open(filename, 'w') as f:
f.write(template.render(header = gen_header, **t))
......
......@@ -25,6 +25,7 @@ import os
import collections
from templates import template_dir
from modules import utils
TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
......@@ -75,13 +76,7 @@ def main():
"""
dirname = 'spec/arb_shader_texture_lod/compiler'
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
for params in LOD_TESTS:
name = os.path.join(
......
......@@ -26,6 +26,7 @@ import os
import os.path
from templates import template_file
from modules import utils
TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]),
'template.glsl_parser_test.mako')
......@@ -85,13 +86,7 @@ def main():
lod = 'Lod' if api == 'glsl-4.00' else 'LOD'
dirname = os.path.join("spec", api.lower(), "compiler",
"built-in-functions")
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
for sampler_type, coord_type in SAMPLER_TYPE_TO_COORD_TYPE.iteritems():
requirements = [requirement['extensions']] if requirement['extensions'] else []
......
......@@ -25,6 +25,7 @@ from __future__ import print_function
import os
from templates import template_dir
from modules import utils
TEMPLATES = template_dir(os.path.splitext(os.path.basename(__file__))[0])
......@@ -77,13 +78,7 @@ def generate_tests(type_list, base_name, major, minor):
'glsl-{0}.{1}'.format(major, minor),
'execution',
'uniform-initializer')
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
for target in ("vs", "fs"):
for t in ALL_TEMPLATES:
......@@ -138,8 +133,7 @@ def generate_array_tests(type_list, base_name, major, minor):
'glsl-{0}.{1}'.format(major, minor),
'execution',
'uniform-initializer')
if not os.path.exists(dirname):
os.makedirs(dirname)
utils.safe_makedirs(dirname)
def parts():
"""Generate parts."""
......
......@@ -26,17 +26,13 @@
import os
import textwrap
from modules import utils
TYPES = ['char', 'uchar', 'short', 'ushort', 'int', 'uint', 'long', 'ulong', 'float', 'double']
VEC_SIZES = ['', '2', '4', '8', '16']
dirName = os.path.join("cl", "store")
if not os.path.exists(dirName):
try:
os.makedirs(dirName)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
def gen_array(size):
......
......@@ -28,6 +28,7 @@ import os
import itertools
from templates import template_dir
from modules import utils
TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
......@@ -171,13 +172,7 @@ def main():
"""main function."""
dirname = os.path.join('spec', 'glsl-1.30', 'linker',
'interpolation-qualifiers')
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
utils.safe_makedirs(dirname)
for fs_mode, vs_mode in itertools.product(INTERPOLATION_MODES, repeat=2):
make_fs_vs_tests(fs_mode, vs_mode, dirname)
......
# Copyright (c) 2014 Intel Corporation
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Helper functions for test generators."""
from __future__ import print_function, absolute_import
import os
import errno
def safe_makedirs(dirs):
"""A safe function for creating a directory tree.
This function wraps os.makedirs, and provides a couple of sanity checks,
first, if the directory already exists it doesn't try to create it, and
second if the directory comes into existence between the check and creation
time (like if another generator creates it) then the exception will be
caught.
"""
if not os.path.exists(dirs):
try:
os.makedirs(dirs)
except OSError as e:
if e.errno == errno.EEXIST:
pass
else:
raise
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