blob: ee437dfb7586a812e45afe84f04c8b94e4d04d9c [file] [log] [blame] [edit]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SRC_STORAGE_BLOBFS_TEST_INTEGRATION_BLOBFS_FIXTURES_H_
#define SRC_STORAGE_BLOBFS_TEST_INTEGRATION_BLOBFS_FIXTURES_H_
#include <fcntl.h>
#include <fidl/fuchsia.io/cpp/fidl.h>
#include <lib/fdio/fd.h>
#include <lib/fidl/cpp/wire/status.h>
#include <lib/zx/result.h>
#include <zircon/errors.h>
#include <zircon/types.h>
#include <cstdint>
#include <fbl/unique_fd.h>
#include <gtest/gtest.h>
#include "lib/fidl/cpp/wire/channel.h"
#include "src/storage/fs_test/fs_test.h"
#include "src/storage/fs_test/fs_test_fixture.h"
namespace blobfs {
class BaseBlobfsTest : public fs_test::BaseFilesystemTest {
public:
using fs_test::BaseFilesystemTest::BaseFilesystemTest;
int root_fd() {
if (!root_fd_) {
root_fd_.reset(open(fs().mount_path().c_str(), O_DIRECTORY));
}
return root_fd_.get();
}
zx::result<int> exec_root_fd() {
if (!exec_root_fd_) {
auto [client, server] = fidl::Endpoints<fuchsia_io::Directory>::Create();
fuchsia_io::wire::Flags flags = fuchsia_io::wire::kPermReadable |
fuchsia_io::wire::Flags::kPermInheritWrite |
fuchsia_io::wire::Flags::kPermInheritExecute;
const fidl::Status result = fidl::WireCall(fs().ServiceDirectory())
->Open("blob-exec", flags, {}, server.TakeChannel());
if (!result.ok()) {
return zx::error(result.status());
}
if (zx_status_t status =
fdio_fd_create(client.TakeChannel().release(), exec_root_fd_.reset_and_get_address());
status != ZX_OK) {
return zx::error(status);
}
}
return zx::ok(exec_root_fd_.get());
}
private:
fbl::unique_fd root_fd_;
fbl::unique_fd exec_root_fd_;
};
// A test fixture for running tests with different blobfs settings.
class ParameterizedBlobfsTest : public BaseBlobfsTest,
public testing::WithParamInterface<fs_test::TestFilesystemOptions> {
protected:
ParameterizedBlobfsTest() : BaseBlobfsTest(GetParam()) {}
};
// Different blobfs settings to use with |ParameterizedBlobfsTest|.
fs_test::TestFilesystemOptions BlobfsDefaultTestParam();
fs_test::TestFilesystemOptions BlobfsWithFvmTestParam();
fs_test::TestFilesystemOptions BlobfsWithPaddedLayoutTestParam();
fs_test::TestFilesystemOptions BlobfsWithFixedDiskSizeTestParam(uint64_t disk_size);
// A test fixture for tests that only run against blobfs with the default settings.
class BlobfsTest : public BaseBlobfsTest {
protected:
explicit BlobfsTest() : BaseBlobfsTest(BlobfsDefaultTestParam()) {}
};
// A test fixture for tests that only run against blobfs with FVM.
class BlobfsWithFvmTest : public BaseBlobfsTest {
protected:
explicit BlobfsWithFvmTest() : BaseBlobfsTest(BlobfsWithFvmTestParam()) {}
};
} // namespace blobfs
#endif // SRC_STORAGE_BLOBFS_TEST_INTEGRATION_BLOBFS_FIXTURES_H_