From: Viktor Szakats Date: Mon, 2 Sep 2024 12:46:00 +0000 (+0200) Subject: tests: speed up builds with single-binary test bundles X-Git-Tag: curl-8_11_0~370 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=71cf0d1fca9e1f53524e1545ef0c08d174458d80;p=thirdparty%2Fcurl.git tests: speed up builds with single-binary test bundles Add support for single-block binaries that contain all libtests and unit tests respectively. Enable with: - autotools: `--enable-test-bundles` - cmake: `-DCURL_TEST_BUNDLES=ON` (They are compatible with `--enable-unity` and `-DCMAKE_UNITY_BUILD=ON` options, for further speed-up.) Makes libtests and unit tests build _fast_, needing little disk space even in static mode. Similar to CMake unity mode, but with a custom script, also supporting autotools builds. The price is having to deal with symbols/macros colliding between `lib*.c` and `unit*.c` sources. Maybe with naming conventions or other solutions this can be improved gradually and reduce the need for manual intervention by `mk-bundle.mk`. I've included a script that does the bulk of detecting name collisions. Also: - CI: enable test bundles. - CI: build tests in more jobs. - lib2305: fix FILE handle leak. - unit1661: fix memleak found by torture test by releasing the `bufref` structure in `unit_stop()` that was allocated in `unit_setup()`. ``` test 1661...[bufref unit tests] Leak detected: memory still allocated: 13 bytes allocated by /home/runner/work/curl/curl/tests/unit/unit1661.c:70 1661: torture FAILED: function number 1 in test. ``` Ref: https://github.com/curl/curl/actions/runs/10967279334/job/30456745290?pr=14772#step:8:41 Similar test suite builds with autotools default and cmake+bundle+unity: - GHA/Linux: 33s vs 7s https://github.com/curl/curl/actions/runs/10705668823/job/29681617374 - GHA/macOS 34s vs 2s https://github.com/curl/curl/actions/runs/10705668813/job/29681632885 - GHA/FreeBSD: 15m25 vs 6m21 (full workflow time, ~qemu) https://github.com/curl/curl/actions/runs/10705668811/job/29681607915 - GHA/Cygwin: 9m52 vs 32s https://github.com/curl/curl/actions/runs/10705668809/job/29681609965 - GHA/MSYS2: 3m52 vs 14s https://github.com/curl/curl/actions/runs/10705668808/job/29681624295 - GHA/mingw-w64: 5m45 vs 30s https://github.com/curl/curl/actions/runs/10705668808/job/29681628787 Autotools test suite builds compared between master -> `--enable-test-bundles`: - GHA/Linux: 33s -> 9s (run tests: 22m23 -> 20m44) https://github.com/curl/curl/actions/runs/10710030193/job/29695932185 https://github.com/curl/curl/actions/runs/10967831456/job/30458220344 - GHA/macOS: 25s -> 4s (run tests: 2m58 -> 2m24) https://github.com/curl/curl/actions/runs/10710030195/job/29695938444 https://github.com/curl/curl/actions/runs/10967831452/job/30458225762 - GHA/non-native (FreeBSD): 4m8 -> 3m12 (full workflow time, ~qemu) https://github.com/curl/curl/actions/runs/10710030198/job/29695928401 https://github.com/curl/curl/actions/runs/10967831458/job/30458212692 - GHA/Cygwin: 9m25 -> 1m9 (run tests: 9m19 -> 3m28) https://github.com/curl/curl/actions/runs/10710030212/job/29695928213 https://github.com/curl/curl/actions/runs/10967831453/job/30458213268 - GHA/MSYS2: 3m54 -> 32s (run tests: 6m3 -> 3m59) https://github.com/curl/curl/actions/runs/10710030190/job/29704850591 https://github.com/curl/curl/actions/runs/10967831449/job/30459280005 - GHA/mingw-w64: 5m42 -> 1m5 (run tests: 7m41 -> 5m36) https://github.com/curl/curl/actions/runs/10710030190/job/29704852058 https://github.com/curl/curl/actions/runs/10967831449/job/30459280862 - Azure MSYS2 mingw64 openssl: 38m55 -> 11m58 https://dev.azure.com/daniel0244/curl/_build/results?buildId=25546&view=logs&j=b58b8c59-0f61-52e9-0f9e-fad562a1e77f&t=0f9230a7-3b10-53ca-9938-700ece377c5e https://dev.azure.com/daniel0244/curl/_build/results?buildId=25547&view=logs&jobId=39473db1-3945-55d5-deb5-c218fad88dce&j=b58b8c59-0f61-52e9-0f9e-fad562a1e77f&t=0f9230a7-3b10-53ca-9938-700ece377c5e - Azure Ubuntu default: 2m15 -> 55s (all build) https://dev.azure.com/daniel0244/curl/_build/results?buildId=25546&view=logs&j=9d58b9ac-e1e6-53b6-f83a-1f9f1d912522&t=a6b38d83-e7cf-5a9b-c762-a178412717b7 https://dev.azure.com/daniel0244/curl/_build/results?buildId=25547&view=logs&jobId=39473db1-3945-55d5-deb5-c218fad88dce&j=9d58b9ac-e1e6-53b6-f83a-1f9f1d912522&t=a6b38d83-e7cf-5a9b-c762-a178412717b7 Cmake test suite builds compared between master -> `-DCURL_TEST_BUNDLES=ON` + unity: - GHA/Linux: 29s -> 7s (run tests: 4m50 -> 4m57, 20m43 -> 20m45) https://github.com/curl/curl/actions/runs/10710030193/job/29695941814 https://github.com/curl/curl/actions/runs/10705668823/job/29681622201 - GHA/Linux old: 44s -> 13s (bundle+no unity) (run tests: 5m5 -> 5m6) https://github.com/curl/curl/actions/runs/10718264094/job/29719794727 https://github.com/curl/curl/actions/runs/10718653175/job/29721009613 - GHA/macOS: 32s -> 2s (run tests: 2m43 -> 2m40) https://github.com/curl/curl/actions/runs/10710030195/job/29695931956 https://github.com/curl/curl/actions/runs/10705668813/job/29681638937 - GHA/non-native (*BSD): inconclusive (full workflow time, ~qemu) https://github.com/curl/curl/actions/runs/10710030198 https://github.com/curl/curl/actions/runs/10705668811 - GHA/Cygwin: 3m9 -> 32s https://github.com/curl/curl/actions/runs/10710030212/job/29695929075 https://github.com/curl/curl/actions/runs/10705668809/job/29681609965 - GHA/MSYS2: 2m24 -> 14s https://github.com/curl/curl/actions/runs/10710030190/job/29704850996 https://github.com/curl/curl/actions/runs/10705668808/job/29681624295 - GHA/mingw-w64: 3m56 -> 30s (run tests: 4m2 -> 3m52) https://github.com/curl/curl/actions/runs/10710030190/job/29704852219 https://github.com/curl/curl/actions/runs/10705668808/job/29681631393 - GHA/mingw-w64-old: 7m19 -> 1m44 (run tests: 3m30 -> 2m53) https://github.com/curl/curl/actions/runs/10710030190/job/29704849763 https://github.com/curl/curl/actions/runs/10705668808/job/29681622329 - GHA/MSVC: 3m22 -> 13s (run tests: 9m43 -> 4m22) https://github.com/curl/curl/actions/runs/10710030190/job/29704850411 https://github.com/curl/curl/actions/runs/10705668808/job/29681623313 - AppVeyor CI MSVC 2008: 4m3 -> 45s (full build) - AppVeyor CI MSVC 2010: 2m56 -> 1m8 (full build) - AppVeyor CI MSVC 2022: 10m19 -> 2m23 (full build) https://ci.appveyor.com/project/curlorg/curl/builds/50538455 https://ci.appveyor.com/project/curlorg/curl/builds/50536558 - AppVeyor CI total build time: 10m30 (master) -> 6m48 (unity) -> 4m5 (bundle) -> 3m24 (bundle+unity) -> 5m7 (bundle+unity+all jobs building tests) Closes #14772 --- diff --git a/.circleci/config.yml b/.circleci/config.yml index a0e802909d..264fcb5f80 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -33,7 +33,7 @@ commands: - run: command: | autoreconf -fi - ./configure --disable-dependency-tracking --enable-unity --enable-warnings --enable-werror --with-openssl \ + ./configure --disable-dependency-tracking --enable-unity --enable-test-bundles --enable-warnings --enable-werror --with-openssl \ || { tail -1000 config.log; false; } configure-openssl-no-verbose: @@ -41,7 +41,7 @@ commands: - run: command: | autoreconf -fi - ./configure --disable-dependency-tracking --enable-unity --disable-verbose --enable-werror --with-openssl \ + ./configure --disable-dependency-tracking --enable-unity --enable-test-bundles --disable-verbose --enable-werror --with-openssl \ || { tail -1000 config.log; false; } configure-no-proxy: @@ -49,7 +49,7 @@ commands: - run: command: | autoreconf -fi - ./configure --disable-dependency-tracking --enable-unity --disable-proxy --enable-werror --with-openssl \ + ./configure --disable-dependency-tracking --enable-unity --enable-test-bundles --disable-proxy --enable-werror --with-openssl \ || { tail -1000 config.log; false; } install-cares: @@ -110,7 +110,7 @@ commands: - run: command: | autoreconf -fi - ./configure --disable-dependency-tracking --enable-unity --enable-warnings --enable-werror --with-openssl --enable-ares \ + ./configure --disable-dependency-tracking --enable-unity --enable-test-bundles --enable-warnings --enable-werror --with-openssl --enable-ares \ || { tail -1000 config.log; false; } configure-wolfssh: @@ -118,7 +118,7 @@ commands: - run: command: | autoreconf -fi - LDFLAGS="-Wl,-rpath,$HOME/wssh/lib" ./configure --disable-dependency-tracking --enable-unity --enable-warnings --enable-werror --with-wolfssl=$HOME/wssl --with-wolfssh=$HOME/wssh \ + LDFLAGS="-Wl,-rpath,$HOME/wssh/lib" ./configure --disable-dependency-tracking --enable-unity --enable-test-bundles --enable-warnings --enable-werror --with-wolfssl=$HOME/wssl --with-wolfssh=$HOME/wssh \ || { tail -1000 config.log; false; } configure-cares-debug: @@ -126,7 +126,7 @@ commands: - run: command: | autoreconf -fi - ./configure --disable-dependency-tracking --enable-unity --enable-debug --enable-werror --with-openssl --enable-ares \ + ./configure --disable-dependency-tracking --enable-unity --enable-test-bundles --enable-debug --enable-werror --with-openssl --enable-ares \ || { tail -1000 config.log; false; } build: diff --git a/.github/workflows/awslc.yml b/.github/workflows/awslc.yml index 73b3d35f2f..742075561c 100644 --- a/.github/workflows/awslc.yml +++ b/.github/workflows/awslc.yml @@ -142,7 +142,9 @@ jobs: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 - - run: cmake -Bbuild -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DOPENSSL_ROOT_DIR=$HOME/awslc -DBUILD_SHARED_LIBS=ON . + - run: | + cmake -B build -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON -DCURL_WERROR=ON \ + -DOPENSSL_ROOT_DIR=$HOME/awslc -DBUILD_SHARED_LIBS=ON name: 'cmake generate out-of-tree' - run: cmake --build build --parallel @@ -150,3 +152,6 @@ jobs: - run: cmake --install build --prefix $HOME/curl --strip name: 'cmake install' + + - run: cmake --build build --parallel --target testdeps + name: 'cmake build tests' diff --git a/.github/workflows/cygwin.yml b/.github/workflows/cygwin.yml index 7159314155..a2653058bb 100644 --- a/.github/workflows/cygwin.yml +++ b/.github/workflows/cygwin.yml @@ -81,7 +81,7 @@ jobs: timeout-minutes: 5 run: | PATH="/usr/bin:$(cygpath "${SYSTEMROOT}")/System32" - mkdir bld && cd bld && ../configure --enable-unity --enable-warnings --enable-werror \ + mkdir bld && cd bld && ../configure --enable-unity --enable-test-bundles --enable-warnings --enable-werror \ --prefix="${HOME}"/install \ --enable-websockets \ --with-openssl \ @@ -139,7 +139,7 @@ jobs: run: | PATH="/usr/bin:$(cygpath "${SYSTEMROOT}")/System32" cmake -B bld -G Ninja ${options} \ - -DCMAKE_UNITY_BUILD=ON \ + -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON \ -DCURL_WERROR=ON \ -DENABLE_WEBSOCKETS=ON \ -DCURL_BROTLI=ON \ diff --git a/.github/workflows/http3-linux.yml b/.github/workflows/http3-linux.yml index d58f64ea1e..8bd34ab059 100644 --- a/.github/workflows/http3-linux.yml +++ b/.github/workflows/http3-linux.yml @@ -451,7 +451,7 @@ jobs: - run: autoreconf -fi name: 'autoreconf' - - run: ./configure --disable-dependency-tracking --enable-unity ${{ matrix.build.configure }} + - run: ./configure --disable-dependency-tracking --enable-unity --enable-test-bundles ${{ matrix.build.configure }} name: 'configure' - run: make V=1 diff --git a/.github/workflows/linux-old.yml b/.github/workflows/linux-old.yml index 6075393214..fb10892ddb 100644 --- a/.github/workflows/linux-old.yml +++ b/.github/workflows/linux-old.yml @@ -79,7 +79,7 @@ jobs: run: | mkdir bld-1 cd bld-1 - cmake .. -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON \ + cmake .. -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON \ -DENABLE_ARES=OFF -DCURL_ZSTD=OFF -DCURL_USE_GSSAPI=OFF -DCURL_USE_LIBSSH2=ON -DCURL_USE_LIBSSH=OFF -DUSE_LIBRTMP=ON -DENABLE_WEBSOCKETS=ON make install src/curl --disable --version @@ -88,7 +88,7 @@ jobs: run: | mkdir bld-cares cd bld-cares - cmake .. -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON \ + cmake .. -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON -DCURL_WERROR=ON -DBUILD_SHARED_LIBS=ON \ -DENABLE_ARES=ON -DCURL_ZSTD=ON -DCURL_USE_GSSAPI=ON -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=ON -DUSE_LIBRTMP=ON -DENABLE_WEBSOCKETS=ON \ -DCURL_LIBCURL_VERSIONED_SYMBOLS=ON @@ -113,7 +113,7 @@ jobs: run: | mkdir bld-am cd bld-am - ../configure --disable-dependency-tracking --enable-unity --enable-warnings --enable-werror \ + ../configure --disable-dependency-tracking --enable-unity --enable-test-bundles --enable-warnings --enable-werror \ --with-openssl --enable-ares --with-libssh --with-zstd --with-gssapi --with-librtmp --enable-websockets \ --prefix="$PWD"/../install-am diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 2ca69877e5..be96dd2e1b 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -498,7 +498,7 @@ jobs: - run: | ${{ matrix.build.configure-prefix }} \ - ./configure --disable-dependency-tracking --enable-unity --enable-warnings --enable-werror \ + ./configure --disable-dependency-tracking --enable-unity --enable-test-bundles --enable-warnings --enable-werror \ ${{ matrix.build.configure }} if: ${{ matrix.build.configure }} name: 'configure (autotools)' diff --git a/.github/workflows/linux32.yml b/.github/workflows/linux32.yml index 43494f289c..14380450d9 100644 --- a/.github/workflows/linux32.yml +++ b/.github/workflows/linux32.yml @@ -70,7 +70,7 @@ jobs: name: 'autoreconf' - run: | - ./configure --disable-dependency-tracking --enable-unity --enable-warnings --enable-werror \ + ./configure --disable-dependency-tracking --enable-unity --enable-test-bundles --enable-warnings --enable-werror \ ${{ matrix.build.configure }} name: 'configure' diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 96ac6704a4..61aa95d9a1 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -193,7 +193,7 @@ jobs: options+=" --with-sysroot=$(xcrun --sdk macosx --show-sdk-path 2>/dev/null)" CFLAGS+=" --sysroot=$(xcrun --sdk macosx --show-sdk-path 2>/dev/null)" fi - mkdir bld && cd bld && ../configure --enable-unity --enable-warnings --enable-werror \ + mkdir bld && cd bld && ../configure --enable-unity --enable-test-bundles --enable-warnings --enable-werror \ --disable-dependency-tracking \ --with-libpsl=$(brew --prefix libpsl) \ ${{ matrix.configure }} ${options} @@ -343,7 +343,7 @@ jobs: fi done fi - cmake -B bld -G Ninja -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON \ + cmake -B bld -G Ninja -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON -DCURL_WERROR=ON \ -DCMAKE_OSX_DEPLOYMENT_TARGET=${{ matrix.build.macos-version-min }} \ "-DCMAKE_C_COMPILER_TARGET=$(uname -m | sed 's/arm64/aarch64/')-apple-darwin$(uname -r)" \ ${{ matrix.build.generate }} @@ -608,7 +608,7 @@ jobs: [ '${{ matrix.config }}' = 'SecureTransport' ] && options+=' --with-secure-transport' CFLAGS+=' -mmacosx-version-min=${{ matrix.macos-version-min }}' # would pick up nghttp2, libidn2, but libssh2 is disabled by default - mkdir bld && cd bld && ../configure --enable-unity --enable-warnings --enable-werror \ + mkdir bld && cd bld && ../configure --enable-unity --enable-test-bundles --enable-warnings --enable-werror \ --disable-dependency-tracking \ --disable-docs --disable-manual \ --without-nghttp2 --without-libidn2 \ @@ -618,7 +618,7 @@ jobs: [ '${{ matrix.config }}' = 'OpenSSL' ] && options+=' -DCURL_USE_OPENSSL=ON' [ '${{ matrix.config }}' = 'SecureTransport' ] && options+=' -DCURL_USE_SECTRANSP=ON' # would pick up nghttp2, libidn2, and libssh2 - cmake -B bld -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON \ + cmake -B bld -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON -DCURL_WERROR=ON \ -DCMAKE_OSX_DEPLOYMENT_TARGET=${{ matrix.macos-version-min }} \ "-DCMAKE_IGNORE_PREFIX_PATH=$(brew --prefix)" \ "-DCMAKE_C_COMPILER_TARGET=$(uname -m | sed 's/arm64/aarch64/')-apple-darwin$(uname -r)" \ diff --git a/.github/workflows/non-native.yml b/.github/workflows/non-native.yml index cfa030a33a..1efe502809 100644 --- a/.github/workflows/non-native.yml +++ b/.github/workflows/non-native.yml @@ -55,7 +55,7 @@ jobs: # https://pkgsrc.se/ sudo pkgin -y install cmake ninja-build pkg-config perl brotli heimdal openldap-client libssh2 libidn2 libpsl nghttp2 py311-impacket cmake -B bld -G Ninja \ - -DCMAKE_UNITY_BUILD=ON \ + -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON \ -DCURL_WERROR=ON \ -DENABLE_DEBUG=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG= \ -DENABLE_WEBSOCKETS=ON \ @@ -64,8 +64,8 @@ jobs: || { cat bld/CMakeFiles/CMake*.yaml; false; } cmake --build bld --config Debug --parallel 3 bld/src/curl --disable --version + cmake --build bld --config Debug --parallel 3 --target testdeps if [ '${{ matrix.arch }}' = 'x86_64' ]; then # Slow on emulated CPU - cmake --build bld --config Debug --parallel 3 --target testdeps export TFLAGS='-j0' # flakies: ~389 ~392 ~TFTP and more cmake --build bld --config Debug --target test-ci fi @@ -92,7 +92,7 @@ jobs: # https://openbsd.app/ sudo pkg_add cmake ninja perl brotli openldap-client libssh2 libidn2 libpsl nghttp2 python3 py3-impacket cmake -B bld -G Ninja \ - -DCMAKE_UNITY_BUILD=ON \ + -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON \ -DCURL_WERROR=ON \ -DENABLE_DEBUG=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG= \ -DENABLE_WEBSOCKETS=ON \ @@ -101,8 +101,8 @@ jobs: || { cat bld/CMakeFiles/CMake*.yaml; false; } cmake --build bld --config Debug --parallel 3 bld/src/curl --disable --version + cmake --build bld --config Debug --parallel 3 --target testdeps if [ '${{ matrix.arch }}' = 'x86_64' ]; then # Slow on emulated CPU - cmake --build bld --config Debug --parallel 3 --target testdeps export TFLAGS='-j8 ~3017 ~TFTP ~FTP' # FIXME: TFTP requests executed twice? Related: `curl: (69) TFTP: Access Violation`? cmake --build bld --config Debug --target test-ci fi @@ -136,7 +136,7 @@ jobs: pkgconf brotli openldap26-client libidn2 libnghttp2 nghttp2 stunnel py311-impacket autoreconf -fi export CC='${{ matrix.compiler }}' - mkdir bld && cd bld && ../configure --enable-unity --enable-debug --enable-warnings --enable-werror \ + mkdir bld && cd bld && ../configure --enable-unity --enable-test-bundles --enable-debug --enable-warnings --enable-werror \ --prefix="${HOME}"/install \ --enable-websockets \ --with-openssl \ @@ -144,8 +144,8 @@ jobs: --disable-dependency-tracking || { tail -n 1000 config.log; false; } make -j3 install src/curl --disable --version + make -j3 -C tests if [ '${{ matrix.arch }}' = 'x86_64' ]; then # Slow on emulated CPU - make -j3 -C tests make test-ci V=1 TFLAGS='-j8 ~FTP' fi echo '::group::build examples' @@ -165,7 +165,7 @@ jobs: pkgconf brotli openldap26-client libidn2 libnghttp2 nghttp2 stunnel py311-impacket cmake -B bld -G Ninja \ '-DCMAKE_C_COMPILER=${{ matrix.compiler }}' \ - -DCMAKE_UNITY_BUILD=ON \ + -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON \ -DCURL_WERROR=ON \ -DENABLE_DEBUG=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG= \ -DENABLE_WEBSOCKETS=ON \ @@ -174,8 +174,8 @@ jobs: || { cat bld/CMakeFiles/CMake*.yaml; false; } cmake --build bld --config Debug --parallel 3 bld/src/curl --disable --version + cmake --build bld --config Debug --parallel 3 --target testdeps if [ '${{ matrix.arch }}' = 'x86_64' ]; then # Slow on emulated CPU - cmake --build bld --config Debug --parallel 3 --target testdeps export TFLAGS='-j8 ~FTP' cmake --build bld --config Debug --target test-ci fi @@ -198,7 +198,7 @@ jobs: run: | ln -s /usr/bin/gcpp /usr/bin/cpp # Some tests expect `cpp`, which is named `gcpp` in this env. autoreconf -fi - mkdir bld && cd bld && ../configure --enable-unity --enable-debug --enable-warnings --enable-werror \ + mkdir bld && cd bld && ../configure --enable-unity --enable-test-bundles --enable-debug --enable-warnings --enable-werror \ --prefix="${HOME}"/install \ --enable-websockets \ --with-openssl \ diff --git a/.github/workflows/torture.yml b/.github/workflows/torture.yml index 450ebaa08c..ae6a318635 100644 --- a/.github/workflows/torture.yml +++ b/.github/workflows/torture.yml @@ -69,7 +69,7 @@ jobs: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 - run: | - cmake -G Ninja -DCMAKE_UNITY_BUILD=ON -DCURL_WERROR=ON \ + cmake -G Ninja -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON -DCURL_WERROR=ON \ -DCURL_BROTLI=ON -DCURL_ZSTD=ON \ ${{ matrix.build.generate }} name: 'cmake configure' diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index e6f5e2c70e..cf1bc44e75 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -103,7 +103,7 @@ jobs: if: ${{ matrix.build == 'autotools' }} timeout-minutes: 5 run: | - mkdir bld && cd bld && ../configure --enable-unity --enable-warnings --enable-werror \ + mkdir bld && cd bld && ../configure --enable-unity --enable-test-bundles --enable-warnings --enable-werror \ --prefix="${HOME}"/install \ --enable-websockets \ --with-openssl \ @@ -196,7 +196,7 @@ jobs: "-DCMAKE_C_FLAGS=${cflags}" \ "-DCMAKE_RC_COMPILE_OBJECT=${rcopts}" \ '-DCMAKE_BUILD_TYPE=${{ matrix.type }}' \ - -DCMAKE_UNITY_BUILD=ON \ + -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON \ -DCURL_WERROR=ON \ -DENABLE_WEBSOCKETS=ON \ -DCURL_BROTLI=ON \ @@ -329,7 +329,7 @@ jobs: '-GMSYS Makefiles' \ -DCMAKE_C_COMPILER=gcc \ '-DCMAKE_BUILD_TYPE=${{ matrix.type }}' \ - -DCMAKE_UNITY_BUILD=ON \ + -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON \ -DCURL_WERROR=ON \ -DENABLE_WEBSOCKETS=ON \ -DCURL_USE_LIBPSL=OFF \ @@ -415,7 +415,7 @@ jobs: - name: 'autotools configure' if: ${{ matrix.build == 'autotools' }} run: | - mkdir bld && cd bld && ../configure --enable-unity --enable-warnings --enable-werror \ + mkdir bld && cd bld && ../configure --enable-unity --enable-test-bundles --enable-warnings --enable-werror \ --host=${TRIPLET} \ --with-schannel --with-winidn \ --without-libpsl \ @@ -429,6 +429,10 @@ jobs: if: ${{ matrix.build == 'autotools' }} run: make -C bld -j5 + - name: 'autotools build tests' + if: ${{ matrix.build == 'autotools' }} + run: make -C bld -j5 -C tests + - name: 'autotools build examples' if: ${{ matrix.build == 'autotools' }} run: make -C bld -j5 examples @@ -440,7 +444,7 @@ jobs: -DCMAKE_SYSTEM_NAME=Windows \ -DCMAKE_C_COMPILER_TARGET=${TRIPLET} \ -DCMAKE_C_COMPILER=${TRIPLET}-gcc \ - -DCMAKE_UNITY_BUILD=ON \ + -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON \ -DCURL_WERROR=ON \ -DCURL_USE_SCHANNEL=ON -DUSE_WIN32_IDN=ON \ -DCURL_USE_LIBPSL=OFF @@ -453,6 +457,10 @@ jobs: if: ${{ matrix.build == 'cmake' }} run: cmake --build bld --parallel 5 + - name: 'cmake build tests' + if: ${{ matrix.build == 'cmake' }} + run: cmake --build bld --parallel 5 --target testdeps + - name: 'cmake build examples' if: ${{ matrix.build == 'cmake' }} run: cmake --build bld --parallel 5 --target curl-examples @@ -565,7 +573,7 @@ jobs: '-DVCPKG_TARGET_TRIPLET=${{ matrix.arch }}-${{ matrix.plat }}' \ -DCMAKE_VS_GLOBALS=TrackFileAccess=false \ '-DCMAKE_BUILD_TYPE=${{ matrix.type }}' \ - -DCMAKE_UNITY_BUILD=ON \ + -DCMAKE_UNITY_BUILD=ON -DCURL_TEST_BUNDLES=ON \ -DCURL_WERROR=ON \ -DENABLE_WEBSOCKETS=ON \ -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG= \ diff --git a/.github/workflows/wolfssl.yml b/.github/workflows/wolfssl.yml index 3f7a9ba4df..49b1bd9174 100644 --- a/.github/workflows/wolfssl.yml +++ b/.github/workflows/wolfssl.yml @@ -84,7 +84,7 @@ jobs: - run: autoreconf -fi name: 'autoreconf' - - run: ./configure --disable-dependency-tracking --enable-unity --enable-warnings --enable-werror ${{ matrix.build.configure }} + - run: ./configure --disable-dependency-tracking --enable-unity --enable-test-bundles --enable-warnings --enable-werror ${{ matrix.build.configure }} name: 'configure' - run: make V=1 diff --git a/appveyor.sh b/appveyor.sh index 7237137d99..05939e5485 100644 --- a/appveyor.sh +++ b/appveyor.sh @@ -56,6 +56,7 @@ if [ "${BUILD_SYSTEM}" = 'CMake' ]; then "-DBUILD_SHARED_LIBS=${SHARED}" \ "-DENABLE_WEBSOCKETS=${WEBSOCKETS:-}" \ "-DCMAKE_UNITY_BUILD=${UNITY}" \ + '-DCURL_TEST_BUNDLES=ON' \ '-DCURL_WERROR=ON' \ "-DENABLE_DEBUG=${DEBUG}" \ "-DENABLE_UNICODE=${ENABLE_UNICODE}" \ diff --git a/appveyor.yml b/appveyor.yml index 63fe9c8ca5..79cb58d57a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -35,13 +35,13 @@ environment: OPENSSL: 'OFF' DEBUG: 'ON' SHARED: 'OFF' - TFLAGS: 'skipall' + TFLAGS: 'skiprun' EXAMPLES: 'OFF' matrix: # generated CMake-based Visual Studio builds - - job_name: 'CMake, VS2008, Release, x86, Schannel, Build-only' + - job_name: 'CMake, VS2008, Release, x86, Schannel, Build-tests' APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2015' BUILD_SYSTEM: CMake PRJ_GEN: 'Visual Studio 9 2008' @@ -60,9 +60,8 @@ environment: ENABLE_UNICODE: 'OFF' HTTP_ONLY: 'OFF' SHARED: 'ON' - TFLAGS: 'skiprun' EXAMPLES: 'ON' - - job_name: 'CMake, VS2022, Release, x64, OpenSSL 3.2, WebSockets, Build-only' + - job_name: 'CMake, VS2022, Release, x64, OpenSSL 3.2, WebSockets, Build-tests' APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2022' BUILD_SYSTEM: CMake PRJ_GEN: 'Visual Studio 17 2022' @@ -85,7 +84,6 @@ environment: HTTP_ONLY: 'OFF' DEBUG: 'OFF' CURLDEBUG: 'ON' - TFLAGS: 'skiprun' - job_name: 'CMake, VS2010, Debug, x64, Schannel, Static, Build-tests & examples' APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2015' BUILD_SYSTEM: CMake @@ -94,9 +92,8 @@ environment: SCHANNEL: 'ON' ENABLE_UNICODE: 'OFF' HTTP_ONLY: 'OFF' - TFLAGS: 'skiprun' EXAMPLES: 'ON' - - job_name: 'CMake, VS2022, Debug, x64, Schannel, Static, Unicode, Build-only' + - job_name: 'CMake, VS2022, Debug, x64, Schannel, Static, Unicode, Build-tests' APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2022' BUILD_SYSTEM: CMake PRJ_GEN: 'Visual Studio 17 2022' @@ -105,7 +102,7 @@ environment: SCHANNEL: 'ON' ENABLE_UNICODE: 'ON' HTTP_ONLY: 'OFF' - - job_name: 'CMake, VS2022, Release, x64, Schannel, Shared, Unicode, DEBUGBULID, no-CURLDEBUG, Build-only' + - job_name: 'CMake, VS2022, Release, x64, Schannel, Shared, Unicode, DEBUGBULID, no-CURLDEBUG, Build-tests' APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2022' BUILD_SYSTEM: CMake PRJ_GEN: 'Visual Studio 17 2022' @@ -116,7 +113,7 @@ environment: HTTP_ONLY: 'OFF' SHARED: 'ON' CURLDEBUG: 'OFF' - - job_name: 'CMake, VS2022, Debug, x64, no SSL, Static, Build-only' + - job_name: 'CMake, VS2022, Debug, x64, no SSL, Static, Build-tests' APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2022' BUILD_SYSTEM: CMake PRJ_GEN: 'Visual Studio 17 2022' @@ -125,7 +122,7 @@ environment: SCHANNEL: 'OFF' ENABLE_UNICODE: 'OFF' HTTP_ONLY: 'OFF' - - job_name: 'CMake, VS2022, Debug, x64, no SSL, Static, HTTP only, Build-only' + - job_name: 'CMake, VS2022, Debug, x64, no SSL, Static, HTTP only, Build-tests' APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2022' BUILD_SYSTEM: CMake PRJ_GEN: 'Visual Studio 17 2022' diff --git a/configure.ac b/configure.ac index f8b0e9751d..bf265b62a8 100644 --- a/configure.ac +++ b/configure.ac @@ -629,6 +629,29 @@ AS_HELP_STRING([--disable-unity],[Disable unity (default)]), AM_CONDITIONAL([USE_UNITY], [test "$want_unity" = 'yes']) +dnl ----------------------- +dnl whether to bundle tests +dnl ----------------------- + +want_test_bundles='no' +AC_MSG_CHECKING([whether to build tests into single-binary bundles]) +AC_ARG_ENABLE(test-bundles, +AS_HELP_STRING([--enable-test-bundles],[Enable test bundles]) +AS_HELP_STRING([--disable-test-bundles],[Disable test bundles (default)]), +[ case "$enableval" in + yes) + want_test_bundles='yes' + AC_MSG_RESULT([yes]) + ;; + *) + AC_MSG_RESULT([no]) + ;; + esac ], + AC_MSG_RESULT([no]) +) + +AM_CONDITIONAL([USE_TEST_BUNDLES], [test "$want_test_bundles" = 'yes']) + dnl ************************************************************ dnl switch off particular protocols dnl diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3a9e8e76ac..22226b4a41 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,6 +21,8 @@ # SPDX-License-Identifier: curl # ########################################################################### +option(CURL_TEST_BUNDLES "Bundle libtests/unittests into single binaries" OFF) + find_program(TEST_NGHTTPX "nghttpx") if(NOT TEST_NGHTTPX) set(TEST_NGHTTPX "nghttpx") @@ -38,6 +40,9 @@ add_subdirectory(unit) add_subdirectory(certs EXCLUDE_FROM_ALL) function(add_runtests _targetname _test_flags) + if(CURL_TEST_BUNDLES) + set(_test_flags "${_test_flags} -bundle") + endif() # Use a special '$TFLAGS' placeholder as last argument which will be # replaced by the contents of the environment variable in runtests.pl. # This is a workaround for CMake's limitation where commands executed by diff --git a/tests/Makefile.am b/tests/Makefile.am index d3d5e804d4..250ad3cabb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -71,6 +71,8 @@ EXTRA_DIST = \ http2-server.pl \ http3-server.pl \ memanalyze.pl \ + mk-bundle-hints.sh \ + mk-bundle.pl \ negtelnetserver.py \ nghttpx.conf \ pathhelp.pm \ @@ -116,10 +118,16 @@ CLEANFILES = .http.pid .https.pid .ftp.pid .ftps.pid $(MANDISTPAGES) curl: @cd $(top_builddir) && $(MAKE) +TEST_COMMON = + if CROSSCOMPILING TEST = @echo "NOTICE: we can't run the tests when cross-compiling!" else # if not cross-compiling: -TEST = srcdir=$(srcdir) $(PERL) $(PERLFLAGS) $(srcdir)/runtests.pl +if USE_TEST_BUNDLES +TEST_COMMON += -bundle +endif + +TEST = srcdir=$(srcdir) $(PERL) $(PERLFLAGS) $(srcdir)/runtests.pl $(TEST_COMMON) TEST_Q = -a -s TEST_AM = -a -am TEST_F = -a -p -r diff --git a/tests/globalconfig.pm b/tests/globalconfig.pm index ca78f5dbec..e1f17df436 100644 --- a/tests/globalconfig.pm +++ b/tests/globalconfig.pm @@ -65,6 +65,7 @@ BEGIN { %feature %keywords @protocols + $bundle ); } use pathhelp qw(exe_ext); @@ -102,6 +103,7 @@ our $VCURL=$CURL; # what curl binary to use to verify the servers with # the path to the script that analyzes the memory debug output file our $memanalyze="$perl $srcdir/memanalyze.pl"; our $valgrind; # path to valgrind, or empty if disabled +our $bundle = 0; # use bundled server, libtest, unit binaries # paths in $LOGDIR our $LOCKDIR = "lock"; # root of the server directory with lock files diff --git a/tests/libtest/.gitignore b/tests/libtest/.gitignore index 2b4dc1a362..9fd1a098c7 100644 --- a/tests/libtest/.gitignore +++ b/tests/libtest/.gitignore @@ -5,6 +5,7 @@ lib[1234][0-9][0-9][0-9] lib[56][0-9][0-9] lib1521.c +libtests.c libauthretry libntlmconnect libprereq diff --git a/tests/libtest/CMakeLists.txt b/tests/libtest/CMakeLists.txt index d11316ba69..2e0b848ee6 100644 --- a/tests/libtest/CMakeLists.txt +++ b/tests/libtest/CMakeLists.txt @@ -22,13 +22,39 @@ # ########################################################################### -# Get 'noinst_PROGRAMS', '*_SOURCES', WARNLESS, MULTIBYTE, TIMEDIFF variables +# Get 'LIBTESTPROGS', '*_SOURCES', 'TESTUTIL', 'TSTTRACE', 'WARNLESS', 'MULTIBYTE', 'TIMEDIFF', 'THREADS', 'FIRSTFILES' variables transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") set_source_files_properties("../../lib/curl_multibyte.c" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) -foreach(_target IN LISTS noinst_PROGRAMS) +add_custom_command( + OUTPUT "lib1521.c" + COMMAND ${PERL_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl" < "${CURL_SOURCE_DIR}/include/curl/curl.h" > "lib1521.c" + DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl" + "${CURL_SOURCE_DIR}/include/curl/curl.h" + VERBATIM) + +if(CURL_TEST_BUNDLES) + add_custom_command( + OUTPUT "libtest_bundle.c" + COMMAND ${PERL_EXECUTABLE} "${CURL_SOURCE_DIR}/tests/mk-bundle.pl" "${CMAKE_CURRENT_SOURCE_DIR}" > "libtest_bundle.c" + DEPENDS + "${CURL_SOURCE_DIR}/tests/mk-bundle.pl" ${FIRSTFILES} "lib1521.c" + "${CMAKE_CURRENT_SOURCE_DIR}/Makefile.inc" + VERBATIM) + + set(LIBTESTPROGS "libtests") + set(libtests_SOURCES "libtest_bundle.c") + list(APPEND libtests_SOURCES ${TESTUTIL} ${TSTTRACE}) + if(LIB_SELECTED STREQUAL LIB_SHARED) + # These are part of the libcurl static lib. Add them here when linking shared. + list(APPEND libtests_SOURCES ${WARNLESS} ${MULTIBYTE} ${TIMEDIFF} ${THREADS}) + endif() +endif() + +foreach(_target IN LISTS LIBTESTPROGS) if(DEFINED ${_target}_SOURCES) set(_sources ${${_target}_SOURCES}) else() @@ -50,16 +76,11 @@ foreach(_target IN LISTS noinst_PROGRAMS) "${CURL_SOURCE_DIR}/lib" # for "curl_setup.h" "${CURL_SOURCE_DIR}/tests/libtest" # to be able to build generated tests ) + if(NOT CURL_TEST_BUNDLES) + set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS ${_upper_target}) + endif() + set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_NO_GETADDRINFO_OVERRIDE") set_target_properties(${_target_name} PROPERTIES - COMPILE_DEFINITIONS ${_upper_target} OUTPUT_NAME "${_target}" PROJECT_LABEL "Test libtest ${_target}") endforeach() - -add_custom_command( - OUTPUT "lib1521.c" - COMMAND ${PERL_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl" < "${CURL_SOURCE_DIR}/include/curl/curl.h" > "lib1521.c" - DEPENDS - "${CMAKE_CURRENT_SOURCE_DIR}/mk-lib1521.pl" - "${CURL_SOURCE_DIR}/include/curl/curl.h" - VERBATIM) diff --git a/tests/libtest/Makefile.am b/tests/libtest/Makefile.am index 2e360cad44..6358ec1bea 100644 --- a/tests/libtest/Makefile.am +++ b/tests/libtest/Makefile.am @@ -34,7 +34,8 @@ AUTOMAKE_OPTIONS = foreign nostdinc AM_CPPFLAGS = -I$(top_srcdir)/include \ -I$(top_builddir)/lib \ - -I$(top_srcdir)/lib + -I$(top_srcdir)/lib \ + -I$(top_srcdir)/tests/libtest EXTRA_DIST = test307.pl test610.pl test613.pl test1013.pl test1022.pl \ notexists.pl CMakeLists.txt mk-lib1521.pl .checksrc @@ -55,7 +56,7 @@ TESTUTIL_LIBS = $(top_builddir)/lib/libcurl.la @LIBCURL_PC_LIBS_PRIVATE@ LDADD = $(SUPPORTFILES_LIBS) # Makefile.inc provides the source defines (TESTUTIL, SUPPORTFILES, -# noinst_PROGRAMS, lib*_SOURCES, and lib*_CFLAGS) +# LIBTESTPROGS, lib*_SOURCES, and lib*_CFLAGS) include Makefile.inc noinst_LTLIBRARIES = @@ -87,6 +88,26 @@ libstubgss_la_LIBADD = libstubgss_la_DEPENDENCIES = endif +if USE_TEST_BUNDLES +AM_CPPFLAGS += -DCURL_NO_GETADDRINFO_OVERRIDE + +libtest_bundle.c: $(top_srcdir)/tests/mk-bundle.pl lib1521.c + @PERL@ $(top_srcdir)/tests/mk-bundle.pl $(srcdir) > libtest_bundle.c + +noinst_PROGRAMS = libtests +nodist_libtests_SOURCES = libtest_bundle.c +libtests_SOURCES = $(TESTUTIL) $(TSTTRACE) +libtests_LDADD = $(TESTUTIL_LIBS) +CLEANFILES += libtest_bundle.c + +if USE_CPPFLAG_CURL_STATICLIB +else +# These are part of the libcurl static lib. Add them here when linking shared. +libtests_SOURCES += $(WARNLESS) $(MULTIBYTE) $(TIMEDIFF) $(THREADS) +endif +else +noinst_PROGRAMS = $(LIBTESTPROGS) +endif lib1521.c: $(top_srcdir)/tests/libtest/mk-lib1521.pl $(top_srcdir)/include/curl/curl.h @PERL@ $(top_srcdir)/tests/libtest/mk-lib1521.pl < $(top_srcdir)/include/curl/curl.h > lib1521.c diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index 492548658a..948d9f76d5 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -35,12 +35,13 @@ MULTIBYTE = ../../lib/curl_multibyte.c ../../lib/curl_multibyte.h # these files are used in every single test program below TIMEDIFF = ../../lib/timediff.c ../../lib/timediff.h -SUPPORTFILES = $(TIMEDIFF) first.c test.h +FIRSTFILES = first.c first.h +SUPPORTFILES = $(TIMEDIFF) $(FIRSTFILES) test.h THREADS = ../../lib/curl_threads.c ../../lib/curl_threads.h # These are all libcurl test programs -noinst_PROGRAMS = libauthretry libntlmconnect libprereq \ +LIBTESTPROGS = libauthretry libntlmconnect libprereq \ lib500 lib501 lib502 lib503 lib504 lib505 lib506 lib507 lib508 lib509 \ lib510 lib511 lib512 lib513 lib514 lib515 lib516 lib517 lib518 lib519 \ lib520 lib521 lib523 lib524 lib525 lib526 lib527 lib529 lib530 lib532 \ diff --git a/tests/libtest/first.c b/tests/libtest/first.c index 0e98ac87cb..68c649e08b 100644 --- a/tests/libtest/first.c +++ b/tests/libtest/first.c @@ -22,6 +22,7 @@ * ***************************************************************************/ #include "test.h" +#include "first.h" #ifdef HAVE_LOCALE_H # include /* for setlocale() */ @@ -137,6 +138,8 @@ int main(int argc, char **argv) { char *URL; CURLcode result; + int basearg; + test_func_t test_func; #ifdef O_BINARY # ifdef __HIGHC__ @@ -157,25 +160,64 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); #endif - if(argc < 2) { + test_argc = argc; + test_argv = argv; + +#ifdef CURLTESTS_BUNDLED + { + char *test_name; + + --test_argc; + ++test_argv; + + basearg = 2; + + if(argc < (basearg + 1)) { + fprintf(stderr, "Pass testname and URL as arguments please\n"); + return 1; + } + + test_name = argv[basearg - 1]; + test_func = NULL; + { + size_t tmp; + for(tmp = 0; tmp < (sizeof(s_tests)/sizeof((s_tests)[0])); ++tmp) { + if(strcmp(test_name, s_tests[tmp].name) == 0) { + test_func = s_tests[tmp].ptr; + break; + } + } + } + + if(!test_func) { + fprintf(stderr, "Test '%s' not found.\n", test_name); + return 1; + } + + fprintf(stderr, "Test: %s\n", test_name); + } +#else + basearg = 1; + + if(argc < (basearg + 1)) { fprintf(stderr, "Pass URL as argument please\n"); return 1; } - test_argc = argc; - test_argv = argv; + test_func = test; +#endif - if(argc > 2) - libtest_arg2 = argv[2]; + if(argc > (basearg + 1)) + libtest_arg2 = argv[basearg + 1]; - if(argc > 3) - libtest_arg3 = argv[3]; + if(argc > (basearg + 2)) + libtest_arg3 = argv[basearg + 2]; - URL = argv[1]; /* provide this to the rest */ + URL = argv[basearg]; /* provide this to the rest */ fprintf(stderr, "URL: %s\n", URL); - result = test(URL); + result = test_func(URL); fprintf(stderr, "Test ended with result %d\n", result); #ifdef _WIN32 diff --git a/tests/libtest/first.h b/tests/libtest/first.h new file mode 100644 index 0000000000..1e4ae5fc37 --- /dev/null +++ b/tests/libtest/first.h @@ -0,0 +1,38 @@ +#ifndef HEADER_LIBTEST_FIRST_H +#define HEADER_LIBTEST_FIRST_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ +#include "curl_setup.h" +#include + +typedef CURLcode (*test_func_t)(char *); + +#ifdef CURLTESTS_BUNDLED +struct onetest { + const char *name; + test_func_t ptr; +}; +#endif + +#endif /* HEADER_LIBTEST_FIRST_H */ diff --git a/tests/libtest/lib1156.c b/tests/libtest/lib1156.c index f514b4e410..8959db7638 100644 --- a/tests/libtest/lib1156.c +++ b/tests/libtest/lib1156.c @@ -47,7 +47,7 @@ struct testparams { CURLcode result; /* Code that should be returned by curl_easy_perform(). */ }; -static const struct testparams params[] = { +static const struct testparams testparams[] = { { 0, CURLE_OK }, { F_CONTENTRANGE, CURLE_OK }, { F_FAIL, CURLE_OK }, @@ -143,7 +143,7 @@ CURLcode test(char *URL) return TEST_ERR_MAJOR_BAD; } - for(i = 0; i < sizeof(params) / sizeof(params[0]); i++) { + for(i = 0; i < sizeof(testparams) / sizeof(testparams[0]); i++) { curl = curl_easy_init(); if(!curl) { fprintf(stderr, "curl_easy_init() failed\n"); @@ -156,7 +156,7 @@ CURLcode test(char *URL) #ifdef SINGLETEST if(SINGLETEST == i) #endif - status |= onetest(curl, URL, params + i, i); + status |= onetest(curl, URL, testparams + i, i); curl_easy_cleanup(curl); } diff --git a/tests/libtest/lib1514.c b/tests/libtest/lib1514.c index 496fffc8bd..6b4e18bac0 100644 --- a/tests/libtest/lib1514.c +++ b/tests/libtest/lib1514.c @@ -30,7 +30,7 @@ #include "memdebug.h" -static char data[]="dummy"; +static char testdata[]="dummy"; struct WriteThis { char *readptr; @@ -59,7 +59,7 @@ CURLcode test(char *URL) CURL *curl; CURLcode result = CURLE_OK; CURLcode res = CURLE_OK; - struct WriteThis pooh = { data, sizeof(data)-1 }; + struct WriteThis pooh = { testdata, sizeof(testdata)-1 }; global_init(CURL_GLOBAL_ALL); diff --git a/tests/libtest/lib1517.c b/tests/libtest/lib1517.c index 94ebc49d22..3957eb1990 100644 --- a/tests/libtest/lib1517.c +++ b/tests/libtest/lib1517.c @@ -25,7 +25,7 @@ #include "memdebug.h" -static char data[]="this is what we post to the silly web server\n"; +static char testdata[]="this is what we post to the silly web server\n"; struct WriteThis { char *readptr; @@ -70,8 +70,8 @@ CURLcode test(char *URL) #endif } - pooh.readptr = data; - pooh.sizeleft = strlen(data); + pooh.readptr = testdata; + pooh.sizeleft = strlen(testdata); if(curl_global_init(CURL_GLOBAL_ALL)) { fprintf(stderr, "curl_global_init() failed\n"); diff --git a/tests/libtest/lib1525.c b/tests/libtest/lib1525.c index d6c24fcce9..c8a3063f36 100644 --- a/tests/libtest/lib1525.c +++ b/tests/libtest/lib1525.c @@ -32,17 +32,17 @@ #include "memdebug.h" -static char data [] = "Hello Cloud!\n"; +static char testdata[] = "Hello Cloud!\n"; static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream) { size_t amount = nmemb * size; /* Total bytes curl wants */ - if(amount < strlen(data)) { - return strlen(data); + if(amount < strlen(testdata)) { + return strlen(testdata); } (void)stream; - memcpy(ptr, data, strlen(data)); - return strlen(data); + memcpy(ptr, testdata, strlen(testdata)); + return strlen(testdata); } @@ -84,7 +84,7 @@ CURLcode test(char *URL) test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite); test_setopt(curl, CURLOPT_READFUNCTION, read_callback); test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L); - test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(data)); + test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(testdata)); res = curl_easy_perform(curl); diff --git a/tests/libtest/lib1526.c b/tests/libtest/lib1526.c index 344028c110..8093079f55 100644 --- a/tests/libtest/lib1526.c +++ b/tests/libtest/lib1526.c @@ -31,17 +31,17 @@ #include "memdebug.h" -static char data [] = "Hello Cloud!\n"; +static char testdata[] = "Hello Cloud!\n"; static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream) { size_t amount = nmemb * size; /* Total bytes curl wants */ - if(amount < strlen(data)) { - return strlen(data); + if(amount < strlen(testdata)) { + return strlen(testdata); } (void)stream; - memcpy(ptr, data, strlen(data)); - return strlen(data); + memcpy(ptr, testdata, strlen(testdata)); + return strlen(testdata); } CURLcode test(char *URL) @@ -87,7 +87,7 @@ CURLcode test(char *URL) test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite); test_setopt(curl, CURLOPT_READFUNCTION, read_callback); test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L); - test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(data)); + test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(testdata)); res = curl_easy_perform(curl); diff --git a/tests/libtest/lib1527.c b/tests/libtest/lib1527.c index 931f2555a6..26581b2a3e 100644 --- a/tests/libtest/lib1527.c +++ b/tests/libtest/lib1527.c @@ -31,17 +31,17 @@ #include "memdebug.h" -static char data [] = "Hello Cloud!\n"; +static char testdata[] = "Hello Cloud!\n"; static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream) { size_t amount = nmemb * size; /* Total bytes curl wants */ - if(amount < strlen(data)) { - return strlen(data); + if(amount < strlen(testdata)) { + return strlen(testdata); } (void)stream; - memcpy(ptr, data, strlen(data)); - return strlen(data); + memcpy(ptr, testdata, strlen(testdata)); + return strlen(testdata); } @@ -85,7 +85,7 @@ CURLcode test(char *URL) test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite); test_setopt(curl, CURLOPT_READFUNCTION, read_callback); test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L); - test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(data)); + test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(testdata)); test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_UNIFIED); res = curl_easy_perform(curl); diff --git a/tests/libtest/lib1554.c b/tests/libtest/lib1554.c index a8439b08e2..3c48f3fe08 100644 --- a/tests/libtest/lib1554.c +++ b/tests/libtest/lib1554.c @@ -36,8 +36,8 @@ static const char *ldata_names[] = { "NULL", }; -static void my_lock(CURL *handle, curl_lock_data data, - curl_lock_access laccess, void *useptr) +static void test_lock(CURL *handle, curl_lock_data data, + curl_lock_access laccess, void *useptr) { (void)handle; (void)data; @@ -46,7 +46,7 @@ static void my_lock(CURL *handle, curl_lock_data data, printf("-> Mutex lock %s\n", ldata_names[data]); } -static void my_unlock(CURL *handle, curl_lock_data data, void *useptr) +static void test_unlock(CURL *handle, curl_lock_data data, void *useptr) { (void)handle; (void)data; @@ -70,8 +70,8 @@ CURLcode test(char *URL) } curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); - curl_share_setopt(share, CURLSHOPT_LOCKFUNC, my_lock); - curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, my_unlock); + curl_share_setopt(share, CURLSHOPT_LOCKFUNC, test_lock); + curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, test_unlock); /* Loop the transfer and cleanup the handle properly every lap. This will still reuse connections since the pool is in the shared object! */ diff --git a/tests/libtest/lib1565.c b/tests/libtest/lib1565.c index 7f833868ad..b6b8ecf12d 100644 --- a/tests/libtest/lib1565.c +++ b/tests/libtest/lib1565.c @@ -40,7 +40,7 @@ static CURL *pending_handles[CONN_NUM]; static int pending_num = 0; static CURLcode test_failure = CURLE_OK; -static CURLM *multi = NULL; +static CURLM *testmulti = NULL; static const char *url; static void *run_thread(void *ptr) @@ -72,7 +72,7 @@ static void *run_thread(void *ptr) pthread_mutex_unlock(&lock); - res_multi_wakeup(multi); + res_multi_wakeup(testmulti); } test_cleanup: @@ -107,7 +107,7 @@ CURLcode test(char *URL) global_init(CURL_GLOBAL_ALL); - multi_init(multi); + multi_init(testmulti); url = URL; @@ -121,16 +121,16 @@ CURLcode test(char *URL) } while(1) { - multi_perform(multi, &still_running); + multi_perform(testmulti, &still_running); abort_on_test_timeout(); - while((message = curl_multi_info_read(multi, &num))) { + while((message = curl_multi_info_read(testmulti, &num))) { if(message->msg == CURLMSG_DONE) { res = message->data.result; if(res) goto test_cleanup; - multi_remove_handle(multi, message->easy_handle); + multi_remove_handle(testmulti, message->easy_handle); finished_num++; } else { @@ -146,14 +146,14 @@ CURLcode test(char *URL) if(CONN_NUM == finished_num) break; - multi_poll(multi, NULL, 0, TEST_HANG_TIMEOUT, &num); + multi_poll(testmulti, NULL, 0, TEST_HANG_TIMEOUT, &num); abort_on_test_timeout(); pthread_mutex_lock(&lock); while(pending_num > 0) { - res_multi_add_handle(multi, pending_handles[pending_num - 1]); + res_multi_add_handle(testmulti, pending_handles[pending_num - 1]); if(res) { pthread_mutex_unlock(&lock); goto test_cleanup; @@ -191,7 +191,7 @@ test_cleanup: if(tid_valid) pthread_join(tid, NULL); - curl_multi_cleanup(multi); + curl_multi_cleanup(testmulti); for(i = 0; i < pending_num; i++) curl_easy_cleanup(pending_handles[i]); for(i = 0; i < started_num; i++) diff --git a/tests/libtest/lib1591.c b/tests/libtest/lib1591.c index 0a361ada16..c0200d5429 100644 --- a/tests/libtest/lib1591.c +++ b/tests/libtest/lib1591.c @@ -31,24 +31,24 @@ #include #include "memdebug.h" -static char data [] = "Hello Cloud!\r\n"; +static char testdata[] = "Hello Cloud!\r\n"; static size_t consumed = 0; static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream) { size_t amount = nmemb * size; /* Total bytes curl wants */ - if(consumed == strlen(data)) { + if(consumed == strlen(testdata)) { return 0; } - if(amount > strlen(data)-consumed) { - amount = strlen(data); + if(amount > strlen(testdata)-consumed) { + amount = strlen(testdata); } consumed += amount; (void)stream; - memcpy(ptr, data, amount); + memcpy(ptr, testdata, amount); return amount; } diff --git a/tests/libtest/lib1662.c b/tests/libtest/lib1662.c index 91c02fce05..1e9e2b0617 100644 --- a/tests/libtest/lib1662.c +++ b/tests/libtest/lib1662.c @@ -23,7 +23,7 @@ ***************************************************************************/ #include "test.h" -static char data[]="mooaaa"; +static char testdata[]="mooaaa"; struct WriteThis { size_t sizeleft; @@ -32,13 +32,13 @@ struct WriteThis { static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) { struct WriteThis *pooh = (struct WriteThis *)userp; - size_t len = strlen(data); + size_t len = strlen(testdata); if(size*nmemb < len) return 0; if(pooh->sizeleft) { - memcpy(ptr, data, strlen(data)); + memcpy(ptr, testdata, strlen(testdata)); pooh->sizeleft = 0; return len; } diff --git a/tests/libtest/lib1911.c b/tests/libtest/lib1911.c index 625ec262a7..0fd62a8b92 100644 --- a/tests/libtest/lib1911.c +++ b/tests/libtest/lib1911.c @@ -31,7 +31,7 @@ define not publicly exposed so we set our own */ #define MAX_INPUT_LENGTH 8000000 -static char buffer[MAX_INPUT_LENGTH + 2]; +static char testbuf[MAX_INPUT_LENGTH + 2]; CURLcode test(char *URL) { @@ -48,10 +48,10 @@ CURLcode test(char *URL) } /* make it a null-terminated C string with just As */ - memset(buffer, 'A', MAX_INPUT_LENGTH + 1); - buffer[MAX_INPUT_LENGTH + 1] = 0; + memset(testbuf, 'A', MAX_INPUT_LENGTH + 1); + testbuf[MAX_INPUT_LENGTH + 1] = 0; - printf("string length: %d\n", (int)strlen(buffer)); + printf("string length: %d\n", (int)strlen(testbuf)); for(o = curl_easy_option_next(NULL); o; @@ -76,7 +76,7 @@ CURLcode test(char *URL) /* This is a string. Make sure that passing in a string longer CURL_MAX_INPUT_LENGTH returns an error */ - result = curl_easy_setopt(easy, o->id, buffer); + result = curl_easy_setopt(easy, o->id, testbuf); switch(result) { case CURLE_BAD_FUNCTION_ARGUMENT: /* the most normal */ case CURLE_UNKNOWN_OPTION: /* left out from the build */ diff --git a/tests/libtest/lib1940.c b/tests/libtest/lib1940.c index 7ee523f150..e8dbcdd13f 100644 --- a/tests/libtest/lib1940.c +++ b/tests/libtest/lib1940.c @@ -26,7 +26,7 @@ #include "memdebug.h" -static const char *show[]={ +static const char *testdata[]={ "daTE", "Server", "content-type", @@ -50,9 +50,9 @@ static void showem(CURL *easy, unsigned int type) { int i; struct curl_header *header; - for(i = 0; show[i]; i++) { - if(CURLHE_OK == curl_easy_header(easy, show[i], 0, type, HEADER_REQUEST, - &header)) { + for(i = 0; testdata[i]; i++) { + if(CURLHE_OK == curl_easy_header(easy, testdata[i], 0, type, + HEADER_REQUEST, &header)) { if(header->amount > 1) { /* more than one, iterate over them */ size_t index = 0; @@ -63,7 +63,7 @@ static void showem(CURL *easy, unsigned int type) if(++index == amount) break; - if(CURLHE_OK != curl_easy_header(easy, show[i], index, type, + if(CURLHE_OK != curl_easy_header(easy, testdata[i], index, type, HEADER_REQUEST, &header)) break; } while(1); diff --git a/tests/libtest/lib2301.c b/tests/libtest/lib2301.c index cd31207703..bfac8305f3 100644 --- a/tests/libtest/lib2301.c +++ b/tests/libtest/lib2301.c @@ -27,7 +27,7 @@ #ifdef USE_WEBSOCKETS #if 0 -static CURLcode ping(CURL *curl, const char *send_payload) +static CURLcode send_ping(CURL *curl, const char *send_payload) { size_t sent; CURLcode result = @@ -80,7 +80,7 @@ static void websocket(CURL *curl) int i = 0; fprintf(stderr, "ws: websocket() starts\n"); do { - if(ping(curl, "foobar")) + if(send_ping(curl, "foobar")) return; if(recv_pong(curl, "foobar")) return; diff --git a/tests/libtest/lib2304.c b/tests/libtest/lib2304.c index 57329c4c75..0052bfdba8 100644 --- a/tests/libtest/lib2304.c +++ b/tests/libtest/lib2304.c @@ -26,7 +26,7 @@ #ifdef USE_WEBSOCKETS -static CURLcode ping(CURL *curl, const char *send_payload) +static CURLcode send_ping(CURL *curl, const char *send_payload) { size_t sent; CURLcode result = @@ -98,7 +98,7 @@ static void websocket(CURL *curl) do { recv_any(curl); fprintf(stderr, "Send ping\n"); - if(ping(curl, "foobar")) + if(send_ping(curl, "foobar")) return; fprintf(stderr, "Receive pong\n"); if(recv_pong(curl, "foobar")) { diff --git a/tests/libtest/lib2305.c b/tests/libtest/lib2305.c index 5ccb9bfa61..2ec9c3e7f2 100644 --- a/tests/libtest/lib2305.c +++ b/tests/libtest/lib2305.c @@ -55,6 +55,7 @@ static void websocket(CURL *curl) if(result == CURLE_AGAIN) /* crude busy-loop */ continue; + fclose(save); printf("curl_ws_recv returned %d\n", result); return; } diff --git a/tests/libtest/lib3207.c b/tests/libtest/lib3207.c index f43f7d5b10..6c819b3596 100644 --- a/tests/libtest/lib3207.c +++ b/tests/libtest/lib3207.c @@ -38,8 +38,7 @@ #define THREAD_SIZE 16 #define PER_THREAD_SIZE 8 -struct Ctx -{ +struct Ctx { const char *URL; CURLSH *share; int result; @@ -126,8 +125,8 @@ test_cleanup: #if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32) -static void my_lock(CURL *handle, curl_lock_data data, - curl_lock_access laccess, void *useptr) +static void test_lock(CURL *handle, curl_lock_data data, + curl_lock_access laccess, void *useptr) { curl_mutex_t *mutexes = (curl_mutex_t*) useptr; (void)handle; @@ -135,14 +134,14 @@ static void my_lock(CURL *handle, curl_lock_data data, Curl_mutex_acquire(&mutexes[data]); } -static void my_unlock(CURL *handle, curl_lock_data data, void *useptr) +static void test_unlock(CURL *handle, curl_lock_data data, void *useptr) { curl_mutex_t *mutexes = (curl_mutex_t*) useptr; (void)handle; Curl_mutex_release(&mutexes[data]); } -static void execute(struct Curl_share *share, struct Ctx *ctx) +static void execute(CURLSH *share, struct Ctx *ctx) { int i; curl_mutex_t mutexes[CURL_LOCK_DATA_LAST - 1]; @@ -150,8 +149,8 @@ static void execute(struct Curl_share *share, struct Ctx *ctx) for(i = 0; i < CURL_LOCK_DATA_LAST - 1; i++) { Curl_mutex_init(&mutexes[i]); } - curl_share_setopt(share, CURLSHOPT_LOCKFUNC, my_lock); - curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, my_unlock); + curl_share_setopt(share, CURLSHOPT_LOCKFUNC, test_lock); + curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, test_unlock); curl_share_setopt(share, CURLSHOPT_USERDATA, (void *)mutexes); curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION); @@ -173,7 +172,7 @@ static void execute(struct Curl_share *share, struct Ctx *ctx) #else /* without pthread, run serially */ -static void execute(struct Curl_share *share, struct Ctx *ctx) +static void execute(CURLSH *share, struct Ctx *ctx) { int i; (void) share; diff --git a/tests/libtest/lib500.c b/tests/libtest/lib500.c index 8b27aef04a..9aa3466698 100644 --- a/tests/libtest/lib500.c +++ b/tests/libtest/lib500.c @@ -28,7 +28,7 @@ #ifdef LIB585 -static int counter; +static int testcounter; static curl_socket_t tst_opensocket(void *clientp, curlsocktype purpose, @@ -36,14 +36,14 @@ static curl_socket_t tst_opensocket(void *clientp, { (void)clientp; (void)purpose; - printf("[OPEN] counter: %d\n", ++counter); + printf("[OPEN] counter: %d\n", ++testcounter); return socket(addr->family, addr->socktype, addr->protocol); } static int tst_closesocket(void *clientp, curl_socket_t sock) { (void)clientp; - printf("[CLOSE] counter: %d\n", counter--); + printf("[CLOSE] counter: %d\n", testcounter--); return sclose(sock); } @@ -51,7 +51,7 @@ static void setupcallbacks(CURL *curl) { curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, tst_opensocket); curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, tst_closesocket); - counter = 0; + testcounter = 0; } #else @@ -174,3 +174,5 @@ test_cleanup: return res; } + +#undef setupcallbacks diff --git a/tests/libtest/lib506.c b/tests/libtest/lib506.c index 9a5e5a2c1e..03eb11ddda 100644 --- a/tests/libtest/lib506.c +++ b/tests/libtest/lib506.c @@ -42,8 +42,8 @@ struct userdata { static int locks[3]; /* lock callback */ -static void my_lock(CURL *handle, curl_lock_data data, - curl_lock_access laccess, void *useptr) +static void test_lock(CURL *handle, curl_lock_data data, + curl_lock_access laccess, void *useptr) { const char *what; struct userdata *user = (struct userdata *)useptr; @@ -82,7 +82,7 @@ static void my_lock(CURL *handle, curl_lock_data data, } /* unlock callback */ -static void my_unlock(CURL *handle, curl_lock_data data, void *useptr) +static void test_unlock(CURL *handle, curl_lock_data data, void *useptr) { const char *what; struct userdata *user = (struct userdata *)useptr; @@ -127,7 +127,7 @@ static struct curl_slist *sethost(struct curl_slist *headers) /* the dummy thread function */ -static void *fire(void *ptr) +static void *test_fire(void *ptr) { CURLcode code; struct curl_slist *headers; @@ -207,11 +207,11 @@ CURLcode test(char *URL) if(CURLSHE_OK == scode) { printf("CURLSHOPT_LOCKFUNC\n"); - scode = curl_share_setopt(share, CURLSHOPT_LOCKFUNC, my_lock); + scode = curl_share_setopt(share, CURLSHOPT_LOCKFUNC, test_lock); } if(CURLSHE_OK == scode) { printf("CURLSHOPT_UNLOCKFUNC\n"); - scode = curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, my_unlock); + scode = curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, test_unlock); } if(CURLSHE_OK == scode) { printf("CURLSHOPT_USERDATA\n"); @@ -272,7 +272,7 @@ CURLcode test(char *URL) /* simulate thread, direct call of "thread" function */ printf("*** run %d\n",i); - fire(&tdata); + test_fire(&tdata); curl_free(tdata.url); } diff --git a/tests/libtest/lib508.c b/tests/libtest/lib508.c index 00bb881d76..fc25a0df60 100644 --- a/tests/libtest/lib508.c +++ b/tests/libtest/lib508.c @@ -25,7 +25,7 @@ #include "memdebug.h" -static char data[]="this is what we post to the silly web server\n"; +static char testdata[]="this is what we post to the silly web server\n"; struct WriteThis { char *readptr; @@ -56,8 +56,8 @@ CURLcode test(char *URL) struct WriteThis pooh; - pooh.readptr = data; - pooh.sizeleft = strlen(data); + pooh.readptr = testdata; + pooh.sizeleft = strlen(testdata); if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); diff --git a/tests/libtest/lib510.c b/tests/libtest/lib510.c index d293112f94..2abd1cb7ed 100644 --- a/tests/libtest/lib510.c +++ b/tests/libtest/lib510.c @@ -25,7 +25,7 @@ #include "memdebug.h" -static const char *post[]={ +static const char * const testpost[]={ "one", "two", "three", @@ -46,7 +46,7 @@ static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) if(size*nmemb < 1) return 0; - data = post[pooh->counter]; + data = testpost[pooh->counter]; if(data) { size_t len = strlen(data); diff --git a/tests/libtest/lib518.c b/tests/libtest/lib518.c index ef70e03d68..4cde4b1e47 100644 --- a/tests/libtest/lib518.c +++ b/tests/libtest/lib518.c @@ -50,7 +50,7 @@ #if defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) -static int *fd = NULL; +static int *testfd = NULL; static struct rlimit num_open; static char msgbuff[256]; @@ -68,10 +68,10 @@ static void close_file_descriptors(void) for(num_open.rlim_cur = 0; num_open.rlim_cur < num_open.rlim_max; num_open.rlim_cur++) - if(fd[num_open.rlim_cur] > 0) - close(fd[num_open.rlim_cur]); - free(fd); - fd = NULL; + if(testfd[num_open.rlim_cur] > 0) + close(testfd[num_open.rlim_cur]); + free(testfd); + testfd = NULL; } static int fopen_works(void) @@ -120,7 +120,7 @@ static void rlim2str(char *buf, size_t len, rlim_t val) } } -static int rlimit(int keep_open) +static int test_rlimit(int keep_open) { rlim_t nitems, i; int *memchunk = NULL; @@ -239,7 +239,7 @@ static int rlimit(int keep_open) * avoid a low memory condition once the file descriptors are * open. System conditions that could make the test fail should * be addressed in the precheck phase. This chunk of memory shall - * be always free()ed before exiting the rlimit() function so + * be always free()ed before exiting the test_rlimit() function so * that it becomes available to the test. */ @@ -276,7 +276,7 @@ static int rlimit(int keep_open) /* verify that we won't overflow size_t in malloc() */ - if((size_t)(num_open.rlim_max) > ((size_t)-1) / sizeof(*fd)) { + if((size_t)(num_open.rlim_max) > ((size_t)-1) / sizeof(*testfd)) { rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_max); msnprintf(strbuff, sizeof(strbuff), "unable to allocate an array for %s " "file descriptors, would overflow size_t", strbuff1); @@ -291,9 +291,9 @@ static int rlimit(int keep_open) rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max); fprintf(stderr, "allocating array for %s file descriptors\n", strbuff); - fd = malloc(sizeof(*fd) * (size_t)(num_open.rlim_max)); - if(!fd) { - store_errmsg("fd, malloc() failed", errno); + testfd = malloc(sizeof(*testfd) * (size_t)(num_open.rlim_max)); + if(!testfd) { + store_errmsg("testfd, malloc() failed", errno); fprintf(stderr, "%s\n", msgbuff); free(memchunk); return -7; @@ -301,25 +301,25 @@ static int rlimit(int keep_open) /* initialize it to fight lazy allocation */ - fprintf(stderr, "initializing fd array\n"); + fprintf(stderr, "initializing testfd array\n"); for(num_open.rlim_cur = 0; num_open.rlim_cur < num_open.rlim_max; num_open.rlim_cur++) - fd[num_open.rlim_cur] = -1; + testfd[num_open.rlim_cur] = -1; rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max); fprintf(stderr, "trying to open %s file descriptors\n", strbuff); /* open a dummy descriptor */ - fd[0] = open(DEV_NULL, O_RDONLY); - if(fd[0] < 0) { + testfd[0] = open(DEV_NULL, O_RDONLY); + if(testfd[0] < 0) { msnprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL); store_errmsg(strbuff, errno); fprintf(stderr, "%s\n", msgbuff); - free(fd); - fd = NULL; + free(testfd); + testfd = NULL; free(memchunk); return -8; } @@ -330,11 +330,11 @@ static int rlimit(int keep_open) num_open.rlim_cur < num_open.rlim_max; num_open.rlim_cur++) { - fd[num_open.rlim_cur] = dup(fd[0]); + testfd[num_open.rlim_cur] = dup(testfd[0]); - if(fd[num_open.rlim_cur] < 0) { + if(testfd[num_open.rlim_cur] < 0) { - fd[num_open.rlim_cur] = -1; + testfd[num_open.rlim_cur] = -1; rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_cur); msnprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed", strbuff1); @@ -355,11 +355,11 @@ static int rlimit(int keep_open) fprintf(stderr, "%s\n", msgbuff); for(num_open.rlim_cur = 0; - fd[num_open.rlim_cur] >= 0; + testfd[num_open.rlim_cur] >= 0; num_open.rlim_cur++) - close(fd[num_open.rlim_cur]); - free(fd); - fd = NULL; + close(testfd[num_open.rlim_cur]); + free(testfd); + testfd = NULL; free(memchunk); return -9; } @@ -396,8 +396,8 @@ static int rlimit(int keep_open) for(rl.rlim_cur = 0; rl.rlim_cur < num_open.rlim_max; rl.rlim_cur++) { - if((fd[rl.rlim_cur] > 0) && - ((unsigned int)fd[rl.rlim_cur] > num_open.rlim_cur)) { + if((testfd[rl.rlim_cur] > 0) && + ((unsigned int)testfd[rl.rlim_cur] > num_open.rlim_cur)) { msnprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d", FD_SETSIZE); store_errmsg(strbuff, 0); @@ -452,14 +452,14 @@ CURLcode test(char *URL) if(!strcmp(URL, "check")) { /* used by the test script to ask if we can run this test or not */ - if(rlimit(FALSE)) { - fprintf(stdout, "rlimit problem: %s\n", msgbuff); + if(test_rlimit(FALSE)) { + fprintf(stdout, "test_rlimit problem: %s\n", msgbuff); return (CURLcode)1; } return CURLE_OK; /* sure, run this! */ } - if(rlimit(TRUE)) { + if(test_rlimit(TRUE)) { /* failure */ return TEST_ERR_MAJOR_BAD; } diff --git a/tests/libtest/lib530.c b/tests/libtest/lib530.c index 36a4c8af00..5f24c904bc 100644 --- a/tests/libtest/lib530.c +++ b/tests/libtest/lib530.c @@ -38,15 +38,13 @@ #define TEST_HANG_TIMEOUT 60 * 1000 -struct Sockets -{ +struct Sockets { curl_socket_t *sockets; int count; /* number of sockets actually stored in array */ int max_count; /* max number of sockets that fit in allocated array */ }; -struct ReadWriteSockets -{ +struct ReadWriteSockets { struct Sockets read, write; }; diff --git a/tests/libtest/lib537.c b/tests/libtest/lib537.c index 7d454b4e42..d05cd16ab1 100644 --- a/tests/libtest/lib537.c +++ b/tests/libtest/lib537.c @@ -50,7 +50,7 @@ #if defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) -static int *fd = NULL; +static int *testfd = NULL; static struct rlimit num_open; static char msgbuff[256]; @@ -68,10 +68,10 @@ static void close_file_descriptors(void) for(num_open.rlim_cur = 0; num_open.rlim_cur < num_open.rlim_max; num_open.rlim_cur++) - if(fd[num_open.rlim_cur] > 0) - close(fd[num_open.rlim_cur]); - free(fd); - fd = NULL; + if(testfd[num_open.rlim_cur] > 0) + close(testfd[num_open.rlim_cur]); + free(testfd); + testfd = NULL; } static int fopen_works(void) @@ -120,7 +120,7 @@ static void rlim2str(char *buf, size_t len, rlim_t val) } } -static int rlimit(int keep_open) +static int test_rlimit(int keep_open) { int *tmpfd; rlim_t nitems, i; @@ -221,7 +221,7 @@ static int rlimit(int keep_open) * avoid a low memory condition once the file descriptors are * open. System conditions that could make the test fail should * be addressed in the precheck phase. This chunk of memory shall - * be always free()ed before exiting the rlimit() function so + * be always free()ed before exiting the test_rlimit() function so * that it becomes available to the test. */ @@ -273,7 +273,7 @@ static int rlimit(int keep_open) /* verify that we won't overflow size_t in malloc() */ - if((size_t)(num_open.rlim_max) > ((size_t)-1) / sizeof(*fd)) { + if((size_t)(num_open.rlim_max) > ((size_t)-1) / sizeof(*testfd)) { rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_max); msnprintf(strbuff, sizeof(strbuff), "unable to allocate an array for %s " "file descriptors, would overflow size_t", strbuff1); @@ -289,14 +289,14 @@ static int rlimit(int keep_open) rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max); fprintf(stderr, "allocating array for %s file descriptors\n", strbuff); - fd = malloc(sizeof(*fd) * (size_t)(num_open.rlim_max)); - if(!fd) { - fprintf(stderr, "fd, malloc() failed\n"); + testfd = malloc(sizeof(*testfd) * (size_t)(num_open.rlim_max)); + if(!testfd) { + fprintf(stderr, "testfd, malloc() failed\n"); num_open.rlim_max /= 2; } - } while(num_open.rlim_max && !fd); - if(!fd) { - store_errmsg("fd, malloc() failed", errno); + } while(num_open.rlim_max && !testfd); + if(!testfd) { + store_errmsg("testfd, malloc() failed", errno); fprintf(stderr, "%s\n", msgbuff); free(memchunk); return -6; @@ -304,25 +304,25 @@ static int rlimit(int keep_open) /* initialize it to fight lazy allocation */ - fprintf(stderr, "initializing fd array\n"); + fprintf(stderr, "initializing testfd array\n"); for(num_open.rlim_cur = 0; num_open.rlim_cur < num_open.rlim_max; num_open.rlim_cur++) - fd[num_open.rlim_cur] = -1; + testfd[num_open.rlim_cur] = -1; rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max); fprintf(stderr, "trying to open %s file descriptors\n", strbuff); /* open a dummy descriptor */ - fd[0] = open(DEV_NULL, O_RDONLY); - if(fd[0] < 0) { + testfd[0] = open(DEV_NULL, O_RDONLY); + if(testfd[0] < 0) { msnprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL); store_errmsg(strbuff, errno); fprintf(stderr, "%s\n", msgbuff); - free(fd); - fd = NULL; + free(testfd); + testfd = NULL; free(memchunk); return -7; } @@ -333,11 +333,11 @@ static int rlimit(int keep_open) num_open.rlim_cur < num_open.rlim_max; num_open.rlim_cur++) { - fd[num_open.rlim_cur] = dup(fd[0]); + testfd[num_open.rlim_cur] = dup(testfd[0]); - if(fd[num_open.rlim_cur] < 0) { + if(testfd[num_open.rlim_cur] < 0) { - fd[num_open.rlim_cur] = -1; + testfd[num_open.rlim_cur] = -1; rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_cur); msnprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed", strbuff1); @@ -357,10 +357,10 @@ static int rlimit(int keep_open) fprintf(stderr, "%s\n", strbuff); for(num_open.rlim_cur = num_open.rlim_max; - fd[num_open.rlim_cur] >= 0; + testfd[num_open.rlim_cur] >= 0; num_open.rlim_cur++) { - close(fd[num_open.rlim_cur]); - fd[num_open.rlim_cur] = -1; + close(testfd[num_open.rlim_cur]); + testfd[num_open.rlim_cur] = -1; } rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max); @@ -368,9 +368,9 @@ static int rlimit(int keep_open) /* we don't care if we can't shrink it */ - tmpfd = realloc(fd, sizeof(*fd) * (size_t)(num_open.rlim_max)); + tmpfd = realloc(testfd, sizeof(*testfd) * (size_t)(num_open.rlim_max)); if(tmpfd) { - fd = tmpfd; + testfd = tmpfd; tmpfd = NULL; } @@ -409,8 +409,8 @@ static int rlimit(int keep_open) for(rl.rlim_cur = 0; rl.rlim_cur < num_open.rlim_max; rl.rlim_cur++) { - if((fd[rl.rlim_cur] > 0) && - ((unsigned int)fd[rl.rlim_cur] > num_open.rlim_cur)) { + if((testfd[rl.rlim_cur] > 0) && + ((unsigned int)testfd[rl.rlim_cur] > num_open.rlim_cur)) { msnprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d", FD_SETSIZE); store_errmsg(strbuff, 0); @@ -465,14 +465,14 @@ CURLcode test(char *URL) if(!strcmp(URL, "check")) { /* used by the test script to ask if we can run this test or not */ - if(rlimit(FALSE)) { - fprintf(stdout, "rlimit problem: %s\n", msgbuff); + if(test_rlimit(FALSE)) { + fprintf(stdout, "test_rlimit problem: %s\n", msgbuff); return (CURLcode)1; } return CURLE_OK; /* sure, run this! */ } - if(rlimit(TRUE)) { + if(test_rlimit(TRUE)) { /* failure */ return TEST_ERR_MAJOR_BAD; } diff --git a/tests/libtest/lib540.c b/tests/libtest/lib540.c index 649b4d4283..b53b955639 100644 --- a/tests/libtest/lib540.c +++ b/tests/libtest/lib540.c @@ -46,46 +46,46 @@ #define NUM_HANDLES 2 -static CURL *eh[NUM_HANDLES]; +static CURL *testeh[NUM_HANDLES]; static CURLcode init(int num, CURLM *cm, const char *url, const char *userpwd, struct curl_slist *headers) { CURLcode res = CURLE_OK; - res_easy_init(eh[num]); + res_easy_init(testeh[num]); if(res) goto init_failed; - res_easy_setopt(eh[num], CURLOPT_URL, url); + res_easy_setopt(testeh[num], CURLOPT_URL, url); if(res) goto init_failed; - res_easy_setopt(eh[num], CURLOPT_PROXY, PROXY); + res_easy_setopt(testeh[num], CURLOPT_PROXY, PROXY); if(res) goto init_failed; - res_easy_setopt(eh[num], CURLOPT_PROXYUSERPWD, userpwd); + res_easy_setopt(testeh[num], CURLOPT_PROXYUSERPWD, userpwd); if(res) goto init_failed; - res_easy_setopt(eh[num], CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY); + res_easy_setopt(testeh[num], CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY); if(res) goto init_failed; - res_easy_setopt(eh[num], CURLOPT_VERBOSE, 1L); + res_easy_setopt(testeh[num], CURLOPT_VERBOSE, 1L); if(res) goto init_failed; - res_easy_setopt(eh[num], CURLOPT_HEADER, 1L); + res_easy_setopt(testeh[num], CURLOPT_HEADER, 1L); if(res) goto init_failed; - res_easy_setopt(eh[num], CURLOPT_HTTPHEADER, headers); /* custom Host: */ + res_easy_setopt(testeh[num], CURLOPT_HTTPHEADER, headers); /* custom Host: */ if(res) goto init_failed; - res_multi_add_handle(cm, eh[num]); + res_multi_add_handle(cm, testeh[num]); if(res) goto init_failed; @@ -93,8 +93,8 @@ static CURLcode init(int num, CURLM *cm, const char *url, const char *userpwd, init_failed: - curl_easy_cleanup(eh[num]); - eh[num] = NULL; + curl_easy_cleanup(testeh[num]); + testeh[num] = NULL; return res; /* failure */ } @@ -174,8 +174,8 @@ static CURLcode loop(int num, CURLM *cm, const char *url, const char *userpwd, curl_multi_remove_handle(cm, e); curl_easy_cleanup(e); for(i = 0; i < NUM_HANDLES; i++) { - if(eh[i] == e) { - eh[i] = NULL; + if(testeh[i] == e) { + testeh[i] = NULL; break; } } @@ -201,7 +201,7 @@ CURLcode test(char *URL) int i; for(i = 0; i < NUM_HANDLES; i++) - eh[i] = NULL; + testeh[i] = NULL; start_test_timing(); @@ -243,8 +243,8 @@ test_cleanup: /* proper cleanup sequence - type PB */ for(i = 0; i < NUM_HANDLES; i++) { - curl_multi_remove_handle(cm, eh[i]); - curl_easy_cleanup(eh[i]); + curl_multi_remove_handle(cm, testeh[i]); + curl_easy_cleanup(testeh[i]); } curl_multi_cleanup(cm); diff --git a/tests/libtest/lib552.c b/tests/libtest/lib552.c index 5900a20fb5..76244ab339 100644 --- a/tests/libtest/lib552.c +++ b/tests/libtest/lib552.c @@ -30,7 +30,7 @@ #include "warnless.h" #include "memdebug.h" -struct data { +struct testdata { char trace_ascii; /* 1 or 0 */ }; @@ -89,7 +89,7 @@ int my_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *userp) { - struct data *config = (struct data *)userp; + struct testdata *config = (struct testdata *)userp; const char *text; (void)handle; /* prevent compiler warning */ @@ -170,7 +170,7 @@ CURLcode test(char *URL) { CURL *curl; CURLcode res = CURLE_OK; - struct data config; + struct testdata config; size_t i; static const char fill[] = "test data"; diff --git a/tests/libtest/lib554.c b/tests/libtest/lib554.c index 95fdf9eff3..10c19a3804 100644 --- a/tests/libtest/lib554.c +++ b/tests/libtest/lib554.c @@ -25,7 +25,7 @@ #include "memdebug.h" -static char data[]= +static char testdata[]= "this is what we post to the silly web server\n"; struct WriteThis { @@ -59,7 +59,7 @@ static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) #endif } -static CURLcode once(char *URL, bool oldstyle) +static CURLcode test_once(char *URL, bool oldstyle) { CURL *curl; CURLcode res = CURLE_OK; @@ -70,8 +70,8 @@ static CURLcode once(char *URL, bool oldstyle) struct WriteThis pooh; struct WriteThis pooh2; - pooh.readptr = data; - pooh.sizeleft = strlen(data); + pooh.readptr = testdata; + pooh.sizeleft = strlen(testdata); /* Fill in the file upload field */ if(oldstyle) { @@ -104,8 +104,8 @@ static CURLcode once(char *URL, bool oldstyle) /* Now add the same data with another name and make it not look like a file upload but still using the callback */ - pooh2.readptr = data; - pooh2.sizeleft = strlen(data); + pooh2.readptr = testdata; + pooh2.sizeleft = strlen(testdata); CURL_IGNORE_DEPRECATION( /* Fill in the file upload field */ @@ -213,9 +213,9 @@ CURLcode test(char *URL) return TEST_ERR_MAJOR_BAD; } - res = once(URL, TRUE); /* old */ + res = test_once(URL, TRUE); /* old */ if(!res) - res = once(URL, FALSE); /* new */ + res = test_once(URL, FALSE); /* new */ curl_global_cleanup(); diff --git a/tests/libtest/lib557.c b/tests/libtest/lib557.c index 89b4b9ca45..82b7f7f5a9 100644 --- a/tests/libtest/lib557.c +++ b/tests/libtest/lib557.c @@ -27,8 +27,6 @@ * curl_m*printf formatting capabilities and handling of some data types. */ -#define CURL_NO_FMT_CHECKS /* disable compiler *printf format checks */ - #include "test.h" #include @@ -39,6 +37,12 @@ #include "memdebug.h" +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat" +#pragma GCC diagnostic ignored "-Wformat-extra-args" +#endif + #if (SIZEOF_CURL_OFF_T > SIZEOF_LONG) # define MPRNT_SUFFIX_CURL_OFF_T LL #else @@ -1507,3 +1511,7 @@ CURLcode test(char *URL) else return CURLE_OK; } + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif diff --git a/tests/libtest/lib578.c b/tests/libtest/lib578.c index bc632a17e7..6be64a1aa1 100644 --- a/tests/libtest/lib578.c +++ b/tests/libtest/lib578.c @@ -26,9 +26,9 @@ #include "memdebug.h" /* The size of data should be kept below MAX_INITIAL_POST_SIZE! */ -static char data[]="this is a short string.\n"; +static char testdata[]="this is a short string.\n"; -static size_t data_size = sizeof(data) / sizeof(char); +static size_t data_size = sizeof(testdata) / sizeof(char); static int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) @@ -75,7 +75,7 @@ CURLcode test(char *URL) /* Set the expected POST size */ test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)data_size); - test_setopt(curl, CURLOPT_POSTFIELDS, data); + test_setopt(curl, CURLOPT_POSTFIELDS, testdata); /* we want to use our own progress function */ CURL_IGNORE_DEPRECATION( diff --git a/tests/libtest/lib579.c b/tests/libtest/lib579.c index 7e314c308c..9b1591fad1 100644 --- a/tests/libtest/lib579.c +++ b/tests/libtest/lib579.c @@ -25,7 +25,7 @@ #include "memdebug.h" -static const char * const post[]={ +static const char * const testpost[]={ "one", "two", "three", @@ -81,7 +81,7 @@ static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) if(size*nmemb < 1) return 0; - data = post[pooh->counter]; + data = testpost[pooh->counter]; if(data) { size_t len = strlen(data); diff --git a/tests/libtest/lib582.c b/tests/libtest/lib582.c index 5f393d6621..d1609a83d3 100644 --- a/tests/libtest/lib582.c +++ b/tests/libtest/lib582.c @@ -31,15 +31,13 @@ #define TEST_HANG_TIMEOUT 60 * 1000 -struct Sockets -{ +struct Sockets { curl_socket_t *sockets; int count; /* number of sockets actually stored in array */ int max_count; /* max number of sockets that fit in allocated array */ }; -struct ReadWriteSockets -{ +struct ReadWriteSockets { struct Sockets read, write; }; diff --git a/tests/libtest/lib586.c b/tests/libtest/lib586.c index 8a510a586b..c6d9f7d7f1 100644 --- a/tests/libtest/lib586.c +++ b/tests/libtest/lib586.c @@ -38,8 +38,8 @@ struct userdata { }; /* lock callback */ -static void my_lock(CURL *handle, curl_lock_data data, - curl_lock_access laccess, void *useptr) +static void test_lock(CURL *handle, curl_lock_data data, + curl_lock_access laccess, void *useptr) { const char *what; struct userdata *user = (struct userdata *)useptr; @@ -69,7 +69,7 @@ static void my_lock(CURL *handle, curl_lock_data data, } /* unlock callback */ -static void my_unlock(CURL *handle, curl_lock_data data, void *useptr) +static void test_unlock(CURL *handle, curl_lock_data data, void *useptr) { const char *what; struct userdata *user = (struct userdata *)useptr; @@ -96,7 +96,7 @@ static void my_unlock(CURL *handle, curl_lock_data data, void *useptr) } /* the dummy thread function */ -static void *fire(void *ptr) +static void *test_fire(void *ptr) { CURLcode code; struct Tdata *tdata = (struct Tdata*)ptr; @@ -160,11 +160,11 @@ CURLcode test(char *URL) if(CURLSHE_OK == scode) { printf("CURLSHOPT_LOCKFUNC\n"); - scode = curl_share_setopt(share, CURLSHOPT_LOCKFUNC, my_lock); + scode = curl_share_setopt(share, CURLSHOPT_LOCKFUNC, test_lock); } if(CURLSHE_OK == scode) { printf("CURLSHOPT_UNLOCKFUNC\n"); - scode = curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, my_unlock); + scode = curl_share_setopt(share, CURLSHOPT_UNLOCKFUNC, test_unlock); } if(CURLSHE_OK == scode) { printf("CURLSHOPT_USERDATA\n"); @@ -193,7 +193,7 @@ CURLcode test(char *URL) /* simulate thread, direct call of "thread" function */ printf("*** run %d\n",i); - fire(&tdata); + test_fire(&tdata); } diff --git a/tests/libtest/lib643.c b/tests/libtest/lib643.c index 9207caae82..bd7f5e0f8c 100644 --- a/tests/libtest/lib643.c +++ b/tests/libtest/lib643.c @@ -25,7 +25,7 @@ #include "memdebug.h" -static char data[]= +static char testdata[]= "dummy\n"; struct WriteThis { @@ -56,7 +56,7 @@ static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) return 0; /* no more data left to deliver */ } -static CURLcode once(char *URL, bool oldstyle) +static CURLcode test_once(char *URL, bool oldstyle) { CURL *curl; CURLcode res = CURLE_OK; @@ -67,9 +67,9 @@ static CURLcode once(char *URL, bool oldstyle) struct WriteThis pooh2; curl_off_t datasize = -1; - pooh.readptr = data; + pooh.readptr = testdata; #ifndef LIB645 - datasize = (curl_off_t)strlen(data); + datasize = (curl_off_t)strlen(testdata); #endif pooh.sizeleft = datasize; @@ -122,9 +122,9 @@ static CURLcode once(char *URL, bool oldstyle) /* Now add the same data with another name and make it not look like a file upload but still using the callback */ - pooh2.readptr = data; + pooh2.readptr = testdata; #ifndef LIB645 - datasize = (curl_off_t)strlen(data); + datasize = (curl_off_t)strlen(testdata); #endif pooh2.sizeleft = datasize; @@ -256,9 +256,9 @@ CURLcode test(char *URL) return TEST_ERR_MAJOR_BAD; } - res = once(URL, TRUE); /* old */ + res = test_once(URL, TRUE); /* old */ if(!res) - res = once(URL, FALSE); /* new */ + res = test_once(URL, FALSE); /* new */ if(!res) res = cyclic_add(); diff --git a/tests/libtest/lib650.c b/tests/libtest/lib650.c index 2945e366f6..f0d459e663 100644 --- a/tests/libtest/lib650.c +++ b/tests/libtest/lib650.c @@ -25,10 +25,10 @@ #include "memdebug.h" -static char data[] = +static char testdata[] = "this is what we post to the silly web server"; -static const char name[] = "fieldname"; +static const char testname[] = "fieldname"; /* This test attempts to use all form API features that are not @@ -81,8 +81,8 @@ CURLcode test(char *URL) headers = headers2; CURL_IGNORE_DEPRECATION( formrc = curl_formadd(&formpost, &lastptr, - CURLFORM_COPYNAME, &name, - CURLFORM_COPYCONTENTS, &data, + CURLFORM_COPYNAME, &testname, + CURLFORM_COPYCONTENTS, &testdata, CURLFORM_CONTENTHEADER, headers, CURLFORM_END); ) @@ -91,20 +91,20 @@ CURLcode test(char *URL) goto test_cleanup; } - contentlength = (long)(strlen(data) - 1); + contentlength = (long)(strlen(testdata) - 1); CURL_IGNORE_DEPRECATION( /* Use a form array for the non-copy test. */ formarray[0].option = CURLFORM_PTRCONTENTS; - formarray[0].value = data; + formarray[0].value = testdata; formarray[1].option = CURLFORM_CONTENTSLENGTH; formarray[1].value = (char *)(size_t)contentlength; formarray[2].option = CURLFORM_END; formarray[2].value = NULL; formrc = curl_formadd(&formpost, &lastptr, - CURLFORM_PTRNAME, name, - CURLFORM_NAMELENGTH, strlen(name) - 1, + CURLFORM_PTRNAME, testname, + CURLFORM_NAMELENGTH, strlen(testname) - 1, CURLFORM_ARRAY, formarray, CURLFORM_FILENAME, "remotefile.txt", CURLFORM_END); @@ -117,7 +117,7 @@ CURLcode test(char *URL) /* Now change in-memory data to affect CURLOPT_PTRCONTENTS value. Copied values (first field) must not be affected. CURLOPT_PTRNAME actually copies the name thus we do not test this here. */ - data[0]++; + testdata[0]++; CURL_IGNORE_DEPRECATION( /* Check multi-files and content type propagation. */ diff --git a/tests/libtest/lib651.c b/tests/libtest/lib651.c index 3993dfa622..7fb97def86 100644 --- a/tests/libtest/lib651.c +++ b/tests/libtest/lib651.c @@ -25,7 +25,7 @@ #include "memdebug.h" -static char buffer[17000]; /* more than 16K */ +static char testbuf[17000]; /* more than 16K */ CURLcode test(char *URL) { @@ -37,12 +37,12 @@ CURLcode test(char *URL) /* create a buffer with AAAA...BBBBB...CCCC...etc */ int i; - int size = (int)sizeof(buffer)/1000; + int size = (int)sizeof(testbuf)/1000; for(i = 0; i < size ; i++) - memset(&buffer[i * 1000], 65 + i, 1000); + memset(&testbuf[i * 1000], 65 + i, 1000); - buffer[ sizeof(buffer)-1] = 0; /* null-terminate */ + testbuf[sizeof(testbuf)-1] = 0; /* null-terminate */ if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); @@ -53,7 +53,7 @@ CURLcode test(char *URL) /* Check proper name and data copying. */ formrc = curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "hello", - CURLFORM_COPYCONTENTS, buffer, + CURLFORM_COPYCONTENTS, testbuf, CURLFORM_END); ) if(formrc) diff --git a/tests/libtest/lib652.c b/tests/libtest/lib652.c index 50c645fffd..591aa7269a 100644 --- a/tests/libtest/lib652.c +++ b/tests/libtest/lib652.c @@ -25,7 +25,7 @@ #include "memdebug.h" -static char buffer[17000]; /* more than 16K */ +static char testbuf[17000]; /* more than 16K */ CURLcode test(char *URL) { @@ -35,12 +35,12 @@ CURLcode test(char *URL) curl_mimepart *part; struct curl_slist *recipients = NULL; - /* create a buffer with AAAA...BBBBB...CCCC...etc */ + /* create a testbuf with AAAA...BBBBB...CCCC...etc */ int i; - int size = (int)sizeof(buffer) / 10; + int size = (int)sizeof(testbuf) / 10; for(i = 0; i < size ; i++) - memset(&buffer[i * 10], 65 + (i % 26), 10); + memset(&testbuf[i * 10], 65 + (i % 26), 10); if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); @@ -77,7 +77,7 @@ CURLcode test(char *URL) fprintf(stderr, "curl_mime_type() failed\n"); goto test_cleanup; } - res = curl_mime_data(part, buffer, sizeof(buffer)); + res = curl_mime_data(part, testbuf, sizeof(testbuf)); if(res) { fprintf(stderr, "curl_mime_data() failed\n"); goto test_cleanup; diff --git a/tests/libtest/lib654.c b/tests/libtest/lib654.c index b85edcff85..66ec29d17c 100644 --- a/tests/libtest/lib654.c +++ b/tests/libtest/lib654.c @@ -25,7 +25,7 @@ #include "memdebug.h" -static char data[]= +static char testdata[]= "dummy\n"; struct WriteThis { @@ -94,8 +94,8 @@ CURLcode test(char *URL) test_setopt(easy, CURLOPT_HEADER, 1L); /* Prepare the callback structure. */ - pooh.readptr = data; - pooh.sizeleft = (curl_off_t) strlen(data); + pooh.readptr = testdata; + pooh.sizeleft = (curl_off_t) strlen(testdata); pooh.freecount = 0; /* Build the mime tree. */ diff --git a/tests/libtest/lib666.c b/tests/libtest/lib666.c index e010e27f18..dd172be4ab 100644 --- a/tests/libtest/lib666.c +++ b/tests/libtest/lib666.c @@ -25,7 +25,7 @@ #include "memdebug.h" -static char buffer[17000]; /* more than 16K */ +static char testbuf[17000]; /* more than 16K */ CURLcode test(char *URL) { @@ -37,12 +37,12 @@ CURLcode test(char *URL) /* Checks huge binary-encoded mime post. */ - /* Create a buffer with pseudo-binary data. */ - for(i = 0; i < sizeof(buffer); i++) + /* Create a testbuf with pseudo-binary data. */ + for(i = 0; i < sizeof(testbuf); i++) if(i % 77 == 76) - buffer[i] = '\n'; + testbuf[i] = '\n'; else - buffer[i] = (char) (0x41 + i % 26); /* A...Z */ + testbuf[i] = (char) (0x41 + i % 26); /* A...Z */ if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); @@ -79,7 +79,7 @@ CURLcode test(char *URL) fprintf(stderr, "curl_mime_filename() failed\n"); goto test_cleanup; } - res = curl_mime_data(part, buffer, sizeof(buffer)); + res = curl_mime_data(part, testbuf, sizeof(testbuf)); if(res) { fprintf(stderr, "curl_mime_data() failed\n"); goto test_cleanup; diff --git a/tests/libtest/lib667.c b/tests/libtest/lib667.c index c54323277c..d190601464 100644 --- a/tests/libtest/lib667.c +++ b/tests/libtest/lib667.c @@ -25,7 +25,7 @@ #include "memdebug.h" -static char data[]= +static char testdata[]= "dummy"; struct WriteThis { @@ -84,8 +84,8 @@ CURLcode test(char *URL) test_setopt(easy, CURLOPT_HEADER, 1L); /* Prepare the callback structure. */ - pooh.readptr = data; - pooh.sizeleft = (curl_off_t) strlen(data); + pooh.readptr = testdata; + pooh.sizeleft = (curl_off_t) strlen(testdata); /* Build the mime tree. */ mime = curl_mime_init(easy); diff --git a/tests/libtest/lib668.c b/tests/libtest/lib668.c index 2ee0008dfb..141e0ea571 100644 --- a/tests/libtest/lib668.c +++ b/tests/libtest/lib668.c @@ -25,7 +25,7 @@ #include "memdebug.h" -static char data[]= "dummy"; +static char testdata[]= "dummy"; struct WriteThis { char *readptr; @@ -77,8 +77,8 @@ CURLcode test(char *URL) test_setopt(easy, CURLOPT_HEADER, 1L); /* Prepare the callback structures. */ - pooh1.readptr = data; - pooh1.sizeleft = (curl_off_t) strlen(data); + pooh1.readptr = testdata; + pooh1.sizeleft = (curl_off_t) strlen(testdata); pooh2 = pooh1; /* Build the mime tree. */ @@ -86,7 +86,7 @@ CURLcode test(char *URL) part = curl_mime_addpart(mime); curl_mime_name(part, "field1"); /* Early end of data detection can be done because the data size is known. */ - curl_mime_data_cb(part, (curl_off_t) strlen(data), + curl_mime_data_cb(part, (curl_off_t) strlen(testdata), read_callback, NULL, NULL, &pooh1); part = curl_mime_addpart(mime); curl_mime_name(part, "field2"); diff --git a/tests/libtest/lib670.c b/tests/libtest/lib670.c index 8c4a7b9651..4f797c583a 100644 --- a/tests/libtest/lib670.c +++ b/tests/libtest/lib670.c @@ -30,7 +30,7 @@ #define PAUSE_TIME 5 -static const char name[] = "field"; +static const char testname[] = "field"; struct ReadThis { CURL *easy; @@ -139,7 +139,7 @@ CURLcode test(char *URL) /* Build the mime tree. */ mime = curl_mime_init(pooh.easy); part = curl_mime_addpart(mime); - res = curl_mime_name(part, name); + res = curl_mime_name(part, testname); if(res != CURLE_OK) { fprintf(stderr, "Something went wrong when building the mime structure: %d\n", @@ -157,7 +157,7 @@ CURLcode test(char *URL) CURL_IGNORE_DEPRECATION( /* Build the form. */ formrc = curl_formadd(&formpost, &lastptr, - CURLFORM_COPYNAME, name, + CURLFORM_COPYNAME, testname, CURLFORM_STREAM, &pooh, CURLFORM_CONTENTLEN, (curl_off_t) 2, CURLFORM_END); diff --git a/tests/libtest/lib677.c b/tests/libtest/lib677.c index d3bc1574eb..ebb9f40848 100644 --- a/tests/libtest/lib677.c +++ b/tests/libtest/lib677.c @@ -27,7 +27,7 @@ #include "warnless.h" #include "memdebug.h" -static const char cmd[] = "A1 IDLE\r\n"; +static const char testcmd[] = "A1 IDLE\r\n"; static char testbuf[1024]; CURLcode test(char *URL) @@ -82,7 +82,8 @@ CURLcode test(char *URL) if(!state) { CURLcode ec; - ec = curl_easy_send(curl, cmd + pos, sizeof(cmd) - 1 - pos, &len); + ec = curl_easy_send(curl, testcmd + pos, + sizeof(testcmd) - 1 - pos, &len); if(ec == CURLE_AGAIN) { continue; } @@ -96,7 +97,7 @@ CURLcode test(char *URL) pos += len; else pos = 0; - if(pos == sizeof(cmd) - 1) { + if(pos == sizeof(testcmd) - 1) { state++; pos = 0; } diff --git a/tests/libtest/libntlmconnect.c b/tests/libtest/libntlmconnect.c index e2e5b64103..9cbcb50bb5 100644 --- a/tests/libtest/libntlmconnect.c +++ b/tests/libtest/libntlmconnect.c @@ -33,31 +33,31 @@ #define TEST_HANG_TIMEOUT 60 * 1000 #define MAX_EASY_HANDLES 3 -static int counter[MAX_EASY_HANDLES]; -static CURL *easy[MAX_EASY_HANDLES]; -static curl_socket_t sockets[MAX_EASY_HANDLES]; -static CURLcode res = CURLE_OK; +static int ntlm_counter[MAX_EASY_HANDLES]; +static CURL *ntlm_easy[MAX_EASY_HANDLES]; +static curl_socket_t ntlm_sockets[MAX_EASY_HANDLES]; +static CURLcode ntlmcb_res = CURLE_OK; static size_t callback(char *ptr, size_t size, size_t nmemb, void *data) { - ssize_t idx = ((CURL **) data) - easy; + ssize_t idx = ((CURL **) data) - ntlm_easy; curl_socket_t sock; long longdata; CURLcode code; const size_t failure = (size && nmemb) ? 0 : 1; (void)ptr; - counter[idx] += (int)(size * nmemb); + ntlm_counter[idx] += (int)(size * nmemb); /* Get socket being used for this easy handle, otherwise CURL_SOCKET_BAD */ CURL_IGNORE_DEPRECATION( - code = curl_easy_getinfo(easy[idx], CURLINFO_LASTSOCKET, &longdata); + code = curl_easy_getinfo(ntlm_easy[idx], CURLINFO_LASTSOCKET, &longdata); ) if(CURLE_OK != code) { fprintf(stderr, "%s:%d curl_easy_getinfo() failed, " "with code %d (%s)\n", __FILE__, __LINE__, (int)code, curl_easy_strerror(code)); - res = TEST_ERR_MAJOR_BAD; + ntlmcb_res = TEST_ERR_MAJOR_BAD; return failure; } if(longdata == -1L) @@ -67,16 +67,16 @@ static size_t callback(char *ptr, size_t size, size_t nmemb, void *data) if(sock != CURL_SOCKET_BAD) { /* Track relationship between this easy handle and the socket. */ - if(sockets[idx] == CURL_SOCKET_BAD) { + if(ntlm_sockets[idx] == CURL_SOCKET_BAD) { /* An easy handle without previous socket, record the socket. */ - sockets[idx] = sock; + ntlm_sockets[idx] = sock; } - else if(sock != sockets[idx]) { + else if(sock != ntlm_sockets[idx]) { /* An easy handle with a socket different to previously tracked one, log and fail right away. Known bug #37. */ fprintf(stderr, "Handle %d started on socket %d and moved to %d\n", - curlx_sztosi(idx), (int)sockets[idx], (int)sock); - res = TEST_ERR_MAJOR_BAD; + curlx_sztosi(idx), (int)ntlm_sockets[idx], (int)sock); + ntlmcb_res = TEST_ERR_MAJOR_BAD; return failure; } } @@ -91,6 +91,7 @@ enum HandleState { CURLcode test(char *url) { + CURLcode res = CURLE_OK; CURLM *multi = NULL; int running; int i; @@ -107,8 +108,8 @@ CURLcode test(char *url) } for(i = 0; i < MAX_EASY_HANDLES; ++i) { - easy[i] = NULL; - sockets[i] = CURL_SOCKET_BAD; + ntlm_easy[i] = NULL; + ntlm_sockets[i] = CURL_SOCKET_BAD; } res_global_init(CURL_GLOBAL_ALL); @@ -130,28 +131,31 @@ CURLcode test(char *url) /* Start a new handle if we aren't at the max */ if(state == ReadyForNewHandle) { - easy_init(easy[num_handles]); + easy_init(ntlm_easy[num_handles]); if(num_handles % 3 == 2) { msnprintf(full_url, urllen, "%s0200", url); - easy_setopt(easy[num_handles], CURLOPT_HTTPAUTH, CURLAUTH_NTLM); + easy_setopt(ntlm_easy[num_handles], CURLOPT_HTTPAUTH, CURLAUTH_NTLM); } else { msnprintf(full_url, urllen, "%s0100", url); - easy_setopt(easy[num_handles], CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + easy_setopt(ntlm_easy[num_handles], CURLOPT_HTTPAUTH, CURLAUTH_BASIC); } - easy_setopt(easy[num_handles], CURLOPT_FRESH_CONNECT, 1L); - easy_setopt(easy[num_handles], CURLOPT_URL, full_url); - easy_setopt(easy[num_handles], CURLOPT_VERBOSE, 1L); - easy_setopt(easy[num_handles], CURLOPT_HTTPGET, 1L); - easy_setopt(easy[num_handles], CURLOPT_USERPWD, "testuser:testpass"); - easy_setopt(easy[num_handles], CURLOPT_WRITEFUNCTION, callback); - easy_setopt(easy[num_handles], CURLOPT_WRITEDATA, easy + num_handles); - easy_setopt(easy[num_handles], CURLOPT_HEADER, 1L); - - multi_add_handle(multi, easy[num_handles]); + easy_setopt(ntlm_easy[num_handles], CURLOPT_FRESH_CONNECT, 1L); + easy_setopt(ntlm_easy[num_handles], CURLOPT_URL, full_url); + easy_setopt(ntlm_easy[num_handles], CURLOPT_VERBOSE, 1L); + easy_setopt(ntlm_easy[num_handles], CURLOPT_HTTPGET, 1L); + easy_setopt(ntlm_easy[num_handles], CURLOPT_USERPWD, + "testuser:testpass"); + easy_setopt(ntlm_easy[num_handles], CURLOPT_WRITEFUNCTION, callback); + easy_setopt(ntlm_easy[num_handles], CURLOPT_WRITEDATA, + ntlm_easy + num_handles); + easy_setopt(ntlm_easy[num_handles], CURLOPT_HEADER, 1L); + + multi_add_handle(multi, ntlm_easy[num_handles]); num_handles += 1; state = NeedSocketForNewHandle; + res = ntlmcb_res; } multi_perform(multi, &running); @@ -223,9 +227,9 @@ test_cleanup: /* proper cleanup sequence - type PB */ for(i = 0; i < MAX_EASY_HANDLES; i++) { - printf("Data connection %d: %d\n", i, counter[i]); - curl_multi_remove_handle(multi, easy[i]); - curl_easy_cleanup(easy[i]); + printf("Data connection %d: %d\n", i, ntlm_counter[i]); + curl_multi_remove_handle(multi, ntlm_easy[i]); + curl_easy_cleanup(ntlm_easy[i]); } curl_multi_cleanup(multi); diff --git a/tests/libtest/mk-lib1521.pl b/tests/libtest/mk-lib1521.pl index 0eee841c27..b5dae5cb94 100755 --- a/tests/libtest/mk-lib1521.pl +++ b/tests/libtest/mk-lib1521.pl @@ -201,7 +201,7 @@ print <
] + +use strict; +use warnings; + +my $src_dir = @ARGV ? $ARGV[0] : "."; + +# Read list of tests +open my $fh, "<", "$src_dir/Makefile.inc" or die "Cannot open '$src_dir/Makefile.inc': $!"; + +print <
) { + chomp $line; + if($line =~ /([a-z0-9]+)_SOURCES\ =\ ([a-z0-9]+)\.c/) { + my $name = $1; + my $namu = uc($name); + my $src = "$2.c"; + + # Make common symbols unique across test sources + foreach my $symb ("test", @reused_symbols) { + print "#undef $symb\n"; + print "#define $symb ${symb}_$name\n"; + } + + print "#define $namu\n"; + print "#include \"$src\"\n"; + print "#undef $namu\n"; + + # Reset macros re-used by multiple tests + foreach my $undef ("test", @reused_macros) { + print "#undef $undef\n"; + } + + print "\n"; + + $tlist .= " {\"$name\", test_$name},\n"; + } +} + +close $fh; + +print <