1 /*
2 * Copyright (C) 2014 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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "SessionStatsBuilderTest"
19
20 #include <gtest/gtest.h>
21 #include <utils/Errors.h>
22
23 #include "../utils/SessionStatsBuilder.h"
24
25 using namespace std;
26 using namespace android;
27
TEST(SessionStatsBuilderTest,FpsHistogramTest)28 TEST(SessionStatsBuilderTest, FpsHistogramTest) {
29 SessionStatsBuilder b{};
30
31 int64_t requestCount, resultErrorCount;
32 bool deviceError;
33 pair<int32_t, int32_t> mostRequestedFpsRange;
34 map<int, StreamStats> streamStatsMap;
35
36 // Verify we get the most common FPS
37 int64_t fc = 0;
38 for (size_t i = 0; i < 10; i++, fc++) b.incFpsRequestedCount(30, 30, fc);
39 for (size_t i = 0; i < 15; i++, fc++) b.incFpsRequestedCount(15, 30, fc);
40 for (size_t i = 0; i < 20; i++, fc++) b.incFpsRequestedCount(15, 15, fc);
41 for (size_t i = 0; i < 10; i++, fc++) b.incFpsRequestedCount(60, 60, fc);
42
43 b.buildAndReset(&requestCount, &resultErrorCount,
44 &deviceError, &mostRequestedFpsRange, &streamStatsMap);
45 ASSERT_EQ(mostRequestedFpsRange, make_pair(15, 15)) << "Incorrect most common FPS selected";
46
47 // Verify empty stats behavior
48 b.buildAndReset(&requestCount, &resultErrorCount,
49 &deviceError, &mostRequestedFpsRange, &streamStatsMap);
50 ASSERT_EQ(mostRequestedFpsRange, make_pair(0, 0)) << "Incorrect empty stats FPS reported";
51
52 // Verify one frame behavior
53 b.incFpsRequestedCount(30, 30, 1);
54 b.buildAndReset(&requestCount, &resultErrorCount,
55 &deviceError, &mostRequestedFpsRange, &streamStatsMap);
56 ASSERT_EQ(mostRequestedFpsRange, make_pair(30, 30)) << "Incorrect single-frame FPS reported";
57
58 // Verify overflow stats behavior
59 fc = 0;
60 for (size_t range = 1; range < SessionStatsBuilder::FPS_HISTOGRAM_MAX_SIZE + 2; range++) {
61 int count = SessionStatsBuilder::FPS_HISTOGRAM_MAX_SIZE * 3;
62 for (size_t i = 0; i < count - range; i++, fc++) b.incFpsRequestedCount(range, range, fc);
63 }
64 // Should have the oldest bucket dropped, so second oldest should be most common
65 b.buildAndReset(&requestCount, &resultErrorCount,
66 &deviceError, &mostRequestedFpsRange, &streamStatsMap);
67 ASSERT_EQ(mostRequestedFpsRange, make_pair(2, 2)) << "Incorrect stats overflow behavior";
68
69 }
70