From e86462db779692d1e1c703d12fbcaa168d22e8f4 Mon Sep 17 00:00:00 2001 From: Wiktor Garbacz Date: Fri, 21 Jul 2023 01:53:00 -0700 Subject: [PATCH] Remove redundant buffer test It tested Comms rather than different Buffer functionality. PiperOrigin-RevId: 549880115 Change-Id: I095464540fa21cc4b3bee1d87e1e046807b6f18c --- sandboxed_api/sandbox2/BUILD.bazel | 2 - sandboxed_api/sandbox2/CMakeLists.txt | 2 - sandboxed_api/sandbox2/buffer_test.cc | 39 +----------- sandboxed_api/sandbox2/testcases/BUILD.bazel | 2 - .../sandbox2/testcases/CMakeLists.txt | 2 - sandboxed_api/sandbox2/testcases/buffer.cc | 62 ++++--------------- 6 files changed, 13 insertions(+), 96 deletions(-) diff --git a/sandboxed_api/sandbox2/BUILD.bazel b/sandboxed_api/sandbox2/BUILD.bazel index 3052a31..cf1995c 100644 --- a/sandboxed_api/sandbox2/BUILD.bazel +++ b/sandboxed_api/sandbox2/BUILD.bazel @@ -791,11 +791,9 @@ cc_test( tags = ["no_qemu_user_mode"], deps = [ ":buffer", - ":comms", ":sandbox2", "//sandboxed_api:testing", "//sandboxed_api/util:status_matchers", - "@com_google_absl//absl/log", "@com_google_googletest//:gtest_main", ], ) diff --git a/sandboxed_api/sandbox2/CMakeLists.txt b/sandboxed_api/sandbox2/CMakeLists.txt index e781e60..2212b14 100644 --- a/sandboxed_api/sandbox2/CMakeLists.txt +++ b/sandboxed_api/sandbox2/CMakeLists.txt @@ -870,8 +870,6 @@ if(BUILD_TESTING AND SAPI_BUILD_TESTING) ) target_link_libraries(sandbox2_buffer_test PRIVATE sandbox2::buffer - sandbox2::comms - sandbox2::ipc sandbox2::sandbox2 sapi::testing sapi::status_matchers diff --git a/sandboxed_api/sandbox2/buffer_test.cc b/sandboxed_api/sandbox2/buffer_test.cc index 785ddfa..13b8887 100644 --- a/sandboxed_api/sandbox2/buffer_test.cc +++ b/sandboxed_api/sandbox2/buffer_test.cc @@ -18,7 +18,6 @@ #include #include -#include #include #include #include @@ -26,8 +25,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "absl/log/log.h" -#include "sandboxed_api/sandbox2/comms.h" #include "sandboxed_api/sandbox2/executor.h" #include "sandboxed_api/sandbox2/ipc.h" #include "sandboxed_api/sandbox2/policy.h" @@ -42,7 +39,6 @@ namespace { using ::sapi::CreateDefaultPermissiveTestPolicy; using ::sapi::GetTestSourcePath; using ::testing::Eq; -using ::testing::IsTrue; using ::testing::Ne; // Test all public methods of sandbox2::Buffer. @@ -64,7 +60,7 @@ TEST(BufferTest, TestImplementation) { // Test sharing of buffer between executor/sandboxee using dup/MapFd. TEST(BufferTest, TestWithSandboxeeMapFd) { const std::string path = GetTestSourcePath("sandbox2/testcases/buffer"); - std::vector args = {path, "1"}; + std::vector args = {path}; auto executor = std::make_unique(path, args); SAPI_ASSERT_OK_AND_ASSIGN(auto policy, CreateDefaultPermissiveTestPolicy(path).TryBuild()); @@ -93,38 +89,5 @@ TEST(BufferTest, TestWithSandboxeeMapFd) { struct stat stat_buf; EXPECT_THAT(fstat(buffer->fd(), &stat_buf), Ne(-1)); } - -// Test sharing of buffer between executor/sandboxee using SendFD/RecvFD. -TEST(BufferTest, TestWithSandboxeeSendRecv) { - const std::string path = GetTestSourcePath("sandbox2/testcases/buffer"); - std::vector args = {path, "2"}; - auto executor = std::make_unique(path, args); - - SAPI_ASSERT_OK_AND_ASSIGN(auto policy, - CreateDefaultPermissiveTestPolicy(path).TryBuild()); - - Sandbox2 s2(std::move(executor), std::move(policy)); - ASSERT_THAT(s2.RunAsync(), IsTrue()); - Comms* comms = s2.comms(); - - SAPI_ASSERT_OK_AND_ASSIGN(auto buffer, - Buffer::CreateWithSize(1ULL << 20 /* 1MiB */)); - uint8_t* buf = buffer->data(); - // Test that we can write data to the sandboxee. - buf[0] = 'A'; - EXPECT_THAT(comms->SendFD(buffer->fd()), IsTrue()); - - auto result = s2.AwaitResult(); - EXPECT_THAT(result.final_status(), Eq(Result::OK)); - EXPECT_THAT(result.reason_code(), Eq(0)); - - // Test that we can read data from the sandboxee. - EXPECT_THAT(buf[buffer->size() - 1], Eq('B')); - - // Test that internal buffer fd remains valid. - struct stat stat_buf; - EXPECT_THAT(fstat(buffer->fd(), &stat_buf), Ne(-1)); -} - } // namespace } // namespace sandbox2 diff --git a/sandboxed_api/sandbox2/testcases/BUILD.bazel b/sandboxed_api/sandbox2/testcases/BUILD.bazel index 0c71d1a..94777af 100644 --- a/sandboxed_api/sandbox2/testcases/BUILD.bazel +++ b/sandboxed_api/sandbox2/testcases/BUILD.bazel @@ -60,8 +60,6 @@ cc_binary( features = ["fully_static_link"], deps = [ "//sandboxed_api/sandbox2:buffer", - "//sandboxed_api/sandbox2:comms", - "@com_google_absl//absl/strings:str_format", ], ) diff --git a/sandboxed_api/sandbox2/testcases/CMakeLists.txt b/sandboxed_api/sandbox2/testcases/CMakeLists.txt index 4f0fc19..481e66d 100644 --- a/sandboxed_api/sandbox2/testcases/CMakeLists.txt +++ b/sandboxed_api/sandbox2/testcases/CMakeLists.txt @@ -49,9 +49,7 @@ set_target_properties(sandbox2_testcase_buffer PROPERTIES ) target_link_libraries(sandbox2_testcase_buffer PRIVATE -static - absl::str_format sandbox2::buffer - sandbox2::comms sapi::base ) diff --git a/sandboxed_api/sandbox2/testcases/buffer.cc b/sandboxed_api/sandbox2/testcases/buffer.cc index d4f62b8..733be92 100644 --- a/sandboxed_api/sandbox2/testcases/buffer.cc +++ b/sandboxed_api/sandbox2/testcases/buffer.cc @@ -14,60 +14,22 @@ // A binary that uses a buffer from its executor. -#include -#include - -#include "absl/strings/str_format.h" #include "sandboxed_api/sandbox2/buffer.h" -#include "sandboxed_api/sandbox2/comms.h" + +#include int main(int argc, char* argv[]) { - if (argc != 2) { - absl::FPrintF(stderr, "argc != 2\n"); + auto buffer_or = sandbox2::Buffer::CreateFromFd(3); + if (!buffer_or.ok()) { return EXIT_FAILURE; } - - int testno = atoi(argv[1]); // NOLINT - switch (testno) { - case 1: { // Dup and map to static FD - auto buffer_or = sandbox2::Buffer::CreateFromFd(3); - if (!buffer_or.ok()) { - return EXIT_FAILURE; - } - auto buffer = std::move(buffer_or).value(); - uint8_t* buf = buffer->data(); - // Test that we can read data from the executor. - if (buf[0] != 'A') { - return EXIT_FAILURE; - } - // Test that we can write data to the executor. - buf[buffer->size() - 1] = 'B'; - return EXIT_SUCCESS; - } - - case 2: { // Send and receive FD - sandbox2::Comms comms(sandbox2::Comms::kDefaultConnection); - int fd; - if (!comms.RecvFD(&fd)) { - return EXIT_FAILURE; - } - auto buffer_or = sandbox2::Buffer::CreateFromFd(fd); - if (!buffer_or.ok()) { - return EXIT_FAILURE; - } - auto buffer = std::move(buffer_or).value(); - uint8_t* buf = buffer->data(); - // Test that we can read data from the executor. - if (buf[0] != 'A') { - return EXIT_FAILURE; - } - // Test that we can write data to the executor. - buf[buffer->size() - 1] = 'B'; - return EXIT_SUCCESS; - } - - default: - absl::FPrintF(stderr, "Unknown test: %d\n", testno); + auto buffer = std::move(buffer_or).value(); + uint8_t* buf = buffer->data(); + // Test that we can read data from the executor. + if (buf[0] != 'A') { + return EXIT_FAILURE; } - return EXIT_FAILURE; + // Test that we can write data to the executor. + buf[buffer->size() - 1] = 'B'; + return EXIT_SUCCESS; }