Move tint unittest behind a build flag.

This CL moves the Tint unittest code behind a build flag in order
to hide the //testing/test.gni dependency from downstream consumers.

The unittests are enabled by default and can be disabled by setting
`tint_build_unittests` to false.

Bug: dawn:1517
Change-Id: Id560ed98416ba0725b62a93ddd27caf341699e75
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94481
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
dan sinclair 2022-06-22 12:40:43 +00:00 committed by Dawn LUCI CQ
parent 32bcc0413d
commit 77bf233cef
3 changed files with 805 additions and 792 deletions

View File

@ -19,3 +19,5 @@ tint_build_spv_reader = true
tint_build_spv_writer = true
tint_build_wgsl_reader = true
tint_build_wgsl_writer = true
tint_build_unittests = true

View File

@ -13,9 +13,13 @@
# limitations under the License.
import("//build_overrides/build.gni")
import("//testing/test.gni")
import("../../tint_overrides_with_defaults.gni")
if (tint_build_unittests) {
import("//testing/test.gni")
}
###############################################################################
# Common - Configs, etc. shared across targets
###############################################################################
@ -849,15 +853,16 @@ source_set("libtint") {
}
}
###############################################################################
# Gtest Gmock - Handle building inside and outside of Chromium.
###############################################################################
# When building outside of Chromium we need to define our own targets for GTest
# and GMock. However when compiling inside of Chromium we need to reuse the
# existing targets, both because Chromium has a special harness for swarming
# and because otherwise the "gn check" fails.
if (tint_build_unittests) {
###############################################################################
# Gtest Gmock - Handle building inside and outside of Chromium.
###############################################################################
# When building outside of Chromium we need to define our own targets for GTest
# and GMock. However when compiling inside of Chromium we need to reuse the
# existing targets, both because Chromium has a special harness for swarming
# and because otherwise the "gn check" fails.
if (!build_with_chromium) {
if (!build_with_chromium) {
# When we aren't in Chromium we define out own targets based on the location
# of the googletest repo.
config("gtest_config") {
@ -893,7 +898,7 @@ if (!build_with_chromium) {
":gtest",
]
}
} else {
} else {
# When we are in Chromium we reuse its targets, and also add some deps that
# are needed to launch the test in swarming mode.
group("gmock_and_gtest") {
@ -906,15 +911,15 @@ if (!build_with_chromium) {
"//third_party/googletest:gmock",
]
}
}
}
###############################################################################
# Wrapping of Chromium targets
###############################################################################
# These targets are separated because they are Chromium sources files that
# can't use the tint_internal config, otherwise Tint's warning flags get
# applied while compiling a bunch of Chromium's //base (via header inclusion)
source_set("tint_unittests_main") {
###############################################################################
# Wrapping of Chromium targets
###############################################################################
# These targets are separated because they are Chromium sources files that
# can't use the tint_internal config, otherwise Tint's warning flags get
# applied while compiling a bunch of Chromium's //base (via header inclusion)
source_set("tint_unittests_main") {
testonly = true
deps = [ ":gmock_and_gtest" ]
if (build_with_chromium) {
@ -929,12 +934,12 @@ source_set("tint_unittests_main") {
":tint_unittests_spv_reader_src",
]
}
}
}
###############################################################################
# Tests - For libtint core and optional modules
###############################################################################
config("tint_unittests_config") {
###############################################################################
# Tests - For libtint core and optional modules
###############################################################################
config("tint_unittests_config") {
include_dirs = [
"${tint_googletest_dir}/googlemock/include",
"${tint_googletest_dir}/googletest/include",
@ -944,9 +949,9 @@ config("tint_unittests_config") {
":tint_common_config",
":tint_public_config",
]
}
}
template("tint_unittests_source_set") {
template("tint_unittests_source_set") {
source_set(target_name) {
forward_variables_from(invoker, "*", [ "configs" ])
@ -970,9 +975,9 @@ template("tint_unittests_source_set") {
":tint_utils_io",
]
}
}
}
tint_unittests_source_set("tint_unittests_ast_src") {
tint_unittests_source_set("tint_unittests_ast_src") {
sources = [
"ast/alias_test.cc",
"ast/array_test.cc",
@ -1047,17 +1052,17 @@ tint_unittests_source_set("tint_unittests_ast_src") {
"ast/while_statement_test.cc",
"ast/workgroup_attribute_test.cc",
]
}
}
tint_unittests_source_set("tint_unittests_diagnostic_src") {
tint_unittests_source_set("tint_unittests_diagnostic_src") {
sources = [
"diagnostic/diagnostic_test.cc",
"diagnostic/formatter_test.cc",
"diagnostic/printer_test.cc",
]
}
}
tint_unittests_source_set("tint_unittests_inspector_src") {
tint_unittests_source_set("tint_unittests_inspector_src") {
sources = [
"inspector/inspector_test.cc",
"inspector/test_inspector_builder.cc",
@ -1065,9 +1070,9 @@ tint_unittests_source_set("tint_unittests_inspector_src") {
"inspector/test_inspector_runner.cc",
"inspector/test_inspector_runner.h",
]
}
}
tint_unittests_source_set("tint_unittests_resolver_src") {
tint_unittests_source_set("tint_unittests_resolver_src") {
sources = [
"resolver/array_accessor_test.cc",
"resolver/assignment_validation_test.cc",
@ -1116,9 +1121,9 @@ tint_unittests_source_set("tint_unittests_resolver_src") {
"resolver/var_let_validation_test.cc",
]
deps = [ ":tint_unittests_ast_src" ]
}
}
tint_unittests_source_set("tint_unittests_sem_src") {
tint_unittests_source_set("tint_unittests_sem_src") {
sources = [
"sem/atomic_test.cc",
"sem/bool_test.cc",
@ -1146,13 +1151,13 @@ tint_unittests_source_set("tint_unittests_sem_src") {
"sem/u32_test.cc",
"sem/vector_test.cc",
]
}
}
tint_unittests_source_set("tint_unittests_text_src") {
tint_unittests_source_set("tint_unittests_text_src") {
sources = [ "text/unicode_test.cc" ]
}
}
tint_unittests_source_set("tint_unittests_transform_src") {
tint_unittests_source_set("tint_unittests_transform_src") {
sources = [
"transform/add_empty_entry_point_test.cc",
"transform/add_spirv_block_attribute_test.cc",
@ -1197,9 +1202,9 @@ tint_unittests_source_set("tint_unittests_transform_src") {
"transform/wrap_arrays_in_structs_test.cc",
"transform/zero_init_workgroup_memory_test.cc",
]
}
}
tint_unittests_source_set("tint_unittests_utils_src") {
tint_unittests_source_set("tint_unittests_utils_src") {
sources = [
"utils/bitcast_test.cc",
"utils/crc32_test.cc",
@ -1218,9 +1223,9 @@ tint_unittests_source_set("tint_unittests_utils_src") {
"utils/unique_allocator_test.cc",
"utils/unique_vector_test.cc",
]
}
}
tint_unittests_source_set("tint_unittests_writer_src") {
tint_unittests_source_set("tint_unittests_writer_src") {
sources = [
"writer/append_vector_test.cc",
"writer/flatten_bindings_test.cc",
@ -1228,9 +1233,9 @@ tint_unittests_source_set("tint_unittests_writer_src") {
"writer/generate_external_texture_bindings_test.cc",
"writer/text_generator_test.cc",
]
}
}
tint_unittests_source_set("tint_unittests_spv_reader_src") {
tint_unittests_source_set("tint_unittests_spv_reader_src") {
sources = [
"reader/spirv/enum_converter_test.cc",
"reader/spirv/fail_stream_test.cc",
@ -1268,9 +1273,9 @@ tint_unittests_source_set("tint_unittests_spv_reader_src") {
]
deps = [ ":libtint_spv_reader_src" ]
}
}
tint_unittests_source_set("tint_unittests_spv_writer_src") {
tint_unittests_source_set("tint_unittests_spv_writer_src") {
sources = [
"writer/spirv/binary_writer_test.cc",
"writer/spirv/builder_accessor_expression_test.cc",
@ -1311,9 +1316,9 @@ tint_unittests_source_set("tint_unittests_spv_writer_src") {
":tint_unittests_ast_src",
"${tint_spirv_tools_dir}/:spvtools",
]
}
}
tint_unittests_source_set("tint_unittests_wgsl_reader_src") {
tint_unittests_source_set("tint_unittests_wgsl_reader_src") {
sources = [
"reader/wgsl/lexer_test.cc",
"reader/wgsl/parser_impl_additive_expression_test.cc",
@ -1393,9 +1398,9 @@ tint_unittests_source_set("tint_unittests_wgsl_reader_src") {
]
deps = [ ":libtint_wgsl_reader_src" ]
}
}
tint_unittests_source_set("tint_unittests_wgsl_writer_src") {
tint_unittests_source_set("tint_unittests_wgsl_writer_src") {
sources = [
"writer/wgsl/generator_impl_alias_type_test.cc",
"writer/wgsl/generator_impl_array_accessor_test.cc",
@ -1433,9 +1438,9 @@ tint_unittests_source_set("tint_unittests_wgsl_writer_src") {
":libtint_wgsl_writer_src",
":tint_unittests_ast_src",
]
}
}
tint_unittests_source_set("tint_unittests_msl_writer_src") {
tint_unittests_source_set("tint_unittests_msl_writer_src") {
sources = [
"writer/msl/generator_impl_array_accessor_test.cc",
"writer/msl/generator_impl_assign_test.cc",
@ -1472,9 +1477,9 @@ tint_unittests_source_set("tint_unittests_msl_writer_src") {
":libtint_msl_writer_src",
":tint_unittests_ast_src",
]
}
}
tint_unittests_source_set("tint_unittests_hlsl_writer_src") {
tint_unittests_source_set("tint_unittests_hlsl_writer_src") {
sources = [
"writer/hlsl/generator_impl_array_accessor_test.cc",
"writer/hlsl/generator_impl_assign_test.cc",
@ -1512,9 +1517,9 @@ tint_unittests_source_set("tint_unittests_hlsl_writer_src") {
":libtint_hlsl_writer_src",
":tint_unittests_ast_src",
]
}
}
tint_unittests_source_set("tint_unittests_glsl_writer_src") {
tint_unittests_source_set("tint_unittests_glsl_writer_src") {
sources = [
"writer/glsl/generator_impl_array_accessor_test.cc",
"writer/glsl/generator_impl_assign_test.cc",
@ -1555,9 +1560,9 @@ tint_unittests_source_set("tint_unittests_glsl_writer_src") {
":tint_unittests_ast_src",
":tint_unittests_transform_src",
]
}
}
tint_unittests_source_set("tint_unittests_core_src") {
tint_unittests_source_set("tint_unittests_core_src") {
sources = [
"castable_test.cc",
"clone_context_test.cc",
@ -1575,9 +1580,9 @@ tint_unittests_source_set("tint_unittests_core_src") {
]
deps = [ ":tint_unittests_ast_src" ]
}
}
if (build_with_chromium) {
if (build_with_chromium) {
tint_unittests_source_set("tint_unittests_fuzzer_src") {
sources = [ "fuzzers/random_generator_test.cc" ]
@ -1586,9 +1591,9 @@ if (build_with_chromium) {
"fuzzers:tint_fuzzer_common_src",
]
}
}
}
source_set("tint_unittests_src") {
source_set("tint_unittests_src") {
testonly = true
deps = [
@ -1644,9 +1649,9 @@ source_set("tint_unittests_src") {
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
}
}
}
test("tint_unittests") {
test("tint_unittests") {
deps = [
":gmock_and_gtest",
":tint_unittests_src",
@ -1665,4 +1670,5 @@ test("tint_unittests") {
}
testonly = true
}
}

View File

@ -71,4 +71,9 @@ declare_args() {
if (!defined(tint_build_glsl_writer)) {
tint_build_glsl_writer = true
}
# Build unittests
if (!defined(tint_build_unittests)) {
tint_build_unittests = true
}
}