Fix uses of readlink in tests.
readlink does not append a terminator, and a few tests assumed it did.
Test: Unit tests pass.
Change-Id: I3ccea4e7895cd919b45e1ca0c90aa6f0031de320
diff --git a/tests/bug_26110743_test.cpp b/tests/bug_26110743_test.cpp
index 89c6dcc..883280f 100644
--- a/tests/bug_26110743_test.cpp
+++ b/tests/bug_26110743_test.cpp
@@ -22,6 +22,8 @@
#include <sys/stat.h>
#include <sys/prctl.h>
+#include <string>
+
#include <android-base/scopeguard.h>
extern "C" pid_t gettid();
@@ -35,8 +37,9 @@
const char* ERRORMSG = "Please apply the following two kernel patches:\n"
"* https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=73af963f9f3036dffed55c3a2898598186db1045\n"
"* https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=96d0df79f2644fc823f26c06491e182d87a90c2a\n";
- ASSERT_NE(-1, readlink(buf, buf2, sizeof(buf2))) << ERRORMSG;
- ASSERT_STREQ("/dev/null", buf2);
+ ssize_t length = readlink(buf, buf2, sizeof(buf2));
+ ASSERT_LT(0, length) << ERRORMSG;
+ ASSERT_EQ("/dev/null", std::string(buf2, length));
close(fd);
}
@@ -79,8 +82,9 @@
snprintf(buf, sizeof(buf), "/proc/%d/task/%d/fd/%d", mypid, mytid, fd);
const char* ERRORMSG = "Please apply the following kernel patch:\n"
"* https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=54708d2858e79a2bdda10bf8a20c80eb96c20613\n";
- ASSERT_NE(-1, readlink(buf, buf2, sizeof(buf2))) << ERRORMSG;
- ASSERT_STREQ("/dev/null", buf2);
+ ssize_t length = readlink(buf, buf2, sizeof(buf2));
+ ASSERT_LT(0, length) << ERRORMSG;
+ ASSERT_EQ("/dev/null", std::string(buf2, length));
close(fd);
}
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index d93c63f..d96da02 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -2510,10 +2510,15 @@
TEST(STDIO_TEST, dev_std_files) {
// POSIX only mentions /dev/stdout, but we should have all three (http://b/31824379).
char path[PATH_MAX];
- ASSERT_GT(readlink("/dev/stdin", path, sizeof(path)), 0);
- ASSERT_STREQ("/proc/self/fd/0", path);
- ASSERT_GT(readlink("/dev/stdout", path, sizeof(path)), 0);
- ASSERT_STREQ("/proc/self/fd/1", path);
- ASSERT_GT(readlink("/dev/stderr", path, sizeof(path)), 0);
- ASSERT_STREQ("/proc/self/fd/2", path);
+ ssize_t length = readlink("/dev/stdin", path, sizeof(path));
+ ASSERT_LT(0, length);
+ ASSERT_EQ("/proc/self/fd/0", std::string(path, length));
+
+ length = readlink("/dev/stdout", path, sizeof(path));
+ ASSERT_LT(0, length);
+ ASSERT_EQ("/proc/self/fd/1", std::string(path, length));
+
+ length = readlink("/dev/stderr", path, sizeof(path));
+ ASSERT_LT(0, length);
+ ASSERT_EQ("/proc/self/fd/2", std::string(path, length));
}