From 1bcbf851107b35a8e3dee99dad7e84fa61f0ccab Mon Sep 17 00:00:00 2001 From: Kalesh Singh Date: Fri, 12 Feb 2021 11:29:50 -0500 Subject: [PATCH] Memtrack HAL: Remove MemtrackType::NUM_TYPES Remove NUM_TYPES from MemtrackType enum, since this can cause conflicts if the enum changes. Use enum_range to iterate the MemtrackType enum. Bug: 179432507 Test: atest VtsHalMemtrackTargetTest Change-Id: Iadad3e0547c1c2f6aaf0f55a2d50e4c625a909e0 --- .../android/hardware/memtrack/DeviceInfo.aidl | 29 +++++++++++++----- .../android/hardware/memtrack/IMemtrack.aidl | 29 +++++++++++++----- .../hardware/memtrack/MemtrackRecord.aidl | 29 +++++++++++++----- .../hardware/memtrack/MemtrackType.aidl | 30 ++++++++++++++----- .../hardware/memtrack/MemtrackType.aidl | 1 - memtrack/aidl/default/Memtrack.cpp | 3 +- .../aidl/vts/VtsHalMemtrackTargetTest.cpp | 23 +++++++------- 7 files changed, 103 insertions(+), 41 deletions(-) diff --git a/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/DeviceInfo.aidl b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/DeviceInfo.aidl index 00abff9edc..3e25c56e43 100644 --- a/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/DeviceInfo.aidl +++ b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/DeviceInfo.aidl @@ -1,14 +1,29 @@ -/////////////////////////////////////////////////////////////////////////////// +/* + * Copyright (C) 2020 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. + *//////////////////////////////////////////////////////////////////////////////// // THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // /////////////////////////////////////////////////////////////////////////////// -// This file is a snapshot of an AIDL interface (or parcelable). Do not try to -// edit this file. It looks like you are doing that because you have modified -// an AIDL interface in a backward-incompatible way, e.g., deleting a function -// from an interface or a field from a parcelable and it broke the build. That -// breakage is intended. +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. // -// You must not make a backward incompatible changes to the AIDL files built +// You must not make a backward incompatible change to any AIDL file built // with the aidl_interface module type with versions property set. The module // type is used to build AIDL files in a way that they can be used across // independently updatable components of the system. If a device is shipped diff --git a/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/IMemtrack.aidl b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/IMemtrack.aidl index 844a1bb3d4..2e2b68e2f1 100644 --- a/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/IMemtrack.aidl +++ b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/IMemtrack.aidl @@ -1,14 +1,29 @@ -/////////////////////////////////////////////////////////////////////////////// +/* + * Copyright (C) 2020 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. + *//////////////////////////////////////////////////////////////////////////////// // THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // /////////////////////////////////////////////////////////////////////////////// -// This file is a snapshot of an AIDL interface (or parcelable). Do not try to -// edit this file. It looks like you are doing that because you have modified -// an AIDL interface in a backward-incompatible way, e.g., deleting a function -// from an interface or a field from a parcelable and it broke the build. That -// breakage is intended. +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. // -// You must not make a backward incompatible changes to the AIDL files built +// You must not make a backward incompatible change to any AIDL file built // with the aidl_interface module type with versions property set. The module // type is used to build AIDL files in a way that they can be used across // independently updatable components of the system. If a device is shipped diff --git a/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/MemtrackRecord.aidl b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/MemtrackRecord.aidl index 09ecefc6c4..0e15ce32dd 100644 --- a/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/MemtrackRecord.aidl +++ b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/MemtrackRecord.aidl @@ -1,14 +1,29 @@ -/////////////////////////////////////////////////////////////////////////////// +/* + * Copyright (C) 2020 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. + *//////////////////////////////////////////////////////////////////////////////// // THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // /////////////////////////////////////////////////////////////////////////////// -// This file is a snapshot of an AIDL interface (or parcelable). Do not try to -// edit this file. It looks like you are doing that because you have modified -// an AIDL interface in a backward-incompatible way, e.g., deleting a function -// from an interface or a field from a parcelable and it broke the build. That -// breakage is intended. +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. // -// You must not make a backward incompatible changes to the AIDL files built +// You must not make a backward incompatible change to any AIDL file built // with the aidl_interface module type with versions property set. The module // type is used to build AIDL files in a way that they can be used across // independently updatable components of the system. If a device is shipped diff --git a/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/MemtrackType.aidl b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/MemtrackType.aidl index 7f3f93904f..b19869e61f 100644 --- a/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/MemtrackType.aidl +++ b/memtrack/aidl/aidl_api/android.hardware.memtrack/current/android/hardware/memtrack/MemtrackType.aidl @@ -1,14 +1,29 @@ -/////////////////////////////////////////////////////////////////////////////// +/* + * Copyright (C) 2020 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. + *//////////////////////////////////////////////////////////////////////////////// // THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // /////////////////////////////////////////////////////////////////////////////// -// This file is a snapshot of an AIDL interface (or parcelable). Do not try to -// edit this file. It looks like you are doing that because you have modified -// an AIDL interface in a backward-incompatible way, e.g., deleting a function -// from an interface or a field from a parcelable and it broke the build. That -// breakage is intended. +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. // -// You must not make a backward incompatible changes to the AIDL files built +// You must not make a backward incompatible change to any AIDL file built // with the aidl_interface module type with versions property set. The module // type is used to build AIDL files in a way that they can be used across // independently updatable components of the system. If a device is shipped @@ -23,5 +38,4 @@ enum MemtrackType { GRAPHICS = 2, MULTIMEDIA = 3, CAMERA = 4, - NUM_TYPES = 5, } diff --git a/memtrack/aidl/android/hardware/memtrack/MemtrackType.aidl b/memtrack/aidl/android/hardware/memtrack/MemtrackType.aidl index 715c6bff43..5db735a2e5 100644 --- a/memtrack/aidl/android/hardware/memtrack/MemtrackType.aidl +++ b/memtrack/aidl/android/hardware/memtrack/MemtrackType.aidl @@ -27,5 +27,4 @@ enum MemtrackType { GRAPHICS = 2, MULTIMEDIA = 3, CAMERA = 4, - NUM_TYPES, } diff --git a/memtrack/aidl/default/Memtrack.cpp b/memtrack/aidl/default/Memtrack.cpp index 000b25c030..49a6582989 100644 --- a/memtrack/aidl/default/Memtrack.cpp +++ b/memtrack/aidl/default/Memtrack.cpp @@ -26,7 +26,8 @@ ndk::ScopedAStatus Memtrack::getMemory(int pid, MemtrackType type, if (pid < 0) { return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT)); } - if (type < MemtrackType::OTHER || type >= MemtrackType::NUM_TYPES) { + if (type != MemtrackType::OTHER && type != MemtrackType::GL && type != MemtrackType::GRAPHICS && + type != MemtrackType::MULTIMEDIA && type != MemtrackType::CAMERA) { return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); } _aidl_return->clear(); diff --git a/memtrack/aidl/vts/VtsHalMemtrackTargetTest.cpp b/memtrack/aidl/vts/VtsHalMemtrackTargetTest.cpp index d5f4612ca2..8905f50eaf 100644 --- a/memtrack/aidl/vts/VtsHalMemtrackTargetTest.cpp +++ b/memtrack/aidl/vts/VtsHalMemtrackTargetTest.cpp @@ -46,17 +46,19 @@ class MemtrackAidlTest : public testing::TestWithParam { TEST_P(MemtrackAidlTest, GetMemoryInvalidPid) { int pid = -1; - MemtrackType type = MemtrackType::OTHER; - std::vector records; - auto status = memtrack_->getMemory(pid, type, &records); + for (MemtrackType type : ndk::enum_range()) { + std::vector records; - EXPECT_EQ(status.getExceptionCode(), EX_ILLEGAL_ARGUMENT); + auto status = memtrack_->getMemory(pid, type, &records); + + EXPECT_EQ(status.getExceptionCode(), EX_ILLEGAL_ARGUMENT); + } } TEST_P(MemtrackAidlTest, GetMemoryInvalidType) { int pid = 1; - MemtrackType type = MemtrackType::NUM_TYPES; + MemtrackType type = static_cast(-1); std::vector records; auto status = memtrack_->getMemory(pid, type, &records); @@ -66,12 +68,13 @@ TEST_P(MemtrackAidlTest, GetMemoryInvalidType) { TEST_P(MemtrackAidlTest, GetMemory) { int pid = 1; - MemtrackType type = MemtrackType::OTHER; - std::vector records; + for (MemtrackType type : ndk::enum_range()) { + std::vector records; - auto status = memtrack_->getMemory(pid, type, &records); + auto status = memtrack_->getMemory(pid, type, &records); - EXPECT_TRUE(status.isOk()); + EXPECT_TRUE(status.isOk()); + } } TEST_P(MemtrackAidlTest, GetGpuDeviceInfo) { @@ -87,7 +90,7 @@ TEST_P(MemtrackAidlTest, GetGpuDeviceInfo) { ->getRuntimeInfo(RuntimeInfo::FetchFlag::CPU_VERSION) ->kernelVersion(); EXPECT_LT(kernel_version, min_kernel_version) - << "Devices with 5.10 or later kernels must implement getGpuDeviceInfo()"; + << "Devices with 5.4 or later kernels must implement getGpuDeviceInfo()"; return; }