From 2b1f054ed1489c63db9f444af1b1a588937ba947 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Fri, 28 Aug 2020 16:29:48 +0200 Subject: test: add tests to check exec-* commands Signed-off-by: Michael Olbrich --- Makefile.am | 3 +++ test/basic-images.test | 19 ++++++++++++++++++- test/exec-check.sh | 33 +++++++++++++++++++++++++++++++++ test/exec-fail.config | 4 ++++ test/exec.config | 27 +++++++++++++++++++++++++++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100755 test/exec-check.sh create mode 100644 test/exec-fail.config create mode 100644 test/exec.config diff --git a/Makefile.am b/Makefile.am index f0bad83..3c8c810 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,9 @@ EXTRA_DIST += \ test/basic-images.test \ test/cpio.config \ test/cramfs.config \ + test/exec-check.sh \ + test/exec-fail.config \ + test/exec.config \ test/ext2.config \ test/ext2test.dump \ test/ext2percent.config \ diff --git a/test/basic-images.test b/test/basic-images.test index cb104c3..059a5dd 100755 --- a/test/basic-images.test +++ b/test/basic-images.test @@ -24,7 +24,7 @@ setup_data() { find "${root_orig}" -print0 | xargs -0 touch -c -d "2011-11-11 UTC" find "${root_orig}"/ -mindepth 1 -printf "%P\n" | sort > "${filelist_orig}" - cp "${testdir}"/*.conf* . + cp "${testdir}"/*.conf* "${testdir}"/*.sh . } run_genimage() { @@ -373,6 +373,23 @@ test_expect_success rauc "rauc" " test_cmp '${testdir}/test2.raucb.info' test2.raucb.info " +setup_exec_files() { + rm -rf input && + mkdir input && + dd if=/dev/zero of=input/file1.img bs=512 count=7 && + dd if=/dev/zero of=input/file2.img bs=512 count=7 && + dd if=/dev/zero of=input/file3.img bs=512 count=7 && + dd if=/dev/zero of=input/file4.img bs=512 count=7 +} + +test_expect_success "exec" " + setup_exec_files && + run_genimage exec.config" + +test_expect_success "exec-fail" " + setup_exec_files && + test_must_fail run_genimage exec-fail.config" + test_done # vim: syntax=sh diff --git a/test/exec-check.sh b/test/exec-check.sh new file mode 100755 index 0000000..ad1373d --- /dev/null +++ b/test/exec-check.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +exec >&2 + +name="${1}" +empty="${2}" + +set -ex + +: OUTPUTPATH +test "${OUTPUTPATH}" = "${PWD}/images" +: INPUTPATH +test "${INPUTPATH}" = "${PWD}/input" +: ROOTPATH +test "${ROOTPATH}" = "${PWD}/root" +: TMPPATH +test "${TMPPATH}" = "${PWD}/tmp" +: IMAGE +test "${IMAGE}" = "${name}" +: IMAGEOUTFILE +test "${IMAGEOUTFILE}" = "${PWD}/images/${name}" +: IMAGENAME +test "${IMAGENAME}" = "exec-test" +: IMAGESIZE +test "${IMAGESIZE}" = "3584" +: IMAGEMOUNTPOINT +test "${IMAGEMOUNTPOINT}" = "" +: IMAGEMOUNTPATH +if [ "${empty}" = "empty" ]; then + test "${IMAGEMOUNTPATH}" = "" +else + test "${IMAGEMOUNTPATH}" = "${PWD}/tmp/root" +fi diff --git a/test/exec-fail.config b/test/exec-fail.config new file mode 100644 index 0000000..dc223e5 --- /dev/null +++ b/test/exec-fail.config @@ -0,0 +1,4 @@ +image file1.img { + file {} + exec-pre = "false" +} diff --git a/test/exec.config b/test/exec.config new file mode 100644 index 0000000..a261276 --- /dev/null +++ b/test/exec.config @@ -0,0 +1,27 @@ +image file1.img { + file {} + name = "exec-test" + exec-pre = "./exec-check.sh file1.img" +} + +image file2.img { + file {} + name = "exec-test" + mountpoint = "/" + exec-post = "./exec-check.sh file2.img" +} + +image file3.img { + file {} + name = "exec-test" + empty = true + exec-pre = "./exec-check.sh file3.img empty" +} + +image file4.img { + file {} + name = "exec-test" + empty = true + mountpoint = "/" + exec-post = "./exec-check.sh file4.img empty" +} -- cgit v1.2.3