diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 156bceb..c314af9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -63,8 +63,8 @@ build-job: # This job runs in the build stage, which runs first. extends: - .standard-rules # Reuse the configuration in `.standard-rules` here script: - - echo "Build default workflow ..." - - cmake --workflow --preset default --fresh + - echo "Build Release workflow ..." + - cmake --workflow --preset Release --fresh - echo "Build workflow complete." unit-test-job: # This job runs in the test stage. @@ -73,8 +73,8 @@ unit-test-job: # This job runs in the test stage. - .standard-rules # Reuse the configuration in `.standard-rules` here script: - echo "Running unit tests... This will take about a view seconds." - - cmake --preset default --fresh - - cmake --build --preset default --target test + - cmake --preset Release --fresh + - cmake --build --preset Release --target test - gcovr . lint-test-job: # This job also runs in the test stage. diff --git a/CMakeLists.txt b/CMakeLists.txt index 228e478..1ff5d92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,9 +89,8 @@ if(PROJECT_IS_TOP_LEVEL AND CMAKE_BUILD_TYPE STREQUAL "Debug") set(ENABLE_SANITIZER_THREAD "ENABLE_SANITIZER_THREAD") else() check_sanitizers_support( - ENABLE_SANITIZER_ADDRESS ENABLE_SANITIZER_UNDEFINED_BEHAVIOR - ENABLE_SANITIZER_LEAK ENABLE_SANITIZER_THREAD - ENABLE_SANITIZER_MEMORY + ENABLE_SANITIZER_ADDRESS ENABLE_SANITIZER_UNDEFINED_BEHAVIOR ENABLE_SANITIZER_LEAK + ENABLE_SANITIZER_THREAD ENABLE_SANITIZER_MEMORY ) endif() @@ -186,7 +185,7 @@ if(NETKIT_TFTP_TESTS) if(UNIX) add_test( NAME tftpd_test - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh $ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) endif() diff --git a/CMakePresets.json b/CMakePresets.json index 0d350fe..0291d4e 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,128 +1,141 @@ { - "version": 6, - "cmakeMinimumRequired": { - "major": 3, - "minor": 25, - "patch": 0 - }, - "configurePresets": [ - { - "name": "default", - "displayName": "Default user Config", - "description": "Default build using Ninja generator", - "generator": "Ninja", - "binaryDir": "${sourceDir}/build", - "installDir": "${sourceDir}/stagedir", - "cacheVariables": { - "CMAKE_PREFIX_PATH": { - "type": "path", - "value": "${sourceDir}/stagedir" - }, - "CMAKE_CXX_STANDARD": "20", - "CMAKE_BUILD_TYPE": "Release", - "CMAKE_DEBUG_POSTFIX": "D", - "BUILD_SHARED_LIBS": true - }, - "environment": { - "CMAKE_EXPORT_COMPILE_COMMANDS": "YES", - "CPM_USE_LOCAL_PACKAGES": "NO", - "CPM_SOURCE_CACHE": "$env{HOME}/.cache/CPM", - "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" - }, - "warnings": { - "deprecated": true, - "uninitialized": true - } - }, - { - "name": "ninja-multi", - "inherits": "default", - "displayName": "Ninja Multi-Config", - "description": "Default build using Ninja Multi-Config generator", - "generator": "Ninja Multi-Config" - }, - { - "name": "windows-only", - "inherits": "default", - "displayName": "Windows-only configuration", - "description": "This build is only available on Windows", - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - } - } - ], - "buildPresets": [ - { - "name": "default", - "configurePreset": "default" + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 }, - { - "name": "install", - "configurePreset": "default", - "targets": ["install"] - } - ], - "testPresets": [ - { - "name": "default", - "configurePreset": "default", - "output": {"outputOnFailure": true}, - "execution": {"noTestsAction": "error", "stopOnFailure": true} - } - ], - "packagePresets": [ - { - "name": "default", - "configurePreset": "default", - "generators": [ - "TGZ" - ] - } - ], - "workflowPresets": [ - { - "name": "default", - "steps": [ + "configurePresets": [ { - "type": "configure", - "name": "default" + "name": "Release", + "displayName": "Release user Config", + "description": "Release build using Ninja generator", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/{presetName}", + "installDir": "${sourceDir}/stagedir", + "cacheVariables": { + "CMAKE_PREFIX_PATH": { + "type": "path", + "value": "${sourceDir}/stagedir" + }, + "CMAKE_CXX_STANDARD": "20", + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_DEBUG_POSTFIX": "D", + "BUILD_SHARED_LIBS": true + }, + "environment": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "YES", + "CPM_USE_LOCAL_PACKAGES": "NO", + "CPM_SOURCE_CACHE": "$env{HOME}/.cache/CPM", + "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" + }, + "warnings": { + "deprecated": true, + "uninitialized": true + } }, { - "type": "build", - "name": "default" - }, + "name": "Debug", + "inherits": "Release", + "displayName": "Ninja Multi-Config", + "description": "Debug build using Ninja Multi-Config generator", + "generator": "Ninja Multi-Config" + } + ], + "buildPresets": [ { - "type": "test", - "name": "default" + "name": "Debug", + "configurePreset": "Debug", + "configuration": "Debug" }, { - "type": "build", - "name": "install" + "name": "Release", + "configurePreset": "Release" }, { - "type": "package", - "name": "default" + "name": "install", + "configurePreset": "Release", + "targets": [ + "install" + ] } - ] - }, - { - "name": "debug", - "steps": [ + ], + "testPresets": [ { - "type": "configure", - "name": "default" + "name": "Release", + "configurePreset": "Release", + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } }, { - "type": "build", - "name": "default" + "name": "Debug", + "configurePreset": "Debug", + "configuration": "Debug", + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } + } + ], + "packagePresets": [ + { + "name": "Release", + "configurePreset": "Release", + "generators": [ + "TGZ" + ] + } + ], + "workflowPresets": [ + { + "name": "Release", + "steps": [ + { + "type": "configure", + "name": "Release" + }, + { + "type": "build", + "name": "Release" + }, + { + "type": "test", + "name": "Release" + }, + { + "type": "build", + "name": "install" + }, + { + "type": "package", + "name": "Release" + } + ] }, { - "type": "test", - "name": "default" + "name": "Debug", + "steps": [ + { + "type": "configure", + "name": "Debug" + }, + { + "type": "build", + "name": "Debug" + }, + { + "type": "test", + "name": "Debug" + } + ] } - ] - } - ] + ] } diff --git a/test.sh b/test.sh index e387d25..502e187 100755 --- a/test.sh +++ b/test.sh @@ -12,6 +12,7 @@ cd ${PWD} UNAME=`uname` script_dir=`dirname "$0"` ln -sf ${script_dir}/tftpy_client.py . +tftpd_test="$1" ############################################## if test "${UNAME}" == "Linux"; then @@ -24,7 +25,7 @@ fi ############################################## ## TODO: upload should fail, no tftpboot dir -# bin/tftpd_test 1234 & +# $tftpd_test 1234 & # sleep 1 # ${TFTP} -m binary -c put build.ninja zero.dat && exit 1 # wait @@ -37,7 +38,7 @@ chmod 400 ${TFTPDIR}/zero.dat # NOTE: we start server at bg # download must fail, dir not world readable -bin/tftpd_test 1234 & +$tftpd_test 1234 & sleep 1 chmod 700 ${TFTPDIR} sync @@ -45,13 +46,13 @@ ${TFTP} --download=zero.dat && exit 1 wait ## TODO: upload should fail in secure mode if file not world writeable -# bin/tftpd_test 1234 & +# $tftpd_test 1234 & # ${TFTP} -m binary -c put build.ninja zero.dat && exit 1 # wait # must fail no such file chmod 777 ${TFTPDIR} -bin/tftpd_test 1234 & +$tftpd_test 1234 & sleep 1 ${TFTP} --download=none.dat && exit 1 wait @@ -67,16 +68,16 @@ fi ############################################## ## test exact blocksize upload -dd if=bin/tftpd_test of=test1block.dat bs=512 count=1 -bin/tftpd_test 1234 & +dd if=$tftpd_test of=test1block.dat bs=512 count=1 +$tftpd_test 1234 & sleep 1 ${TFTP} --upload=test1block.dat diff ${TFTPDIR}/test1block.dat test1block.dat wait ############################################## ## test modulo blocksize upload -dd if=bin/tftpd_test of=test1k.dat bs=1024 count=1 -bin/tftpd_test 1234 & +dd if=$tftpd_test of=test1k.dat bs=1024 count=1 +$tftpd_test 1234 & sleep 1 ${TFTP} --upload=test1k.dat diff ${TFTPDIR}/test1k.dat test1k.dat @@ -84,8 +85,8 @@ wait ############################################## # NOTE: we start server at bg # only one upload should fail -dd if=bin/tftpd_test of=test16k.dat bs=1024 count=16 -bin/tftpd_test 1234 & +dd if=$tftpd_test of=test16k.dat bs=1024 count=16 +$tftpd_test 1234 & sleep 1 ${TFTP} --input=test16k.dat --upload=first.dat & ${TFTP} --input=test16k.dat --upload=second.dat & @@ -98,47 +99,47 @@ test -f ${TFTPDIR}/second.dat && diff test16k.dat ${TFTPDIR}/second.dat # not 1 client only! touch ${TFTPDIR}/zero.dat chmod 666 ${TFTPDIR}/zero.dat -bin/tftpd_test 1234 & +$tftpd_test 1234 & sleep 1 ${TFTP} --download=zero.dat && exit 1 wait ############################################## if test "${UNAME}" == "Linux"; then - dd if=bin/tftpd_test of=test64k.dat bs=1024 count=64 + dd if=$tftpd_test of=test64k.dat bs=1024 count=64 - bin/tftpd_test 1234 & + $tftpd_test 1234 & sleep 1 ${TFTP} --blksize=16384 --upload=test64k.dat --input=test64k.dat wait #--------------------------------------------- - bin/tftpd_test 1234 & + $tftpd_test 1234 & sleep 1 ${TFTP} --blksize=32768 --upload=test64k.dat --input=test64k.dat wait #--------------------------------------------- - bin/tftpd_test 1234 & + $tftpd_test 1234 & sleep 1 ${TFTP} --blksize=65536 --upload=test64k.dat --input=test64k.dat wait else /bin/dd if=/dev/zero of=test64m.dat bs=1m count=64 - bin/tftpd_test 1234 & + $tftpd_test 1234 & sleep 1 ${TFTP} --blksize=1024 --upload=test64m.dat --input=test64m.dat wait #--------------------------------------------- - bin/tftpd_test 1234 & + $tftpd_test 1234 & sleep 1 ${TFTP} --blksize=2048 --upload=test64m.dat --input=test64m.dat wait #--------------------------------------------- - bin/tftpd_test 1234 & + $tftpd_test 1234 & sleep 1 ${TFTP} --blksize=4096 --upload=test64m.dat --input=test64m.dat wait @@ -150,7 +151,7 @@ fi ############################################## # normal binary upload with duplicate ack's # TODO: should not fail -## bin/tftpd_test 1234 & +## $tftpd_test 1234 & ## sleep 1 ## printf "rexmt 1\nverbose\ntrace\nbinary\nput build.ninja\n" | bin/tftp 127.0.0.1 1234 ## test -f ${TFTPDIR}/build.ninja && diff ${TFTPDIR}/build.ninja build.ninja @@ -161,47 +162,47 @@ fi # upload large file > 224K: echo "NOTE: must fail, disk full!" if test "${UNAME}" == "Linux"; then - bin/tftpd_test 1234 & + /bin/dd if=/dev/zero of=test256k.dat bs=1024 count=256 + $tftpd_test 1234 & sleep 1 - ${TFTP} --input=bin/tftpd_test --upload=tftpd_test && exit 1 - #XXX diff ${TFTPDIR}/tftpd_test bin/tftpd_test || echo "OK" + ${TFTP} --input=test256k.dat --upload=test256k.dat && exit 1 wait fi ############################################## echo "NOTE: absolute path upload must fail!" -dd if=bin/tftpd_test of=test32k.dat bs=1024 count=32 -bin/tftpd_test 1234 & +dd if=$tftpd_test of=test32k.dat bs=1024 count=32 +$tftpd_test 1234 & sleep 1 ${TFTP} --input=test32k.dat --upload=${TFTPDIR}/test32k.dat && exit 1 wait ############################################## # TODO: ascii upload should fail -## bin/tftpd_test 1234 & +## $tftpd_test 1234 & ## sleep 1 ## ${TFTP} -m ascii -c put build.ninja && exit 1 ## wait # relative path upload must fail -bin/tftpd_test 1234 & +$tftpd_test 1234 & sleep 1 ${TFTP} --input=build.ninja --upload=../build.ninja && exit 1 wait # relative path upload must fail -bin/tftpd_test 1234 & +$tftpd_test 1234 & sleep 1 ${TFTP} --input=build.ninja --upload=./../build.ninja && exit 1 wait # invalid absolute path upload must fail -bin/tftpd_test 1234 & +$tftpd_test 1234 & sleep 1 ${TFTP} --input=build.ninja --upload=//srv///tftp/build.ninja && exit 1 wait # relative path to nonexisting subdir must fail -bin/tftpd_test 1234 & +$tftpd_test 1234 & sleep 1 ${TFTP} --input=build.ninja --upload=./tftp/build.ninja && exit 1 wait @@ -209,8 +210,8 @@ wait ############################################## echo "test idle timeout (10 seconds) ..." # port must be free, no error expected -bin/tftpd_test 1234 +$tftpd_test 1234 # test help -bin/tftpd_test || echo "OK" +$tftpd_test || echo "OK"