diff options
author | Michael Olbrich <m.olbrich@pengutronix.de> | 2020-09-02 13:17:34 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-02 13:17:34 +0000 |
commit | fa592228f5d539c0fb7350c4db65e98d7bb272dc (patch) | |
tree | da64d463a5bac9f12703c3445d88b7c5fa509c8a | |
parent | f4524ddcc76593e46e981ad108c0e3011d1d7313 (diff) | |
parent | 2b1f054ed1489c63db9f444af1b1a588937ba947 (diff) | |
download | genimage-fa592228f5d539c0fb7350c4db65e98d7bb272dc.tar.gz genimage-fa592228f5d539c0fb7350c4db65e98d7bb272dc.tar.xz |
Merge pull request #119 from michaelolbrich/exec
exec-* environment fixes and related stuff
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | genimage.c | 4 | ||||
-rw-r--r-- | genimage.h | 2 | ||||
-rw-r--r-- | image-file.c | 2 | ||||
-rwxr-xr-x | test/basic-images.test | 19 | ||||
-rwxr-xr-x | test/exec-check.sh | 33 | ||||
-rw-r--r-- | test/exec-fail.config | 4 | ||||
-rw-r--r-- | test/exec.config | 27 |
8 files changed, 89 insertions, 5 deletions
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 \ @@ -465,7 +465,7 @@ static int collect_mountpoints(void) return 0; } -const char *mountpath(struct image *image) +const char *mountpath(const struct image *image) { struct mountpoint *mp; @@ -586,7 +586,7 @@ static int setenv_image(const struct image *image) if (ret) return ret; - ret = overwriteenv("IMAGEMOUNTPATH", image->mp ? image->mp->mountpath : NULL); + ret = overwriteenv("IMAGEMOUNTPATH", image->empty ? NULL : mountpath(image)); if (ret) return ret; @@ -22,7 +22,7 @@ const char *imagepath(void); const char *inputpath(void); const char *rootpath(void); const char *tmppath(void); -const char *mountpath(struct image *); +const char *mountpath(const struct image *); struct flash_type; struct mountpoint { diff --git a/image-file.c b/image-file.c index 776a711..519c65b 100644 --- a/image-file.c +++ b/image-file.c @@ -40,7 +40,7 @@ static int file_generate(struct image *image) if (!strcmp(f->infile, imageoutfile(image))) return 0; - ret = systemp(image, "cp %s %s", f->infile, imageoutfile(image)); + ret = systemp(image, "cp '%s' '%s'", f->infile, imageoutfile(image)); return ret; } 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" +} |