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/sys_prctl_test.cpp b/tests/sys_prctl_test.cpp
index 6d1fa1d..bbc1c67 100644
--- a/tests/sys_prctl_test.cpp
+++ b/tests/sys_prctl_test.cpp
@@ -31,6 +31,8 @@
#include "android-base/file.h"
#include "android-base/strings.h"
+#include "utils.h"
+
// http://b/20017123.
TEST(sys_prctl, bug_20017123) {
#if defined(PR_SET_VMA) // PR_SET_VMA is only available in Android kernels.
@@ -91,7 +93,7 @@
// but they can check or lower it
err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_SYS_ADMIN, 0, 0);
EXPECT_EQ(-1, err);
- EXPECT_EQ(EPERM, errno);
+ EXPECT_ERRNO(EPERM);
err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_SYS_ADMIN, 0, 0);
EXPECT_EQ(0, err);
@@ -102,15 +104,15 @@
// ULONG_MAX isn't a legal cap
err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, ULONG_MAX, 0, 0);
EXPECT_EQ(-1, err);
- EXPECT_EQ(EINVAL, errno);
+ EXPECT_ERRNO(EINVAL);
err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, ULONG_MAX, 0, 0);
EXPECT_EQ(-1, err);
- EXPECT_EQ(EINVAL, errno);
+ EXPECT_ERRNO(EINVAL);
err = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER, ULONG_MAX, 0, 0);
EXPECT_EQ(-1, err);
- EXPECT_EQ(EINVAL, errno);
+ EXPECT_ERRNO(EINVAL);
#else
GTEST_SKIP() << "PR_CAP_AMBIENT not available";
#endif