Skip to content

Commit

Permalink
Merge pull request #41 from jluebbe/test-bootchooser
Browse files Browse the repository at this point in the history
Test bootchooser
  • Loading branch information
Enrico Jorns committed Apr 26, 2016
2 parents 906df57 + 5310346 commit dea6095
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 12 deletions.
24 changes: 14 additions & 10 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ TEST_LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh
TEST_LOG_COMPILER = $(top_srcdir)/tap-test

check_PROGRAMS = \
test/bootchooser.test \
test/checksum.test \
test/config_file.test \
test/manifest.test \
Expand All @@ -83,37 +84,40 @@ check_LTLIBRARIES = librauctest.la

librauctest_la_SOURCES = \
test/common.c
librauctest_la_LIBADD = $(GLIB_LIBS)
librauctest_la_LIBADD = $(GLIB_LIBS) librauc.la

TESTS = $(check_PROGRAMS) test/rauc.t

test_bootchooser_test_SOURCES = test/bootchooser.c
test_bootchooser_test_LDADD = librauctest.la

test_bundle_test_SOURCES = test/bundle.c
test_bundle_test_LDADD = librauc.la librauctest.la
test_bundle_test_LDADD = librauctest.la

test_checksum_test_SOURCES = test/checksum.c
test_checksum_test_LDADD = librauc.la
test_checksum_test_LDADD = librauctest.la

test_config_file_test_SOURCES = test/config_file.c
test_config_file_test_LDADD = librauctest.la librauc.la
test_config_file_test_LDADD = librauctest.la

test_manifest_test_SOURCES = test/manifest.c
test_manifest_test_LDADD = librauc.la
test_manifest_test_LDADD = librauctest.la

test_service_test_CFLAGS = $(AM_CFLAGS) -DTEST_SERVICES=\""$(abs_top_builddir)/test/services"\"
test_service_test_SOURCES = test/service.c
test_service_test_LDADD = librauctest.la librauc.la
test_service_test_LDADD = librauctest.la

test_signature_test_SOURCES = test/signature.c
test_signature_test_LDADD = librauctest.la librauc.la
test_signature_test_LDADD = librauctest.la

test_install_test_SOURCES = test/install.c
test_install_test_LDADD = librauc.la librauctest.la
test_install_test_LDADD = librauctest.la

test_network_test_SOURCES = test/network.c
test_network_test_LDADD = librauc.la
test_network_test_LDADD = librauctest.la

test_progress_test_SOURCES = test/progress.c
test_progress_test_LDADD = librauc.la
test_progress_test_LDADD = librauctest.la

SPHINXOPTS =
SPHINXBUILD = sphinx-build
Expand Down
5 changes: 3 additions & 2 deletions test/bin/barebox-state
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,22 @@ function check_var {
echo "Invalid variable: $1"
exit 1
fi
printf "$1=$2\n"
}

for i in $SETVAR; do
var="${i%=*}"
val="${i#*=}"

check_var $var
check_var "$var" "$val"

done

for i in $GETVAR; do
var="${i%=*}"
val="${i#*=}"

check_var $var
check_var "$var"

done

