summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Kalesh Singh <kaleshsingh@google.com> 2023-08-10 13:38:17 -0700
committer Kalesh Singh <kaleshsingh@google.com> 2023-08-11 01:29:45 -0700
commitf5a3b8a848ef1c3f72d2fa960437ca9b66ead654 (patch)
tree8d4da7f62fdc22e82d8ffec2a3ce03969fbc3a58
parent24c9102d0facd739aa2af7ae3db462f05409740e (diff)
protoutil: Fix EncodedBuffer test
Commit ag/10780537 ("Optimize memory usage in incidentd") broke the libprotoutil_test since it page aligns the chunk size but didn't update the tests. Fix the tests by page aligning TEST_CHUNK_SIZE; and add a test mapping. Test: atest -c libprotoutil_test Bug: 295228590 Change-Id: I85d828a10cc67334751c3c3a451a75c4dbe3eb76 Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
-rw-r--r--libs/protoutil/Android.bp4
-rw-r--r--libs/protoutil/AndroidTest.xml26
-rw-r--r--libs/protoutil/TEST_MAPPING12
-rw-r--r--libs/protoutil/tests/EncodedBuffer_test.cpp11
4 files changed, 22 insertions, 31 deletions
diff --git a/libs/protoutil/Android.bp b/libs/protoutil/Android.bp
index 128be3c33ac5..28856c87f7c6 100644
--- a/libs/protoutil/Android.bp
+++ b/libs/protoutil/Android.bp
@@ -80,6 +80,10 @@ cc_test {
"libgmock",
],
+ test_suites: [
+ "general-tests",
+ ],
+
proto: {
type: "full",
},
diff --git a/libs/protoutil/AndroidTest.xml b/libs/protoutil/AndroidTest.xml
deleted file mode 100644
index 46d418e1bb0a..000000000000
--- a/libs/protoutil/AndroidTest.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2018 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.
--->
-<configuration description="Config for libprotoutil_test">
- <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
- <option name="cleanup" value="true" />
- <option name="push" value="libprotoutil_test->/data/nativetest/libprotoutil_test" />
- </target_preparer>
- <option name="test-suite-tag" value="apct" />
- <test class="com.android.tradefed.testtype.GTest" >
- <option name="native-test-device-path" value="/data/nativetest" />
- <option name="module-name" value="libprotoutil_test" />
- </test>
-</configuration>
diff --git a/libs/protoutil/TEST_MAPPING b/libs/protoutil/TEST_MAPPING
new file mode 100644
index 000000000000..b10dd9b067b6
--- /dev/null
+++ b/libs/protoutil/TEST_MAPPING
@@ -0,0 +1,12 @@
+{
+ "presubmit": [
+ {
+ "name": "libprotoutil_test"
+ }
+ ],
+ "hwasan-postsubmit": [
+ {
+ "name": "libprotoutil_test"
+ }
+ ]
+}
diff --git a/libs/protoutil/tests/EncodedBuffer_test.cpp b/libs/protoutil/tests/EncodedBuffer_test.cpp
index f895154c4983..8a7becf68d69 100644
--- a/libs/protoutil/tests/EncodedBuffer_test.cpp
+++ b/libs/protoutil/tests/EncodedBuffer_test.cpp
@@ -18,7 +18,8 @@
using namespace android::util;
using android::sp;
-constexpr size_t TEST_CHUNK_SIZE = 16UL;
+constexpr size_t __TEST_CHUNK_SIZE = 16UL;
+constexpr size_t TEST_CHUNK_SIZE = (__TEST_CHUNK_SIZE + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
constexpr size_t TEST_CHUNK_HALF_SIZE = TEST_CHUNK_SIZE / 2;
constexpr size_t TEST_CHUNK_3X_SIZE = 3 * TEST_CHUNK_SIZE;
@@ -34,13 +35,13 @@ TEST(EncodedBufferTest, WriteSimple) {
expectPointer(buffer->wp(), 0);
EXPECT_EQ(buffer->currentToWrite(), TEST_CHUNK_SIZE);
for (size_t i = 0; i < TEST_CHUNK_HALF_SIZE; i++) {
- buffer->writeRawByte(50 + i);
+ buffer->writeRawByte(static_cast<uint8_t>(50 + i));
}
EXPECT_EQ(buffer->size(), TEST_CHUNK_HALF_SIZE);
expectPointer(buffer->wp(), TEST_CHUNK_HALF_SIZE);
EXPECT_EQ(buffer->currentToWrite(), TEST_CHUNK_HALF_SIZE);
for (size_t i = 0; i < TEST_CHUNK_SIZE; i++) {
- buffer->writeRawByte(80 + i);
+ buffer->writeRawByte(static_cast<uint8_t>(80 + i));
}
EXPECT_EQ(buffer->size(), TEST_CHUNK_SIZE + TEST_CHUNK_HALF_SIZE);
expectPointer(buffer->wp(), TEST_CHUNK_SIZE + TEST_CHUNK_HALF_SIZE);
@@ -49,10 +50,10 @@ TEST(EncodedBufferTest, WriteSimple) {
// verifies the buffer's data
expectPointer(buffer->ep(), 0);
for (size_t i = 0; i < TEST_CHUNK_HALF_SIZE; i++) {
- EXPECT_EQ(buffer->readRawByte(), 50 + i);
+ EXPECT_EQ(buffer->readRawByte(), static_cast<uint8_t>(50 + i));
}
for (size_t i = 0; i < TEST_CHUNK_SIZE; i++) {
- EXPECT_EQ(buffer->readRawByte(), 80 + i);
+ EXPECT_EQ(buffer->readRawByte(), static_cast<uint8_t>(80 + i));
}
// clears the buffer