From 1ad1d43f6e100c48c0bf56b92d875ec4a22e7f8a Mon Sep 17 00:00:00 2001 From: Ian McKellar Date: Thu, 19 Oct 2023 05:09:04 +0000 Subject: [PATCH] [fidl][cpp] Fix hlcpp conversion w/ unknown interactions We were missing Natural/HLCPP conversion rules for transport errors so it wasn't possible to even build the hlcpp_conversion.h for FIDL libraries with two-way flexible methods. The type is the same between Natural and HLCPP bindings so the fix is just to have a no-op conversion. Change-Id: Ib4150db3bee55f98ba0f862e6072afed647ca767 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/934374 Fuchsia-Auto-Submit: Ian McKellar Commit-Queue: Auto-Submit API-Review: Adam Barth Reviewed-by: Mitchell Kember --- .../fidl/cpp/fidl_cpp_hlcpp_conversion.api | 2 +- .../include/lib/fidl/cpp/hlcpp_conversion.h | 11 ++ .../fidl/cpp/tests/hlcpp_conversion/BUILD.gn | 1 + .../cpp/tests/hlcpp_conversion/fidl/BUILD.gn | 6 ++ .../hlcpp_conversion/fidl/protocols.test.fidl | 100 ++++++++++++++++++ .../protocol_endpoint_conversion_test.cc | 1 + 6 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/lib/fidl/cpp/tests/hlcpp_conversion/fidl/protocols.test.fidl diff --git a/src/lib/fidl/cpp/fidl_cpp_hlcpp_conversion.api b/src/lib/fidl/cpp/fidl_cpp_hlcpp_conversion.api index df485171da1a..abd2c9044d1e 100644 --- a/src/lib/fidl/cpp/fidl_cpp_hlcpp_conversion.api +++ b/src/lib/fidl/cpp/fidl_cpp_hlcpp_conversion.api @@ -1,3 +1,3 @@ { - "pkg/fidl_cpp_hlcpp_conversion/include/lib/fidl/cpp/hlcpp_conversion.h": "a1a95b2ba032918a786ac281627b834f" + "pkg/fidl_cpp_hlcpp_conversion/include/lib/fidl/cpp/hlcpp_conversion.h": "d1bff0d7426fea5c89da263382bf5354" } \ No newline at end of file diff --git a/src/lib/fidl/cpp/include/lib/fidl/cpp/hlcpp_conversion.h b/src/lib/fidl/cpp/include/lib/fidl/cpp/hlcpp_conversion.h index fb5458e7b9e3..2687f4008106 100644 --- a/src/lib/fidl/cpp/include/lib/fidl/cpp/hlcpp_conversion.h +++ b/src/lib/fidl/cpp/include/lib/fidl/cpp/hlcpp_conversion.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -79,6 +80,16 @@ struct HLCPPToNaturalTraits {}; #endif +/* Natural to HLCPP types for transport errors */ +template <> +struct NaturalToHLCPPTraits<::fidl::internal::TransportErr> final + : public NaturalToHLCPPTraitsIdentical<::fidl::internal::TransportErr> {}; + +/* HLCPP to Natural types for transport errors */ +template <> +struct HLCPPToNaturalTraits<::fidl::internal::TransportErr> final + : public HLCPPToNaturalTraitsIdentical<::fidl::internal::TransportErr> {}; + /* Natural to HLCPP traits for strings. */ template <> struct NaturalToHLCPPTraits final : public NaturalToHLCPPTraitsIdentical { diff --git a/src/lib/fidl/cpp/tests/hlcpp_conversion/BUILD.gn b/src/lib/fidl/cpp/tests/hlcpp_conversion/BUILD.gn index f9ba72289f2b..2e357ef9e4eb 100644 --- a/src/lib/fidl/cpp/tests/hlcpp_conversion/BUILD.gn +++ b/src/lib/fidl/cpp/tests/hlcpp_conversion/BUILD.gn @@ -25,6 +25,7 @@ test("fidl_hlcpp_conversion_tests_bin") { deps = [ "fidl:test.enums.abc_cpp_hlcpp_conversion", "fidl:test.enums.xyz_cpp_hlcpp_conversion", + "fidl:test.protocols_cpp_hlcpp_conversion", "//sdk/testing/fidl/protocols_tests:test.protocol.connector_cpp", "//sdk/testing/fidl/protocols_tests:test.protocol.connector_cpp_hlcpp_conversion", "//sdk/testing/fidl/types_tests:test.types_cpp_hlcpp_conversion", diff --git a/src/lib/fidl/cpp/tests/hlcpp_conversion/fidl/BUILD.gn b/src/lib/fidl/cpp/tests/hlcpp_conversion/fidl/BUILD.gn index 2854bc355076..763ba41e62e1 100644 --- a/src/lib/fidl/cpp/tests/hlcpp_conversion/fidl/BUILD.gn +++ b/src/lib/fidl/cpp/tests/hlcpp_conversion/fidl/BUILD.gn @@ -17,3 +17,9 @@ fidl("test.enums.xyz") { sources = [ "enums.xyz.test.fidl" ] enable_hlcpp = true } + +fidl("test.protocols") { + testonly = true + sources = [ "protocols.test.fidl" ] + enable_hlcpp = true +} diff --git a/src/lib/fidl/cpp/tests/hlcpp_conversion/fidl/protocols.test.fidl b/src/lib/fidl/cpp/tests/hlcpp_conversion/fidl/protocols.test.fidl new file mode 100644 index 000000000000..3474f572c2e7 --- /dev/null +++ b/src/lib/fidl/cpp/tests/hlcpp_conversion/fidl/protocols.test.fidl @@ -0,0 +1,100 @@ +// Copyright 2023 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. + +library test.protocols; + +closed protocol ClosedProtocol { + strict StrictOneWay(struct { + arg int32; + }); + + strict StrictTwoWay(struct { + arg int32; + }) -> (struct { + res int32; + }); + + strict StrictTwoWayError(struct { + arg int32; + }) -> (struct { + res int32; + }) error int32; + + strict -> OnStrictEvent(struct { + arg int32; + }); +}; + +ajar protocol AjarProtocol { + strict StrictOneWay(struct { + arg int32; + }); + + strict StrictTwoWay(struct { + arg int32; + }) -> (struct { + res int32; + }); + + strict StrictTwoWayError(struct { + arg int32; + }) -> (struct { + res int32; + }) error int32; + + strict -> OnStrictEvent(struct { + arg int32; + }); + + flexible FlexibleOneWay(struct { + arg int32; + }); + + flexible -> OnFlexibleEvent(struct { + arg int32; + }); +}; + + +open protocol OpenProtocol { + strict StrictOneWay(struct { + arg int32; + }); + + strict StrictTwoWay(struct { + arg int32; + }) -> (struct { + res int32; + }); + + strict StrictTwoWayError(struct { + arg int32; + }) -> (struct { + res int32; + }) error int32; + + strict -> OnStrictEvent(struct { + arg int32; + }); + + flexible FlexibleOneWay(struct { + arg int32; + }); + + flexible -> OnFlexibleEvent(struct { + arg int32; + }); + + flexible FlexibleTwoWay(struct { + arg int32; + }) -> (struct { + res int32; + }); + + flexible FlexibleTwoWayError(struct { + arg int32; + }) -> (struct { + res int32; + }) error int32; +}; diff --git a/src/lib/fidl/cpp/tests/hlcpp_conversion/protocol_endpoint_conversion_test.cc b/src/lib/fidl/cpp/tests/hlcpp_conversion/protocol_endpoint_conversion_test.cc index a3f8f89f68da..fca30fc93931 100644 --- a/src/lib/fidl/cpp/tests/hlcpp_conversion/protocol_endpoint_conversion_test.cc +++ b/src/lib/fidl/cpp/tests/hlcpp_conversion/protocol_endpoint_conversion_test.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include #include