Skip to content

Commit

Permalink
[Tests] Add a simple set of smoke tests for server+client
Browse files Browse the repository at this point in the history
  • Loading branch information
amadio committed Jun 19, 2023
1 parent 5c1452e commit 6a48ab2
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ endif()
if( BUILD_CEPH )
add_subdirectory( XrdCephTests )
endif()

add_subdirectory(XRootD)
33 changes: 33 additions & 0 deletions tests/XRootD/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
if(XRDCL_ONLY)
return()
endif()

execute_process(COMMAND id -u OUTPUT_VARIABLE UID OUTPUT_STRIP_TRAILING_WHITESPACE)

if (UID EQUAL 0)
return()
endif()

set(XRD_TEST_PORT "10940" CACHE STRING "Port for XRootD Test Server")

list(APPEND XRDENV "XRDCP=$<TARGET_FILE:xrdcp>")
list(APPEND XRDENV "XRDFS=$<TARGET_FILE:xrdfs>")
list(APPEND XRDENV "CRC32C=$<TARGET_FILE:xrdcrc32c>")
list(APPEND XRDENV "ADLER32=$<TARGET_FILE:xrdadler32>")
list(APPEND XRDENV "HOST=root://localhost:${XRD_TEST_PORT}")

configure_file(xrootd.cfg xrootd.cfg @ONLY)

add_test(NAME XRootD::start
COMMAND sh -c "mkdir -p data && \
$<TARGET_FILE:xrootd> -b -k fifo -l xrootd.log -s xrootd.pid -c xrootd.cfg")
set_tests_properties(XRootD::start PROPERTIES FIXTURES_SETUP XRootD)

add_test(NAME XRootD::stop COMMAND sh -c "sleep 1 && rm -rf data && kill $(< xrootd.pid)")
set_tests_properties(XRootD::stop PROPERTIES FIXTURES_CLEANUP XRootD)

add_test(NAME XRootD::smoke-test
COMMAND sh -c "${CMAKE_CURRENT_SOURCE_DIR}/smoke.sh")

set_tests_properties(XRootD::smoke-test PROPERTIES
ENVIRONMENT "${XRDENV}" FIXTURES_REQUIRED XRootD)
98 changes: 98 additions & 0 deletions tests/XRootD/smoke.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash

: ${ADLER32:=$(command -v xrdadler32)}
: ${CRC32C:=$(command -v xrdcrc32c)}
: ${XRDCP:=$(command -v xrdcp)}
: ${XRDFS:=$(command -v xrdfs)}
: ${OPENSSL:=$(command -v openssl)}
: ${HOST:=root://localhost:${PORT:-1094}}

for PROG in ${ADLER32} ${CRC32C} ${XRDCP} ${XRDFS} ${OPENSSL}; do
if [[ ! -x "${PROG}" ]]; then
echo 1>&2 "$(basename $0): error: '${PROG}': command not found"
exit 1
fi
done

# This script assumes that ${HOST} exports an empty / as read/write.
# It also assumes that any authentication required is already setup.

set -e

${XRDCP} --version
${XRDFS} ${HOST} query config version

# query some common server configurations

CONFIG_PARAMS=( version role sitename )

for PARAM in ${CONFIG_PARAMS[@]}; do
${XRDFS} ${HOST} query config ${PARAM}
done

# some extra query commands that don't make any changes

${XRDFS} ${HOST} stat /
${XRDFS} ${HOST} statvfs /
${XRDFS} ${HOST} spaceinfo /

# create local temporary directory
TMPDIR=$(mktemp -d /tmp/xrdfs-test-XXXXXX)

# cleanup after ourselves if something fails
trap "rm -rf ${TMPDIR}" EXIT

# create remote temporary directory
# this will get cleaned up by CMake upon fixture tear down
${XRDFS} ${HOST} mkdir -p ${TMPDIR}

# create local files with random contents using OpenSSL

FILES=$(seq -w 1 ${NFILES:-10})

for i in $FILES; do
${OPENSSL} rand -out "${TMPDIR}/${i}.ref" $((1024 * $RANDOM))
done

# upload local files to the server in parallel

for i in $FILES; do
${XRDCP} ${TMPDIR}/${i}.ref ${HOST}/${TMPDIR}/${i}.ref
done

# list uploaded files, then download them to check for corruption

${XRDFS} ${HOST} ls -l ${TMPDIR}

for i in $FILES; do
${XRDCP} ${HOST}/${TMPDIR}/${i}.ref ${TMPDIR}/${i}.dat
done

# check that all checksums for downloaded files match

for i in $FILES; do
REF32C=$(${CRC32C} -< ${TMPDIR}/${i}.ref)
NEW32C=$(${CRC32C} -< ${TMPDIR}/${i}.dat)
REFA32=$(${ADLER32} < ${TMPDIR}/${i}.ref)
NEWA32=$(${ADLER32} < ${TMPDIR}/${i}.dat)
echo -n "Server checksum for ${i}.ref: "
${XRDFS} ${HOST} query checksum ${TMPDIR}/${i}.ref
echo "Checksum for ${i}.ref: crc32c: ${REF32C}, adler32: ${REFA32}"
echo "Checksum for ${i}.dat: crc32c: ${NEW32C}, adler32: ${NEWA32}"

if [[ "${NEW32C}" != "${REF32C}" || "${NEWA32}" != "${REFA32}" ]]; then
echo 1>&2 "$(basename $0): error: checksum check failed for file: ${i}.dat"
exit 1
fi
done

for i in $FILES; do
${XRDFS} ${HOST} rm ${TMPDIR}/${i}.ref &
done

wait

${XRDFS} ${HOST} rmdir ${TMPDIR}

echo "ALL TESTS PASSED"
exit 0
8 changes: 8 additions & 0 deletions tests/XRootD/xrootd.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This minimal configuration file starts a standalone server
# that exports the data directory as / without authentication.

all.export /
all.sitename XRootD
oss.localroot @CMAKE_CURRENT_BINARY_DIR@/data
xrd.port @XRD_TEST_PORT@
xrootd.chksum adler32

0 comments on commit 6a48ab2

Please sign in to comment.