blob: bee22b1d86dcfa7724351881fa53e3830a364798 [file] [log] [blame]
# Copyright 2020 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/go/go_library.gni")
import("//build/go/go_test.gni")
import("//build/json/validate_json.gni")
import("//tools/fidl/fidlc/testdata/info.gni")
go_library("fidlgen") {
sources = [
"formatter.go",
"generator.go",
"identifiers.go",
"identifiers_test.go",
"names.go",
"names.go",
"names_test.go",
"reserved_names.go",
"strings.go",
"strings_test.go",
"struct.go",
"struct_test.go",
"templates.go",
"types.go",
"types_test.go",
"write_file_if_changed.go",
]
}
if (is_host) {
go_test("fidlgen_lib_test") {
library = ":fidlgen"
deps = [ "//third_party/golibs:github.com/google/go-cmp" ]
}
}
group("tests") {
testonly = true
deps = [
":fidlgen_lib_test($host_toolchain)",
":roundtrip_tests($default_toolchain)",
]
}
# These tests perform a round-trip of the IR: valid JSON IR is read into its go
# representation by the library utilities, unmarshaled back to JSON, and then
# validated again as IR. This ensures that the library - and thus all backends
# that depend on it - have an accurate representation of the IR.
if (current_toolchain == default_toolchain) {
roundtrip_test_deps = []
foreach(info, fidl_testdata_info) {
roundtrip_target = "roundtrip.${info.name}"
validate_target = "validate.${info.name}"
output_json = "$target_gen_dir/${info.name}.json"
compiled_action(roundtrip_target) {
testonly = true
visibility = [ ":$validate_target" ]
input_json = "${info.fidl_gen_dir}/${info.target_name}.fidl.json"
inputs = [ input_json ]
outputs = [ output_json ]
tool = "testing:roundtripper"
args = [
"-in",
rebase_path(input_json, root_build_dir),
"-out",
rebase_path(output_json, root_build_dir),
]
deps = [ "${info.target}($fidl_toolchain)" ]
}
validate_json(validate_target) {
testonly = true
visibility = [ ":*" ]
data = output_json
schema = "//tools/fidl/fidlc/schema.json"
deps = [ ":$roundtrip_target" ]
}
roundtrip_test_deps += [ ":$validate_target" ]
}
group("roundtrip_tests") {
testonly = true
deps = roundtrip_test_deps
}
}