blob: 463c1ecf010cfda9a2831a79b5196a0e3c35c850 [file]
// Copyright 2026 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.
use crypt_policy as _;
use fshost_test_fixture::disk_builder::{DataSpec, VolumesSpec};
use fuchsia_async as fasync;
use futures::FutureExt as _;
pub mod config;
use config::{blob_fs_type, data_fs_spec, data_fs_type, new_builder, volumes_spec};
#[fuchsia::test]
async fn ramdisk_blob_and_data_mounted() {
let mut builder = new_builder();
builder.fshost().set_config_value("ramdisk_image", true);
builder
.with_zbi_ramdisk()
.format_volumes(volumes_spec())
.format_data(DataSpec { zxcrypt: false, ..data_fs_spec() });
let fixture = builder.build().await;
fixture.check_fs_type("blob", blob_fs_type()).await;
fixture.check_fs_type("data", data_fs_type()).await;
fixture.check_test_data_file().await;
fixture.check_test_blob().await;
fixture.tear_down().await;
}
#[fuchsia::test]
async fn ramdisk_blob_and_data_mounted_no_existing_data_partition() {
let mut builder = new_builder();
builder.fshost().set_config_value("ramdisk_image", true);
builder
.with_zbi_ramdisk()
.format_volumes(VolumesSpec { create_data_partition: false, ..volumes_spec() })
.format_data(DataSpec { zxcrypt: false, ..data_fs_spec() });
let fixture = builder.build().await;
fixture.check_fs_type("blob", blob_fs_type()).await;
fixture.check_fs_type("data", data_fs_type()).await;
fixture.check_test_blob().await;
fixture.tear_down().await;
}
#[fuchsia::test]
async fn ramdisk_data_ignores_non_ramdisk() {
let mut builder = new_builder();
builder.fshost().set_config_value("ramdisk_image", true);
builder
.with_disk()
.format_volumes(volumes_spec())
.format_data(DataSpec { zxcrypt: false, ..data_fs_spec() });
let fixture = builder.build().await;
// There isn't really a good way to tell that something is not mounted, but at this point we
// would be pretty close to it, so a timeout of a couple seconds should safeguard against
// potential issues.
futures::select! {
_ = fixture.check_fs_type("data", data_fs_type()).fuse() => {
panic!("check_fs_type returned unexpectedly - data was mounted");
},
_ = fixture.check_fs_type("blob", blob_fs_type()).fuse() => {
panic!("check_fs_type returned unexpectedly - blob was mounted");
},
_ = fasync::Timer::new(std::time::Duration::from_secs(2)).fuse() => (),
}
fixture.tear_down().await;
}
#[fuchsia::test]
async fn ramdisk_image_set() {
// Set the ramdisk_image flag
let mut builder = new_builder();
builder.fshost().set_config_value("ramdisk_image", true);
builder.with_disk().format_volumes(volumes_spec());
let fixture = builder.build().await;
// Use the same approach as ramdisk_data_ignores_non_ramdisk() to ensure that
// neither blobfs nor data were mounted using a timeout
futures::select! {
_ = fixture.check_fs_type("data", data_fs_type()).fuse() => {
panic!("check_fs_type returned unexpectedly - data was mounted");
},
_ = fixture.check_fs_type("blob", blob_fs_type()).fuse() => {
panic!("check_fs_type returned unexpectedly - blob was mounted");
},
_ = fasync::Timer::new(std::time::Duration::from_secs(2)).fuse() => {
},
}
fixture.tear_down().await;
}
#[fuchsia::test]
async fn ramdisk_image_serves_zbi_ramdisk_contents_with_unformatted_data() {
let mut builder = new_builder();
builder.fshost().set_config_value("ramdisk_image", true);
builder.with_zbi_ramdisk().format_volumes(volumes_spec());
let fixture = builder.build().await;
fixture.check_fs_type("blob", blob_fs_type()).await;
fixture.check_fs_type("data", data_fs_type()).await;
fixture.tear_down().await;
}