sleep/usleep: switch to trivial implementations.

Upstream keeps rearranging the deckchairs for these, so let's just
switch to the [roughly] one-liners rather than track that...

Test: treehugger
Change-Id: If655cf7a7f316657de44d41fadd43a8c55ee6f23
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index 4e17242..378b4ac 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -24,13 +24,17 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
+
 #include <atomic>
+#include <chrono>
 
 #include "SignalUtils.h"
 #include "utils.h"
 
 #include "private/bionic_constants.h"
 
+using namespace std::chrono_literals;
+
 TEST(time, time) {
   // Acquire time
   time_t p1, t1 = time(&p1);
@@ -797,7 +801,7 @@
   ASSERT_EQ(EINVAL, errno);
 }
 
-TEST(time, clock_nanosleep) {
+TEST(time, clock_nanosleep_EINVAL) {
   timespec in;
   timespec out;
   ASSERT_EQ(EINVAL, clock_nanosleep(-1, 0, &in, &out));
@@ -810,6 +814,29 @@
   ASSERT_EQ(EINVAL, clock_nanosleep(CLOCK_THREAD_CPUTIME_ID, 0, &in, nullptr));
 }
 
+TEST(time, clock_nanosleep) {
+  auto t0 = std::chrono::steady_clock::now();
+  const timespec ts = {.tv_nsec = 5000000};
+  ASSERT_EQ(0, clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, nullptr));
+  auto t1 = std::chrono::steady_clock::now();
+  ASSERT_GE(t1-t0, 5000000ns);
+}
+
+TEST(time, nanosleep) {
+  auto t0 = std::chrono::steady_clock::now();
+  const timespec ts = {.tv_nsec = 5000000};
+  ASSERT_EQ(0, nanosleep(&ts, nullptr));
+  auto t1 = std::chrono::steady_clock::now();
+  ASSERT_GE(t1-t0, 5000000ns);
+}
+
+TEST(time, nanosleep_EINVAL) {
+  timespec ts = {.tv_sec = -1};
+  errno = 0;
+  ASSERT_EQ(-1, nanosleep(&ts, nullptr));
+  ASSERT_EQ(EINVAL, errno);
+}
+
 TEST(time, bug_31938693) {
   // User-visible symptoms in N:
   // http://b/31938693