Snap for 6001391 from 078cb32b44aa225bb313d9e08bfd6d12b72097e8 to qt-aml-tzdata-release
Change-Id: I2a5f9d0a469a2e06467782e7719da37c8e5695be
diff --git a/Android.bp b/Android.bp
index 819732d..9207656 100644
--- a/Android.bp
+++ b/Android.bp
@@ -30,8 +30,8 @@
}
cc_library_headers {
- name: "libhidl_gtest_helpers",
- export_include_dirs: ["gtest_helpers"],
+ name: "libhidl_gtest_helper",
+ export_include_dirs: ["gtest_helper"],
}
cc_test {
diff --git a/base/Status.cpp b/base/Status.cpp
index 08631cc..7698ff8 100644
--- a/base/Status.cpp
+++ b/base/Status.cpp
@@ -155,6 +155,20 @@
}
}
+ void return_status::onIgnored() const {
+ if (gReturnRestriction == HidlReturnRestriction::NONE) {
+ return;
+ }
+
+ if (gReturnRestriction == HidlReturnRestriction::ERROR_IF_UNCHECKED) {
+ LOG(ERROR) << "Failed to check status of HIDL Return.";
+ CallStack::logStack("unchecked HIDL return", CallStack::getCurrent(10).get(),
+ ANDROID_LOG_ERROR);
+ } else {
+ LOG(FATAL) << "Failed to check status of HIDL Return.";
+ }
+ }
+
void return_status::assertOk() const {
if (!isOk()) {
LOG(FATAL) << "Failed HIDL return status not checked. Usually this happens because of "
@@ -171,22 +185,13 @@
if (mCheckedStatus) return;
assertOk();
-
- if (gReturnRestriction == HidlReturnRestriction::NONE) {
- return;
- }
-
- if (gReturnRestriction == HidlReturnRestriction::ERROR_IF_UNCHECKED) {
- LOG(ERROR) << "Failed to check status of HIDL Return.";
- CallStack::logStack("unchecked HIDL return", CallStack::getCurrent(10).get(), ANDROID_LOG_ERROR);
- } else {
- LOG(FATAL) << "Failed to check status of HIDL Return.";
- }
+ onIgnored();
}
return_status& return_status::operator=(return_status&& other) noexcept {
if (!mCheckedStatus) {
assertOk();
+ onIgnored();
}
std::swap(mStatus, other.mStatus);
diff --git a/base/include/hidl/Status.h b/base/include/hidl/Status.h
index 07d352f..74901bb 100644
--- a/base/include/hidl/Status.h
+++ b/base/include/hidl/Status.h
@@ -141,6 +141,11 @@
Status mStatus {};
mutable bool mCheckedStatus = false;
+ // called when an unchecked status is discarded
+ // makes sure this status is checked according to the preference
+ // set by setProcessHidlReturnRestriction
+ void onIgnored() const;
+
template <typename T, typename U>
friend Return<U> StatusOf(const Return<T> &other);
protected:
diff --git a/gtest_helper/hidl/GtestPrinter.h b/gtest_helper/hidl/GtestPrinter.h
new file mode 100644
index 0000000..4b5ac2d
--- /dev/null
+++ b/gtest_helper/hidl/GtestPrinter.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#include <gtest/gtest.h>
+
+namespace android {
+namespace hardware {
+
+static inline std::string Sanitize(std::string name) {
+ for (size_t i = 0; i < name.size(); i++) {
+ // gtest test names must only contain alphanumeric characters
+ if (!std::isalnum(name[i])) name[i] = '_';
+ }
+ return name;
+}
+
+static inline std::string PrintInstanceNameToString(
+ const testing::TestParamInfo<std::string>& info) {
+ // test names need to be unique -> index prefix
+ std::string name = std::to_string(info.index) + "/" + info.param;
+ return Sanitize(name);
+}
+
+template <typename... T>
+static inline std::string PrintInstanceTupleNameToString(
+ const testing::TestParamInfo<std::tuple<T...>>& info) {
+ std::vector<std::string> instances = std::apply(
+ [](auto&&... elems) {
+ std::vector<std::string> instances;
+ instances.reserve(sizeof...(elems));
+ (instances.push_back(std::forward<decltype(elems)>(elems)), ...);
+ return instances;
+ },
+ info.param);
+ std::string param_string;
+ for (const std::string& instance : instances) {
+ param_string += instance + "_";
+ }
+ param_string += std::to_string(info.index);
+
+ return Sanitize(param_string);
+}
+
+} // namespace hardware
+} // namespace android
diff --git a/gtest_helpers/hidl/GtestPrinter.h b/gtest_helpers/hidl/GtestPrinter.h
deleted file mode 100644
index c9f5dd3..0000000
--- a/gtest_helpers/hidl/GtestPrinter.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * 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.
- */
-
-#include <gtest/gtest.h>
-
-namespace android {
-namespace hardware {
-
-static inline std::string PrintInstanceNameToString(
- const testing::TestParamInfo<std::string>& info) {
- // test names need to be unique -> index prefix
- std::string name = std::to_string(info.index) + "/" + info.param;
-
- for (size_t i = 0; i < name.size(); i++) {
- // gtest test names must only contain alphanumeric characters
- if (!std::isalnum(name[i])) name[i] = '_';
- }
-
- return name;
-}
-
-} // namespace hardware
-} // namespace android
diff --git a/test_main.cpp b/test_main.cpp
index fc71231..e4cdd29 100644
--- a/test_main.cpp
+++ b/test_main.cpp
@@ -546,6 +546,36 @@
"");
}
+TEST_F(LibHidlTest, DetectUncheckedReturn) {
+ using ::android::hardware::HidlReturnRestriction;
+ using ::android::hardware::Return;
+ using ::android::hardware::setProcessHidlReturnRestriction;
+ using ::android::hardware::Status;
+
+ setProcessHidlReturnRestriction(HidlReturnRestriction::FATAL_IF_UNCHECKED);
+
+ EXPECT_DEATH(
+ {
+ auto ret = Return<void>(Status::ok());
+ (void)ret;
+ },
+ "");
+ EXPECT_DEATH(
+ {
+ auto ret = Return<void>(Status::ok());
+ ret = Return<void>(Status::ok());
+ ret.isOk();
+ },
+ "");
+
+ auto ret = Return<void>(Status::ok());
+ (void)ret.isOk();
+ ret = Return<void>(Status::ok());
+ (void)ret.isOk();
+
+ setProcessHidlReturnRestriction(HidlReturnRestriction::NONE);
+}
+
std::string toString(const ::android::hardware::Status &s) {
using ::android::hardware::operator<<;
std::ostringstream oss;