From ad3e6e5d5a9746bfe9d4600172798c9d6309b149 Mon Sep 17 00:00:00 2001 From: Yi Jin Date: Tue, 3 Apr 2018 15:10:34 -0700 Subject: [PATCH] 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 --- cmds/incidentd/src/PrivacyBuffer.cpp | 2 +- cmds/incidentd/src/Section.h | 2 +- core/proto/android/os/incident.proto | 2 +- core/proto/android/service/notification.proto | 6 ++--- libs/protoutil/Android.bp | 17 ++++++++++++ libs/protoutil/AndroidTest.xml | 26 +++++++++++++++++++ libs/protoutil/src/EncodedBuffer.cpp | 10 ++++--- libs/protoutil/tests/EncodedBuffer_test.cpp | 25 ++++++++++++++++++ 8 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 libs/protoutil/AndroidTest.xml create mode 100644 libs/protoutil/tests/EncodedBuffer_test.cpp diff --git a/cmds/incidentd/src/PrivacyBuffer.cpp b/cmds/incidentd/src/PrivacyBuffer.cpp index 6cd2fe15c1d89..d753e5e6404e0 100644 --- a/cmds/incidentd/src/PrivacyBuffer.cpp +++ b/cmds/incidentd/src/PrivacyBuffer.cpp @@ -34,7 +34,7 @@ namespace incidentd { void PrivacyBuffer::writeFieldOrSkip(uint32_t fieldTag, bool skip) { uint8_t wireType = read_wire_type(fieldTag); size_t bytesToWrite = 0; - uint32_t varint = 0; + uint64_t varint = 0; switch (wireType) { case WIRE_TYPE_VARINT: diff --git a/cmds/incidentd/src/Section.h b/cmds/incidentd/src/Section.h index 34a3613cf0d06..20ecdb1cdfbd8 100644 --- a/cmds/incidentd/src/Section.h +++ b/cmds/incidentd/src/Section.h @@ -31,7 +31,7 @@ namespace android { namespace os { namespace incidentd { -const int64_t REMOTE_CALL_TIMEOUT_MS = 10 * 1000; // 10 seconds +const int64_t REMOTE_CALL_TIMEOUT_MS = 30 * 1000; // 30 seconds /** * Base class for sections diff --git a/core/proto/android/os/incident.proto b/core/proto/android/os/incident.proto index 6467976bbf592..2a7c256031fe5 100644 --- a/core/proto/android/os/incident.proto +++ b/core/proto/android/os/incident.proto @@ -170,7 +170,7 @@ message IncidentProto { ]; optional BatteryTypeProto battery_type = 2006 [ - (section).type = SECTION_FILE, + (section).type = SECTION_NONE, // disabled since the path is device specific! (section).args = "/sys/class/power_supply/bms/battery_type" ]; diff --git a/core/proto/android/service/notification.proto b/core/proto/android/service/notification.proto index cccd2fe568003..bcd7f29a2fcf3 100644 --- a/core/proto/android/service/notification.proto +++ b/core/proto/android/service/notification.proto @@ -65,7 +65,7 @@ message NotificationRecordProto { optional bool can_vibrate = 7; optional bool can_show_light = 8; optional string group_key = 9 [ (.android.privacy).dest = DEST_EXPLICIT ]; - optional int32 importance = 10; + optional sint32 importance = 10; } message ListenersDisablingEffectsProto { @@ -122,11 +122,11 @@ message RankingHelperProto { // Default value is UNKNOWN_UID = USER_NULL = -10000. optional int32 uid = 2; // Default is IMPORTANCE_UNSPECIFIED (-1000). - optional int32 importance = 3; + optional sint32 importance = 3; // Default is PRIORITY_DEFAULT (0). optional int32 priority = 4; // Default is VISIBILITY_NO_OVERRIDE (-1000). - optional int32 visibility = 5; + optional sint32 visibility = 5; // Default is true. optional bool show_badge = 6; repeated android.app.NotificationChannelProto channels = 7; diff --git a/libs/protoutil/Android.bp b/libs/protoutil/Android.bp index 4f1d2d5a4fe5e..7ad83ca796953 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 0000000000000..46d418e1bb0a9 --- /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 3a5e2e9ef5d0c..c017851a16233 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 0000000000000..615ab4ab29ed7 --- /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()); +}