Add ASSERT_ERRNO and EXPECT_ERRNO (and use them).

We've talked about this many times in the past, but partners struggle to
understand "expected 38, got 22" in these contexts, and I always have to
go and check the header files just to be sure I'm sure.

I actually think the glibc geterrorname_np() function (which would
return "ENOSYS" rather than "Function not implemented") would be more
helpful, but I'll have to go and implement that first, and then come
back.

Being forced to go through all our errno assertions did also make me
want to use a more consistent style for our ENOSYS assertions in
particular --- there's a particularly readable idiom, and I'll also come
back and move more of those checks to the most readable idiom.

I've added a few missing `errno = 0`s before tests, and removed a few
stray `errno = 0`s from tests that don't actually make assertions about
errno, since I had to look at every single reference to errno anyway.

Test: treehugger
Change-Id: Iba7c56f2adc30288c3e00ade106635e515e88179
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index ec59aa7..5e97c63 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -150,7 +150,7 @@
 #if !defined(__LP64__)
   // 32-bit bionic has a signed 32-bit time_t.
   ASSERT_EQ(-1, mktime(&tm));
-  ASSERT_EQ(EOVERFLOW, errno);
+  ASSERT_ERRNO(EOVERFLOW);
 #else
   // Everyone else should be using a signed 64-bit time_t.
   ASSERT_GE(sizeof(time_t) * 8, 64U);
@@ -164,7 +164,7 @@
   // mktime to interpret that time as local standard, hence offset
   // is 8 hours, not 7.
   ASSERT_EQ(static_cast<time_t>(4108348800U), mktime(&tm));
-  ASSERT_EQ(0, errno);
+  ASSERT_ERRNO(0);
 #endif
 }
 
@@ -182,7 +182,7 @@
 
   errno = 0;
   ASSERT_NE(static_cast<time_t>(-1), mktime(&t));
-  ASSERT_EQ(0, errno);
+  ASSERT_ERRNO(0);
 
   // This will overflow for LP32.
   t.tm_year = INT_MAX;
@@ -190,10 +190,10 @@
   errno = 0;
 #if !defined(__LP64__)
   ASSERT_EQ(static_cast<time_t>(-1), mktime(&t));
-  ASSERT_EQ(EOVERFLOW, errno);
+  ASSERT_ERRNO(EOVERFLOW);
 #else
   ASSERT_EQ(static_cast<time_t>(67768036166016000U), mktime(&t));
-  ASSERT_EQ(0, errno);
+  ASSERT_ERRNO(0);
 #endif
 
   // This will overflow for LP32 or LP64.
@@ -204,7 +204,7 @@
 
   errno = 0;
   ASSERT_EQ(static_cast<time_t>(-1), mktime(&t));
-  ASSERT_EQ(EOVERFLOW, errno);
+  ASSERT_ERRNO(EOVERFLOW);
 }
 
 TEST(time, mktime_invalid_tm_TZ_combination) {
@@ -222,7 +222,7 @@
 
   EXPECT_EQ(static_cast<time_t>(-1), mktime(&t));
   // mktime sets errno to EOVERFLOW if result is unrepresentable.
-  EXPECT_EQ(EOVERFLOW, errno);
+  EXPECT_ERRNO(EOVERFLOW);
 }
 
 // Transitions in the tzdata file are generated up to the year 2100. Testing
@@ -233,14 +233,13 @@
 #if !defined(__LP64__)
   // 32-bit bionic has a signed 32-bit time_t.
   ASSERT_EQ(-1, mktime(&tm));
-  ASSERT_EQ(EOVERFLOW, errno);
+  ASSERT_ERRNO(EOVERFLOW);
 #else
   setenv("TZ", "Europe/London", 1);
   tzset();
   errno = 0;
-
   ASSERT_EQ(static_cast<time_t>(5686156800U), mktime(&tm));
-  ASSERT_EQ(0, errno);
+  ASSERT_ERRNO(0);
 #endif
 }
 
@@ -649,7 +648,7 @@
   if (pid == 0) {
     // Timers are not inherited by the child.
     ASSERT_EQ(-1, timer_delete(timer_id));
-    ASSERT_EQ(EINVAL, errno);
+    ASSERT_ERRNO(EINVAL);
     _exit(0);
   }
 
@@ -804,7 +803,7 @@
   // A SIGEV_SIGNAL timer is easy; the kernel does all that.
   timer_t timer_id;
   ASSERT_EQ(-1, timer_create(invalid_clock, nullptr, &timer_id));
-  ASSERT_EQ(EINVAL, errno);
+  ASSERT_ERRNO(EINVAL);
 
   // A SIGEV_THREAD timer is more interesting because we have stuff to clean up.
   sigevent se;
@@ -812,7 +811,7 @@
   se.sigev_notify = SIGEV_THREAD;
   se.sigev_notify_function = NoOpNotifyFunction;
   ASSERT_EQ(-1, timer_create(invalid_clock, &se, &timer_id));
-  ASSERT_EQ(EINVAL, errno);
+  ASSERT_ERRNO(EINVAL);
 }
 
 TEST(time, timer_create_multiple) {
@@ -915,7 +914,7 @@
   cur_time = time(NULL);
   while ((kill(tdd.tid, 0) != -1 || errno != ESRCH) && (time(NULL) - cur_time) < 5);
   ASSERT_EQ(-1, kill(tdd.tid, 0));
-  ASSERT_EQ(ESRCH, errno);
+  ASSERT_ERRNO(ESRCH);
 #endif
 }
 
@@ -973,7 +972,7 @@
   errno = 0;
   timespec ts;
   ASSERT_EQ(-1, clock_gettime(-1, &ts));
-  ASSERT_EQ(EINVAL, errno);
+  ASSERT_ERRNO(EINVAL);
 }
 
 TEST(time, clock_getres_CLOCK_REALTIME) {
@@ -1011,7 +1010,7 @@
   errno = 0;
   timespec ts = { -1, -1 };
   ASSERT_EQ(-1, clock_getres(-1, &ts));
-  ASSERT_EQ(EINVAL, errno);
+  ASSERT_ERRNO(EINVAL);
   ASSERT_EQ(-1, ts.tv_nsec);
   ASSERT_EQ(-1, ts.tv_sec);
 }
@@ -1064,14 +1063,14 @@
     << "commit/?id=e1b6b6ce55a0a25c8aa8af019095253b2133a41a\n"
     << "* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/"
     << "commit/?id=c80ed088a519da53f27b798a69748eaabc66aadf\n";
-  ASSERT_EQ(0, errno);
+  ASSERT_ERRNO(0);
 }
 
 TEST(time, clock_settime) {
   errno = 0;
   timespec ts;
   ASSERT_EQ(-1, clock_settime(-1, &ts));
-  ASSERT_EQ(EINVAL, errno);
+  ASSERT_ERRNO(EINVAL);
 }
 
 TEST(time, clock_nanosleep_EINVAL) {
@@ -1107,7 +1106,7 @@
   timespec ts = {.tv_sec = -1};
   errno = 0;
   ASSERT_EQ(-1, nanosleep(&ts, nullptr));
-  ASSERT_EQ(EINVAL, errno);
+  ASSERT_ERRNO(EINVAL);
 }
 
 TEST(time, bug_31938693) {