From ad3e6e5d5a9746bfe9d4600172798c9d6309b149 Mon Sep 17 00:00:00 2001 From: Yi Jin Date: Tue, 3 Apr 2018 15:10:34 -0700 Subject: This cl tries to fix cts tests IncidentdTest 1. Disable BatteryType section which is device-specific 2. Make timeout longer since meminfo section timedout in test 3. make some negative values sint 4. varint can be 64 bits, there is a bug implicitly convert it to 32 which loses values. 5. Found another bug which failed to read 64 bits varint, create a native test to make sure it works. Bug: 77291057 Test: atest CtsIncidentHostTestCases:com.android.server.cts.IncidentdTest Change-Id: I04cc730741f7901f37ac57a11af7777d57118a23 --- libs/protoutil/Android.bp | 17 +++++++++++++++++ libs/protoutil/AndroidTest.xml | 26 ++++++++++++++++++++++++++ libs/protoutil/src/EncodedBuffer.cpp | 10 ++++++---- libs/protoutil/tests/EncodedBuffer_test.cpp | 25 +++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 libs/protoutil/AndroidTest.xml create mode 100644 libs/protoutil/tests/EncodedBuffer_test.cpp (limited to 'libs') diff --git a/libs/protoutil/Android.bp b/libs/protoutil/Android.bp index 4f1d2d5a4fe5..7ad83ca79695 100644 --- a/libs/protoutil/Android.bp +++ b/libs/protoutil/Android.bp @@ -37,3 +37,20 @@ cc_library { "liblog", ], } + +cc_test { + name: "libprotoutil_test", + + srcs: [ + "tests/EncodedBuffer_test.cpp", + ], + + shared_libs: [ + "libcutils", + "libprotoutil", + ], + + static_libs: [ + "libgmock", + ], +} diff --git a/libs/protoutil/AndroidTest.xml b/libs/protoutil/AndroidTest.xml new file mode 100644 index 000000000000..46d418e1bb0a --- /dev/null +++ b/libs/protoutil/AndroidTest.xml @@ -0,0 +1,26 @@ + + + + + + diff --git a/libs/protoutil/src/EncodedBuffer.cpp b/libs/protoutil/src/EncodedBuffer.cpp index 3a5e2e9ef5d0..c017851a1623 100644 --- a/libs/protoutil/src/EncodedBuffer.cpp +++ b/libs/protoutil/src/EncodedBuffer.cpp @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#define LOG_TAG "libprotoutil" + +#include #include #include - -#include +#include namespace android { namespace util { @@ -228,7 +230,7 @@ EncodedBuffer::readRawVarint() size_t start = mEp.pos(); while (true) { uint8_t byte = readRawByte(); - val += (byte & 0x7F) << shift; + val |= (UINT64_C(0x7F) & byte) << shift; if ((byte & 0x80) == 0) break; shift += 7; } @@ -345,7 +347,7 @@ EncodedBuffer::iterator::readRawVarint() uint64_t val = 0, shift = 0; while (true) { uint8_t byte = next(); - val += (byte & 0x7F) << shift; + val |= (INT64_C(0x7F) & byte) << shift; if ((byte & 0x80) == 0) break; shift += 7; } diff --git a/libs/protoutil/tests/EncodedBuffer_test.cpp b/libs/protoutil/tests/EncodedBuffer_test.cpp new file mode 100644 index 000000000000..615ab4ab29ed --- /dev/null +++ b/libs/protoutil/tests/EncodedBuffer_test.cpp @@ -0,0 +1,25 @@ +// 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. +#include +#include +#include + +using namespace android::util; + +TEST(EncodedBufferTest, ReadVarint) { + EncodedBuffer buffer; + uint64_t val = UINT64_C(1522865904593); + buffer.writeRawVarint64(val); + EXPECT_EQ(val, buffer.begin().readRawVarint()); +} -- cgit v1.2.3