mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Remove redundant buffer test
It tested Comms rather than different Buffer functionality. PiperOrigin-RevId: 549880115 Change-Id: I095464540fa21cc4b3bee1d87e1e046807b6f18c
This commit is contained in:
parent
7683f6995b
commit
e86462db77
|
@ -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",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include <syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
@ -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<std::string> args = {path, "1"};
|
||||
std::vector<std::string> args = {path};
|
||||
auto executor = std::make_unique<Executor>(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<std::string> args = {path, "2"};
|
||||
auto executor = std::make_unique<Executor>(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
|
||||
|
|
|
@ -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",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
@ -14,22 +14,11 @@
|
|||
|
||||
// A binary that uses a buffer from its executor.
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "sandboxed_api/sandbox2/buffer.h"
|
||||
#include "sandboxed_api/sandbox2/comms.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 2) {
|
||||
absl::FPrintF(stderr, "argc != 2\n");
|
||||
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;
|
||||
|
@ -44,30 +33,3 @@ int main(int argc, char* argv[]) {
|
|||
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);
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user