Skip to content

Commit

Permalink
Merge pull request #1221 from jluebbe/optional-slot-artifacts
Browse files Browse the repository at this point in the history
test: fix pre-check tests and generate slot artifacts only when needed
  • Loading branch information
ejoerns committed Sep 5, 2023
2 parents 9a8daaa + 7d00ff6 commit 2333433
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 56 deletions.
4 changes: 2 additions & 2 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Some of them only run in CI, but most of them can be executed locally.
When working on a new feature or fixing a bug, please make sure these tests
succeed.

Code Style - uncrustify
Code Style - uncrustify
~~~~~~~~~~~~~~~~~~~~~~~

To maintain a consistent code style, we use the `uncrustify
Expand Down Expand Up @@ -73,7 +73,7 @@ from the RAUC source code's root directory but they will also be triggered by
the general test suite run (see below).
If you add or change subcommands or arguments of the CLI tool, make sure these
tests succeed and extend them if possible.
As many of these tests need root permissions, we recommend running them using the
As many of these tests need root permissions, we recommend running them using the
``qemu-test`` helper below.

glib Unit Tests - gtest
Expand Down
2 changes: 1 addition & 1 deletion docs/integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ To register the custom bootloader backend handler, assign your handler to the
Custom bootloader backend interface
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

According to :ref:`sec-boot-slot` the custom bootloader handler is called by
According to :ref:`sec-boot-slot` the custom bootloader handler is called by
RAUC to trigger the following actions:

* get the primary slot
Expand Down
4 changes: 2 additions & 2 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ Example configuration:
Normally, this option is not needed as every access to the bundle payload during
installation is already protected by ``dm-verity``.
The default value is ``false`` which means that this pre-check is not performed.

This option is useful when the installation should be aborted early even if the corrupt
part of the bundle is not used during installation (perhaps due to adaptive updates or
image variants).

It has no effect for ``plain`` bundles, as the signature verification already checks the
whole bundle.
whole bundle.

.. _keyring-section:

Expand Down
2 changes: 1 addition & 1 deletion src/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -2549,7 +2549,7 @@ static gboolean read_complete_dm_device(gchar *dev, GError **error)
g_set_error(error,
G_FILE_ERROR,
g_file_error_from_errno(err),
"Check %s device failed between %"G_GOFFSET_FORMAT " and %"G_GOFFSET_FORMAT " bytes with error: %s", dev, chunk*sizeof(buf), (chunk+1)*sizeof(buf), g_strerror(err));
"Check %s device failed between %"G_GOFFSET_FORMAT " and %"G_GOFFSET_FORMAT " bytes with error: %s", dev, chunk*chunk_size, (chunk+1)*chunk_size, g_strerror(err));
ret = FALSE;
break;
}
Expand Down
25 changes: 14 additions & 11 deletions test/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ static void bundle_test_create_check_mount_with_pre_check_corrupt(BundleFixture
res = mount_bundle(bundle, &ierror);
g_assert_error(ierror, G_FILE_ERROR, G_FILE_ERROR_IO);
g_assert_false(res);
g_assert_nonnull(strstr(ierror->message, "failed between 1048576 and 1114112 bytes with error: Input/output error"));
}

static void bundle_test_extract_signature(BundleFixture *fixture,
Expand Down Expand Up @@ -843,25 +844,27 @@ int main(int argc, char *argv[])
bundle_fixture_set_up_bundle_codesign, bundle_test_purpose_codesign,
bundle_fixture_tear_down);

g_test_add(dup_test_printf(ptrs, "/bundle/create_mount_extract_with_pre_check/%s", format_name),
BundleFixture, bundle_data,
bundle_fixture_set_up_bundle, bundle_test_create_mount_extract_with_pre_check,
bundle_fixture_tear_down);

g_test_add(dup_test_printf(ptrs, "/bundle/create_mount_with_pre_check_corrupt/%s", format_name),
BundleFixture, bundle_data,
bundle_fixture_set_up_bundle_corrupt, bundle_test_create_check_mount_with_pre_check_corrupt,
bundle_fixture_tear_down);
if (format != R_MANIFEST_FORMAT_PLAIN) {
g_test_add(dup_test_printf(ptrs, "/bundle/create_mount_extract_with_pre_check/%s", format_name),
BundleFixture, bundle_data,
bundle_fixture_set_up_bundle, bundle_test_create_mount_extract_with_pre_check,
bundle_fixture_tear_down);

g_test_add(dup_test_printf(ptrs, "/bundle/create_mount_with_pre_check_corrupt/%s", format_name),
BundleFixture, bundle_data,
bundle_fixture_set_up_bundle_corrupt, bundle_test_create_check_mount_with_pre_check_corrupt,
bundle_fixture_tear_down);
}
}

/* test casync manifest contents */
g_test_add("/bundle/check_casync/old",
BundleFixture, bundle_data,
BundleFixture, NULL,
bundle_fixture_set_up, bundle_test_check_casync_old,
bundle_fixture_tear_down);

g_test_add("/bundle/check_casync/new",
BundleFixture, bundle_data,
BundleFixture, NULL,
bundle_fixture_set_up, bundle_test_check_casync_new,
bundle_fixture_tear_down);

Expand Down
26 changes: 13 additions & 13 deletions test/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,19 @@ int test_prepare_manifest_file(const gchar *dirname, const gchar *filename, cons
rm->hook_name = g_strdup("hook.sh");
}

img = g_new0(RaucImage, 1);

img->slotclass = g_strdup("rootfs");
img->filename = g_strdup("rootfs.ext4");
if (options->hooks)
img->hooks.post_install = TRUE;
rm->images = g_list_append(rm->images, img);

img = g_new0(RaucImage, 1);

img->slotclass = g_strdup("appfs");
img->filename = g_strdup("appfs.ext4");
rm->images = g_list_append(rm->images, img);
if (options->slots) {
img = g_new0(RaucImage, 1);
img->slotclass = g_strdup("rootfs");
img->filename = g_strdup("rootfs.ext4");
if (options->hooks)
img->hooks.post_install = TRUE;
rm->images = g_list_append(rm->images, img);

img = g_new0(RaucImage, 1);
img->slotclass = g_strdup("appfs");
img->filename = g_strdup("appfs.ext4");
rm->images = g_list_append(rm->images, img);
}

g_assert_true(save_manifest_file(path, rm, NULL));

Expand Down
1 change: 1 addition & 0 deletions test/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
typedef struct {
gboolean custom_handler;
gboolean hooks;
gboolean slots;
RManifestBundleFormat format;
} ManifestTestOptions;

Expand Down
58 changes: 32 additions & 26 deletions test/install-fixtures.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ void fixture_helper_set_up_bundle(gchar *tmpdir,
g_autoptr(GError) error = NULL;
gboolean res = FALSE;

g_assert_nonnull(tmpdir);
g_assert_nonnull(options);

/* needs to run as root */
if (!test_running_as_root())
return;
Expand All @@ -139,34 +142,30 @@ void fixture_helper_set_up_bundle(gchar *tmpdir,
testfilepath = g_build_filename(mountdir, "verify.txt", NULL);

/* Setup bundle content */
g_assert(test_prepare_dummy_file(tmpdir, "content/rootfs.ext4",
SLOT_SIZE, "/dev/zero") == 0);
g_assert(test_prepare_dummy_file(tmpdir, "content/appfs.ext4",
SLOT_SIZE, "/dev/zero") == 0);
g_assert(test_prepare_dummy_file(tmpdir, "content/bootloader.ext4",
SLOT_SIZE, "/dev/zero") == 0);
g_assert_true(test_make_filesystem(tmpdir, "content/rootfs.ext4"));
g_assert_true(test_make_filesystem(tmpdir, "content/appfs.ext4"));
g_assert_true(test_make_filesystem(tmpdir, "content/bootloader.ext4"));
if (manifest_content) {
g_autofree gchar *tmpfile = write_tmp_file(tmpdir, "content/manifest.raucm", manifest_content, NULL);
g_assert_nonnull(tmpfile);
} else {
g_assert(test_prepare_manifest_file(tmpdir, "content/manifest.raucm", options) == 0);
if (options->slots) {
g_assert(test_prepare_dummy_file(tmpdir, "content/rootfs.ext4",
SLOT_SIZE, "/dev/zero") == 0);
g_assert(test_prepare_dummy_file(tmpdir, "content/appfs.ext4",
SLOT_SIZE, "/dev/zero") == 0);
g_assert(test_prepare_dummy_file(tmpdir, "content/bootloader.ext4",
SLOT_SIZE, "/dev/zero") == 0);
g_assert_true(test_make_filesystem(tmpdir, "content/rootfs.ext4"));
g_assert_true(test_make_filesystem(tmpdir, "content/appfs.ext4"));
g_assert_true(test_make_filesystem(tmpdir, "content/bootloader.ext4"));

/* Make images user-writable */
test_make_slot_user_writable(tmpdir, "content/rootfs.ext4");
test_make_slot_user_writable(tmpdir, "content/appfs.ext4");
test_make_slot_user_writable(tmpdir, "content/bootloader.ext4");

/* Write test file to slot */
g_assert(test_mkdir_relative(tmpdir, "mnt", 0777) == 0);
g_assert_true(test_mount(rootfspath, mountdir));
g_assert_true(g_file_set_contents(testfilepath, "0xdeadbeaf", -1, NULL));
g_assert_true(r_umount(mountdir, NULL));
g_assert(test_rmdir(tmpdir, "mnt") == 0);
}

/* Make images user-writable */
test_make_slot_user_writable(tmpdir, "content/rootfs.ext4");
test_make_slot_user_writable(tmpdir, "content/appfs.ext4");
test_make_slot_user_writable(tmpdir, "content/bootloader.ext4");

/* Write test file to slot */
g_assert(test_mkdir_relative(tmpdir, "mnt", 0777) == 0);
g_assert_true(test_mount(rootfspath, mountdir));
g_assert_true(g_file_set_contents(testfilepath, "0xdeadbeaf", -1, NULL));
g_assert_true(r_umount(mountdir, NULL));
g_assert(test_rmdir(tmpdir, "mnt") == 0);

/* Copy custom handler */
if (options->custom_handler) {
g_assert_true(test_copy_file("test/install-content/custom_handler.sh", NULL,
Expand All @@ -179,6 +178,13 @@ void fixture_helper_set_up_bundle(gchar *tmpdir,
tmpdir, "content/hook.sh"));
}

if (manifest_content) {
g_autofree gchar *tmpfile = write_tmp_file(tmpdir, "content/manifest.raucm", manifest_content, NULL);
g_assert_nonnull(tmpfile);
} else {
g_assert(test_prepare_manifest_file(tmpdir, "content/manifest.raucm", options) == 0);
}

/* Create bundle */
res = create_bundle(bundlepath, contentdir, &error);
g_assert_no_error(error);
Expand Down
7 changes: 7 additions & 0 deletions test/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,7 @@ int main(int argc, char *argv[])
install_data = dup_test_data(ptrs, (&(InstallData) {
.manifest_test_options = {
.format = format,
.slots = TRUE,
},
}));
g_test_add(dup_test_printf(ptrs, "/install/bootname/%s", format_name),
Expand Down Expand Up @@ -1520,6 +1521,7 @@ int main(int argc, char *argv[])
.manifest_test_options = {
.custom_handler = TRUE,
.hooks = FALSE,
.slots = TRUE,
},
}));
g_test_add(dup_test_printf(ptrs, "/install/bundle-custom-handler/%s", format_name),
Expand All @@ -1532,6 +1534,7 @@ int main(int argc, char *argv[])
.manifest_test_options = {
.custom_handler = FALSE,
.hooks = TRUE,
.slots = TRUE,
},
}));
g_test_add(dup_test_printf(ptrs, "/install/bundle-hook/install-check/%s", format_name),
Expand All @@ -1544,6 +1547,7 @@ int main(int argc, char *argv[])
.manifest_test_options = {
.custom_handler = FALSE,
.hooks = TRUE,
.slots = TRUE,
},
}));
g_test_add(dup_test_printf(ptrs, "/install/bundle-hook/slot-install/%s", format_name),
Expand All @@ -1556,6 +1560,7 @@ int main(int argc, char *argv[])
.manifest_test_options = {
.custom_handler = FALSE,
.hooks = TRUE,
.slots = TRUE,
},
}));
g_test_add(dup_test_printf(ptrs, "/install/bundle-hook/slot-post-install/%s", format_name),
Expand All @@ -1568,6 +1573,7 @@ int main(int argc, char *argv[])
.manifest_test_options = {
.custom_handler = TRUE,
.hooks = TRUE,
.slots = TRUE,
},
}));
g_test_add(dup_test_printf(ptrs, "/install/already-mounted/%s", format_name),
Expand All @@ -1579,6 +1585,7 @@ int main(int argc, char *argv[])
install_data = dup_test_data(ptrs, (&(InstallData) {
.manifest_test_options = {
.format = R_MANIFEST_FORMAT_VERITY,
.slots = TRUE,
},
}));
g_test_add("/install/adaptive",
Expand Down
1 change: 1 addition & 0 deletions test/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static void service_install_fixture_set_up(ServiceFixture *fixture, gconstpointe
&(ManifestTestOptions) {
.custom_handler = FALSE,
.hooks = FALSE,
.slots = TRUE,
});

/* Write a D-Bus service file with current tmpdir */
Expand Down

0 comments on commit 2333433

Please sign in to comment.