blob: 33ba528832124c580830144438b95c58a9d3fae8 [file] [log] [blame]
From e51d9986aaca4e9ff359c2e66c04e9dc77bf0134 Mon Sep 17 00:00:00 2001
From: Yabin Cui <yabinc@google.com>
Date: Thu, 25 May 2023 18:24:22 +0000
Subject: [PATCH] fs tests: avoid fifo/socket/hardlink SELinux denials
Maybe it should use new Lit features instead of checking __ANDROID__.
Change-Id: I92cc1c5f6ab34ec7f1b8656f3a2ce4653ef5a0ec
---
.../directory_entry.obs/file_size.pass.cpp | 2 +-
.../directory_entry.obs/file_type_obs.pass.cpp | 12 ++++++++++--
.../directory_entry.obs/hard_link_count.pass.cpp | 4 +++-
.../filesystems/fs.op.funcs/fs.op.copy/copy.pass.cpp | 6 ++++--
.../fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp | 4 ++--
.../fs.op.create_hard_link/create_hard_link.pass.cpp | 9 +++++++++
.../fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp | 8 ++++++--
.../fs.op.hard_lk_ct/hard_link_count.pass.cpp | 5 ++++-
.../fs.op.funcs/fs.op.is_empty/is_empty.pass.cpp | 4 ++--
.../fs.op.funcs/fs.op.status/status.pass.cpp | 4 ++--
.../fs.op.symlink_status/symlink_status.pass.cpp | 4 ++--
11 files changed, 45 insertions(+), 17 deletions(-)
diff --git a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp
index fa105a74b6be..a5a18c1afbbf 100644
--- a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp
@@ -85,7 +85,7 @@ static void not_regular_file() {
std::errc expected_err;
} TestCases[] = {
{env.create_dir("dir"), std::errc::is_a_directory},
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__ANDROID__)
{env.create_fifo("fifo"), std::errc::not_supported},
#endif
{env.create_directory_symlink("dir", "sym"), std::errc::is_a_directory}};
diff --git a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_type_obs.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_type_obs.pass.cpp
index 6591d5191d9d..a2839a7d9a4e 100644
--- a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_type_obs.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_type_obs.pass.cpp
@@ -62,7 +62,9 @@ static void test_without_ec() {
scoped_test_env env;
path f = env.create_file("foo", 42);
path d = env.create_dir("dir");
+#if !defined(__ANDROID__)
path hl = env.create_hardlink("foo", "hl");
+#endif
auto test_path = [=](const path &p) {
directory_entry e(p);
file_status st = status(p);
@@ -82,8 +84,10 @@ static void test_without_ec() {
};
test_path(f);
test_path(d);
+#if !defined(__ANDROID__)
test_path(hl);
-#ifndef _WIN32
+#endif
+#if !defined(_WIN32) && !defined(__ANDROID__)
path fifo = env.create_fifo("fifo");
test_path(fifo);
#endif
@@ -98,7 +102,9 @@ static void test_with_ec() {
scoped_test_env env;
path f = env.create_file("foo", 42);
path d = env.create_dir("dir");
+#if !defined(__ANDROID__)
path hl = env.create_hardlink("foo", "hl");
+#endif
auto test_path = [=](const path &p) {
directory_entry e(p);
std::error_code status_ec = GetTestEC();
@@ -146,8 +152,10 @@ static void test_with_ec() {
};
test_path(f);
test_path(d);
+#if !defined(__ANDROID__)
test_path(hl);
-#ifndef _WIN32
+#endif
+#if !defined(_WIN32) && !defined(__ANDROID__)
path fifo = env.create_fifo("fifo");
test_path(fifo);
#endif
diff --git a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/hard_link_count.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/hard_link_count.pass.cpp
index e8c4742290ba..bb27241b6109 100644
--- a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/hard_link_count.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/hard_link_count.pass.cpp
@@ -70,6 +70,7 @@ static void basic() {
assert(ent.hard_link_count(ec) == expect);
assert(!ec);
}
+#if !defined(__ANDROID__)
env.create_file("file", 99);
env.create_hardlink("file", "hl");
{
@@ -78,6 +79,7 @@ static void basic() {
assert(ent.hard_link_count(ec) == 2);
assert(!ec);
}
+#endif
}
static void not_regular_file() {
@@ -105,7 +107,7 @@ static void not_regular_file() {
permissions(dir, old_perms);
};
test_path(dir2);
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__ANDROID__)
const path fifo = env.create_fifo("dir/fifo");
const path sym_to_fifo = env.create_symlink("dir/fifo", "dir/sym");
test_path(fifo);
diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy/copy.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy/copy.pass.cpp
index 2d7acf3d9469..e10783ac2bdc 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy/copy.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy/copy.pass.cpp
@@ -64,7 +64,7 @@ static void test_error_reporting()
scoped_test_env env;
const path file = env.create_file("file1", 42);
const path dir = env.create_dir("dir");
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__ANDROID__)
const path fifo = env.create_fifo("fifo");
assert(is_other(fifo));
#endif
@@ -95,7 +95,7 @@ static void test_error_reporting()
assert(ec != test_ec);
assert(checkThrow(dir, file, ec));
}
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__ANDROID__)
{ // is_other(from)
std::error_code ec = test_ec;
fs::copy(fifo, dir, ec);
@@ -168,6 +168,7 @@ static void from_is_regular_file()
assert(is_symlink(dest));
assert(equivalent(file, canonical(dest)));
}
+#if !defined(__ANDROID__) // SELinux restriction (maybe root shell would work?)
{ // create hard link to file
const path dest = env.make_env_path("hardlink");
assert(hard_link_count(file) == 1);
@@ -177,6 +178,7 @@ static void from_is_regular_file()
assert(exists(dest));
assert(hard_link_count(file) == 2);
}
+#endif
{ // is_directory(t)
const path dest_dir = env.create_dir("dest_dir");
const path expect_dest = dest_dir / file.filename();
diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp
index 06d2c0bbd3a2..c054afd09fad 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp
@@ -75,7 +75,7 @@ static void test_error_reporting() {
}
}
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__ANDROID__)
static void non_regular_file_test() {
scoped_test_env env;
const path fifo = env.create_fifo("fifo");
@@ -187,7 +187,7 @@ static void copy_file() {
int main(int, char**) {
test_signatures();
test_error_reporting();
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__ANDROID__)
non_regular_file_test();
#endif
test_attributes_get_copied();
diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_hard_link/create_hard_link.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_hard_link/create_hard_link.pass.cpp
index 5145cd455118..7b3043e4fec6 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_hard_link/create_hard_link.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.create_hard_link/create_hard_link.pass.cpp
@@ -42,6 +42,12 @@ static void test_error_reporting()
}
}
+// TODO(rprichard): For Android, the other create_hard_link calls are OK and
+// do not trip an SELinux error, because they fail for other reasons first.
+// If we add a "fs_hard_link" Lit feature, though, we may want to disable the
+// other calls here too. (Maybe this hard link stuff can be tested on Android
+// with root?)
+#if !defined(__ANDROID__)
static void create_file_hard_link()
{
scoped_test_env env;
@@ -55,6 +61,7 @@ static void create_file_hard_link()
assert(equivalent(dest, file));
assert(hard_link_count(file) == 2);
}
+#endif
static void create_directory_hard_link_fails()
{
@@ -70,7 +77,9 @@ static void create_directory_hard_link_fails()
int main(int, char**) {
test_signatures();
test_error_reporting();
+#if !defined(__ANDROID__)
create_file_hard_link();
+#endif
create_directory_hard_link_fails();
return 0;
diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp
index e9c8935773a0..b405c914bf53 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp
@@ -85,6 +85,7 @@ static void equivalent_reports_error_if_input_dne() {
}
}
+#if !defined(__ANDROID__)
static void equivalent_hardlink_succeeds() {
scoped_test_env env;
path const file = env.create_file("file", 42);
@@ -94,8 +95,9 @@ static void equivalent_hardlink_succeeds() {
assert(equivalent(file, hl2));
assert(equivalent(hl1, hl2));
}
+#endif
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__ANDROID__)
static void equivalent_is_other_succeeds() {
scoped_test_env env;
path const file = env.create_file("file", 42);
@@ -114,8 +116,10 @@ int main(int, char**) {
signature_test();
equivalent_test();
equivalent_reports_error_if_input_dne();
+#if !defined(__ANDROID__)
equivalent_hardlink_succeeds();
-#ifndef _WIN32
+#endif
+#if !defined(_WIN32) && !defined(__ANDROID__)
equivalent_is_other_succeeds();
#endif
diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp
index b646b46fec5d..20ba1ca0ef4a 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.hard_lk_ct/hard_link_count.pass.cpp
@@ -70,6 +70,7 @@ static void hard_link_count_for_directory()
hard_link_count(static_env.Dir3) == 1);
}
+#if !defined(__ANDROID__)
static void hard_link_count_increments_test()
{
scoped_test_env env;
@@ -79,7 +80,7 @@ static void hard_link_count_increments_test()
env.create_hardlink(file, "file_hl");
assert(hard_link_count(file) == 2);
}
-
+#endif
static void hard_link_count_error_cases()
{
@@ -100,7 +101,9 @@ int main(int, char**) {
signature_test();
hard_link_count_for_file();
hard_link_count_for_directory();
+#if !defined(__ANDROID__)
hard_link_count_increments_test();
+#endif
hard_link_count_error_cases();
return 0;
diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.is_empty/is_empty.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.is_empty/is_empty.pass.cpp
index 752e68260dc9..ec56397d2b61 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.is_empty/is_empty.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.is_empty/is_empty.pass.cpp
@@ -111,7 +111,7 @@ static void test_directory_access_denied()
}
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__ANDROID__)
static void test_fifo_fails()
{
scoped_test_env env;
@@ -134,7 +134,7 @@ int main(int, char**) {
test_is_empty_file();
test_is_empty_fails();
test_directory_access_denied();
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__ANDROID__)
test_fifo_fails();
#endif
diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.status/status.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.status/status.pass.cpp
index 17abaf76b9c9..dc0af0078624 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.status/status.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.status/status.pass.cpp
@@ -118,10 +118,10 @@ static void status_file_types_test()
#ifndef _WIN32
{static_env.CharFile, file_type::character},
#endif
-#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(_WIN32) // No support for domain sockets
+#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(_WIN32) && !defined(__ANDROID__) // No support for domain sockets
{env.create_socket("socket"), file_type::socket},
#endif
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__ANDROID__)
{env.create_fifo("fifo"), file_type::fifo}
#endif
};
diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.symlink_status/symlink_status.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.symlink_status/symlink_status.pass.cpp
index 3ab50c37254f..cde6f061ede8 100644
--- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.symlink_status/symlink_status.pass.cpp
+++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.symlink_status/symlink_status.pass.cpp
@@ -127,10 +127,10 @@ static void symlink_status_file_types_test()
#ifndef _WIN32
{static_env.CharFile, file_type::character},
#endif
-#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(_WIN32) // No support for domain sockets
+#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(_WIN32) && !defined(__ANDROID__) // No support for domain sockets
{env.create_socket("socket"), file_type::socket},
#endif
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__ANDROID__)
{env.create_fifo("fifo"), file_type::fifo}
#endif
};
--
2.41.0.rc0.172.g3f132b7071-goog