def check_sets(old, ostat, new, nstat, set_): """ Check that the statuses are added to the correct set """ old['tests']['sometest']['result'] = ostat new['tests']['sometest']['result'] = nstat with utils.tempfile(json.dumps(old)) as ofile: with utils.tempfile(json.dumps(new)) as nfile: summ = summary.Summary([ofile, nfile]) print(summ.tests) nt.assert_equal(1, len(summ.tests[set_]), msg="{0} was not appended".format(set_))
def glslparser_exetensions_seperators(): """ GlslParserTest() can only have [A-Za-z_] as characters This test generates a number of tests that should catch the majority of errors relating to seperating extensions in the config block of a glslparser test """ @nt.raises(exceptions.PiglitFatalError) def check_bad_character(tfile): """ Check for bad characters """ glsl.GLSLParserTest(tfile) problems = [ ('comma seperator', '// require_extensions: ARB_ham, ARB_turkey\n'), ('semi-colon seperator', '// require_extensions: ARB_ham; ARB_turkey\n'), ('trailing semi-colon', '// require_extensions: ARB_ham ARB_turkey\n;'), ('Non-alpha character', '// require_extensions: ARB_$$$\n'), ] content = ('// [config]\n' '// expect_result: pass\n' '// glsl_version: 1.10\n' '{}' '// [end config]\n') for name, value in problems: test = content.format(value) with utils.tempfile(test) as tfile: check_bad_character.description = ( 'test.glsl_parser_test.GLSLParserTest: require_extensions {0} ' 'should raise an error'.format(name)) yield check_bad_character, tfile
def test_good_extensions(): """ Generates tests with good extensions which shouldn't raise errors """ @utils.not_raises(exceptions.PiglitFatalError) def check_good_extension(file_): """ A good extension should not raise a GLSLParserException """ glsl.GLSLParserTest(file_) content = ('// [config]\n' '// expect_result: pass\n' '// glsl_version: 1.10\n' '// require_extensions: {}\n' '// [end config]\n') options = [ 'GL_EXT_texture_array', 'GL_EXT_texture_array ARB_example', '!GL_ARB_ham_sandwhich', ] for x in options: test = content.format(x) check_good_extension.description = ( 'test.glsl_parser_test.GLSLParserTest: ' 'require_extension {} is valid'.format(x)) with utils.tempfile(test) as tfile: yield check_good_extension, tfile
def _make_result(data): """Write data to a file and return a result.TestrunResult object.""" with utils.tempfile( json.dumps(data, default=backends.json.piglit_encoder)) as t: with open(t, 'r') as f: # pylint: disable=protected-access return backends.json._update_three_to_four(backends.json._load(f))
def test_find_config_start(): """test.glsl_parser_test.GLSLParserTest: successfully finds [config] section """ content = ('// [config]\n' '// glsl_version: 1.10\n' '//\n') with utils.tempfile(content) as tfile: glsl.GLSLParserTest(tfile)
def test_no_expect_result(): """test.glsl_parser_test.GLSLParserTest: exception is raised if "expect_result" key is missing """ content = ('// [config]\n' '// glsl_version: 1.10\n' '//\n') with utils.tempfile(content) as tfile: glsl.GLSLParserTest(tfile)
def test_no_glsl_version(): """test.glsl_parser_test.GLSLParserTest: exception is raised if "glsl_version" key is missing """ content = ('// [config]\n' '// expect_result: pass\n' '// [end config]\n') with utils.tempfile(content) as tfile: glsl.GLSLParserTest(tfile)
def test_info_split(self): """backends.json.update_results (0 -> 1): info can split into any number of elements""" data = copy.copy(self.DATA) data['tests']['sometest']['info'] = \ 'Returncode: 1\n\nErrors:stderr\n\nOutput: stdout\n\nmore\n\nstuff' with utils.tempfile(json.dumps(data)) as t: with open(t, 'r') as f: backends.json._update_zero_to_one(backends.json._load(f))
def setup_class(cls): """Class setup. Create a TestrunResult with v4 data.""" cls.DATA['tests']['a@test'] = cls.DATA['tests']['a@test'].to_json() cls.DATA['tests']['a@test']['time'] = 1.2 with utils.tempfile( json.dumps(cls.DATA, default=backends.json.piglit_encoder)) as t: with open(t, 'r') as f: cls.result = backends.json._update_seven_to_eight( backends.json._load(f))
def test_no_config_start(): """test.glsl_parser_test.GLSLParserTest: exception is raised if [config] section is missing """ content = "// expect_result: pass\n" "// glsl_version: 1.10\n" "// [end config]\n" with utils.tempfile(content) as tfile: with nt.assert_raises(glsl.GLSLParserNoConfigError) as exc: glsl.GLSLParserTest(tfile) nt.assert_equal( exc.exception, "No [config] section found!", msg="No config section was found and no exception raised" )
def test_bad_section_name(): """test.glsl_parser_test.GLSLParserTest: A section name not in the _CONFIG_KEYS name raises an error""" content = ('// [config]\n' '// expect_result: pass\n' '// glsl_version: 1.10\n' '// new_awesome_key: foo\n' '// [end config]\n') with utils.tempfile(content) as tfile: glsl.GLSLParserTest(tfile)
def test_parse_gl_test_no_decimal(): """test.shader_test.ShaderTest: raises if version lacks decminal""" data = ('[require]\n' 'GL = 2\n') with utils.tempfile(data) as temp: with nt.assert_raises(exceptions.PiglitFatalError) as exc: testm.ShaderTest(temp) nt.assert_equal(exc.exception, "No GL version set", msg="A GL version was passed without a decimal, " "which should have raised an exception, but " "did not")
def setup_class(cls): """Class setup. Create a TestrunResult with v4 data.""" cls.old = cls.DATA['tests'].keys() cls.new = [ "a@test@group@of@great@length", "has@windows", ] with utils.tempfile(json.dumps(cls.DATA)) as t: with open(t, 'r') as f: cls.result = backends.json._update_four_to_five(backends.json._load(f))
def setup_class(cls): data = copy.deepcopy(utils.JSON_DATA) data['tests']['with_subtests']['result'] = 'pass' data['tests']['with_subtests']['subtest']['subtest1'] = 'fail' data['tests']['with_subtests']['subtest']['subtest2'] = 'warn' data['tests']['with_subtests']['subtest']['subtest3'] = 'crash' data['tests']['is_skip']['result'] = 'skip' with utils.tempfile(json.dumps(data)) as sumfile: cls.summ = summary.Summary([sumfile])
def test_find_requirements_gl_requirements(): """test.shader_test.ShaderTest: populates gl_requirements properly""" data = ('[require]\n' 'GL = 2.0\n' 'GL_ARB_ham_sandwhich\n') with utils.tempfile(data) as temp: test = testm.ShaderTest(temp) nt.eq_(test.gl_required, set(['GL_ARB_ham_sandwhich']))
def test_parse_gles3_test(): """test.shader_test.ShaderTest: Identifies GLES3 tests successfully""" data = ('[require]\n' 'GL ES >= 3.0\n' 'GLSL ES >= 3.00\n') with utils.tempfile(data) as temp: test = testm.ShaderTest(temp) nt.assert_equal( os.path.basename(test.command[0]), "shader_runner_gles3", msg="This test should have run with shader_runner_gles3, " "but instead ran with " + os.path.basename(test.command[0]))
def test_parse_listfile_return(): """core.parse_listfile(): returns a list-like object Given a file with a newline seperated list of results, parse_listfile should return a list of files with no whitespace """ contents = "/tmp/foo\n/tmp/bar\n" with utils.tempfile(contents) as tfile: results = core.parse_listfile(tfile) assert isinstance(results, collections.Container)
def test_glslparser_initializer(): """test.glsl_parser_test.GLSLParserTest: clas initializes correctly""" content = textwrap.dedent("""\ /* * [config] * expect_result: pass * glsl_version: 1.10 * [end config] */ """) with utils.tempfile(content) as f: glsl.GLSLParserTest(f)
def setup_class(cls): data = { "results_version": 2, "name": "test", "options": { "profile": ['quick'], "dmesg": False, "verbose": False, "platform": "gbm", "sync": False, "valgrind": False, "filter": [], "concurrent": "all", "test_count": 0, "exclude_tests": [], "exclude_filter": [], "env": { "lspci": "stuff", "uname": "more stuff", "glxinfo": "and stuff", "wglinfo": "stuff" } }, "tests": { "test/is/a/test": { "returncode": 0, "err": None, "environment": None, "command": "foo", "result": "skip", "time": 0.123, "out": None, }, "Test/Is/SomE/Other1/Test": { "returncode": 0, "err": None, "environment": None, "command": "foo", "result": "skip", "time": 0.123, "out": None, } } } with utils.tempfile( json.dumps(data, default=backends.json.piglit_encoder)) as t: with open(t, 'r') as f: # pylint: disable=protected-access cls.RESULT = backends.json._update_two_to_three(backends.json._load(f))
def test_parse_listfile_tilde(): """core.parse_listfile(): tildes (~) are properly expanded. According to the python docs for python 2.7 (http://docs.python.org/2/library/os.path.html#module-os.path), both os.path.expanduser and os.path.expandvars work on both *nix systems (Linux, *BSD, OSX) and Windows. """ contents = "~/foo\n" with utils.tempfile(contents) as tfile: results = core.parse_listfile(tfile) assert results[0] == os.path.expandvars("$HOME/foo")
def setup_class(cls): data = { "results_version": 1, "name": "test", "options": { "profile": ['quick'], "dmesg": False, "verbose": False, "platform": "gbm", "sync": False, "valgrind": False, "filter": [], "concurrent": "all", "test_count": 0, "exclude_tests": [], "exclude_filter": [], "env": { "lspci": "stuff", "uname": "more stuff", "glxinfo": "and stuff", "wglinfo": "stuff" } }, "tests": { "test/is/a/test": { "returncode": 0, "err": None, "environment": None, "command": "foo", "result": "skip", "time": 0.123, "out": None, } } } with utils.tempfile(json.dumps(data)) as t: with open(t, 'r') as f: cls.result = backends.json._update_one_to_two( backends.json._load(f))
def _load_with_update(self, data=None): """If the file is not results.json, it will be renamed. This ensures that the right file is removed. """ if not data: data = self.DATA try: with utils.tempfile(json.dumps(data)) as t: result = backends.json.load_results(t, 'none') except OSError as e: # There is the potential that the file will be renamed. In that event # remove the renamed files if e.errno == 2: os.unlink(os.path.join(tempfile.tempdir, 'results.json')) os.unlink(os.path.join(tempfile.tempdir, 'results.json.old')) else: raise return result
def setup_class(cls): contents = "/tmp/foo\n/tmp/foo \n/tmp/foo\t\n" with utils.tempfile(contents) as tfile: cls.results = core.parse_listfile(tfile)
def test_iter_deqp_test_cases_bad(): """deqp.iter_deqp_test_casesgen_caselist_txt: PiglitFatalException is raised if line is not TEST: or GROUP: """ with utils.tempfile('this will fail') as tfile: gen = deqp.iter_deqp_test_cases(tfile) nt.eq_('a.deqp.test', next(gen))
def test_iter_deqp_test_cases_group(): """deqp.iter_deqp_test_casesgen_caselist_txt: correctly detects a GROUP: line""" with utils.tempfile('GROUP: a group\nTEST: a.deqp.test') as tfile: gen = deqp.iter_deqp_test_cases(tfile) nt.eq_('a.deqp.test', next(gen))
def test_iter_deqp_test_cases_test(): """deqp.iter_deqp_test_cases: correctly detects a TEST: line""" with utils.tempfile('TEST: a.deqp.test') as tfile: gen = deqp.iter_deqp_test_cases(tfile) nt.eq_('a.deqp.test', next(gen))
def test_no_config_end(): """test.glsl_parser_test.GLSLParserTest: exception is raised if [end config] section is missing """ with utils.tempfile('// [config]\n') as tfile: glsl.GLSLParserTest(tfile)
def _check_config(content): """ This is the test that actually checks the glsl config section """ with utils.tempfile(content) as tfile: return glsl.GLSLParserTest(tfile), tfile
def check_no_duplicates(content): """ Ensure that duplicate entries raise an error """ with utils.tempfile(content) as tfile: glsl.GLSLParserTest(tfile)
def test_load_bad_json(): """backends.json._load: Raises fatal error if json is corrupt""" with utils.tempfile('{"bad json": }') as f: with open(f, "r") as tfile: backends.json._load(tfile)