diff options
| author | pooka <pooka@NetBSD.org> | 2010-12-14 17:48:31 +0000 |
|---|---|---|
| committer | pooka <pooka@NetBSD.org> | 2010-12-14 17:48:31 +0000 |
| commit | d8f080a2b0586aec44bcd0e72cb351acd08366fb (patch) | |
| tree | 13705e918ba98551cd8fc84bc023f827dd5ceba0 /tests/dev | |
| parent | a7b0a9de13fccedd4e6868c63ad31cb4222c344b (diff) | |
Retire the old C helper in h_img2cgd since we can now write everything
with a shellscript in terms of rump.cgdconfig and dd.
Diffstat (limited to 'tests/dev')
| -rw-r--r-- | tests/dev/cgd/Makefile | 12 | ||||
| -rw-r--r-- | tests/dev/cgd/h_img2cgd/Makefile | 20 | ||||
| -rw-r--r-- | tests/dev/cgd/h_img2cgd/img2cgd.c | 223 | ||||
| -rw-r--r-- | tests/dev/cgd/paramsfile (renamed from tests/dev/cgd/h_img2cgd/cgd.conf) | 0 | ||||
| -rw-r--r-- | tests/dev/cgd/t_cgd.sh | 42 |
5 files changed, 33 insertions, 264 deletions
diff --git a/tests/dev/cgd/Makefile b/tests/dev/cgd/Makefile index b0be35f8917..f0e541bb413 100644 --- a/tests/dev/cgd/Makefile +++ b/tests/dev/cgd/Makefile @@ -1,18 +1,12 @@ -# $NetBSD: Makefile,v 1.1 2010/11/11 22:38:47 pooka Exp $ +# $NetBSD: Makefile,v 1.2 2010/12/14 17:48:31 pooka Exp $ # .include <bsd.own.mk> TESTSDIR= ${TESTSBASE}/dev/cgd +FILES= paramsfile +FILESDIR= ${TESTSDIR} TESTS_SH= t_cgd -SUBDIR= h_img2cgd - -LDADD+= -lrumpdev_cgd -lrumpdev -lrumpvfs -LDADD+= -lrump -LDADD+= -lrumpuser -lpthread - -NOMAN= - .include <bsd.test.mk> diff --git a/tests/dev/cgd/h_img2cgd/Makefile b/tests/dev/cgd/h_img2cgd/Makefile deleted file mode 100644 index c121c7bbf8e..00000000000 --- a/tests/dev/cgd/h_img2cgd/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# $NetBSD: Makefile,v 1.2 2010/11/11 22:44:50 pooka Exp $ -# - -PROG= h_img2cgd -SRCS= img2cgd.c -FILES= cgd.conf -NOMAN=1 - -BINDIR= ${TESTSBASE}/dev/cgd/h_img2cgd -FILESDIR= ${TESTSBASE}/dev/cgd/h_img2cgd - -.include <bsd.own.mk> - -RUMP_ACTION= #defined -CPPFLAGS+= -DCGDCONFIG_AS_LIB -.include "${NETBSDSRCDIR}/sbin/cgdconfig/Makefile.cgdconfig" - -WARNS= 3 - -.include <bsd.prog.mk> diff --git a/tests/dev/cgd/h_img2cgd/img2cgd.c b/tests/dev/cgd/h_img2cgd/img2cgd.c deleted file mode 100644 index 17b477b7e1e..00000000000 --- a/tests/dev/cgd/h_img2cgd/img2cgd.c +++ /dev/null @@ -1,223 +0,0 @@ -/* $NetBSD: img2cgd.c,v 1.1 2010/11/11 22:38:47 pooka Exp $ */ - -/* - * Copyright (c) 2009 Antti Kantee. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/types.h> -#include <sys/param.h> - -#include <assert.h> -#include <err.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <rump/rump.h> -#include <rump/rump_syscalls.h> - -#include "cgdconfig.h" - -/* - * We really should use disklabel. However, for the time being, - * use a endian independent magic number at offset == 0 and a - * 64bit size at offset == 8. - */ -#define MYMAGIC 0x11000a00000a0011LL -#define MAGOFF 0 -#define SIZEOFF 8 - -#define SKIPLABEL 8192 -#define IMG_MINSIZE (120*1024) /* label/mbr/etc search looks here and there */ - -static void -usage(void) -{ - - fprintf(stderr, "usage: %s read|write cgd_image file\n", getprogname()); - exit(1); -} - -typedef ssize_t (*readfn)(int, void *, size_t); -typedef ssize_t (*writefn)(int, const void *, size_t); - -#define BLOCKSIZE 512 -#define BLKROUND(a) (((a)+(BLOCKSIZE-1)) & ~(BLOCKSIZE-1)) - -static void -doxfer(int fd_from, int fd_to, off_t nbytes, readfn rfn, writefn wfn, - int roundwrite) -{ - char buf[8192]; - ssize_t n; - - assert(sizeof(buf) % BLOCKSIZE == 0); - if (roundwrite) - nbytes = BLKROUND(nbytes); - - memset(buf, 0, sizeof(buf)); - while (nbytes) { - n = rfn(fd_from, buf, sizeof(buf)); - if (n == -1) - err(1, "read"); - if (n == 0) - break; - n = MIN(n, nbytes); - if (roundwrite) - n = BLKROUND(n); - nbytes -= n; - if (wfn(fd_to, buf, n) == -1) - err(1, "write"); - } -} - -#define RFLAGS (O_RDONLY) -#define WFLAGS (O_WRONLY | O_CREAT | O_TRUNC) -int -main(int argc, char *argv[]) -{ - char *the_argv[10]; - const char *cgd_file, *img_file; - char *config_file; - struct stat sb_cgd, sb_file; - off_t nbytes; - int error; - int fd, fd_r; - int readmode; - - setprogname(argv[0]); - - if (argc != 5) - usage(); - - readmode = 0; /* XXXgcc */ - if (strcmp(argv[2], "read") == 0) - readmode = 1; - else if (strcmp(argv[2], "write") == 0) - readmode = 0; - else - usage(); - - config_file = argv[1]; - cgd_file = argv[3]; - img_file = argv[4]; - - if (stat(img_file, &sb_file) == -1) { - if (!readmode) - err(1, "cannot open file image %s", img_file); - } else { - if (!S_ISREG(sb_file.st_mode)) - errx(1, "%s is not a regular file", img_file); - } - - if (stat(cgd_file, &sb_cgd) == -1) { - if (readmode) - err(1, "cannot open cgd image %s", cgd_file); - } else { - if (!S_ISREG(sb_cgd.st_mode)) - errx(1, "%s is not a regular file", cgd_file); - } - - /* - * Create a file big enough to hold the file we are encrypting. - * This is because cgd works on a device internally and does - * not know how to enlarge a device (surprisingly ...). - */ - if (!readmode) { - uint64_t tmpval; - - fd = open(cgd_file, WFLAGS, 0755); - if (fd == -1) - err(1, "fd"); - ftruncate(fd, - MAX(IMG_MINSIZE, BLKROUND(sb_file.st_size)) + SKIPLABEL); - - /* write magic info */ - tmpval = MYMAGIC; - if (pwrite(fd, &tmpval, 8, MAGOFF) != 8) - err(1, "magic write failed"); - tmpval = htole64(sb_file.st_size); - if (pwrite(fd, &tmpval, 8, SIZEOFF) != 8) - err(1, "size write failed"); - - close(fd); - - nbytes = sb_file.st_size; - } else { - uint64_t tmpval; - - fd = open(cgd_file, RFLAGS); - if (fd == -1) - err(1, "image open failed"); - - if (pread(fd, &tmpval, 8, MAGOFF) != 8) - err(1, "magic read failed"); - if (tmpval != MYMAGIC) - errx(1, "%s is not a valid image", cgd_file); - if (pread(fd, &tmpval, 8, SIZEOFF) != 8) - errx(1, "size read failed"); - close(fd); - - nbytes = le64toh(tmpval); - } - - rump_init(); - if ((error = rump_pub_etfs_register("/cryptfile", cgd_file, - RUMP_ETFS_BLK)) != 0) { - printf("etfs: %d\n", error); - exit(1); - } - - the_argv[0] = strdup("cgdconfig"); - the_argv[1] = strdup("-p"); - the_argv[2] = strdup("cgd0"); - the_argv[3] = strdup("/cryptfile"); - the_argv[4] = config_file; - the_argv[5] = NULL; - error = cgdconfig(5, the_argv); - if (error) { - fprintf(stderr, "cgdconfig failed: %d (%s)\n", - error, strerror(error)); - exit(1); - } - - fd = open(img_file, readmode ? WFLAGS : RFLAGS, 0755); - if (fd == -1) - err(1, "fd"); - fd_r = rump_sys_open("/dev/rcgd0d", O_RDWR, 0755); - if (fd_r == -1) - err(1, "fd_r"); - if (rump_sys_lseek(fd_r, SKIPLABEL, SEEK_SET) == -1) - err(1, "rump lseek"); - - if (readmode) { - doxfer(fd_r, fd, nbytes, rump_sys_read, write, 0); - } else { - doxfer(fd, fd_r, sb_file.st_size, read, rump_sys_write, 1); - } - - return 0; -} diff --git a/tests/dev/cgd/h_img2cgd/cgd.conf b/tests/dev/cgd/paramsfile index 066eab6fc43..066eab6fc43 100644 --- a/tests/dev/cgd/h_img2cgd/cgd.conf +++ b/tests/dev/cgd/paramsfile diff --git a/tests/dev/cgd/t_cgd.sh b/tests/dev/cgd/t_cgd.sh index 6a652fcb5e2..b8e7dbf3cf5 100644 --- a/tests/dev/cgd/t_cgd.sh +++ b/tests/dev/cgd/t_cgd.sh @@ -1,4 +1,4 @@ -# $NetBSD: t_cgd.sh,v 1.1 2010/11/11 22:38:47 pooka Exp $ +# $NetBSD: t_cgd.sh,v 1.2 2010/12/14 17:48:31 pooka Exp $ # # Copyright (c) 2010 The NetBSD Foundation, Inc. # All rights reserved. @@ -36,13 +36,22 @@ basic_body() { d=$(atf_get_srcdir) + atf_check -s exit:0 \ + rump_allserver -d key=/dev/dk,hostpath=dk.img,size=1m unix://csock + + export RUMP_SERVER=unix://csock atf_check -s exit:0 sh -c "echo 12345 | \ - $d/h_img2cgd/h_img2cgd $d/h_img2cgd/cgd.conf write \ - enc.img $d/h_img2cgd/cgd.conf" - atf_check -s exit:0 sh -c "echo 12345 | \ - $d/h_img2cgd/h_img2cgd $d/h_img2cgd/cgd.conf read \ - enc.img clear.txt" - atf_check -s exit:0 cmp clear.txt $d/h_img2cgd/cgd.conf + rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile" + atf_check -s exit:0 -e ignore dd if=${d}/t_cgd rof=/dev/rcgd0d count=2 + atf_check -s exit:0 -e ignore dd if=${d}/t_cgd of=testfile count=2 + atf_check -s exit:0 -e ignore -o file:testfile \ + dd rif=/dev/rcgd0d count=2 +} + +basic_cleanup() +{ + + env RUMP_SERVER=unix://csock rump.halt } atf_test_case wrongpass @@ -57,13 +66,22 @@ wrongpass_body() { d=$(atf_get_srcdir) + atf_check -s exit:0 \ + rump_allserver -d key=/dev/dk,hostpath=dk.img,size=1m unix://csock + + export RUMP_SERVER=unix://csock atf_check -s exit:0 sh -c "echo 12345 | \ - $d/h_img2cgd/h_img2cgd $d/h_img2cgd/cgd.conf write \ - enc.img $d/h_img2cgd/cgd.conf" + rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile" + atf_check -s exit:0 -e ignore dd if=${d}/t_cgd rof=/dev/rcgd0d count=2 + + # unconfig and reconfig cgd + atf_check -s exit:0 rump.cgdconfig -u cgd0 atf_check -s exit:0 sh -c "echo 54321 | \ - $d/h_img2cgd/h_img2cgd $d/h_img2cgd/cgd.conf read \ - enc.img clear.txt" - atf_check -s not-exit:0 cmp -s clear.txt $d/h_img2cgd/cgd.conf + rump.cgdconfig -p cgd0 /dev/dk ${d}/paramsfile" + + atf_check -s exit:0 -e ignore dd if=${d}/t_cgd of=testfile count=2 + atf_check -s exit:0 -e ignore -o not-file:testfile \ + dd rif=/dev/rcgd0d count=2 } atf_init_test_cases() |
