--- base/file_test.cpp.orig 2020-02-11 20:44:45 UTC +++ base/file_test.cpp @@ -61,12 +61,20 @@ TEST(file, ReadFileToString_WriteStringToFile_symlink) ASSERT_EQ(0, unlink(link.path)); ASSERT_EQ(0, symlink(target.path, link.path)); ASSERT_FALSE(android::base::WriteStringToFile("foo", link.path, false)); +#ifdef __linux__ ASSERT_EQ(ELOOP, errno); +#else + ASSERT_EQ(EMLINK, errno); +#endif ASSERT_TRUE(android::base::WriteStringToFile("foo", link.path, true)); std::string s; ASSERT_FALSE(android::base::ReadFileToString(link.path, &s)); +#ifdef __linux__ ASSERT_EQ(ELOOP, errno); +#else + ASSERT_EQ(EMLINK, errno); +#endif ASSERT_TRUE(android::base::ReadFileToString(link.path, &s, true)); ASSERT_EQ("foo", s); } @@ -235,7 +243,7 @@ TEST(file, RemoveFileIfExists_EACCES) { // EACCES -- one of the directories in the path has no search permission // root can bypass permission restrictions, so drop root. if (getuid() == 0) { - passwd* shell = getpwnam("shell"); + passwd* shell = getpwnam("nobody"); setgid(shell->pw_gid); setuid(shell->pw_uid); } @@ -257,6 +265,7 @@ TEST(file, RemoveFileIfExists_EACCES) { TEST(file, Readlink) { #if !defined(_WIN32) +#ifdef __linux__ // Linux doesn't allow empty symbolic links. std::string min("x"); // ext2 and ext4 both have PAGE_SIZE limits. @@ -265,6 +274,10 @@ TEST(file, Readlink) { // in current kernels (and marlin/sailfish where we're seeing this // failure are still on 3.18, far from current). http://b/33306057. std::string max(static_cast(4096 - 2 - 1 - 1), 'x'); +#else + std::string min(""); + std::string max(static_cast(1024 - 1), 'x'); +#endif TemporaryDir td; std::string min_path{std::string(td.path) + "/" + "min"};