Expand Down
57 changes: 57 additions & 0 deletions test/bin/grub-editenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Command line parsing
if [ $# -le 2 ]; then
echo "Invalid arguments $*"
exit 1
fi

shift

if ! [ "$1" = "set" ]; then
echo "Invalid command: '$1'"
exit 1
fi
shift

function check_var {
if [ "$1" = "ORDER" ]; then
if ! [ "$2" = "A B" -o "$2" = "B A" ]; then
echo "Invalid argument for ORDER: '$2'"
exit 1
fi
elif [ "$1" = "A_OK" ]; then
if ! [ "$2" -ge 0 -a "$2" -le 1 ]; then
echo "Invalid argument for A_OK: '$2'"
exit 1
fi
elif [ "$1" = "B_OK" ]; then
if ! [ "$2" -ge 0 -a "$2" -le 1 ]; then
echo "Invalid argument for B_OK: '$2'"
exit 1
fi
elif [ "$1" = "A_TRY" ]; then
if ! [ "$2" -ge 0 -a "$2" -le 1 ]; then
echo "Invalid argument for A_TRY: '$2'"
exit 1
fi
elif [ "$1" = "B_TRY" ]; then
if ! [ "$2" -ge 0 -a "$2" -le 1 ]; then
echo "Invalid argument for B_TRY: '$2'"
exit 1
fi
else
echo "Invalid key: '$1'"
exit 1
fi
printf "$1=$2\n"
}

for i in "$@"; do
var="${i%=*}"
val="${i#*=}"

check_var "$var" "$val"
done

exit 0
148 changes: 148 additions & 0 deletions test/bootchooser.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#include <stdio.h>
#include <locale.h>
#include <glib.h>

#include <bootchooser.h>
#include <context.h>
#include <utils.h>

#include "common.h"

typedef struct {
gchar *tmpdir;
} BootchooserFixture;

static void bootchooser_fixture_set_up(BootchooserFixture *fixture,
gconstpointer user_data)
{
fixture->tmpdir = g_dir_make_tmp("rauc-bootchooser-XXXXXX", NULL);
g_assert_nonnull(fixture->tmpdir);
}

static void bootchooser_fixture_tear_down(BootchooserFixture *fixture,
gconstpointer user_data)
{
g_assert_true(rm_tree(fixture->tmpdir, NULL));
g_free(fixture->tmpdir);
}

static void bootchooser_barebox(BootchooserFixture *fixture,
gconstpointer user_data)
{
RaucSlot *slot;

const gchar *cfg_file = "\
[system]\n\
compatible=FooCorp Super BarBazzer\n\
bootloader=barebox\n\
mountprefix=/mnt/myrauc/\n\
\n\
[keyring]\n\
path=/etc/rauc/keyring/\n\
\n\
[slot.rescue.0]\n\
device=/dev/mtd4\n\
type=raw\n\
bootname=factory0\n\
readonly=true\n\
\n\
[slot.rootfs.0]\n\
device=/dev/sda0\n\
type=ext4\n\
bootname=system0\n\
\n\
[slot.rootfs.1]\n\
device=/dev/sda1\n\
type=ext4\n\
bootname=system1\n";

gchar* pathname = write_tmp_file(fixture->tmpdir, "barebox.conf", cfg_file, NULL);
g_assert_nonnull(pathname);

g_clear_pointer(&r_context_conf()->configpath, g_free);
r_context_conf()->configpath = pathname;
r_context();

slot = find_config_slot_by_device(r_context()->config, "/dev/sda0");
g_assert_nonnull(slot);

g_assert_true(r_boot_set_state(slot, TRUE));
g_assert_true(r_boot_set_state(slot, FALSE));

slot = find_config_slot_by_device(r_context()->config, "/dev/sda1");
g_assert_nonnull(slot);

g_assert_true(r_boot_set_primary(slot));
}

static void bootchooser_grub(BootchooserFixture *fixture,
gconstpointer user_data)
{
RaucSlot *slot;

const gchar *cfg_file = "\
[system]\n\
compatible=FooCorp Super BarBazzer\n\
bootloader=grub\n\
grubenv=grubenv.test\n\
mountprefix=/mnt/myrauc/\n\
\n\
[keyring]\n\
path=/etc/rauc/keyring/\n\
\n\
[slot.rescue.0]\n\
device=/dev/mtd4\n\
type=raw\n\
bootname=R\n\
readonly=true\n\
\n\
[slot.rootfs.0]\n\
device=/dev/sda0\n\
type=ext4\n\
bootname=A\n\
\n\
[slot.rootfs.1]\n\
device=/dev/sda1\n\
type=ext4\n\
bootname=B\n";

gchar* pathname = write_tmp_file(fixture->tmpdir, "grub.conf", cfg_file, NULL);
g_assert_nonnull(pathname);

g_clear_pointer(&r_context_conf()->configpath, g_free);
r_context_conf()->configpath = pathname;
r_context();

slot = find_config_slot_by_device(r_context()->config, "/dev/sda0");
g_assert_nonnull(slot);

g_assert_true(r_boot_set_state(slot, TRUE));
g_assert_true(r_boot_set_state(slot, FALSE));

slot = find_config_slot_by_device(r_context()->config, "/dev/sda1");
g_assert_nonnull(slot);

g_assert_true(r_boot_set_primary(slot));
}

int main(int argc, char *argv[])
{
gchar *path;
setlocale(LC_ALL, "C");

path = g_strdup_printf("%s:%s", "test/bin", g_getenv("PATH"));
g_setenv("PATH", path, TRUE);
g_free(path);

g_test_init(&argc, &argv, NULL);

g_test_add("/bootchoser/barebox", BootchooserFixture, NULL,
bootchooser_fixture_set_up, bootchooser_barebox,
bootchooser_fixture_tear_down);

g_test_add("/bootchoser/grub", BootchooserFixture, NULL,
bootchooser_fixture_set_up, bootchooser_grub,
bootchooser_fixture_tear_down);

return g_test_run ();
}

0 comments on commit dea6095

Please sign in to comment.