diff options
author | Connor O'Brien <connoro@google.com> | 2022-01-31 23:11:40 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-01-31 23:11:40 +0000 |
commit | 0793bb709a812aed1bf59a18351f803b6f1a2763 (patch) | |
tree | 713fb1c7b24c56f9b4045c66e7d660c4360d5769 | |
parent | c2f1f144f4477c79cf287aa366ff20649ed2deb6 (diff) | |
parent | aeb3a986e2e7231ef5983c13c3a09f9741f6ecf2 (diff) | |
download | native-0793bb709a812aed1bf59a18351f803b6f1a2763.tar.gz |
Merge changes Ide638de1,I11bc5cc6
* changes:
libtimeinstate: add tests to presubmit
libtimeinstate: skip tests on non-supporting devices
-rw-r--r-- | libs/cputimeinstate/Android.bp | 1 | ||||
-rw-r--r-- | libs/cputimeinstate/TEST_MAPPING | 7 | ||||
-rw-r--r-- | libs/cputimeinstate/testtimeinstate.cpp | 58 |
3 files changed, 41 insertions, 25 deletions
diff --git a/libs/cputimeinstate/Android.bp b/libs/cputimeinstate/Android.bp index 73f9d4d153..4f63194f03 100644 --- a/libs/cputimeinstate/Android.bp +++ b/libs/cputimeinstate/Android.bp @@ -45,4 +45,5 @@ cc_test { "-Wextra", ], require_root: true, + test_suites: ["general-tests"], } diff --git a/libs/cputimeinstate/TEST_MAPPING b/libs/cputimeinstate/TEST_MAPPING new file mode 100644 index 0000000000..4781520755 --- /dev/null +++ b/libs/cputimeinstate/TEST_MAPPING @@ -0,0 +1,7 @@ +{ + "presubmit": [ + { + "name": "libtimeinstate_test" + } + ] +} diff --git a/libs/cputimeinstate/testtimeinstate.cpp b/libs/cputimeinstate/testtimeinstate.cpp index 2112b10ebc..1513ecafc8 100644 --- a/libs/cputimeinstate/testtimeinstate.cpp +++ b/libs/cputimeinstate/testtimeinstate.cpp @@ -27,6 +27,7 @@ #include <gtest/gtest.h> +#include <android-base/properties.h> #include <android-base/unique_fd.h> #include <bpf/BpfMap.h> #include <cputimeinstate.h> @@ -40,24 +41,31 @@ static constexpr uint64_t NSEC_PER_YEAR = NSEC_PER_SEC * 60 * 60 * 24 * 365; using std::vector; -TEST(TimeInStateTest, IsTrackingSupported) { - isTrackingUidTimesSupported(); - SUCCEED(); -} +class TimeInStateTest : public testing::Test { + protected: + TimeInStateTest() {}; + + void SetUp() { + if (!isTrackingUidTimesSupported() || + !android::base::GetBoolProperty("sys.init.perf_lsm_hooks", false)) { + GTEST_SKIP(); + } + } +}; -TEST(TimeInStateTest, TotalTimeInState) { +TEST_F(TimeInStateTest, TotalTimeInState) { auto times = getTotalCpuFreqTimes(); ASSERT_TRUE(times.has_value()); EXPECT_FALSE(times->empty()); } -TEST(TimeInStateTest, SingleUidTimeInState) { +TEST_F(TimeInStateTest, SingleUidTimeInState) { auto times = getUidCpuFreqTimes(0); ASSERT_TRUE(times.has_value()); EXPECT_FALSE(times->empty()); } -TEST(TimeInStateTest, SingleUidConcurrentTimes) { +TEST_F(TimeInStateTest, SingleUidConcurrentTimes) { auto concurrentTimes = getUidConcurrentTimes(0); ASSERT_TRUE(concurrentTimes.has_value()); ASSERT_FALSE(concurrentTimes->active.empty()); @@ -117,7 +125,7 @@ static void TestUidTimesConsistent(const std::vector<std::vector<uint64_t>> &tim EXPECT_EQ(activeSum, policySum); } -TEST(TimeInStateTest, SingleUidTimesConsistent) { +TEST_F(TimeInStateTest, SingleUidTimesConsistent) { auto times = getUidCpuFreqTimes(0); ASSERT_TRUE(times.has_value()); @@ -127,7 +135,7 @@ TEST(TimeInStateTest, SingleUidTimesConsistent) { ASSERT_NO_FATAL_FAILURE(TestUidTimesConsistent(*times, *concurrentTimes)); } -TEST(TimeInStateTest, AllUidTimeInState) { +TEST_F(TimeInStateTest, AllUidTimeInState) { uint64_t zero = 0; auto maps = {getUidsCpuFreqTimes(), getUidsUpdatedCpuFreqTimes(&zero)}; for (const auto &map : maps) { @@ -163,7 +171,7 @@ void TestCheckUpdate(const std::vector<std::vector<uint64_t>> &before, ASSERT_LE(sumAfter - sumBefore, NSEC_PER_SEC); } -TEST(TimeInStateTest, AllUidUpdatedTimeInState) { +TEST_F(TimeInStateTest, AllUidUpdatedTimeInState) { uint64_t lastUpdate = 0; auto map1 = getUidsUpdatedCpuFreqTimes(&lastUpdate); ASSERT_TRUE(map1.has_value()); @@ -197,7 +205,7 @@ TEST(TimeInStateTest, AllUidUpdatedTimeInState) { } } -TEST(TimeInStateTest, TotalAndAllUidTimeInStateConsistent) { +TEST_F(TimeInStateTest, TotalAndAllUidTimeInStateConsistent) { auto allUid = getUidsCpuFreqTimes(); auto total = getTotalCpuFreqTimes(); @@ -222,7 +230,7 @@ TEST(TimeInStateTest, TotalAndAllUidTimeInStateConsistent) { } } -TEST(TimeInStateTest, SingleAndAllUidTimeInStateConsistent) { +TEST_F(TimeInStateTest, SingleAndAllUidTimeInStateConsistent) { uint64_t zero = 0; auto maps = {getUidsCpuFreqTimes(), getUidsUpdatedCpuFreqTimes(&zero)}; for (const auto &map : maps) { @@ -246,7 +254,7 @@ TEST(TimeInStateTest, SingleAndAllUidTimeInStateConsistent) { } } -TEST(TimeInStateTest, AllUidConcurrentTimes) { +TEST_F(TimeInStateTest, AllUidConcurrentTimes) { uint64_t zero = 0; auto maps = {getUidsConcurrentTimes(), getUidsUpdatedConcurrentTimes(&zero)}; for (const auto &map : maps) { @@ -264,7 +272,7 @@ TEST(TimeInStateTest, AllUidConcurrentTimes) { } } -TEST(TimeInStateTest, AllUidUpdatedConcurrentTimes) { +TEST_F(TimeInStateTest, AllUidUpdatedConcurrentTimes) { uint64_t lastUpdate = 0; auto map1 = getUidsUpdatedConcurrentTimes(&lastUpdate); ASSERT_TRUE(map1.has_value()); @@ -299,7 +307,7 @@ TEST(TimeInStateTest, AllUidUpdatedConcurrentTimes) { } } -TEST(TimeInStateTest, SingleAndAllUidConcurrentTimesConsistent) { +TEST_F(TimeInStateTest, SingleAndAllUidConcurrentTimesConsistent) { uint64_t zero = 0; auto maps = {getUidsConcurrentTimes(), getUidsUpdatedConcurrentTimes(&zero)}; for (const auto &map : maps) { @@ -328,7 +336,7 @@ void TestCheckDelta(uint64_t before, uint64_t after) { ASSERT_LE(after - before, NSEC_PER_SEC * 2 * get_nprocs_conf()); } -TEST(TimeInStateTest, TotalTimeInStateMonotonic) { +TEST_F(TimeInStateTest, TotalTimeInStateMonotonic) { auto before = getTotalCpuFreqTimes(); ASSERT_TRUE(before.has_value()); sleep(1); @@ -344,7 +352,7 @@ TEST(TimeInStateTest, TotalTimeInStateMonotonic) { } } -TEST(TimeInStateTest, AllUidTimeInStateMonotonic) { +TEST_F(TimeInStateTest, AllUidTimeInStateMonotonic) { auto map1 = getUidsCpuFreqTimes(); ASSERT_TRUE(map1.has_value()); sleep(1); @@ -365,7 +373,7 @@ TEST(TimeInStateTest, AllUidTimeInStateMonotonic) { } } -TEST(TimeInStateTest, AllUidConcurrentTimesMonotonic) { +TEST_F(TimeInStateTest, AllUidConcurrentTimesMonotonic) { auto map1 = getUidsConcurrentTimes(); ASSERT_TRUE(map1.has_value()); ASSERT_FALSE(map1->empty()); @@ -393,7 +401,7 @@ TEST(TimeInStateTest, AllUidConcurrentTimesMonotonic) { } } -TEST(TimeInStateTest, AllUidTimeInStateSanityCheck) { +TEST_F(TimeInStateTest, AllUidTimeInStateSanityCheck) { uint64_t zero = 0; auto maps = {getUidsCpuFreqTimes(), getUidsUpdatedCpuFreqTimes(&zero)}; for (const auto &map : maps) { @@ -414,7 +422,7 @@ TEST(TimeInStateTest, AllUidTimeInStateSanityCheck) { } } -TEST(TimeInStateTest, AllUidConcurrentTimesSanityCheck) { +TEST_F(TimeInStateTest, AllUidConcurrentTimesSanityCheck) { uint64_t zero = 0; auto maps = {getUidsConcurrentTimes(), getUidsUpdatedConcurrentTimes(&zero)}; for (const auto &concurrentMap : maps) { @@ -441,7 +449,7 @@ TEST(TimeInStateTest, AllUidConcurrentTimesSanityCheck) { } } -TEST(TimeInStateTest, AllUidConcurrentTimesFailsOnInvalidBucket) { +TEST_F(TimeInStateTest, AllUidConcurrentTimesFailsOnInvalidBucket) { uint32_t uid = 0; { // Find an unused UID @@ -463,7 +471,7 @@ TEST(TimeInStateTest, AllUidConcurrentTimesFailsOnInvalidBucket) { ASSERT_FALSE(deleteMapEntry(fd, &key)); } -TEST(TimeInStateTest, AllUidTimesConsistent) { +TEST_F(TimeInStateTest, AllUidTimesConsistent) { auto tisMap = getUidsCpuFreqTimes(); ASSERT_TRUE(tisMap.has_value()); @@ -481,7 +489,7 @@ TEST(TimeInStateTest, AllUidTimesConsistent) { } } -TEST(TimeInStateTest, RemoveUid) { +TEST_F(TimeInStateTest, RemoveUid) { uint32_t uid = 0; { // Find an unused UID @@ -547,7 +555,7 @@ TEST(TimeInStateTest, RemoveUid) { ASSERT_EQ(allConcurrentTimes->find(uid), allConcurrentTimes->end()); } -TEST(TimeInStateTest, GetCpuFreqs) { +TEST_F(TimeInStateTest, GetCpuFreqs) { auto freqs = getCpuFreqs(); ASSERT_TRUE(freqs.has_value()); @@ -583,7 +591,7 @@ void *testThread(void *) { return nullptr; } -TEST(TimeInStateTest, GetAggregatedTaskCpuFreqTimes) { +TEST_F(TimeInStateTest, GetAggregatedTaskCpuFreqTimes) { uint64_t startTimeNs = timeNanos(); sem_init(&pingsem, 0, 1); |