summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2014-12-01 17:06:01 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-12-01 17:06:02 +0000
commit3e6ef3f90285191976a60d7a94287fb0fec1af5d (patch)
treece5d95130e521a0be1425cbc9b02bf88e0792420 /tests
parentfabb4282be66caed37c405e36c94dd1dc30ddbb2 (diff)
parentd5c652756bb1a52959cd5c62447b62462f90f983 (diff)
downloadbionic-3e6ef3f90285191976a60d7a94287fb0fec1af5d.zip
bionic-3e6ef3f90285191976a60d7a94287fb0fec1af5d.tar.gz
bionic-3e6ef3f90285191976a60d7a94287fb0fec1af5d.tar.bz2
Merge "support _POSIX_CPUTIME"
Diffstat (limited to 'tests')
-rw-r--r--tests/time_test.cpp29
-rw-r--r--tests/unistd_test.cpp4
2 files changed, 31 insertions, 2 deletions
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index e0231b1..691d8ff 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -23,6 +23,7 @@
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <unistd.h>
#include "ScopedSignalHandler.h"
@@ -458,6 +459,34 @@ TEST(time, clock) {
ASSERT_LT(t1 - t0, CLOCKS_PER_SEC / 1000);
}
+pid_t GetInvalidPid() {
+ FILE* fp = fopen("/proc/sys/kernel/pid_max", "r");
+ long pid_max;
+ fscanf(fp, "%ld", &pid_max);
+ pid_t invalid_pid = static_cast<pid_t>(pid_max + 1);
+ fclose(fp);
+ return invalid_pid;
+}
+
+TEST(time, clock_getcpuclockid) {
+ // For current process.
+ clockid_t clockid;
+ ASSERT_EQ(0, clock_getcpuclockid(getpid(), &clockid));
+
+ timespec ts;
+ ASSERT_EQ(0, clock_gettime(clockid, &ts));
+
+ // For parent process.
+ ASSERT_EQ(0, clock_getcpuclockid(getppid(), &clockid));
+ ASSERT_EQ(0, clock_gettime(clockid, &ts));
+
+ // For invalid process.
+ // We can't use -1 for invalid pid here, because clock_getcpuclockid() can't detect it.
+ errno = 0;
+ ASSERT_EQ(ESRCH, clock_getcpuclockid(GetInvalidPid(), &clockid));
+ ASSERT_EQ(0, errno);
+}
+
TEST(time, clock_settime) {
errno = 0;
timespec ts;
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index f0aeb09..34b7bf3 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -529,6 +529,7 @@ TEST(unistd, _POSIX_macros_smoke) {
EXPECT_GT(_POSIX_CHILD_MAX, 0);
EXPECT_NE(_POSIX_CHOWN_RESTRICTED, -1);
EXPECT_EQ(_POSIX_VERSION, _POSIX_CLOCK_SELECTION);
+ EXPECT_EQ(_POSIX_VERSION, _POSIX_CPUTIME);
EXPECT_GT(_POSIX_DELAYTIMER_MAX, 0);
EXPECT_EQ(_POSIX_VERSION, _POSIX_FSYNC);
EXPECT_GT(_POSIX_HOST_NAME_MAX, 0);
@@ -614,7 +615,6 @@ TEST(unistd, _POSIX_macros_smoke) {
EXPECT_EQ(-1, _POSIX_ADVISORY_INFO);
EXPECT_EQ(-1, _POSIX_ASYNCHRONOUS_IO);
EXPECT_EQ(-1, _POSIX_BARRIERS);
- EXPECT_EQ(-1, _POSIX_CPUTIME);
EXPECT_EQ(-1, _POSIX_MESSAGE_PASSING);
EXPECT_EQ(-1, _POSIX_PRIORITIZED_IO);
EXPECT_EQ(-1, _POSIX_REALTIME_SIGNALS);
@@ -665,6 +665,7 @@ TEST(unistd, sysconf) {
VERIFY_SYSCONF_POSITIVE(_SC_CHILD_MAX);
VERIFY_SYSCONF_POSITIVE(_SC_CLK_TCK);
VERIFY_SYSCONF_POSITIVE(_SC_COLL_WEIGHTS_MAX);
+ VERIFY_SYSCONF_POSIX_VERSION(_SC_CPUTIME);
VERIFY_SYSCONF_POSITIVE(_SC_EXPR_NEST_MAX);
VERIFY_SYSCONF_POSITIVE(_SC_LINE_MAX);
VERIFY_SYSCONF_POSITIVE(_SC_NGROUPS_MAX);
@@ -775,7 +776,6 @@ TEST(unistd, sysconf) {
VERIFY_SYSCONF_NOT_SUPPORT(_SC_ADVISORY_INFO);
VERIFY_SYSCONF_NOT_SUPPORT(_SC_ASYNCHRONOUS_IO);
VERIFY_SYSCONF_NOT_SUPPORT(_SC_BARRIERS);
- VERIFY_SYSCONF_NOT_SUPPORT(_SC_CPUTIME);
VERIFY_SYSCONF_NOT_SUPPORT(_SC_MESSAGE_PASSING);
VERIFY_SYSCONF_NOT_SUPPORT(_SC_PRIORITIZED_IO);
VERIFY_SYSCONF_NOT_SUPPORT(_SC_REALTIME_SIGNALS);