Skip to content

Commit

Permalink
test/install: share bundle setup code
Browse files Browse the repository at this point in the history
Created set_up_bunlde(function) that allows to switch including handlers
on or off. Thir removes some lines of code duplication from bundle setup
functions.

Signed-off-by: Enrico Jorns <[email protected]>
  • Loading branch information
ejoerns committed Aug 24, 2016
1 parent dcb064c commit 10369d7
Showing 1 changed file with 14 additions and 52 deletions.
66 changes: 14 additions & 52 deletions test/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ static void install_fixture_set_up(InstallFixture *fixture,
g_free(slotpath);
}

static void install_fixture_set_up_bundle(InstallFixture *fixture,
gconstpointer user_data) {
static void set_up_bundle(InstallFixture *fixture,
gconstpointer user_data,
gboolean handler) {
gchar *contentdir;
gchar *bundlepath;
gchar *mountdir;
Expand Down Expand Up @@ -160,6 +161,11 @@ static void install_fixture_set_up_bundle(InstallFixture *fixture,
g_assert_true(r_umount(mountdir, NULL));
g_assert(test_rmdir(fixture->tmpdir, "mnt") == 0);

/* Copy custom handler */
if (handler) {
g_assert_true(test_copy_file("test/install-content/custom_handler.sh", NULL,
fixture->tmpdir, "content/custom_handler.sh"));
}

/* Update checksums in manifest */
g_assert_true(update_manifest(contentdir, FALSE, NULL));
Expand All @@ -173,58 +179,14 @@ static void install_fixture_set_up_bundle(InstallFixture *fixture,
g_free(testfilepath);
}

static void install_fixture_set_up_bundle_custom_handler(InstallFixture *fixture,
static void install_fixture_set_up_bundle(InstallFixture *fixture,
gconstpointer user_data) {
gchar *contentdir;
gchar *bundlepath;
gchar *mountdir;
gchar *testfilepath;

/* needs to run as root */
if (!test_running_as_root())
return;

install_fixture_set_up(fixture, user_data);

contentdir = g_build_filename(fixture->tmpdir, "content", NULL);
bundlepath = g_build_filename(fixture->tmpdir, "bundle.raucb", NULL);
mountdir = g_build_filename(fixture->tmpdir, "mnt", NULL);
testfilepath = g_build_filename(mountdir, "verify.txt", NULL);

/* Setup bundle content */
g_assert(test_prepare_dummy_file(fixture->tmpdir, "content/rootfs.ext4",
64*1024*1024, "/dev/zero") == 0);
g_assert(test_prepare_dummy_file(fixture->tmpdir, "content/appfs.ext4",
32*1024*1024, "/dev/zero") == 0);
g_assert_true(test_make_filesystem(fixture->tmpdir, "content/rootfs.ext4"));
g_assert_true(test_make_filesystem(fixture->tmpdir, "content/appfs.ext4"));
g_assert(test_prepare_manifest_file(fixture->tmpdir, "content/manifest.raucm", TRUE) == 0);

/* Copy custom handler */
g_assert_true(test_copy_file("test/install-content/custom_handler.sh", NULL,
fixture->tmpdir, "content/custom_handler.sh"));

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

/* Write test file to slot */
g_assert(test_mkdir_relative(fixture->tmpdir, "mnt", 0777) == 0);
g_assert_true(test_mount(g_build_filename(fixture->tmpdir, "content/rootfs.ext4", NULL), mountdir));
g_assert_true(g_file_set_contents(testfilepath, "0xdeadbeaf", -1, NULL));
g_assert_true(r_umount(mountdir, NULL));
g_assert(test_rmdir(fixture->tmpdir, "mnt") == 0);

/* Update checksums in manifest */
g_assert_true(update_manifest(contentdir, FALSE, NULL));

/* Create bundle */
g_assert_true(create_bundle(bundlepath, contentdir, NULL));
set_up_bundle(fixture, user_data, FALSE);
}

g_free(bundlepath);
g_free(contentdir);
g_free(mountdir);
g_free(testfilepath);
static void install_fixture_set_up_bundle_custom_handler(InstallFixture *fixture,
gconstpointer user_data) {
set_up_bundle(fixture, user_data, TRUE);
}

static void install_fixture_set_up_system_conf(InstallFixture *fixture,
Expand Down

0 comments on commit 10369d7

Please sign in to comment.