1 /*
2 * Copyright (C) 2022 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 #include <mediautils/Process.h>
18 #include <mediautils/TidWrapper.h>
19
20 #define LOG_TAG "media_process_tests"
21
22 #include <gtest/gtest.h>
23 #include <utils/Log.h>
24
25 using namespace android;
26 using namespace android::mediautils;
27
28 // Disables false-positives from base::Split()
29 //
30 // See mismatched sanitized libraries here:
31 // https://github.com/google/sanitizers/wiki/AddressSanitizerContainerOverflow
__asan_default_options()32 extern "C" const char* __asan_default_options() {
33 return "detect_container_overflow=0";
34 }
35
TEST(media_process_tests,basic)36 TEST(media_process_tests, basic) {
37 const std::string schedString = getThreadSchedAsString(getThreadIdWrapper());
38
39 (void)schedString;
40 // We don't test schedString, only that we haven't crashed.
41 // ASSERT_FALSE(schedString.empty());
42
43 // schedString is not normative. So we conjure up our own string
44 const std::string fakeString = "\
45 AudioOut_8D (10800, #threads: 36)\n\
46 -------------------------------------------------------------------\n\
47 se.exec_start : 8132077.598026\n\
48 se.vruntime : 798689.872087\n\
49 se.sum_exec_runtime : 136466.957838\n\
50 se.nr_migrations : 132487\n\
51 se.statistics.sum_sleep_runtime : 5629794.565945\n\
52 se.statistics.wait_start : 0.000000\n\
53 se.statistics.sleep_start : 8195727.586392\n\
54 se.statistics.block_start : 0.000000\n\
55 se.statistics.sleep_max : 1995665.869808\n\
56 se.statistics.block_max : 0.591675\n\
57 se.statistics.exec_max : 2.477580\n\
58 se.statistics.slice_max : 0.000000\n\
59 se.statistics.wait_max : 8.608642\n\
60 se.statistics.wait_sum : 4683.266835\n\
61 se.statistics.wait_count : 300964\n\
62 se.statistics.iowait_sum : 0.000000\n\
63 se.statistics.iowait_count : 0\n\
64 se.statistics.nr_migrations_cold : 0\n\
65 se.statistics.nr_failed_migrations_affine : 297\n\
66 se.statistics.nr_failed_migrations_running : 1412\n\
67 se.statistics.nr_failed_migrations_hot : 96\n\
68 se.statistics.nr_forced_migrations : 26\n\
69 se.statistics.nr_wakeups : 281263\n\
70 se.statistics.nr_wakeups_sync : 84\n\
71 se.statistics.nr_wakeups_migrate : 132322\n\
72 se.statistics.nr_wakeups_local : 2165\n\
73 se.statistics.nr_wakeups_remote : 279098\n\
74 se.statistics.nr_wakeups_affine : 0\n\
75 se.statistics.nr_wakeups_affine_attempts : 0\n\
76 se.statistics.nr_wakeups_passive : 0\n\
77 se.statistics.nr_wakeups_idle : 0\n\
78 avg_atom : 0.453434\n\
79 avg_per_cpu : 1.030040\n\
80 nr_switches : 300963\n\
81 nr_voluntary_switches : 281252\n\
82 nr_involuntary_switches : 19711\n\
83 se.load.weight : 73477120\n\
84 se.avg.load_sum : 58\n\
85 se.avg.runnable_sum : 27648\n\
86 se.avg.util_sum : 21504\n\
87 se.avg.load_avg : 48\n\
88 se.avg.runnable_avg : 0\n\
89 se.avg.util_avg : 0\n\
90 se.avg.last_update_time : 8132075824128\n\
91 se.avg.util_est.ewma : 8\n\
92 se.avg.util_est.enqueued : 1\n\
93 uclamp.min : 0\n\
94 uclamp.max : 1024\n\
95 effective uclamp.min : 0\n\
96 effective uclamp.max : 1024\n\
97 policy : 0\n\
98 prio : 101\n\
99 clock-delta : 163";
100
101 std::map<std::string, double> m = parseThreadSchedString(fakeString);
102
103 auto it = m.find("clock-delta");
104 ASSERT_NE(it, m.end());
105 ASSERT_EQ(it->second, 163);
106
107 it = m.find("se.avg.load_avg");
108 ASSERT_NE(it, m.end());
109 ASSERT_EQ(it->second, 48);
110 }
111