Skip to content

Commit

Permalink
test: skip some tests when not running as root
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
  • Loading branch information
jluebbe committed Mar 13, 2016
1 parent 2c04b38 commit dbbbd07
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 13 deletions.
4 changes: 4 additions & 0 deletions test/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ static void bundle_test2(BundleFixture *fixture,
{
gchar *bundlename, *contentdir, *mountpoint;

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

bundlename = g_build_filename(fixture->tmpdir, "bundle.raucb", NULL);
g_assert_nonnull(bundlename);

Expand Down
13 changes: 13 additions & 0 deletions test/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,16 @@ gboolean test_make_slot_user_writable(const gchar* path, const gchar* file) {
const gchar* test_bootname_provider(void) {
return "system0";
}

gboolean test_running_as_root(void) {
uid_t uid = getuid();
uid_t euid = geteuid();

if (uid == 0 && euid == 0)
return TRUE;

g_test_message("not running as root (uid=%lu euid=%lu)",
(unsigned long) uid, (unsigned long) euid);
g_test_skip("not running as root");
return FALSE;
}
1 change: 1 addition & 0 deletions test/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ gboolean test_do_chmod(const gchar *path);
gboolean test_copy_file(const gchar *srcprefix, const gchar *srcfile, const gchar *dstprefix, const gchar *dstfile);
gboolean test_make_slot_user_writable(const gchar* path, const gchar* file);
const gchar* test_bootname_provider(void);
gboolean test_running_as_root(void);
68 changes: 55 additions & 13 deletions test/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ typedef struct {

#define SLOT_SIZE (10*1024*1024)

static void install_fixture_set_up(InstallFixture *fixture,
static void install_fixture_set_up_user(InstallFixture *fixture,
gconstpointer user_data)
{
gchar *configpath;
gchar *certpath;
gchar *keypath;
gchar *capath;
gchar *slotfile;
gchar *slotpath;

fixture->tmpdir = g_dir_make_tmp("rauc-XXXXXX", NULL);
g_assert_nonnull(fixture->tmpdir);
Expand Down Expand Up @@ -87,33 +85,51 @@ static void install_fixture_set_up(InstallFixture *fixture,
g_assert_true(test_make_filesystem(fixture->tmpdir, "images/rootfs-1"));
g_assert_true(test_make_filesystem(fixture->tmpdir, "images/appfs-1"));

/* Set dummy bootname provider */
set_bootname_provider(test_bootname_provider);

g_free(configpath);
g_free(certpath);
g_free(keypath);
g_free(capath);
}

static void install_fixture_set_up(InstallFixture *fixture,
gconstpointer user_data)
{
gchar *slotfile;
gchar *slotpath;

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

install_fixture_set_up_user(fixture, user_data);

/* Make images user-writable */
test_make_slot_user_writable(fixture->tmpdir, "images/rootfs-0");
test_make_slot_user_writable(fixture->tmpdir, "images/appfs-0");
test_make_slot_user_writable(fixture->tmpdir, "images/rootfs-1");
test_make_slot_user_writable(fixture->tmpdir, "images/appfs-1");

/* Set dummy bootname provider */
set_bootname_provider(test_bootname_provider);

/* Provide active mounted slot */
slotfile = g_build_filename(fixture->tmpdir, "images/rootfs-0", NULL);
slotpath = g_build_filename(fixture->tmpdir, "slot", NULL);
g_assert(test_mount(slotfile, slotpath));

g_free(slotfile);
g_free(slotpath);
g_free(configpath);
g_free(certpath);
g_free(keypath);
g_free(capath);
}

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

/* 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);
Expand Down Expand Up @@ -147,6 +163,10 @@ static void install_fixture_set_up_bundle_custom_handler(InstallFixture *fixture
gchar *contentdir;
gchar *bundlepath;

/* 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);
Expand Down Expand Up @@ -205,6 +225,10 @@ static void install_fixture_set_up_network(InstallFixture *fixture,
gchar *contentdir;
gchar *manifestpath;

/* 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);
Expand Down Expand Up @@ -263,6 +287,9 @@ static void install_fixture_set_up_network(InstallFixture *fixture,
static void install_fixture_tear_down(InstallFixture *fixture,
gconstpointer user_data)
{
if (!fixture->tmpdir)
return;

test_umount(fixture->tmpdir, "slot");
test_umount(fixture->tmpdir, "mount");
test_rm_tree(fixture->tmpdir, "");
Expand All @@ -282,7 +309,6 @@ static void install_test_target(InstallFixture *fixture,

g_assert_true(load_manifest_file("test/manifest.raucm", &rm, NULL));

set_bootname_provider(test_bootname_provider);
g_assert_true(determine_slot_states(NULL));

g_assert_nonnull(r_context()->config);
Expand Down Expand Up @@ -339,6 +365,10 @@ static void install_test_bundle(InstallFixture *fixture,
gchar *bundlepath, *mountdir;
RaucInstallArgs *args;

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

/* Set mount path to current temp dir */
mountdir = g_build_filename(fixture->tmpdir, "mount", NULL);
g_assert_nonnull(mountdir);
Expand All @@ -364,6 +394,10 @@ static void install_test_network(InstallFixture *fixture,
{
gchar *manifesturl, *mountdir;

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

/* Set mount path to current temp dir */
mountdir = g_build_filename(fixture->tmpdir, "mount", NULL);
g_assert_nonnull(mountdir);
Expand Down Expand Up @@ -392,6 +426,10 @@ static void install_test_bundle_thread(InstallFixture *fixture,
RaucInstallArgs *args = install_args_new();
gchar *bundlepath, *mountdir;

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

/* Set mount path to current temp dir */
mountdir = g_build_filename(fixture->tmpdir, "mount", NULL);
g_assert_nonnull(mountdir);
Expand Down Expand Up @@ -419,6 +457,10 @@ static void install_test_network_thread(InstallFixture *fixture,
RaucInstallArgs *args = install_args_new();
gchar *manifesturl, *mountdir;

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

/* Set mount path to current temp dir */
mountdir = g_build_filename(fixture->tmpdir, "mount", NULL);
g_assert_nonnull(mountdir);
Expand Down Expand Up @@ -451,11 +493,11 @@ int main(int argc, char *argv[])
g_test_init(&argc, &argv, NULL);

g_test_add("/install/bootname", InstallFixture, NULL,
install_fixture_set_up, install_test_bootname,
install_fixture_set_up_user, install_test_bootname,
install_fixture_tear_down);

g_test_add("/install/target", InstallFixture, NULL,
install_fixture_set_up, install_test_target,
install_fixture_set_up_user, install_test_target,
install_fixture_tear_down);

g_test_add("/install/bundle", InstallFixture, NULL,
Expand Down

0 comments on commit dbbbd07

Please sign in to comment.