| Yiwei Zhang | fdd7e78 | 2020-01-31 15:59:34 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2020 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #undef LOG_TAG | 
|  | 18 | #define LOG_TAG "gpuservice_unittest" | 
|  | 19 |  | 
| Tim Van Patten | a9ad69b | 2021-11-24 19:29:38 -0700 | [diff] [blame] | 20 | #include <unistd.h> | 
| Yiwei Zhang | fdd7e78 | 2020-01-31 15:59:34 -0800 | [diff] [blame] | 21 | #include <cutils/properties.h> | 
|  | 22 | #include <gmock/gmock.h> | 
|  | 23 | #include <gpustats/GpuStats.h> | 
|  | 24 | #include <gtest/gtest.h> | 
| Yiwei Zhang | b59a127 | 2020-02-04 14:58:01 -0800 | [diff] [blame] | 25 | #include <stats_pull_atom_callback.h> | 
|  | 26 | #include <statslog.h> | 
| Yiwei Zhang | fdd7e78 | 2020-01-31 15:59:34 -0800 | [diff] [blame] | 27 | #include <utils/String16.h> | 
|  | 28 | #include <utils/Vector.h> | 
|  | 29 |  | 
| Yiwei Zhang | b59a127 | 2020-02-04 14:58:01 -0800 | [diff] [blame] | 30 | #include "TestableGpuStats.h" | 
|  | 31 |  | 
| Yiwei Zhang | fdd7e78 | 2020-01-31 15:59:34 -0800 | [diff] [blame] | 32 | namespace android { | 
|  | 33 | namespace { | 
|  | 34 |  | 
|  | 35 | using testing::HasSubstr; | 
|  | 36 |  | 
|  | 37 | // clang-format off | 
|  | 38 | #define BUILTIN_DRIVER_PKG_NAME   "system" | 
|  | 39 | #define BUILTIN_DRIVER_VER_NAME   "0" | 
|  | 40 | #define BUILTIN_DRIVER_VER_CODE   0 | 
|  | 41 | #define BUILTIN_DRIVER_BUILD_TIME 123 | 
|  | 42 | #define UPDATED_DRIVER_PKG_NAME   "updated" | 
|  | 43 | #define UPDATED_DRIVER_VER_NAME   "1" | 
|  | 44 | #define UPDATED_DRIVER_VER_CODE   1 | 
|  | 45 | #define UPDATED_DRIVER_BUILD_TIME 234 | 
|  | 46 | #define VULKAN_VERSION            345 | 
| Yiwei Zhang | fdd7e78 | 2020-01-31 15:59:34 -0800 | [diff] [blame] | 47 | #define APP_PKG_NAME_1            "testapp1" | 
|  | 48 | #define APP_PKG_NAME_2            "testapp2" | 
|  | 49 | #define DRIVER_LOADING_TIME_1     678 | 
|  | 50 | #define DRIVER_LOADING_TIME_2     789 | 
|  | 51 | #define DRIVER_LOADING_TIME_3     891 | 
|  | 52 |  | 
|  | 53 | enum InputCommand : int32_t { | 
|  | 54 | DUMP_ALL               = 0, | 
|  | 55 | DUMP_GLOBAL            = 1, | 
|  | 56 | DUMP_APP               = 2, | 
|  | 57 | DUMP_ALL_THEN_CLEAR    = 3, | 
|  | 58 | DUMP_GLOBAL_THEN_CLEAR = 4, | 
|  | 59 | DUMP_APP_THEN_CLEAR    = 5, | 
|  | 60 | }; | 
|  | 61 | // clang-format on | 
|  | 62 |  | 
|  | 63 | class GpuStatsTest : public testing::Test { | 
|  | 64 | public: | 
|  | 65 | GpuStatsTest() { | 
|  | 66 | const ::testing::TestInfo* const test_info = | 
|  | 67 | ::testing::UnitTest::GetInstance()->current_test_info(); | 
|  | 68 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); | 
|  | 69 | } | 
|  | 70 |  | 
|  | 71 | ~GpuStatsTest() { | 
|  | 72 | const ::testing::TestInfo* const test_info = | 
|  | 73 | ::testing::UnitTest::GetInstance()->current_test_info(); | 
|  | 74 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); | 
|  | 75 | } | 
|  | 76 |  | 
|  | 77 | std::string inputCommand(InputCommand cmd); | 
|  | 78 |  | 
|  | 79 | void SetUp() override { | 
| Yiwei Zhang | cf67368 | 2020-02-04 19:22:51 -0800 | [diff] [blame] | 80 | mCpuVulkanVersion = property_get_int32("ro.cpuvulkan.version", 0); | 
|  | 81 | mGlesVersion = property_get_int32("ro.opengles.version", 0); | 
| Yiwei Zhang | fdd7e78 | 2020-01-31 15:59:34 -0800 | [diff] [blame] | 82 | } | 
|  | 83 |  | 
|  | 84 | std::unique_ptr<GpuStats> mGpuStats = std::make_unique<GpuStats>(); | 
|  | 85 | int32_t mCpuVulkanVersion = 0; | 
|  | 86 | int32_t mGlesVersion = 0; | 
|  | 87 | }; | 
|  | 88 |  | 
|  | 89 | std::string GpuStatsTest::inputCommand(InputCommand cmd) { | 
|  | 90 | std::string result; | 
|  | 91 | Vector<String16> args; | 
|  | 92 |  | 
|  | 93 | switch (cmd) { | 
|  | 94 | case InputCommand::DUMP_ALL: | 
|  | 95 | break; | 
|  | 96 | case InputCommand::DUMP_GLOBAL: | 
|  | 97 | args.push_back(String16("--global")); | 
|  | 98 | break; | 
|  | 99 | case InputCommand::DUMP_APP: | 
|  | 100 | args.push_back(String16("--app")); | 
|  | 101 | break; | 
|  | 102 | case InputCommand::DUMP_ALL_THEN_CLEAR: | 
|  | 103 | args.push_back(String16("--clear")); | 
|  | 104 | break; | 
|  | 105 | case InputCommand::DUMP_GLOBAL_THEN_CLEAR: | 
|  | 106 | args.push_back(String16("--global")); | 
|  | 107 | args.push_back(String16("--clear")); | 
|  | 108 | break; | 
|  | 109 | case InputCommand::DUMP_APP_THEN_CLEAR: | 
|  | 110 | args.push_back(String16("--app")); | 
|  | 111 | args.push_back(String16("--clear")); | 
|  | 112 | break; | 
|  | 113 | } | 
|  | 114 |  | 
|  | 115 | mGpuStats->dump(args, &result); | 
|  | 116 | return result; | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | TEST_F(GpuStatsTest, statsEmptyByDefault) { | 
|  | 120 | ASSERT_TRUE(inputCommand(InputCommand::DUMP_ALL).empty()); | 
|  | 121 | } | 
|  | 122 |  | 
|  | 123 | TEST_F(GpuStatsTest, canInsertBuiltinDriverStats) { | 
|  | 124 | mGpuStats->insertDriverStats(BUILTIN_DRIVER_PKG_NAME, BUILTIN_DRIVER_VER_NAME, | 
|  | 125 | BUILTIN_DRIVER_VER_CODE, BUILTIN_DRIVER_BUILD_TIME, APP_PKG_NAME_1, | 
|  | 126 | VULKAN_VERSION, GpuStatsInfo::Driver::GL, true, | 
|  | 127 | DRIVER_LOADING_TIME_1); | 
|  | 128 |  | 
|  | 129 | std::string expectedResult = "driverPackageName = " + std::string(BUILTIN_DRIVER_PKG_NAME); | 
|  | 130 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr(expectedResult)); | 
|  | 131 | expectedResult = "driverVersionName = " + std::string(BUILTIN_DRIVER_VER_NAME); | 
|  | 132 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr(expectedResult)); | 
|  | 133 | expectedResult = "driverVersionCode = " + std::to_string(BUILTIN_DRIVER_VER_CODE); | 
|  | 134 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr(expectedResult)); | 
|  | 135 | expectedResult = "driverBuildTime = " + std::to_string(BUILTIN_DRIVER_BUILD_TIME); | 
|  | 136 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr(expectedResult)); | 
|  | 137 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr("glLoadingCount = 1")); | 
|  | 138 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr("glLoadingFailureCount = 0")); | 
|  | 139 | expectedResult = "appPackageName = " + std::string(APP_PKG_NAME_1); | 
|  | 140 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr(expectedResult)); | 
|  | 141 | expectedResult = "driverVersionCode = " + std::to_string(BUILTIN_DRIVER_VER_CODE); | 
|  | 142 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr(expectedResult)); | 
|  | 143 | expectedResult = "glDriverLoadingTime: " + std::to_string(DRIVER_LOADING_TIME_1); | 
|  | 144 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr(expectedResult)); | 
|  | 145 | } | 
|  | 146 |  | 
|  | 147 | TEST_F(GpuStatsTest, canInsertUpdatedDriverStats) { | 
|  | 148 | mGpuStats->insertDriverStats(UPDATED_DRIVER_PKG_NAME, UPDATED_DRIVER_VER_NAME, | 
|  | 149 | UPDATED_DRIVER_VER_CODE, UPDATED_DRIVER_BUILD_TIME, APP_PKG_NAME_2, | 
|  | 150 | VULKAN_VERSION, GpuStatsInfo::Driver::VULKAN_UPDATED, false, | 
|  | 151 | DRIVER_LOADING_TIME_2); | 
|  | 152 |  | 
|  | 153 | std::string expectedResult = "driverPackageName = " + std::string(UPDATED_DRIVER_PKG_NAME); | 
|  | 154 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr(expectedResult)); | 
|  | 155 | expectedResult = "driverVersionName = " + std::string(UPDATED_DRIVER_VER_NAME); | 
|  | 156 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr(expectedResult)); | 
|  | 157 | expectedResult = "driverVersionCode = " + std::to_string(UPDATED_DRIVER_VER_CODE); | 
|  | 158 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr(expectedResult)); | 
|  | 159 | expectedResult = "driverBuildTime = " + std::to_string(UPDATED_DRIVER_BUILD_TIME); | 
|  | 160 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr(expectedResult)); | 
|  | 161 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr("vkLoadingCount = 1")); | 
|  | 162 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr("vkLoadingFailureCount = 1")); | 
|  | 163 | expectedResult = "appPackageName = " + std::string(APP_PKG_NAME_2); | 
|  | 164 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr(expectedResult)); | 
|  | 165 | expectedResult = "driverVersionCode = " + std::to_string(UPDATED_DRIVER_VER_CODE); | 
|  | 166 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr(expectedResult)); | 
|  | 167 | expectedResult = "vkDriverLoadingTime: " + std::to_string(DRIVER_LOADING_TIME_2); | 
|  | 168 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr(expectedResult)); | 
|  | 169 | } | 
|  | 170 |  | 
|  | 171 | TEST_F(GpuStatsTest, canInsertAngleDriverStats) { | 
|  | 172 | mGpuStats->insertDriverStats(UPDATED_DRIVER_PKG_NAME, UPDATED_DRIVER_VER_NAME, | 
|  | 173 | UPDATED_DRIVER_VER_CODE, UPDATED_DRIVER_BUILD_TIME, APP_PKG_NAME_2, | 
|  | 174 | VULKAN_VERSION, GpuStatsInfo::Driver::ANGLE, true, | 
|  | 175 | DRIVER_LOADING_TIME_3); | 
|  | 176 |  | 
|  | 177 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr("angleLoadingCount = 1")); | 
|  | 178 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr("angleLoadingFailureCount = 0")); | 
|  | 179 | std::string expectedResult = "angleDriverLoadingTime: " + std::to_string(DRIVER_LOADING_TIME_3); | 
|  | 180 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr(expectedResult)); | 
|  | 181 | } | 
|  | 182 |  | 
|  | 183 | TEST_F(GpuStatsTest, canDump3dApiVersion) { | 
|  | 184 | mGpuStats->insertDriverStats(BUILTIN_DRIVER_PKG_NAME, BUILTIN_DRIVER_VER_NAME, | 
|  | 185 | BUILTIN_DRIVER_VER_CODE, BUILTIN_DRIVER_BUILD_TIME, APP_PKG_NAME_1, | 
|  | 186 | VULKAN_VERSION, GpuStatsInfo::Driver::GL, true, | 
|  | 187 | DRIVER_LOADING_TIME_1); | 
|  | 188 |  | 
|  | 189 | std::string expectedResult = "vulkanVersion = " + std::to_string(VULKAN_VERSION); | 
|  | 190 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr(expectedResult)); | 
|  | 191 | expectedResult = "cpuVulkanVersion = " + std::to_string(mCpuVulkanVersion); | 
|  | 192 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr(expectedResult)); | 
|  | 193 | expectedResult = "glesVersion = " + std::to_string(mGlesVersion); | 
|  | 194 | EXPECT_THAT(inputCommand(InputCommand::DUMP_GLOBAL), HasSubstr(expectedResult)); | 
|  | 195 | } | 
|  | 196 |  | 
|  | 197 | TEST_F(GpuStatsTest, canNotInsertTargetStatsBeforeProperSetup) { | 
|  | 198 | mGpuStats->insertTargetStats(APP_PKG_NAME_1, BUILTIN_DRIVER_VER_CODE, | 
|  | 199 | GpuStatsInfo::Stats::CPU_VULKAN_IN_USE, 0); | 
|  | 200 | mGpuStats->insertTargetStats(APP_PKG_NAME_1, BUILTIN_DRIVER_VER_CODE, | 
|  | 201 | GpuStatsInfo::Stats::FALSE_PREROTATION, 0); | 
|  | 202 | mGpuStats->insertTargetStats(APP_PKG_NAME_1, BUILTIN_DRIVER_VER_CODE, | 
|  | 203 | GpuStatsInfo::Stats::GLES_1_IN_USE, 0); | 
|  | 204 |  | 
|  | 205 | EXPECT_TRUE(inputCommand(InputCommand::DUMP_APP).empty()); | 
|  | 206 | } | 
|  | 207 |  | 
|  | 208 | TEST_F(GpuStatsTest, canInsertTargetStatsAfterProperSetup) { | 
|  | 209 | mGpuStats->insertDriverStats(BUILTIN_DRIVER_PKG_NAME, BUILTIN_DRIVER_VER_NAME, | 
|  | 210 | BUILTIN_DRIVER_VER_CODE, BUILTIN_DRIVER_BUILD_TIME, APP_PKG_NAME_1, | 
|  | 211 | VULKAN_VERSION, GpuStatsInfo::Driver::GL, true, | 
|  | 212 | DRIVER_LOADING_TIME_1); | 
|  | 213 | mGpuStats->insertTargetStats(APP_PKG_NAME_1, BUILTIN_DRIVER_VER_CODE, | 
|  | 214 | GpuStatsInfo::Stats::CPU_VULKAN_IN_USE, 0); | 
|  | 215 | mGpuStats->insertTargetStats(APP_PKG_NAME_1, BUILTIN_DRIVER_VER_CODE, | 
|  | 216 | GpuStatsInfo::Stats::FALSE_PREROTATION, 0); | 
|  | 217 | mGpuStats->insertTargetStats(APP_PKG_NAME_1, BUILTIN_DRIVER_VER_CODE, | 
|  | 218 | GpuStatsInfo::Stats::GLES_1_IN_USE, 0); | 
|  | 219 |  | 
|  | 220 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr("cpuVulkanInUse = 1")); | 
|  | 221 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr("falsePrerotation = 1")); | 
|  | 222 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr("gles1InUse = 1")); | 
|  | 223 | } | 
|  | 224 |  | 
| Tim Van Patten | a9ad69b | 2021-11-24 19:29:38 -0700 | [diff] [blame] | 225 | // Verify we always have the most recently used apps in mAppStats, even when we fill it. | 
|  | 226 | TEST_F(GpuStatsTest, canInsertMoreThanMaxNumAppRecords) { | 
|  | 227 | constexpr int kNumExtraApps = 15; | 
|  | 228 | static_assert(kNumExtraApps > GpuStats::APP_RECORD_HEADROOM); | 
|  | 229 |  | 
|  | 230 | // Insert stats for GpuStats::MAX_NUM_APP_RECORDS so we fill it up. | 
|  | 231 | for (int i = 0; i < GpuStats::MAX_NUM_APP_RECORDS + kNumExtraApps; ++i) { | 
|  | 232 | std::stringstream nameStream; | 
|  | 233 | nameStream << "testapp" << "_" << i; | 
|  | 234 | std::string fullPkgName = nameStream.str(); | 
|  | 235 |  | 
|  | 236 | mGpuStats->insertDriverStats(BUILTIN_DRIVER_PKG_NAME, BUILTIN_DRIVER_VER_NAME, | 
|  | 237 | BUILTIN_DRIVER_VER_CODE, BUILTIN_DRIVER_BUILD_TIME, | 
|  | 238 | fullPkgName, VULKAN_VERSION, GpuStatsInfo::Driver::GL, true, | 
|  | 239 | DRIVER_LOADING_TIME_1); | 
|  | 240 | mGpuStats->insertTargetStats(fullPkgName, BUILTIN_DRIVER_VER_CODE, | 
|  | 241 | GpuStatsInfo::Stats::CPU_VULKAN_IN_USE, 0); | 
|  | 242 | mGpuStats->insertTargetStats(fullPkgName, BUILTIN_DRIVER_VER_CODE, | 
|  | 243 | GpuStatsInfo::Stats::FALSE_PREROTATION, 0); | 
|  | 244 | mGpuStats->insertTargetStats(fullPkgName, BUILTIN_DRIVER_VER_CODE, | 
|  | 245 | GpuStatsInfo::Stats::GLES_1_IN_USE, 0); | 
|  | 246 |  | 
|  | 247 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr(fullPkgName.c_str())); | 
|  | 248 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr("cpuVulkanInUse = 1")); | 
|  | 249 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr("falsePrerotation = 1")); | 
|  | 250 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr("gles1InUse = 1")); | 
|  | 251 | } | 
|  | 252 |  | 
|  | 253 | // mAppStats purges GpuStats::APP_RECORD_HEADROOM apps removed everytime it's filled up. | 
|  | 254 | int numPurges = kNumExtraApps / GpuStats::APP_RECORD_HEADROOM; | 
|  | 255 | numPurges += (kNumExtraApps % GpuStats::APP_RECORD_HEADROOM) == 0 ? 0 : 1; | 
|  | 256 |  | 
|  | 257 | // Verify the remaining apps are present. | 
|  | 258 | for (int i = numPurges * GpuStats::APP_RECORD_HEADROOM; | 
|  | 259 | i < GpuStats::MAX_NUM_APP_RECORDS + kNumExtraApps; | 
|  | 260 | ++i) { | 
|  | 261 | std::stringstream nameStream; | 
|  | 262 | // Add a newline to search for the exact package name. | 
|  | 263 | nameStream << "testapp" << "_" << i << "\n"; | 
|  | 264 | std::string fullPkgName = nameStream.str(); | 
|  | 265 |  | 
|  | 266 | EXPECT_THAT(inputCommand(InputCommand::DUMP_APP), HasSubstr(fullPkgName.c_str())); | 
|  | 267 | } | 
|  | 268 | } | 
|  | 269 |  | 
| Yiwei Zhang | fdd7e78 | 2020-01-31 15:59:34 -0800 | [diff] [blame] | 270 | TEST_F(GpuStatsTest, canDumpAllBeforeClearAll) { | 
|  | 271 | mGpuStats->insertDriverStats(BUILTIN_DRIVER_PKG_NAME, BUILTIN_DRIVER_VER_NAME, | 
|  | 272 | BUILTIN_DRIVER_VER_CODE, BUILTIN_DRIVER_BUILD_TIME, APP_PKG_NAME_1, | 
|  | 273 | VULKAN_VERSION, GpuStatsInfo::Driver::GL, true, | 
|  | 274 | DRIVER_LOADING_TIME_1); | 
|  | 275 |  | 
|  | 276 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_ALL_THEN_CLEAR).empty()); | 
|  | 277 | EXPECT_TRUE(inputCommand(InputCommand::DUMP_ALL).empty()); | 
|  | 278 | } | 
|  | 279 |  | 
|  | 280 | TEST_F(GpuStatsTest, canDumpGlobalBeforeClearGlobal) { | 
|  | 281 | mGpuStats->insertDriverStats(BUILTIN_DRIVER_PKG_NAME, BUILTIN_DRIVER_VER_NAME, | 
|  | 282 | BUILTIN_DRIVER_VER_CODE, BUILTIN_DRIVER_BUILD_TIME, APP_PKG_NAME_1, | 
|  | 283 | VULKAN_VERSION, GpuStatsInfo::Driver::GL, true, | 
|  | 284 | DRIVER_LOADING_TIME_1); | 
|  | 285 |  | 
|  | 286 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_GLOBAL_THEN_CLEAR).empty()); | 
|  | 287 | EXPECT_TRUE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); | 
|  | 288 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_APP).empty()); | 
|  | 289 | } | 
|  | 290 |  | 
|  | 291 | TEST_F(GpuStatsTest, canDumpAppBeforeClearApp) { | 
|  | 292 | mGpuStats->insertDriverStats(BUILTIN_DRIVER_PKG_NAME, BUILTIN_DRIVER_VER_NAME, | 
|  | 293 | BUILTIN_DRIVER_VER_CODE, BUILTIN_DRIVER_BUILD_TIME, APP_PKG_NAME_1, | 
|  | 294 | VULKAN_VERSION, GpuStatsInfo::Driver::GL, true, | 
|  | 295 | DRIVER_LOADING_TIME_1); | 
|  | 296 |  | 
|  | 297 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_APP_THEN_CLEAR).empty()); | 
|  | 298 | EXPECT_TRUE(inputCommand(InputCommand::DUMP_APP).empty()); | 
|  | 299 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); | 
|  | 300 | } | 
|  | 301 |  | 
| Yiwei Zhang | b59a127 | 2020-02-04 14:58:01 -0800 | [diff] [blame] | 302 | TEST_F(GpuStatsTest, skipPullInvalidAtom) { | 
|  | 303 | TestableGpuStats testableGpuStats(mGpuStats.get()); | 
|  | 304 | mGpuStats->insertDriverStats(BUILTIN_DRIVER_PKG_NAME, BUILTIN_DRIVER_VER_NAME, | 
|  | 305 | BUILTIN_DRIVER_VER_CODE, BUILTIN_DRIVER_BUILD_TIME, APP_PKG_NAME_1, | 
|  | 306 | VULKAN_VERSION, GpuStatsInfo::Driver::GL, true, | 
|  | 307 | DRIVER_LOADING_TIME_1); | 
|  | 308 |  | 
|  | 309 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); | 
|  | 310 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_APP).empty()); | 
|  | 311 |  | 
|  | 312 | EXPECT_TRUE(testableGpuStats.makePullAtomCallback(-1) == AStatsManager_PULL_SKIP); | 
|  | 313 |  | 
|  | 314 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); | 
|  | 315 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_APP).empty()); | 
|  | 316 | } | 
|  | 317 |  | 
|  | 318 | TEST_F(GpuStatsTest, canPullGlobalAtom) { | 
|  | 319 | TestableGpuStats testableGpuStats(mGpuStats.get()); | 
|  | 320 | mGpuStats->insertDriverStats(BUILTIN_DRIVER_PKG_NAME, BUILTIN_DRIVER_VER_NAME, | 
|  | 321 | BUILTIN_DRIVER_VER_CODE, BUILTIN_DRIVER_BUILD_TIME, APP_PKG_NAME_1, | 
|  | 322 | VULKAN_VERSION, GpuStatsInfo::Driver::GL, true, | 
|  | 323 | DRIVER_LOADING_TIME_1); | 
|  | 324 |  | 
|  | 325 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); | 
|  | 326 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_APP).empty()); | 
|  | 327 |  | 
|  | 328 | EXPECT_TRUE(testableGpuStats.makePullAtomCallback(android::util::GPU_STATS_GLOBAL_INFO) == | 
|  | 329 | AStatsManager_PULL_SUCCESS); | 
|  | 330 |  | 
|  | 331 | EXPECT_TRUE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); | 
|  | 332 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_APP).empty()); | 
|  | 333 | } | 
|  | 334 |  | 
| Yiwei Zhang | 29f8593 | 2020-02-04 17:14:54 -0800 | [diff] [blame] | 335 | TEST_F(GpuStatsTest, canPullAppAtom) { | 
|  | 336 | TestableGpuStats testableGpuStats(mGpuStats.get()); | 
|  | 337 | mGpuStats->insertDriverStats(BUILTIN_DRIVER_PKG_NAME, BUILTIN_DRIVER_VER_NAME, | 
|  | 338 | BUILTIN_DRIVER_VER_CODE, BUILTIN_DRIVER_BUILD_TIME, APP_PKG_NAME_1, | 
|  | 339 | VULKAN_VERSION, GpuStatsInfo::Driver::GL, true, | 
|  | 340 | DRIVER_LOADING_TIME_1); | 
|  | 341 |  | 
|  | 342 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); | 
|  | 343 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_APP).empty()); | 
|  | 344 |  | 
|  | 345 | EXPECT_TRUE(testableGpuStats.makePullAtomCallback(android::util::GPU_STATS_APP_INFO) == | 
|  | 346 | AStatsManager_PULL_SUCCESS); | 
|  | 347 |  | 
|  | 348 | EXPECT_FALSE(inputCommand(InputCommand::DUMP_GLOBAL).empty()); | 
|  | 349 | EXPECT_TRUE(inputCommand(InputCommand::DUMP_APP).empty()); | 
|  | 350 | } | 
|  | 351 |  | 
| Yiwei Zhang | fdd7e78 | 2020-01-31 15:59:34 -0800 | [diff] [blame] | 352 | } // namespace | 
|  | 353 | } // namespace android |