From b9ca728a15b4bb62a77d6a6ea798c42c0be58dc2 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Sat, 10 Oct 2020 00:09:20 +0000 Subject: [PATCH] update tests to new name and create the starting test... This isn't the best as it depends upon a WebDAV server already running.. --- .gitignore | 2 +- tests/Makefile | 2 +- tests/ggate_test.sh | 269 ---------------------------------------- tests/ggatehttp_test.sh | 149 ++++++++++++++++++++++ 4 files changed, 151 insertions(+), 271 deletions(-) delete mode 100644 tests/ggate_test.sh create mode 100644 tests/ggatehttp_test.sh diff --git a/.gitignore b/.gitignore index dfbe2f0..5bef084 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ *.debug ggatehttp/ggatehttp tests/Kyuafile -tests/ggate_test +tests/ggatehttp_test diff --git a/tests/Makefile b/tests/Makefile index 856c207..2506729 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -4,6 +4,6 @@ PACKAGE= tests TESTSDIR= ${TESTSBASE}/sys/geom/class/gate -ATF_TESTS_SH+= ggate_test +ATF_TESTS_SH+= ggatehttp_test .include diff --git a/tests/ggate_test.sh b/tests/ggate_test.sh deleted file mode 100644 index bd401ca..0000000 --- a/tests/ggate_test.sh +++ /dev/null @@ -1,269 +0,0 @@ -# $FreeBSD$ - -PIDFILE=ggated.pid -PLAINFILES=plainfiles -PORT=33080 -CONF=gg.exports - -atf_test_case ggated cleanup -ggated_head() -{ - atf_set "descr" "ggated can proxy geoms" - atf_set "require.progs" "ggatec ggated" - atf_set "require.user" "root" - atf_set "timeout" 60 -} - -ggated_body() -{ - load_ggate - - us=$(alloc_ggate_dev) - work=$(alloc_md) - src=$(alloc_md) - - atf_check -e ignore -o ignore \ - dd if=/dev/random of=/dev/$work bs=1m count=1 conv=notrunc - atf_check -e ignore -o ignore \ - dd if=/dev/random of=/dev/$src bs=1m count=1 conv=notrunc - - echo $CONF >> $PLAINFILES - echo "127.0.0.1 RW /dev/$work" > $CONF - - atf_check ggated -p $PORT -F $PIDFILE $CONF - atf_check ggatec create -p $PORT -u $us 127.0.0.1 /dev/$work - - ggate_dev=/dev/ggate${us} - - wait_for_ggate_device ${ggate_dev} - - atf_check -e ignore -o ignore \ - dd if=/dev/${src} of=${ggate_dev} bs=1m count=1 conv=notrunc - - checksum /dev/$src /dev/$work -} - -ggated_cleanup() -{ - common_cleanup -} - -atf_test_case ggatel_file cleanup -ggatel_file_head() -{ - atf_set "descr" "ggatel can proxy files" - atf_set "require.progs" "ggatel" - atf_set "require.user" "root" - atf_set "timeout" 15 -} - -ggatel_file_body() -{ - load_ggate - - us=$(alloc_ggate_dev) - - echo src work >> ${PLAINFILES} - dd if=/dev/random of=work bs=1m count=1 - dd if=/dev/random of=src bs=1m count=1 - - atf_check ggatel create -u $us work - - ggate_dev=/dev/ggate${us} - - wait_for_ggate_device ${ggate_dev} - - atf_check -e ignore -o ignore \ - dd if=src of=${ggate_dev} bs=1m count=1 conv=notrunc - - checksum src work -} - -ggatel_file_cleanup() -{ - common_cleanup -} - -atf_test_case ggatel_md cleanup -ggatel_md_head() -{ - atf_set "descr" "ggatel can proxy files" - atf_set "require.progs" "ggatel" - atf_set "require.user" "root" - atf_set "timeout" 15 -} - -ggatel_md_body() -{ - load_ggate - - us=$(alloc_ggate_dev) - work=$(alloc_md) - src=$(alloc_md) - - atf_check -e ignore -o ignore \ - dd if=/dev/random of=$work bs=1m count=1 conv=notrunc - atf_check -e ignore -o ignore \ - dd if=/dev/random of=$src bs=1m count=1 conv=notrunc - - atf_check ggatel create -u $us /dev/$work - - ggate_dev=/dev/ggate${us} - - wait_for_ggate_device ${ggate_dev} - - atf_check -e ignore -o ignore \ - dd if=/dev/$src of=${ggate_dev} bs=1m count=1 conv=notrunc - - checksum /dev/$src /dev/$work -} - -ggatel_md_cleanup() -{ - common_cleanup -} - -atf_test_case ggate_sock cleanup -ggate_sock_head() -{ - atf_set "descr" "ggatec can connect to ggated over unix domain socket" - atf_set "require.progs" "ggatec ggated" - atf_set "require.user" "root" - atf_set "timeout" 5 -} - -ggate_sock_body() -{ - load_ggate - - us=$(alloc_ggate_dev) - work=$(alloc_md) - src=$(alloc_md) - - atf_check -e ignore -o ignore \ - dd if=/dev/random of=/dev/$work bs=1m count=1 conv=notrunc - atf_check -e ignore -o ignore \ - dd if=/dev/random of=/dev/$src bs=1m count=1 conv=notrunc - - echo $CONF >> $PLAINFILES - echo "0.0.0.0 RW /dev/$work" > $CONF - - atf_check ggated -q 10 -s local.sock -F $PIDFILE $CONF - atf_check ggatec create -u $us sock:"$(pwd)/local.sock" /dev/$work - - ggate_dev=/dev/ggate${us} - - wait_for_ggate_device ${ggate_dev} - - atf_check -e ignore -o ignore \ - dd if=/dev/${src} of=${ggate_dev} bs=1m count=1 conv=notrunc - - checksum /dev/$src /dev/$work -} - -ggate_sock_cleanup() -{ - common_cleanup -} - -atf_init_test_cases() -{ - atf_add_test_case ggated - atf_add_test_case ggatel_file - atf_add_test_case ggatel_md - atf_add_test_case ggate_sock -} - -alloc_ggate_dev() -{ - local us - - us=0 - while [ -c /dev/ggate${us} ]; do - : $(( us += 1 )) - done - echo ${us} > ggate.devs - echo ${us} -} - -alloc_md() -{ - local md - - md=$(mdconfig -a -t malloc -s 1M) || \ - atf_fail "failed to allocate md device" - echo ${md} >> md.devs - echo ${md} -} - -checksum() -{ - local src work - src=$1 - work=$2 - - src_checksum=$(md5 -q $src) - work_checksum=$(md5 -q $work) - - if [ "$work_checksum" != "$src_checksum" ]; then - atf_fail "work md5 checksum didn't match" - fi - - ggate_checksum=$(md5 -q /dev/ggate${us}) - if [ "$ggate_checksum" != "$src_checksum" ]; then - atf_fail "ggate md5 checksum didn't match" - fi -} - -common_cleanup() -{ - if [ -f "ggate.devs" ]; then - while read test_ggate; do - ggatec destroy -f -u $test_ggate >/dev/null - done < ggate.devs - rm ggate.devs - fi - - if [ -f "$PIDFILE" ]; then - pkill -F "$PIDFILE" - rm $PIDFILE - fi - - if [ -f "PLAINFILES" ]; then - while read f; do - rm -f ${f} - done < ${PLAINFILES} - rm ${PLAINFILES} - fi - - if [ -f "md.devs" ]; then - while read test_md; do - mdconfig -d -u $test_md 2>/dev/null - done < md.devs - rm md.devs - fi - true -} - -load_ggate() -{ - local class=gate - - # If the geom class isn't already loaded, try loading it. - if ! kldstat -q -m g_${class}; then - if ! geom ${class} load; then - atf_skip "could not load module for geom class=${class}" - fi - fi -} - -# Bug 204616: ggatel(8) creates /dev/ggate* asynchronously if `ggatel create` -# isn't called with `-v`. -wait_for_ggate_device() -{ - ggate_device=$1 - - while [ ! -c $ggate_device ]; do - sleep 0.5 - done -} diff --git a/tests/ggatehttp_test.sh b/tests/ggatehttp_test.sh new file mode 100644 index 0000000..af1d7a7 --- /dev/null +++ b/tests/ggatehttp_test.sh @@ -0,0 +1,149 @@ +# $FreeBSD$ + +PIDFILE=ggated.pid +TESTURL=http://127.0.0.1:5555/somefile +TESTFILE=/home/freebsd/lf.test/webdav/data/somefile + +atf_test_case ggatehttp cleanup +ggatehttp_head() +{ + atf_set "descr" "ggatehttp can proxy to http" + atf_set "require.progs" "ggatehttp" + atf_set "require.user" "root" + atf_set "timeout" 10 +} + +ggatehttp_body() +{ + load_ggate + us=$(alloc_ggate_dev) + src=$(alloc_md) + + atf_check -e ignore -o ignore \ + dd if=/dev/random of="$TESTFILE" bs=1m count=1 conv=notrunc + + atf_check ggatehttp create -u $us "$TESTURL" + + ggate_dev=/dev/ggate${us} + + wait_for_ggate_device ${ggate_dev} + + # Test reading + atf_check -e ignore -o ignore \ + dd if=${ggate_dev} of=/dev/${src} bs=1m count=1 conv=notrunc + + checksum /dev/$src "$TESTFILE" + + atf_check -e ignore -o ignore \ + dd if=/dev/random of=/dev/${src} bs=1m count=1 conv=notrunc + + # Test writing + atf_check -e ignore -o ignore \ + dd if=/dev/${src} of=${ggate_dev} bs=1m count=1 conv=notrunc + + checksum /dev/$src "$TESTFILE" +} + +ggatehttp_cleanup() +{ + common_cleanup +} + +atf_init_test_cases() +{ + atf_add_test_case ggatehttp +} + +alloc_ggate_dev() +{ + local us + + us=0 + while [ -c /dev/ggate${us} ]; do + : $(( us += 1 )) + done + echo ${us} > ggate.devs + echo ${us} +} + +alloc_md() +{ + local md + + md=$(mdconfig -a -t malloc -s 1M) || \ + atf_fail "failed to allocate md device" + echo ${md} >> md.devs + echo ${md} +} + +checksum() +{ + local src work + src=$1 + work=$2 + + src_checksum=$(md5 -q $src) + work_checksum=$(md5 -q $work) + + if [ "$work_checksum" != "$src_checksum" ]; then + atf_fail "work md5 checksum didn't match" + fi + + ggate_checksum=$(md5 -q /dev/ggate${us}) + if [ "$ggate_checksum" != "$src_checksum" ]; then + atf_fail "ggate md5 checksum didn't match" + fi +} + +common_cleanup() +{ + if [ -f "ggate.devs" ]; then + while read test_ggate; do + ggatec destroy -f -u $test_ggate >/dev/null + done < ggate.devs + rm ggate.devs + fi + + if [ -f "$PIDFILE" ]; then + pkill -F "$PIDFILE" + rm $PIDFILE + fi + + if [ -f "PLAINFILES" ]; then + while read f; do + rm -f ${f} + done < ${PLAINFILES} + rm ${PLAINFILES} + fi + + if [ -f "md.devs" ]; then + while read test_md; do + mdconfig -d -u $test_md 2>/dev/null + done < md.devs + rm md.devs + fi + true +} + +load_ggate() +{ + local class=gate + + # If the geom class isn't already loaded, try loading it. + if ! kldstat -q -m g_${class}; then + if ! geom ${class} load; then + atf_skip "could not load module for geom class=${class}" + fi + fi +} + +# Bug 204616: ggatel(8) creates /dev/ggate* asynchronously if `ggatel create` +# isn't called with `-v`. +wait_for_ggate_device() +{ + ggate_device=$1 + + while [ ! -c $ggate_device ]; do + sleep 0.5 + done +}