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 ...@@ -43,6 +43,7 @@ from math import copysign, fabs, fmod, frexp, isinf, isnan, modf
from numpy import int8, int16, uint8, uint16, uint32, float32 from numpy import int8, int16, uint8, uint16, uint32, float32
from templates import template_dir from templates import template_dir
from modules import utils
TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0])) TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
...@@ -1027,13 +1028,7 @@ class ShaderTest(object): ...@@ -1027,13 +1028,7 @@ class ShaderTest(object):
def write_file(self): def write_file(self):
dirname = os.path.dirname(self.filename) dirname = os.path.dirname(self.filename)
if not os.path.exists(dirname): utils.safe_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: with open(self.filename, "w") as f:
f.write(self.__template.render(func=self.__func_info)) f.write(self.__template.render(func=self.__func_info))
......
...@@ -52,6 +52,8 @@ import os ...@@ -52,6 +52,8 @@ import os
import os.path import os.path
import sys import sys
from modules import utils
def compute_offset_and_scale(test_vectors): def compute_offset_and_scale(test_vectors):
"""Compute scale and offset values such that for each result in """Compute scale and offset values such that for each result in
...@@ -537,15 +539,7 @@ class ShaderTest(object): ...@@ -537,15 +539,7 @@ class ShaderTest(object):
shader_test += self.make_test() shader_test += self.make_test()
filename = self.filename() filename = self.filename()
dirname = os.path.dirname(filename) dirname = os.path.dirname(filename)
utils.safe_makedirs(dirname)
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
with open(filename, 'w') as f: with open(filename, 'w') as f:
f.write(shader_test) f.write(shader_test)
......
...@@ -52,6 +52,8 @@ import os ...@@ -52,6 +52,8 @@ import os
import os.path import os.path
import sys import sys
from modules import utils
def compute_offset_and_scale(test_vectors): def compute_offset_and_scale(test_vectors):
"""Compute scale and offset values such that for each result in """Compute scale and offset values such that for each result in
...@@ -507,15 +509,7 @@ class ShaderTest(object): ...@@ -507,15 +509,7 @@ class ShaderTest(object):
shader_test += self.make_test() shader_test += self.make_test()
filename = self.filename() filename = self.filename()
dirname = os.path.dirname(filename) dirname = os.path.dirname(filename)
utils.safe_makedirs(dirname)
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
with open(filename, 'w') as f: with open(filename, 'w') as f:
f.write(shader_test) f.write(shader_test)
......
...@@ -25,6 +25,7 @@ import re ...@@ -25,6 +25,7 @@ import re
import os import os
from templates import template_file from templates import template_file
from modules import utils
TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]), TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]),
'template.shader_test.mako') 'template.shader_test.mako')
...@@ -73,13 +74,7 @@ def main(): ...@@ -73,13 +74,7 @@ def main():
""" Main function """ """ Main function """
dirname = os.path.join('spec', 'glsl-1.20', 'execution', dirname = os.path.join('spec', 'glsl-1.20', 'execution',
'built-in-functions') 'built-in-functions')
if not os.path.exists(dirname): utils.safe_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): for test_id, x in enumerate(TEST_VECTORS, start=2):
# make equal tests # make equal tests
......
...@@ -40,6 +40,7 @@ import optparse ...@@ -40,6 +40,7 @@ import optparse
import os import os
import os.path import os.path
from modules import utils
class ParserTest(object): class ParserTest(object):
"""Class used to build a test of a single built-in. This is an """Class used to build a test of a single built-in. This is an
...@@ -198,15 +199,7 @@ class ParserTest(object): ...@@ -198,15 +199,7 @@ class ParserTest(object):
parser_test += self.make_shader() parser_test += self.make_shader()
filename = self.filename() filename = self.filename()
dirname = os.path.dirname(filename) dirname = os.path.dirname(filename)
utils.safe_makedirs(dirname)
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
with open(filename, 'w') as f: with open(filename, 'w') as f:
f.write(parser_test) f.write(parser_test)
......
...@@ -40,6 +40,7 @@ import optparse ...@@ -40,6 +40,7 @@ import optparse
import os import os
import os.path import os.path
from modules import utils
class ParserTest(object): class ParserTest(object):
"""Class used to build a test of a single built-in. This is an """Class used to build a test of a single built-in. This is an
...@@ -199,15 +200,7 @@ class ParserTest(object): ...@@ -199,15 +200,7 @@ class ParserTest(object):
parser_test += self.make_shader() parser_test += self.make_shader()
filename = self.filename() filename = self.filename()
dirname = os.path.dirname(filename) dirname = os.path.dirname(filename)
utils.safe_makedirs(dirname)
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
with open(filename, 'w') as f: with open(filename, 'w') as f:
f.write(parser_test) f.write(parser_test)
......
...@@ -71,6 +71,7 @@ from __future__ import print_function ...@@ -71,6 +71,7 @@ from __future__ import print_function
import os import os
from templates import template_file from templates import template_file
from modules import utils
TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]), TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]),
'template.shader_test.mako') 'template.shader_test.mako')
...@@ -267,15 +268,7 @@ class Test(object): ...@@ -267,15 +268,7 @@ class Test(object):
def generate(self): def generate(self):
filename = self.filename() filename = self.filename()
dirname = os.path.dirname(filename) dirname = os.path.dirname(filename)
utils.safe_makedirs(dirname)
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
with open(filename, 'w') as f: with open(filename, 'w') as f:
f.write(TEMPLATE.render(args=self)) f.write(TEMPLATE.render(args=self))
......
...@@ -26,6 +26,7 @@ import os ...@@ -26,6 +26,7 @@ import os
import itertools import itertools
from templates import template_dir from templates import template_dir
from modules import utils
TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0])) TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
...@@ -89,8 +90,7 @@ def all_tests(): ...@@ -89,8 +90,7 @@ def all_tests():
def main(): def main():
dirname = os.path.join('spec', 'glsl-1.10', 'compiler', 'expressions') dirname = os.path.join('spec', 'glsl-1.10', 'compiler', 'expressions')
if not os.path.exists(dirname): utils.safe_makedirs(dirname)
os.makedirs(dirname)
for args in all_tests(): for args in all_tests():
generate(dirname, *args) generate(dirname, *args)
......
...@@ -22,6 +22,7 @@ from __future__ import print_function ...@@ -22,6 +22,7 @@ from __future__ import print_function
import os import os
from templates import template_file from templates import template_file
from modules import utils
TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]), TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]),
'template.vert.mako') 'template.vert.mako')
...@@ -31,13 +32,7 @@ def main(): ...@@ -31,13 +32,7 @@ def main():
""" Generate tests """ """ Generate tests """
dirname = os.path.join('spec', 'glsl-1.20', 'compiler', dirname = os.path.join('spec', 'glsl-1.20', 'compiler',
'built-in-functions') 'built-in-functions')
if not os.path.exists(dirname): utils.safe_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', for type_ in ['int', 'float', 'bool', 'bvec2', 'bvec3', 'bvec4', 'mat2',
'mat2x2', 'mat2x3', 'mat2x4', 'mat3', 'mat3x2', 'mat3x3', 'mat2x2', 'mat2x3', 'mat2x4', 'mat3', 'mat3x2', 'mat3x3',
......
...@@ -26,6 +26,7 @@ import itertools ...@@ -26,6 +26,7 @@ import itertools
import collections import collections
from templates import template_file from templates import template_file
from modules import utils
TEMPLATE = template_file(os.path.splitext(os.path.basename(__file__))[0], TEMPLATE = template_file(os.path.splitext(os.path.basename(__file__))[0],
'template.shader_test.mako') 'template.shader_test.mako')
...@@ -37,13 +38,8 @@ Parameters = collections.namedtuple( ...@@ -37,13 +38,8 @@ Parameters = collections.namedtuple(
def main(): def main():
""" Generate tests """ """ Generate tests """
dirname = os.path.join('spec', 'glsl-1.20', 'execution') dirname = os.path.join('spec', 'glsl-1.20', 'execution')
if not os.path.exists(dirname): utils.safe_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): for c, r in itertools.product(xrange(2, 5), repeat=2):
vecs = [ vecs = [
......
...@@ -27,6 +27,7 @@ import os ...@@ -27,6 +27,7 @@ import os
from operator import neg from operator import neg
from templates import template_file from templates import template_file
from modules import utils
TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]), TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]),
'template.shader_test.mako') 'template.shader_test.mako')
...@@ -139,13 +140,7 @@ def main(): ...@@ -139,13 +140,7 @@ def main():
dirname = os.path.join('spec', api.lower(), 'execution', dirname = os.path.join('spec', api.lower(), 'execution',
'built-in-functions') 'built-in-functions')
if not os.path.exists(dirname): utils.safe_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 func, attrib in FUNCS.iteritems():
for execution_stage in ('vs', 'fs'): for execution_stage in ('vs', 'fs'):
......
...@@ -26,6 +26,8 @@ import os.path ...@@ -26,6 +26,8 @@ import os.path
from mako.template import Template from mako.template import Template
from textwrap import dedent from textwrap import dedent
from modules import utils
def gen_header(status): def gen_header(status):
""" """
...@@ -143,13 +145,7 @@ def gen(name, src, tests): ...@@ -143,13 +145,7 @@ def gen(name, src, tests):
print(filename) print(filename)
dirname = os.path.dirname(filename) dirname = os.path.dirname(filename)
if not os.path.exists(dirname): utils.safe_makedirs(dirname)
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
with open(filename, 'w') as f: with open(filename, 'w') as f:
f.write(template.render(header = gen_header, **t)) f.write(template.render(header = gen_header, **t))
......
...@@ -25,6 +25,7 @@ import os ...@@ -25,6 +25,7 @@ import os
import collections import collections
from templates import template_dir from templates import template_dir
from modules import utils
TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0])) TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
...@@ -75,13 +76,7 @@ def main(): ...@@ -75,13 +76,7 @@ def main():
""" """
dirname = 'spec/arb_shader_texture_lod/compiler' dirname = 'spec/arb_shader_texture_lod/compiler'
if not os.path.exists(dirname): utils.safe_makedirs(dirname)
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
for params in LOD_TESTS: for params in LOD_TESTS:
name = os.path.join( name = os.path.join(
......
...@@ -26,6 +26,7 @@ import os ...@@ -26,6 +26,7 @@ import os
import os.path import os.path
from templates import template_file from templates import template_file
from modules import utils
TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]), TEMPLATE = template_file(os.path.basename(os.path.splitext(__file__)[0]),
'template.glsl_parser_test.mako') 'template.glsl_parser_test.mako')
...@@ -85,13 +86,7 @@ def main(): ...@@ -85,13 +86,7 @@ def main():
lod = 'Lod' if api == 'glsl-4.00' else 'LOD' lod = 'Lod' if api == 'glsl-4.00' else 'LOD'
dirname = os.path.join("spec", api.lower(), "compiler", dirname = os.path.join("spec", api.lower(), "compiler",
"built-in-functions") "built-in-functions")
if not os.path.exists(dirname): utils.safe_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(): for sampler_type, coord_type in SAMPLER_TYPE_TO_COORD_TYPE.iteritems():
requirements = [requirement['extensions']] if requirement['extensions'] else [] requirements = [requirement['extensions']] if requirement['extensions'] else []
......
...@@ -25,6 +25,7 @@ from __future__ import print_function ...@@ -25,6 +25,7 @@ from __future__ import print_function
import os import os
from templates import template_dir from templates import template_dir
from modules import utils
TEMPLATES = template_dir(os.path.splitext(os.path.basename(__file__))[0]) TEMPLATES = template_dir(os.path.splitext(os.path.basename(__file__))[0])
...@@ -77,13 +78,7 @@ def generate_tests(type_list, base_name, major, minor): ...@@ -77,13 +78,7 @@ def generate_tests(type_list, base_name, major, minor):
'glsl-{0}.{1}'.format(major, minor), 'glsl-{0}.{1}'.format(major, minor),
'execution', 'execution',
'uniform-initializer') 'uniform-initializer')
if not os.path.exists(dirname): utils.safe_makedirs(dirname)
try:
os.makedirs(dirname)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
for target in ("vs", "fs"): for target in ("vs", "fs"):
for t in ALL_TEMPLATES: for t in ALL_TEMPLATES:
...@@ -138,8 +133,7 @@ def generate_array_tests(type_list, base_name, major, minor): ...@@ -138,8 +133,7 @@ def generate_array_tests(type_list, base_name, major, minor):
'glsl-{0}.{1}'.format(major, minor), 'glsl-{0}.{1}'.format(major, minor),
'execution', 'execution',
'uniform-initializer') 'uniform-initializer')
if not os.path.exists(dirname): utils.safe_makedirs(dirname)
os.makedirs(dirname)
def parts(): def parts():
"""Generate parts.""" """Generate parts."""
......
...@@ -26,17 +26,13 @@ ...@@ -26,17 +26,13 @@
import os import os
import textwrap import textwrap
from modules import utils
TYPES = ['char', 'uchar', 'short', 'ushort', 'int', 'uint', 'long', 'ulong', 'float', 'double'] TYPES = ['char', 'uchar', 'short', 'ushort', 'int', 'uint', 'long', 'ulong', 'float', 'double']
VEC_SIZES = ['', '2', '4', '8', '16'] VEC_SIZES = ['', '2', '4', '8', '16']
dirName = os.path.join("cl", "store") dirName = os.path.join("cl", "store")
if not os.path.exists(dirName): utils.safe_makedirs(dirname)
try:
os.makedirs(dirName)
except OSError as e:
if e.errno == 17: # file exists
pass
raise
def gen_array(size): def gen_array(size):
......
...@@ -28,6 +28,7 @@ import os ...@@ -28,6 +28,7 @@ import os
import itertools import itertools
from templates import template_dir from templates import template_dir
from modules import utils
TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0])) TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
...@@ -171,13 +172,7 @@ def main(): ...@@ -171,13 +172,7 @@ def main():
"""main function.""" """main function."""
dirname = os.path.join('spec', 'glsl-1.30', 'linker', dirname = os.path.join('spec', 'glsl-1.30', 'linker',
'interpolation-qualifiers') 'interpolation-qualifiers')
if not os.path.exists(dirname): utils.safe_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): for fs_mode, vs_mode in itertools.product(INTERPOLATION_MODES, repeat=2):
make_fs_vs_tests(fs_mode, vs_mode, dirname) 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