Add test/tct_prepare.bats 92/79692/18
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Tue, 12 Jul 2016 09:49:57 +0000 (11:49 +0200)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Tue, 6 Dec 2016 15:37:13 +0000 (16:37 +0100)
mkfs.ext4 is required.
It does not check error paths.

Change-Id: I54477a575350d9c70d8413a9243a72d3fa27e25c
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
test/tct_prepare.bats [new file with mode: 0755]

diff --git a/test/tct_prepare.bats b/test/tct_prepare.bats
new file mode 100755 (executable)
index 0000000..3dd6f2c
--- /dev/null
@@ -0,0 +1,70 @@
+#!/usr/bin/env bats
+
+export TESTLAB_SCRIPTS="./tct"
+
+. "${TESTLAB_SCRIPTS}/common.sh"
+. "${TESTLAB_SCRIPTS}/prepare/prepare.sh"
+
+TAR_1="${BATS_TMPDIR}/foo1.tar"
+TAR_2="${BATS_TMPDIR}/bar1.tar"
+DEST="${BATS_TMPDIR}/foo_bar_dest"
+MOUNT="${BATS_TMPDIR}/foo_bar_mount"
+
+setup() {
+    FOO_1="$BATS_TMPDIR/foo_1"
+    FOO_2="$BATS_TMPDIR/foo_2"
+    BAR_1="$BATS_TMPDIR/bar_1"
+    BAR_2="$BATS_TMPDIR/bar_2"
+    BAR_3="$BATS_TMPDIR/bar_3"
+    dd if="/dev/urandom" of="$FOO_1" bs=1M count=16
+    truncate -s 100M "$FOO_2"
+    mkfs.ext4 -F "$FOO_2"
+    dd if="/dev/urandom" of="$BAR_1" bs=1M count=24
+    dd if="/dev/urandom" of="$BAR_2" bs=2M count=16
+    dd if="/dev/urandom" of="$BAR_3" bs=2M count=8
+    for i in "$FOO_1" "$FOO_2" "$BAR_1" "$BAR_2" "$BAR_3"
+    do
+        [ -f "$i" ]
+    done
+    tar -C "${BATS_TMPDIR}" -cf "$TAR_1" "foo_1" "foo_2"
+    tar -C "${BATS_TMPDIR}" -cf "$TAR_2" "bar_1" "bar_2" "bar_3"
+    for i in "$FOO_1" "$FOO_2" "$BAR_1" "$BAR_2" "$BAR_3"
+    do
+        [ -f "$i" ]
+        rm "$i"
+    done
+}
+
+teardown() {
+    rm -rf "${TAR_1}" "${TAR_2}" "${MOUNT}" "${DEST}"
+}
+
+@test "image prepare" {
+#test "unpack_image"
+    rm -rf "$DEST"
+    unpack_image "$TAR_1" "$TAR_2" "$DEST"
+    FOO_1="$DEST/foo_1"
+    FOO_2="$DEST/foo_2"
+    BAR_1="$DEST/bar_1"
+    BAR_2="$DEST/bar_2"
+    BAR_3="$DEST/bar_3"
+    for i in "$FOO_1" "$FOO_2" "$BAR_1" "$BAR_2" "$BAR_3"
+    do
+        [ -f "$i" ]
+    done
+#test "mount_image"
+    mount_image "$DEST/foo_2" "$MOUNT"
+    [ -d "$MOUNT/lost+found" ]
+#test "install_iserial"
+    ID="foo_bar"
+    sudo mkdir -p "$MOUNT/usr/lib/systemd/system"
+    sudo mkdir -p "$MOUNT/usr/sbin"
+    sudo mkdir -p "$MOUNT/etc/systemd/system/multi-user.target.wants/"
+    install_iserial "$ID" "$MOUNT"
+    [ -L "$MOUNT/etc/systemd/system/multi-user.target.wants/iserial.service" ]
+    [ -f "$MOUNT/usr/sbin/iserial.sh" ]
+    [ -f "$MOUNT/usr/lib/systemd/system/iserial.service" ]
+#test "unmount_image"
+    unmount_image "$MOUNT"
+    [ ! -d "$MOUNT/lost+found" ]
+}