mirror of
https://github.com/clearlinux/clr-boot-manager.git
synced 2026-09-01 02:34:42 +00:00
tests: Add bootstrapping of faux legacy environment
We now create the relevant GPT structure to allow CBM to detect a legacy boot device. Currently this is only used for the syslinux bootloader, but in future will be extended to permit GRUB too. Signed-off-by: Ikey Doherty <michael.i.doherty@intel.com>
This commit is contained in:
committed by
William Douglas
parent
e15c5a817d
commit
a204ecaff1
+43
-2
@@ -29,6 +29,33 @@
|
||||
#include "harness.h"
|
||||
#include "system-harness.h"
|
||||
|
||||
/**
|
||||
* Coerce legacy lookup
|
||||
*/
|
||||
static inline int legacy_devno_to_wholedisk(__cbm_unused__ dev_t dev, __cbm_unused__ char *diskname,
|
||||
__cbm_unused__ size_t len,
|
||||
__cbm_unused__ dev_t *diskdevno)
|
||||
{
|
||||
*diskdevno = makedev(8, 8);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces detection of GPT legacy boot partition
|
||||
*/
|
||||
static inline unsigned long long legacy_partition_get_flags(__cbm_unused__ blkid_partition par)
|
||||
{
|
||||
return (1ULL << 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the detection of a boot partition GPT UUID
|
||||
*/
|
||||
static inline const char *legacy_partition_get_uuid(__cbm_unused__ blkid_partition par)
|
||||
{
|
||||
return DEFAULT_PART_UUID;
|
||||
}
|
||||
|
||||
static PlaygroundKernel legacy_kernels[] = { { "4.2.1", "kvm", 121, false },
|
||||
{ "4.2.3", "kvm", 124, true },
|
||||
{ "4.2.1", "native", 137, false },
|
||||
@@ -44,13 +71,22 @@ static PlaygroundConfig legacy_config = { "4.2.1-121.kvm",
|
||||
START_TEST(bootman_legacy_get_boot_device)
|
||||
{
|
||||
autofree(char) *boot_device = NULL;
|
||||
prepare_playground(&legacy_config);
|
||||
autofree(BootManager) *m = NULL;
|
||||
autofree(char) *exp = NULL;
|
||||
|
||||
/* Ensure cleanup */
|
||||
m = prepare_playground(&legacy_config);
|
||||
|
||||
boot_device = get_boot_device();
|
||||
fail_if(boot_device != NULL, "Found incorrect UEFI device for Legacy Boot");
|
||||
|
||||
boot_device = get_legacy_boot_device(PLAYGROUND_ROOT);
|
||||
fail_if(!boot_device, "Failed to determine legacy boot device");
|
||||
|
||||
if (asprintf(&exp, "%s/dev/disk/by-partuuid/Test-PartUUID", PLAYGROUND_ROOT) < 0) {
|
||||
abort();
|
||||
}
|
||||
fail_if(!streq(exp, boot_device), "Boot device does not match expected result");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
@@ -72,6 +108,11 @@ int main(void)
|
||||
Suite *s;
|
||||
SRunner *sr;
|
||||
int fail;
|
||||
/* override test ops for legacy testing */
|
||||
CbmBlkidOps blkid_ops = BlkidTestOps;
|
||||
blkid_ops.devno_to_wholedisk = legacy_devno_to_wholedisk;
|
||||
blkid_ops.partition_get_flags = legacy_partition_get_flags;
|
||||
blkid_ops.partition_get_uuid = legacy_partition_get_uuid;
|
||||
|
||||
/* syncing can be problematic during test suite runs */
|
||||
cbm_set_sync_filesystems(false);
|
||||
@@ -80,7 +121,7 @@ int main(void)
|
||||
setenv("CBM_DEBUG", "1", 1);
|
||||
cbm_log_init(stderr);
|
||||
|
||||
cbm_blkid_set_vtable(&BlkidTestOps);
|
||||
cbm_blkid_set_vtable(&blkid_ops);
|
||||
cbm_system_set_vtable(&SystemTestOps);
|
||||
|
||||
s = core_suite();
|
||||
|
||||
+55
-1
@@ -377,9 +377,11 @@ BootManager *prepare_playground(PlaygroundConfig *config)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Pending: Add support for legacy boot */
|
||||
/* Initialise the root devfs/sysfs */
|
||||
if (config->uefi) {
|
||||
set_test_system_uefi();
|
||||
} else {
|
||||
set_test_system_legacy();
|
||||
}
|
||||
|
||||
/* Construct kernel config directory */
|
||||
@@ -554,6 +556,58 @@ mem_fail:
|
||||
abort();
|
||||
}
|
||||
|
||||
void set_test_system_legacy(void)
|
||||
{
|
||||
autofree(char) *ddir = NULL;
|
||||
autofree(char) *diskdir = NULL;
|
||||
autofree(char) *diskfile = NULL;
|
||||
autofree(char) *dfile = NULL;
|
||||
autofree(char) *dlink = NULL;
|
||||
const char *devfs_path = cbm_system_get_devfs_path();
|
||||
|
||||
/* dev tree */
|
||||
if (asprintf(&ddir, "%s/block", devfs_path) < 0) {
|
||||
goto mem_fail;
|
||||
}
|
||||
|
||||
/* dev/block link */
|
||||
if (asprintf(&dlink, "%s/block/%u:%u", devfs_path, 8, 8) < 0) {
|
||||
goto mem_fail;
|
||||
}
|
||||
|
||||
/* "real" dev file for realpath()ing */
|
||||
if (asprintf(&dfile, "%s/leRootDevice", devfs_path) < 0) {
|
||||
goto mem_fail;
|
||||
}
|
||||
|
||||
nc_mkdir_p(ddir, 00755);
|
||||
if (!file_set_text(dfile, "le-root-device")) {
|
||||
goto mem_fail;
|
||||
}
|
||||
|
||||
if (symlink("../leRootDevice", dlink) != 0) {
|
||||
fprintf(stderr, "Cannot create symlink: %s", strerror(errno));
|
||||
abort();
|
||||
}
|
||||
|
||||
/* Create /dev/disk/by-partuuid portions */
|
||||
if (asprintf(&diskdir, "%s/disk/by-partuuid", cbm_system_get_devfs_path()) < 0) {
|
||||
goto mem_fail;
|
||||
}
|
||||
if (asprintf(&diskfile, "%s/%s", diskdir, "Test-PartUUID") < 0) {
|
||||
goto mem_fail;
|
||||
}
|
||||
nc_mkdir_p(diskdir, 00755);
|
||||
if (!file_set_text(diskfile, "clr-boot-manager Legacy testing")) {
|
||||
goto mem_fail;
|
||||
}
|
||||
return;
|
||||
|
||||
mem_fail:
|
||||
DECLARE_OOM();
|
||||
abort();
|
||||
}
|
||||
|
||||
/*
|
||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
||||
*
|
||||
|
||||
@@ -99,6 +99,11 @@ bool create_timeout_conf(void);
|
||||
*/
|
||||
void set_test_system_uefi(void);
|
||||
|
||||
/**
|
||||
* Set up the test harness to emulate legacy boot
|
||||
*/
|
||||
void set_test_system_legacy(void);
|
||||
|
||||
/*
|
||||
* Editor modelines - https://www.wireshark.org/tools/modelines.html
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user