diff --git a/BUILD.gn b/BUILD.gn index 777ebb943c..c2fe1e4377 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -15,8 +15,7 @@ import("scripts/dawn_overrides_with_defaults.gni") import("scripts/dawn_features.gni") import("//build_overrides/build.gni") - -import("//testing/test.gni") +import("generator/dawn_generator.gni") # Use Chromium's dcheck_always_on when available so that we respect it when # running tests on the GPU builders @@ -26,112 +25,6 @@ if (build_with_chromium) { dcheck_always_on = false } -############################################################################### -# Template to wrap the Dawn code generator -############################################################################### - -# Template to help with invocation of the Dawn code generator, looks like this: -# -# dawn_generator("my_target_gen") { -# # Which generator target to output -# target = "my_target" -# # The list of expected outputs, generation fails if there's a mismatch -# outputs = [ -# "MyTarget.cpp", -# "MyTarget.h", -# ] -# } -# -# Using the generated files is done like so: -# -# shared_library("my_target") { -# deps = [ ":my_target_gen "] -# sources = get_target_outputs(":my_target_gen") -# } -# -template("dawn_generator") { - # The base arguments for the generator: from this dawn.json, generate this - # target using templates in this directory. - generator_args = [ - rebase_path("dawn.json", root_build_dir), - "--template-dir", - rebase_path("generator/templates", root_build_dir), - "--targets", - invoker.target, - ] - - # Use the Jinja2 version pulled from the DEPS file. We do it so we don't - # have version problems, and users don't have to install Jinja2. - jinja2_python_path = rebase_path("${dawn_jinja2_dir}/..") - generator_args += [ - "--extra-python-path", - jinja2_python_path, - ] - - # For build parallelism GN wants to know the exact inputs and outputs of - # action targets like we use for our code generator. We avoid asking the - # generator about its inputs by using the "depfile" feature of GN/Ninja. - # - # A ninja limitation is that the depfile is a subset of Makefile that can - # contain a single target, so we output a single "JSON-tarball" instead. - json_tarball = "${target_gen_dir}/${target_name}.json_tarball" - json_tarball_depfile = "${json_tarball}.d" - - generator_args += [ - "--output-json-tarball", - rebase_path(json_tarball, root_build_dir), - "--depfile", - rebase_path(json_tarball_depfile, root_build_dir), - ] - - # After the JSON tarball is created we need an action target to extract it - # with a list of its outputs. The invoker provided a list of expected - # outputs. To make sure the list is in sync between the generator and the - # build files, we write it to a file and ask the generator to assert it is - # correct. - expected_outputs_file = "${target_gen_dir}/${target_name}.expected_outputs" - write_file(expected_outputs_file, invoker.outputs) - - generator_args += [ - "--expected-outputs-file", - rebase_path(expected_outputs_file, root_build_dir), - ] - - # The code generator invocation that will write the JSON tarball, check the - # outputs are what's expected and write a depfile for Ninja. - action("${target_name}_json_tarball") { - script = "generator/main.py" - outputs = [ - json_tarball, - ] - depfile = json_tarball_depfile - args = generator_args - } - - # Extract the JSON tarball into the target_gen_dir - action("${target_name}") { - script = "generator/extract_json.py" - args = [ - rebase_path(json_tarball, root_build_dir), - rebase_path(target_gen_dir, root_build_dir), - ] - - deps = [ - ":${target_name}_json_tarball", - ] - inputs = [ - json_tarball, - ] - - # The expected output list is relative to the target_gen_dir but action - # target outputs are from the root dir so we need to rebase them. - outputs = [] - foreach(source, invoker.outputs) { - outputs += [ "${target_gen_dir}/${source}" ] - } - } -} - ############################################################################### # Common dawn libraries and configs ############################################################################### @@ -783,124 +676,19 @@ static_library("dawn_utils") { # Dawn test targets ############################################################################### -dawn_generator("mock_dawn_gen") { - target = "mock_dawn" - outputs = [ - "mock/mock_dawn.h", - "mock/mock_dawn.cpp", +# FIXME: Temporary proxies until Chrome references src/tests directly. +group("dawn_unittests") { + testonly = true + deps = [ + "src/tests:dawn_unittests", ] } -test("dawn_unittests") { - configs += [ ":dawn_internal" ] - +group("dawn_end2end_tests") { + testonly = true deps = [ - ":dawn_common", - ":dawn_headers", - ":dawn_utils", - ":libdawn", - ":libdawn_native_sources", - ":libdawn_wire", - ":mock_dawn_gen", - "third_party:gmock_and_gtest", + "src/tests:dawn_end2end_tests", ] - - # Add internal Dawn Native headers and config for internal unittests. - deps += [ ":libdawn_native_headers" ] - configs += [ ":libdawn_native_internal" ] - - sources = get_target_outputs(":mock_dawn_gen") - sources += [ - "src/tests/unittests/BitSetIteratorTests.cpp", - "src/tests/unittests/CommandAllocatorTests.cpp", - "src/tests/unittests/EnumClassBitmasksTests.cpp", - "src/tests/unittests/ErrorTests.cpp", - "src/tests/unittests/MathTests.cpp", - "src/tests/unittests/ObjectBaseTests.cpp", - "src/tests/unittests/PerStageTests.cpp", - "src/tests/unittests/RefCountedTests.cpp", - "src/tests/unittests/ResultTests.cpp", - "src/tests/unittests/SerialMapTests.cpp", - "src/tests/unittests/SerialQueueTests.cpp", - "src/tests/unittests/ToBackendTests.cpp", - "src/tests/unittests/WireTests.cpp", - "src/tests/unittests/validation/BindGroupValidationTests.cpp", - "src/tests/unittests/validation/BlendStateValidationTests.cpp", - "src/tests/unittests/validation/BufferValidationTests.cpp", - "src/tests/unittests/validation/CommandBufferValidationTests.cpp", - "src/tests/unittests/validation/ComputeValidationTests.cpp", - "src/tests/unittests/validation/CopyCommandsValidationTests.cpp", - "src/tests/unittests/validation/DepthStencilStateValidationTests.cpp", - "src/tests/unittests/validation/DynamicStateCommandValidationTests.cpp", - "src/tests/unittests/validation/FenceValidationTests.cpp", - "src/tests/unittests/validation/InputStateValidationTests.cpp", - "src/tests/unittests/validation/PushConstantsValidationTests.cpp", - "src/tests/unittests/validation/QueueSubmitValidationTests.cpp", - "src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp", - "src/tests/unittests/validation/RenderPipelineValidationTests.cpp", - "src/tests/unittests/validation/ShaderModuleValidationTests.cpp", - "src/tests/unittests/validation/TextureViewValidationTests.cpp", - "src/tests/unittests/validation/ValidationTest.cpp", - "src/tests/unittests/validation/ValidationTest.h", - "src/tests/unittests/validation/VertexBufferValidationTests.cpp", - ] - - if (dawn_enable_d3d12) { - sources += [ "src/tests/unittests/d3d12/CopySplitTests.cpp" ] - } - - # When building inside Chromium, use their gtest main function because it is - # needed to run in swarming correctly. - if (build_with_chromium) { - sources += [ "//gpu/dawn_unittests_main.cc" ] - } else { - sources += [ "src/tests/UnittestsMain.cpp" ] - } -} - -test("dawn_end2end_tests") { - configs += [ ":dawn_internal" ] - - deps = [ - ":dawn_common", - ":dawn_utils", - ":libdawn", - ":libdawn_native", - ":libdawn_wire", - "third_party:glfw", - "third_party:gmock_and_gtest", - ] - - sources = [ - "src/tests/DawnTest.cpp", - "src/tests/DawnTest.h", - "src/tests/end2end/BasicTests.cpp", - "src/tests/end2end/BindGroupTests.cpp", - "src/tests/end2end/BlendStateTests.cpp", - "src/tests/end2end/BufferTests.cpp", - "src/tests/end2end/ComputeCopyStorageBufferTests.cpp", - "src/tests/end2end/CopyTests.cpp", - "src/tests/end2end/DepthStencilStateTests.cpp", - "src/tests/end2end/DrawElementsTests.cpp", - "src/tests/end2end/FenceTests.cpp", - "src/tests/end2end/IndexFormatTests.cpp", - "src/tests/end2end/InputStateTests.cpp", - "src/tests/end2end/PrimitiveTopologyTests.cpp", - "src/tests/end2end/PushConstantTests.cpp", - "src/tests/end2end/RenderPassLoadOpTests.cpp", - "src/tests/end2end/SamplerTests.cpp", - "src/tests/end2end/ScissorTests.cpp", - "src/tests/end2end/TextureViewTests.cpp", - "src/tests/end2end/ViewportOrientationTests.cpp", - ] - - # When building inside Chromium, use their gtest main function because it is - # needed to run in swarming correctly. - if (build_with_chromium) { - sources += [ "//gpu/dawn_end2end_tests_main.cc" ] - } else { - sources += [ "src/tests/End2EndTestsMain.cpp" ] - } } ############################################################################### diff --git a/generator/dawn_generator.gni b/generator/dawn_generator.gni new file mode 100644 index 0000000000..a8dcefc305 --- /dev/null +++ b/generator/dawn_generator.gni @@ -0,0 +1,122 @@ +# Copyright 2018 The Dawn Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/dawn.gni") +import("../scripts/dawn_overrides_with_defaults.gni") + +############################################################################### +# Template to wrap the Dawn code generator +############################################################################### + +# Template to help with invocation of the Dawn code generator, looks like this: +# +# dawn_generator("my_target_gen") { +# # Which generator target to output +# target = "my_target" +# # The list of expected outputs, generation fails if there's a mismatch +# outputs = [ +# "MyTarget.cpp", +# "MyTarget.h", +# ] +# } +# +# Using the generated files is done like so: +# +# shared_library("my_target") { +# deps = [ ":my_target_gen "] +# sources = get_target_outputs(":my_target_gen") +# } +# +template("dawn_generator") { + # The base arguments for the generator: from this dawn.json, generate this + # target using templates in this directory. + generator_args = [ + rebase_path("${dawn_root}/dawn.json", root_build_dir), + "--template-dir", + rebase_path("${dawn_root}/generator/templates", root_build_dir), + "--targets", + invoker.target, + ] + + # Use the Jinja2 version pulled from the DEPS file. We do it so we don't + # have version problems, and users don't have to install Jinja2. + jinja2_python_path = rebase_path("${dawn_jinja2_dir}/..") + generator_args += [ + "--extra-python-path", + jinja2_python_path, + ] + + # For build parallelism GN wants to know the exact inputs and outputs of + # action targets like we use for our code generator. We avoid asking the + # generator about its inputs by using the "depfile" feature of GN/Ninja. + # + # A ninja limitation is that the depfile is a subset of Makefile that can + # contain a single target, so we output a single "JSON-tarball" instead. + json_tarball = "${target_gen_dir}/${target_name}.json_tarball" + json_tarball_depfile = "${json_tarball}.d" + + generator_args += [ + "--output-json-tarball", + rebase_path(json_tarball, root_build_dir), + "--depfile", + rebase_path(json_tarball_depfile, root_build_dir), + ] + + # After the JSON tarball is created we need an action target to extract it + # with a list of its outputs. The invoker provided a list of expected + # outputs. To make sure the list is in sync between the generator and the + # build files, we write it to a file and ask the generator to assert it is + # correct. + expected_outputs_file = "${target_gen_dir}/${target_name}.expected_outputs" + write_file(expected_outputs_file, invoker.outputs) + + generator_args += [ + "--expected-outputs-file", + rebase_path(expected_outputs_file, root_build_dir), + ] + + # The code generator invocation that will write the JSON tarball, check the + # outputs are what's expected and write a depfile for Ninja. + action("${target_name}_json_tarball") { + script = "${dawn_root}/generator/main.py" + outputs = [ + json_tarball, + ] + depfile = json_tarball_depfile + args = generator_args + } + + # Extract the JSON tarball into the target_gen_dir + action("${target_name}") { + script = "${dawn_root}/generator/extract_json.py" + args = [ + rebase_path(json_tarball, root_build_dir), + rebase_path(target_gen_dir, root_build_dir), + ] + + deps = [ + ":${target_name}_json_tarball", + ] + inputs = [ + json_tarball, + ] + + # The expected output list is relative to the target_gen_dir but action + # target outputs are from the root dir so we need to rebase them. + outputs = [] + foreach(source, invoker.outputs) { + outputs += [ "${target_gen_dir}/${source}" ] + } + } +} diff --git a/scripts/dawn_overrides_with_defaults.gni b/scripts/dawn_overrides_with_defaults.gni index 7c47e0251d..196a448b55 100644 --- a/scripts/dawn_overrides_with_defaults.gni +++ b/scripts/dawn_overrides_with_defaults.gni @@ -24,6 +24,10 @@ if (!defined(dawn_standalone)) { dawn_standalone = false } +if (!defined(dawn_root)) { + dawn_root = get_path_info("..", "abspath") +} + if (!defined(dawn_jinja2_dir)) { dawn_jinja2_dir = "//third_party/jinja2" } diff --git a/src/tests/BUILD.gn b/src/tests/BUILD.gn new file mode 100644 index 0000000000..da80dd06ac --- /dev/null +++ b/src/tests/BUILD.gn @@ -0,0 +1,140 @@ +# Copyright 2018 The Dawn Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/build.gni") +import("../../scripts/dawn_overrides_with_defaults.gni") +import("${dawn_root}/scripts/dawn_features.gni") +import("${dawn_root}/generator/dawn_generator.gni") + +import("//testing/test.gni") + +dawn_generator("mock_dawn_gen") { + target = "mock_dawn" + outputs = [ + "mock/mock_dawn.h", + "mock/mock_dawn.cpp", + ] +} + +test("dawn_unittests") { + configs += [ "${dawn_root}:dawn_internal" ] + + deps = [ + ":mock_dawn_gen", + "${dawn_root}:dawn_common", + "${dawn_root}:dawn_headers", + "${dawn_root}:dawn_utils", + "${dawn_root}:libdawn", + "${dawn_root}:libdawn_native_sources", + "${dawn_root}:libdawn_wire", + "${dawn_root}/third_party:gmock_and_gtest", + ] + + # Add internal Dawn Native headers and config for internal unittests. + deps += [ "${dawn_root}:libdawn_native_headers" ] + configs += [ "${dawn_root}:libdawn_native_internal" ] + + sources = get_target_outputs(":mock_dawn_gen") + sources += [ + "unittests/BitSetIteratorTests.cpp", + "unittests/CommandAllocatorTests.cpp", + "unittests/EnumClassBitmasksTests.cpp", + "unittests/ErrorTests.cpp", + "unittests/MathTests.cpp", + "unittests/ObjectBaseTests.cpp", + "unittests/PerStageTests.cpp", + "unittests/RefCountedTests.cpp", + "unittests/ResultTests.cpp", + "unittests/SerialMapTests.cpp", + "unittests/SerialQueueTests.cpp", + "unittests/ToBackendTests.cpp", + "unittests/WireTests.cpp", + "unittests/validation/BindGroupValidationTests.cpp", + "unittests/validation/BlendStateValidationTests.cpp", + "unittests/validation/BufferValidationTests.cpp", + "unittests/validation/CommandBufferValidationTests.cpp", + "unittests/validation/ComputeValidationTests.cpp", + "unittests/validation/CopyCommandsValidationTests.cpp", + "unittests/validation/DepthStencilStateValidationTests.cpp", + "unittests/validation/DynamicStateCommandValidationTests.cpp", + "unittests/validation/FenceValidationTests.cpp", + "unittests/validation/InputStateValidationTests.cpp", + "unittests/validation/PushConstantsValidationTests.cpp", + "unittests/validation/QueueSubmitValidationTests.cpp", + "unittests/validation/RenderPassDescriptorValidationTests.cpp", + "unittests/validation/RenderPipelineValidationTests.cpp", + "unittests/validation/ShaderModuleValidationTests.cpp", + "unittests/validation/TextureViewValidationTests.cpp", + "unittests/validation/ValidationTest.cpp", + "unittests/validation/ValidationTest.h", + "unittests/validation/VertexBufferValidationTests.cpp", + ] + + if (dawn_enable_d3d12) { + sources += [ "unittests/d3d12/CopySplitTests.cpp" ] + } + + # When building inside Chromium, use their gtest main function because it is + # needed to run in swarming correctly. + if (build_with_chromium) { + sources += [ "//gpu/dawn_unittests_main.cc" ] + } else { + sources += [ "UnittestsMain.cpp" ] + } +} + +test("dawn_end2end_tests") { + configs += [ "${dawn_root}:dawn_internal" ] + + deps = [ + "${dawn_root}:dawn_common", + "${dawn_root}:dawn_utils", + "${dawn_root}:libdawn", + "${dawn_root}:libdawn_native", + "${dawn_root}:libdawn_wire", + "${dawn_root}/third_party:glfw", + "${dawn_root}/third_party:gmock_and_gtest", + ] + + sources = [ + "DawnTest.cpp", + "DawnTest.h", + "end2end/BasicTests.cpp", + "end2end/BindGroupTests.cpp", + "end2end/BlendStateTests.cpp", + "end2end/BufferTests.cpp", + "end2end/ComputeCopyStorageBufferTests.cpp", + "end2end/CopyTests.cpp", + "end2end/DepthStencilStateTests.cpp", + "end2end/DrawElementsTests.cpp", + "end2end/FenceTests.cpp", + "end2end/IndexFormatTests.cpp", + "end2end/InputStateTests.cpp", + "end2end/PrimitiveTopologyTests.cpp", + "end2end/PushConstantTests.cpp", + "end2end/RenderPassLoadOpTests.cpp", + "end2end/SamplerTests.cpp", + "end2end/ScissorTests.cpp", + "end2end/TextureViewTests.cpp", + "end2end/ViewportOrientationTests.cpp", + ] + + # When building inside Chromium, use their gtest main function because it is + # needed to run in swarming correctly. + if (build_with_chromium) { + sources += [ "//gpu/dawn_end2end_tests_main.cc" ] + } else { + sources += [ "End2EndTestsMain.cpp" ] + } +}