diff options
author | Devin Moore <devinmoore@google.com> | 2022-09-26 18:27:35 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-09-26 18:27:35 +0000 |
commit | c3f92fb82147aae7fb34d499925b0828948e4c6e (patch) | |
tree | 2fda146bab33932256357636050c1d6b6d6fd5d3 | |
parent | b70ecd425981d4193d779d7b70377fed0f2cdafa (diff) | |
parent | 70e18912d7e4c0d44698eefecdcf8c8ef7976840 (diff) | |
download | libfmq-c3f92fb82147aae7fb34d499925b0828948e4c6e.tar.gz |
fmq_unit_tests: remove objects form the heap am: cdf8d33b16 am: 6a21b5f737 am: 272fe1e1dd am: 8d0f459682 am: 70e18912d7
Original change: https://android-review.googlesource.com/c/platform/system/libfmq/+/2230529
Change-Id: I1ebac6b37971d7b39e90bbe0b5fe879ad4f1dfbc
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | tests/fmq_unit_tests.cpp | 74 |
1 files changed, 31 insertions, 43 deletions
diff --git a/tests/fmq_unit_tests.cpp b/tests/fmq_unit_tests.cpp index d3fdfbc..438b7d5 100644 --- a/tests/fmq_unit_tests.cpp +++ b/tests/fmq_unit_tests.cpp @@ -301,13 +301,11 @@ void TestBase<T>::ReaderThreadBlocking2(typename T::MQType* fmq, std::atomic<uin TYPED_TEST(BadQueueConfig, QueueSizeTooLarge) { size_t numElementsInQueue = SIZE_MAX / sizeof(uint16_t) + 1; - typename TypeParam::MQType* fmq = - new (std::nothrow) typename TypeParam::MQType(numElementsInQueue); - ASSERT_NE(nullptr, fmq); + typename TypeParam::MQType fmq(numElementsInQueue); /* * Should fail due to size being too large to fit into size_t. */ - ASSERT_FALSE(fmq->isValid()); + ASSERT_FALSE(fmq.isValid()); } // If this test fails and we do leak FDs, the next test will cause a crash @@ -329,10 +327,9 @@ TEST_F(Hidl2AidlOperation, ConvertDescriptorsSync) { size_t numElementsInQueue = 64; // Create HIDL side and get MQDescriptor - MessageQueueSync8* fmq = new (std::nothrow) MessageQueueSync8(numElementsInQueue); - ASSERT_NE(nullptr, fmq); - ASSERT_TRUE(fmq->isValid()); - const HidlMQDescSync8* hidlDesc = fmq->getDesc(); + MessageQueueSync8 fmq(numElementsInQueue); + ASSERT_TRUE(fmq.isValid()); + const HidlMQDescSync8* hidlDesc = fmq.getDesc(); ASSERT_NE(nullptr, hidlDesc); // Create AIDL MQDescriptor to send to another process based off the HIDL MQDescriptor @@ -341,17 +338,16 @@ TEST_F(Hidl2AidlOperation, ConvertDescriptorsSync) { &aidlDesc); // Other process will create the other side of the queue using the AIDL MQDescriptor - AidlMessageQueueSync8* aidlFmq = new (std::nothrow) AidlMessageQueueSync8(aidlDesc); - ASSERT_NE(nullptr, aidlFmq); - ASSERT_TRUE(aidlFmq->isValid()); + AidlMessageQueueSync8 aidlFmq(aidlDesc); + ASSERT_TRUE(aidlFmq.isValid()); // Make sure a write to the HIDL side, will show up for the AIDL side constexpr size_t dataLen = 4; uint8_t data[dataLen] = {12, 11, 10, 9}; - fmq->write(data, dataLen); + fmq.write(data, dataLen); int8_t readData[dataLen]; - ASSERT_TRUE(aidlFmq->read(readData, dataLen)); + ASSERT_TRUE(aidlFmq.read(readData, dataLen)); ASSERT_EQ(data[0], readData[0]); ASSERT_EQ(data[1], readData[1]); @@ -363,10 +359,9 @@ TEST_F(Hidl2AidlOperation, ConvertDescriptorsUnsync) { size_t numElementsInQueue = 64; // Create HIDL side and get MQDescriptor - MessageQueueUnsync8* fmq = new (std::nothrow) MessageQueueUnsync8(numElementsInQueue); - ASSERT_NE(nullptr, fmq); - ASSERT_TRUE(fmq->isValid()); - const HidlMQDescUnsync8* hidlDesc = fmq->getDesc(); + MessageQueueUnsync8 fmq(numElementsInQueue); + ASSERT_TRUE(fmq.isValid()); + const HidlMQDescUnsync8* hidlDesc = fmq.getDesc(); ASSERT_NE(nullptr, hidlDesc); // Create AIDL MQDescriptor to send to another process based off the HIDL MQDescriptor @@ -375,24 +370,22 @@ TEST_F(Hidl2AidlOperation, ConvertDescriptorsUnsync) { &aidlDesc); // Other process will create the other side of the queue using the AIDL MQDescriptor - AidlMessageQueueUnsync8* aidlFmq = new (std::nothrow) AidlMessageQueueUnsync8(aidlDesc); - ASSERT_NE(nullptr, aidlFmq); - ASSERT_TRUE(aidlFmq->isValid()); + AidlMessageQueueUnsync8 aidlFmq(aidlDesc); + ASSERT_TRUE(aidlFmq.isValid()); // Can have multiple readers with unsync flavor - AidlMessageQueueUnsync8* aidlFmq2 = new (std::nothrow) AidlMessageQueueUnsync8(aidlDesc); - ASSERT_NE(nullptr, aidlFmq2); - ASSERT_TRUE(aidlFmq2->isValid()); + AidlMessageQueueUnsync8 aidlFmq2(aidlDesc); + ASSERT_TRUE(aidlFmq2.isValid()); // Make sure a write to the HIDL side, will show up for the AIDL side constexpr size_t dataLen = 4; uint8_t data[dataLen] = {12, 11, 10, 9}; - fmq->write(data, dataLen); + fmq.write(data, dataLen); int8_t readData[dataLen]; - ASSERT_TRUE(aidlFmq->read(readData, dataLen)); + ASSERT_TRUE(aidlFmq.read(readData, dataLen)); int8_t readData2[dataLen]; - ASSERT_TRUE(aidlFmq2->read(readData2, dataLen)); + ASSERT_TRUE(aidlFmq2.read(readData2, dataLen)); ASSERT_EQ(data[0], readData[0]); ASSERT_EQ(data[1], readData[1]); @@ -417,12 +410,12 @@ TEST_F(Hidl2AidlOperation, ConvertFdIndex1) { grantors[1] = {0, 1 /* fdIndex */, 16, 16}; grantors[2] = {0, 1 /* fdIndex */, 16, 16}; - HidlMQDescUnsync8* hidlDesc = new (std::nothrow) HidlMQDescUnsync8(grantors, mqHandle, 10); - ASSERT_TRUE(hidlDesc->isHandleValid()); + HidlMQDescUnsync8 hidlDesc(grantors, mqHandle, 10); + ASSERT_TRUE(hidlDesc.isHandleValid()); AidlMQDescUnsync8 aidlDesc; bool ret = android::unsafeHidlToAidlMQDescriptor<uint8_t, int8_t, UnsynchronizedWrite>( - *hidlDesc, &aidlDesc); + hidlDesc, &aidlDesc); ASSERT_TRUE(ret); } @@ -439,16 +432,14 @@ TEST_F(Hidl2AidlOperation, ConvertMultipleFds) { grantors[1] = {0, 1 /* fdIndex */, 16, 16}; grantors[2] = {0, 0 /* fdIndex */, 16, 16}; - HidlMQDescUnsync8* hidlDesc = new (std::nothrow) HidlMQDescUnsync8(grantors, mqHandle, 10); - ASSERT_TRUE(hidlDesc->isHandleValid()); + HidlMQDescUnsync8 hidlDesc(grantors, mqHandle, 10); + ASSERT_TRUE(hidlDesc.isHandleValid()); AidlMQDescUnsync8 aidlDesc; bool ret = android::unsafeHidlToAidlMQDescriptor<uint8_t, int8_t, UnsynchronizedWrite>( - *hidlDesc, &aidlDesc); + hidlDesc, &aidlDesc); ASSERT_TRUE(ret); EXPECT_EQ(aidlDesc.handle.fds.size(), 2); - native_handle_close(mqHandle); - native_handle_delete(mqHandle); } // TODO(b/165674950) Since AIDL does not support unsigned integers, it can only support @@ -456,23 +447,21 @@ TEST_F(Hidl2AidlOperation, ConvertMultipleFds) { // lifted. Until then, check against SSIZE_MAX instead of SIZE_MAX. TEST_F(AidlOnlyBadQueueConfig, QueueSizeTooLargeForAidl) { size_t numElementsInQueue = SSIZE_MAX / sizeof(uint16_t) + 1; - AidlMessageQueueSync16* fmq = new (std::nothrow) AidlMessageQueueSync16(numElementsInQueue); - ASSERT_NE(nullptr, fmq); + AidlMessageQueueSync16 fmq(numElementsInQueue); /* * Should fail due to size being too large to fit into size_t. */ - ASSERT_FALSE(fmq->isValid()); + ASSERT_FALSE(fmq.isValid()); } TEST_F(AidlOnlyBadQueueConfig, NegativeAidlDescriptor) { aidl::android::hardware::common::fmq::MQDescriptor<uint16_t, SynchronizedReadWrite> desc; desc.quantum = -10; - AidlMessageQueueSync16* fmq = new (std::nothrow) AidlMessageQueueSync16(desc); - ASSERT_NE(nullptr, fmq); + AidlMessageQueueSync16 fmq(desc); /* * Should fail due to quantum being negative. */ - ASSERT_FALSE(fmq->isValid()); + ASSERT_FALSE(fmq.isValid()); } TEST_F(AidlOnlyBadQueueConfig, NegativeAidlDescriptorGrantor) { @@ -481,12 +470,11 @@ TEST_F(AidlOnlyBadQueueConfig, NegativeAidlDescriptorGrantor) { desc.flags = 0; desc.grantors.push_back( aidl::android::hardware::common::fmq::GrantorDescriptor{.offset = 12, .extent = -10}); - AidlMessageQueueSync16* fmq = new (std::nothrow) AidlMessageQueueSync16(desc); - ASSERT_NE(nullptr, fmq); + AidlMessageQueueSync16 fmq(desc); /* * Should fail due to grantor having negative extent. */ - ASSERT_FALSE(fmq->isValid()); + ASSERT_FALSE(fmq.isValid()); } /* |