def test_ExecClsmithSource_syntax_error(): """Test outcome of kernel with syntax error.""" env_ = env.OclgrindOpenCLEnvironment() proc = cl_launcher.ExecClsmithSource( env_, "!@!###syntax error!", driver.NDRange(1, 1, 1), driver.NDRange(1, 1, 1), "---debug", ) assert proc.returncode == 1 assert proc.stdout == "" assert "Error building program: -11" in proc.stderr
def test_ExecClsmithSource_pass(): """And end-to-end test of executing a CLSmith source.""" env_ = env.OclgrindOpenCLEnvironment() proc = cl_launcher.ExecClsmithSource( env_, CLSMITH_EXAMPLE_SRC, driver.NDRange(1, 1, 1), driver.NDRange(1, 1, 1), "---debug", ) assert not proc.returncode assert "3-D global size 1 = [1, 1, 1]" in proc.stderr assert "3-D local size 1 = [1, 1, 1]" in proc.stderr assert "OpenCL optimizations: on" in proc.stderr assert "Platform: " in proc.stderr assert "Device: " in proc.stderr assert "Compilation terminated successfully..." assert proc.stdout == "0,"
def MakeDriver(testcase: deepsmith_pb2.Testcase, optimizations: bool) -> str: """Generate a self-contained C program for the given test case. Args: testcase: The testcase to generate a driver for. Requires three inputs: 'src', 'gsize', and 'lsize'. Returns: A string of C code. Raises: ValueError: In case the testcase is missing the required gsize, lsize, and src inputs. """ if "gsize" not in testcase.inputs: raise ValueError("Field not set: 'Testcase.inputs[\"gsize\"]'") if "lsize" not in testcase.inputs: raise ValueError("Field not set: 'Testcase.inputs[\"lsize\"]'") if "src" not in testcase.inputs: raise ValueError("Field not set: 'Testcase.inputs[\"src\"]'") gsize = driver.NDRange( *[int(x) for x in testcase.inputs["gsize"].split(",")]) lsize = driver.NDRange( *[int(x) for x in testcase.inputs["lsize"].split(",")]) size = max(gsize.product * 2, 256) src = testcase.inputs["src"] # Optionally support custom data generators. data_generator = data.Generator.ARANGE if "data_generator" in testcase.inputs: data_generator = { "arange": data.Generator.ARANGE, "ones": data.Generator.ONES, }.get(testcase.inputs["data_generator"]) if not data_generator: raise ValueError( "Unknown value for 'Testcase.inputs[\"data_generator\"]': " f"'{testcase.inputs['data_generator']}'") try: # Generate a compile-and-execute test harness. inputs = data.MakeData(src=src, size=size, data_generator=data_generator, scalar_val=size) src = cgen.emit_c( src=src, inputs=inputs, gsize=gsize, lsize=lsize, optimizations=optimizations, ) testcase.invariant_opts["driver_type"] = "compile_and_run" except Exception: # Create a compile-only stub if not possible. try: src = cgen.emit_c( src=src, inputs=None, gsize=None, lsize=None, compile_only=True, optimizations=optimizations, ) testcase.invariant_opts[ "driver_type"] = "compile_and_create_kernel" except Exception: # Create a compiler-only stub without creating kernel. src = cgen.emit_c( src=src, inputs=None, gsize=None, lsize=None, compile_only=True, create_kernel=False, optimizations=optimizations, ) testcase.invariant_opts["driver_type"] = "compile_only" return src