From b441359be79dc60d6053309db75ef6e6d27d4518 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 29 Nov 2017 18:17:06 -0800 Subject: [PATCH] Break up clock_getcpuclockid tests. Bug: http://b/69569394 Test: ran tests Change-Id: If273cf8162e7d10aa4aa037181aefea6533a3487 --- tests/time_test.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/time_test.cpp b/tests/time_test.cpp index ddeabbf50..e1fae92a7 100644 --- a/tests/time_test.cpp +++ b/tests/time_test.cpp @@ -654,31 +654,32 @@ TEST(time, clock) { ASSERT_LT(t1 - t0, CLOCKS_PER_SEC / 1000); } -pid_t GetInvalidPid() { - FILE* fp = fopen("/proc/sys/kernel/pid_max", "r"); +static pid_t GetInvalidPid() { + std::unique_ptr fp{fopen("/proc/sys/kernel/pid_max", "r"), fclose}; long pid_max; - fscanf(fp, "%ld", &pid_max); - pid_t invalid_pid = static_cast(pid_max + 1); - fclose(fp); - return invalid_pid; + fscanf(fp.get(), "%ld", &pid_max); + return static_cast(pid_max + 1); } -TEST(time, clock_getcpuclockid) { - // For current process. +TEST(time, clock_getcpuclockid_current) { clockid_t clockid; ASSERT_EQ(0, clock_getcpuclockid(getpid(), &clockid)); - timespec ts; ASSERT_EQ(0, clock_gettime(clockid, &ts)); +} - // For parent process. +TEST(time, clock_getcpuclockid_parent) { + clockid_t clockid; ASSERT_EQ(0, clock_getcpuclockid(getppid(), &clockid)); + timespec ts; ASSERT_EQ(0, clock_gettime(clockid, &ts)); +} - // For invalid process. +TEST(time, clock_getcpuclockid_ESRCH) { // We can't use -1 for invalid pid here, because clock_getcpuclockid() can't detect it. errno = 0; // If this fails, your kernel needs commit e1b6b6ce to be backported. + clockid_t clockid; ASSERT_EQ(ESRCH, clock_getcpuclockid(GetInvalidPid(), &clockid)) << "\n" << "Please ensure that the following kernel patches or their replacements have been applied:\n" << "* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/"