Merge "Change __assert calls to check" am: d5b56a9fb3
Original change: https://android-review.googlesource.com/c/platform/system/libfmq/+/1773609
Change-Id: Icd914077c91652f0e1de47996c23a6725d416d7c
diff --git a/FmqInternal.cpp b/FmqInternal.cpp
index 6b95def..eb8ae2d 100644
--- a/FmqInternal.cpp
+++ b/FmqInternal.cpp
@@ -25,6 +25,10 @@
CHECK(exp);
}
+void check(bool exp, const char* message) {
+ CHECK(exp) << message;
+}
+
void logError(const std::string &message) {
LOG(ERROR) << message;
}
diff --git a/base/fmq/MQDescriptorBase.h b/base/fmq/MQDescriptorBase.h
index 21b8e21..c70fe57 100644
--- a/base/fmq/MQDescriptorBase.h
+++ b/base/fmq/MQDescriptorBase.h
@@ -54,6 +54,7 @@
namespace details {
void logError(const std::string& message);
+void check(bool exp, const char* message);
typedef uint64_t RingBufferPosition;
enum GrantorType : int { READPTRPOS = 0, WRITEPTRPOS, DATAPTRPOS, EVFLAGWORDPOS };
@@ -72,20 +73,12 @@
static inline size_t alignToWordBoundary(size_t length) {
constexpr size_t kAlignmentSize = 64;
- if (kAlignmentSize % __WORDSIZE != 0) {
-#ifdef __BIONIC__
- __assert(__FILE__, __LINE__, "Incompatible word size");
-#endif
- }
+ static_assert(kAlignmentSize % __WORDSIZE == 0, "Incompatible word size");
/*
* Check if alignment to word boundary would cause an overflow.
*/
- if (length > SIZE_MAX - kAlignmentSize / 8 + 1) {
-#ifdef __BIONIC__
- __assert(__FILE__, __LINE__, "Queue size too large");
-#endif
- }
+ check(length <= SIZE_MAX - kAlignmentSize / 8 + 1, "Queue size too large");
return (length + kAlignmentSize / 8 - 1) & ~(kAlignmentSize / 8 - 1U);
}
diff --git a/include/fmq/MessageQueueBase.h b/include/fmq/MessageQueueBase.h
index 2a29937..d24dc7c 100644
--- a/include/fmq/MessageQueueBase.h
+++ b/include/fmq/MessageQueueBase.h
@@ -588,9 +588,8 @@
const auto& grantors = mDesc->grantors();
for (const auto& grantor : grantors) {
- if (hardware::details::isAlignedToWordBoundary(grantor.offset) == false) {
- __assert(__FILE__, __LINE__, "Grantor offsets need to be aligned");
- }
+ hardware::details::check(hardware::details::isAlignedToWordBoundary(grantor.offset) == true,
+ "Grantor offsets need to be aligned");
}
if (flavor == kSynchronizedReadWrite) {
@@ -603,19 +602,11 @@
*/
mReadPtr = new (std::nothrow) std::atomic<uint64_t>;
}
- if (mReadPtr == nullptr) {
-#ifdef __BIONIC__
- __assert(__FILE__, __LINE__, "mReadPtr is null");
-#endif
- }
+ hardware::details::check(mReadPtr != nullptr, "mReadPtr is null");
mWritePtr = reinterpret_cast<std::atomic<uint64_t>*>(
mapGrantorDescr(hardware::details::WRITEPTRPOS));
- if (mWritePtr == nullptr) {
-#ifdef __BIONIC__
- __assert(__FILE__, __LINE__, "mWritePtr is null");
-#endif
- }
+ hardware::details::check(mWritePtr != nullptr, "mWritePtr is null");
if (resetPointers) {
mReadPtr->store(0, std::memory_order_release);
@@ -626,22 +617,13 @@
}
mRing = reinterpret_cast<uint8_t*>(mapGrantorDescr(hardware::details::DATAPTRPOS));
- if (mRing == nullptr) {
-#ifdef __BIONIC__
- __assert(__FILE__, __LINE__, "mRing is null");
-#endif
- }
+ hardware::details::check(mRing != nullptr, "mRing is null");
if (mDesc->countGrantors() > hardware::details::EVFLAGWORDPOS) {
mEvFlagWord = static_cast<std::atomic<uint32_t>*>(
mapGrantorDescr(hardware::details::EVFLAGWORDPOS));
- if (mEvFlagWord != nullptr) {
- android::hardware::EventFlag::createEventFlag(mEvFlagWord, &mEventFlag);
- } else {
-#ifdef __BIONIC__
- __assert(__FILE__, __LINE__, "mEvFlagWord is null");
-#endif
- }
+ hardware::details::check(mEvFlagWord != nullptr, "mEvFlagWord is null");
+ android::hardware::EventFlag::createEventFlag(mEvFlagWord, &mEventFlag);
}
}
diff --git a/tests/fmq_unit_tests.cpp b/tests/fmq_unit_tests.cpp
index be866ec..d3fdfbc 100644
--- a/tests/fmq_unit_tests.cpp
+++ b/tests/fmq_unit_tests.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include <android-base/logging.h>
#include <asm-generic/mman.h>
#include <fmq/AidlMessageQueue.h>
#include <fmq/ConvertMQDescriptors.h>
@@ -514,8 +515,9 @@
* "mRing is null".
*/
TEST_F(DoubleFdFailures, InvalidFd) {
+ android::base::SetLogger(android::base::StdioLogger);
EXPECT_DEATH_IF_SUPPORTED(AidlMessageQueueSync(64, false, android::base::unique_fd(3000), 64),
- "mRing is null");
+ "Check failed: exp mRing is null");
}
/*