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
This commit is contained in:
Viktor Szakats
2024-09-02 14:46:00 +02:00
parent 6a1dcdc5d2
commit 71cf0d1fca
86 changed files with 1008 additions and 497 deletions

View File

@@ -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:

View File

@@ -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'

View File

@@ -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 \

View File

@@ -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

View File

@@ -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

View File

@@ -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)'

View File

@@ -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'

View File

@@ -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)" \

View File

@@ -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 \

View File

@@ -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'

View File

@@ -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= \

View File

@@ -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

View File

@@ -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}" \

View File

@@ -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'

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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 \

View File

@@ -22,6 +22,7 @@
*
***************************************************************************/
#include "test.h"
#include "first.h"
#ifdef HAVE_LOCALE_H
# include <locale.h> /* 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

38
tests/libtest/first.h Normal file
View File

@@ -0,0 +1,38 @@
#ifndef HEADER_LIBTEST_FIRST_H
#define HEADER_LIBTEST_FIRST_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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 <curl/curl.h>
typedef CURLcode (*test_func_t)(char *);
#ifdef CURLTESTS_BUNDLED
struct onetest {
const char *name;
test_func_t ptr;
};
#endif
#endif /* HEADER_LIBTEST_FIRST_H */

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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");

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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! */

View File

@@ -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++)

View File

@@ -31,24 +31,24 @@
#include <stdio.h>
#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;
}

View File

@@ -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;
}

View File

@@ -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 */

View File

@@ -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);

View File

@@ -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;

View File

@@ -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")) {

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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");

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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;
};

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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";

View File

@@ -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();

View File

@@ -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 <limits.h>
@@ -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

View File

@@ -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(

View File

@@ -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);

View File

@@ -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;
};

View File

@@ -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);
}

View File

@@ -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();

View File

@@ -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. */

View File

@@ -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)

View File

@@ -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;

View File

@@ -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. */

View File

@@ -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;

View File

@@ -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);

View File

@@ -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");

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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);
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, easy[num_handles]);
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);

View File

@@ -201,7 +201,7 @@ print <<HEADER
/* This source code is generated by mk-lib1521.pl ! */
struct data {
struct testdata {
char *blaha;
};
@@ -332,7 +332,7 @@ CURLcode test(char *URL)
struct curl_httppost *httppost = NULL;
curl_mime *mimepost = NULL;
FILE *stream = stderr;
struct data object;
struct testdata object;
char *charp;
long val;
curl_off_t oval;

View File

@@ -70,8 +70,10 @@ extern int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
extern void wait_ms(int ms); /* wait this many milliseconds */
#ifndef CURLTESTS_BUNDLED_TEST_H
extern CURLcode test(char *URL); /* the actual test function provided by each
individual libXXX.c file */
#endif
extern char *hexdump(const unsigned char *buffer, size_t len);
@@ -491,6 +493,7 @@ extern int unitfail;
#define global_init(A) \
chk_global_init((A), (__FILE__), (__LINE__))
#ifndef CURLTESTS_BUNDLED_TEST_H
#define NO_SUPPORT_BUILT_IN \
CURLcode test(char *URL) \
{ \
@@ -498,7 +501,22 @@ extern int unitfail;
fprintf(stderr, "Missing support\n"); \
return (CURLcode)1; \
}
#endif
/* ---------------------------------------------------------------- */
#endif /* HEADER_CURL_TEST_H */
#ifdef CURLTESTS_BUNDLED_TEST_H
extern CURLcode test(char *URL); /* the actual test function provided by each
individual libXXX.c file */
#undef NO_SUPPORT_BUILT_IN
#define NO_SUPPORT_BUILT_IN \
CURLcode test(char *URL) \
{ \
(void)URL; \
fprintf(stderr, "Missing support\n"); \
return (CURLcode)1; \
}
#endif

74
tests/mk-bundle-hints.sh Executable file
View File

@@ -0,0 +1,74 @@
#!/usr/bin/env bash
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Viktor Szakats
#
# 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
#
###########################################################################
detect_in_reused_sources=1
if [ "$detect_in_reused_sources" = '1' ]; then
# Make symlinks for all re-used sources
grep -E '^(lib|unit)[0-9]+_SOURCES = ' libtest/Makefile.inc unit/Makefile.inc \
| sed -E 's@^([a-z]+)/[a-zA-Z.]+:(lib|unit)([0-9]+)_SOURCES = (lib|unit)([0-9]+).+@\1 \2 \3 \5@g' | \
while read -r l; do
if [[ "${l}" =~ ([a-z]+)\ ([a-z]+)\ ([0-9]+)\ ([0-9]+) ]]; then
trg="${BASH_REMATCH[3]}"
src="${BASH_REMATCH[4]}"
if [ "${trg}" != "${src}" ]; then
dir="${BASH_REMATCH[1]}"
pfx="${BASH_REMATCH[2]}"
ln -s "${pfx}${src}.c" "${dir}/${pfx}${trg}.c"
fi
fi
done
fi
# Look for symbols possibly re-used in multiple sources.
#
# Falsely picks ups symbols in re-used sources, but guarded for a single use.
# Misses shadowed variables.
# shellcheck disable=SC2046
grep -E '^ *(static|struct) +' $(find libtest unit -maxdepth 1 -name 'lib*.c' -o -name 'unit*.c' -o -name 'mk-*.pl') \
| grep -E '^(libtest|unit)/' \
| grep -E '\.(c|pl):(static|struct)( +[a-zA-Z_* ]+)? +[a-zA-Z_][a-zA-Z0-9_]+ *' | sort -u \
| grep -o -E '[a-zA-Z_][a-zA-Z0-9_]+ *[=;[({]' | tr -d '=;[({ ' \
| grep -v -E '^(NULL$|sizeof$|CURLE_)' \
| sort | uniq -c | sort -k 2 | grep -v -E '^ +1 ' \
| awk '{print " \"" $2 "\","}'
echo '---'
# Extract list of macros that may be re-used by multiple tests.
#
# Picks up false-positive when the macro is defined to the same value everywhere.
# shellcheck disable=SC2046
grep -E '^ *# *define +' $(find libtest unit -maxdepth 1 -name 'lib*.c' -o -name 'unit*.c' -o -name 'mk-*.pl') \
| grep -E '^(libtest|unit)/' \
| grep -o -E '.+\.(c|pl): *# *define +[A-Z_][A-Z0-9_]+' | sort -u \
| grep -o -E '[A-Z_][A-Z0-9_]+' \
| sort | uniq -c | sort -k 2 | grep -v -E '^ +1 ' \
| awk '{print " \"" $2 "\","}'
if [ "$detect_in_reused_sources" = '1' ]; then
# Delete symlinks for all re-used sources
find libtest unit -type l -delete
fi

162
tests/mk-bundle.pl Executable file
View File

@@ -0,0 +1,162 @@
#!/usr/bin/env perl
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Viktor Szakats
#
# 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
#
###########################################################################
# Bundle up individual tests into a single binary. The resulting binary can run
# individual tests by passing their name (without '.c') as the first argument.
#
# Usage: mk-bundle.pl [<directory>]
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 <<HEADER
/* !checksrc! disable COPYRIGHT all */
/* !checksrc! disable INCLUDEDUP all */
#define CURLTESTS_BUNDLED
#define CURLTESTS_BUNDLED_TEST_H
#include "first.h"
HEADER
;
# TODO: Some of these might be subject for de-duplication or sync.
my @reused_symbols = (
"ReadThis",
"ReadWriteSockets",
"Sockets",
"Tdata",
"WriteThis",
"addFd",
"checkFdSet",
"checkForCompletion",
"close_file_descriptors",
"curl", # shadow
"curlSocketCallback",
"curlTimerCallback",
"cyclic_add",
"easy", # unit
"fopen_works",
"getMicroSecondTimeout",
"geterr",
"hash_static", # unit
"header_callback",
"ioctlcallback",
"msgbuff",
"mydtor", # unit
"num_open",
"progress_callback",
"read_callback",
"readcallback",
"recv_pong",
"removeFd",
"rlim2str",
"run_thread",
"send_ping",
"showem",
"store_errmsg",
"suburl",
"test_failure", # shadow
"test_fire",
"test_lock",
"test_once",
"test_parse", # unit
"test_rlimit",
"test_unlock",
"testbuf",
"testcase", # unit
"testdata",
"testfd",
"testname",
"testpost",
"tests", # unit
"teststring",
"trailers_callback",
"transfer_status",
"unit_setup", # unit
"unit_stop", # unit
"updateFdSet",
"userdata",
"websocket",
"websocket_close",
"write_callback",
"write_cb",
"writecb",
"xferinfo",
);
# TODO: Some of these may be #undef-ed manually at the end of each source
my @reused_macros = (
"HEADER_REQUEST",
"NUM_HANDLES",
"SAFETY_MARGIN",
"TEST_HANG_TIMEOUT",
);
my $tlist = "";
while(my $line = <$fh>) {
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 <<FOOTER
static const struct onetest s_tests[] = {
$tlist};
#undef CURLTESTS_BUNDLED_TEST_H
#include "first.c"
FOOTER
;

View File

@@ -848,10 +848,11 @@ sub singletest_run {
my @codepieces = getpart("client", "tool");
my $tool="";
my $tool_name=""; # without exe extension
if(@codepieces) {
$tool = $codepieces[0];
chomp $tool;
$tool .= exe_ext('TOOL');
$tool_name = $codepieces[0];
chomp $tool_name;
$tool = $tool_name . exe_ext('TOOL');
}
my $disablevalgrind;
@@ -904,20 +905,36 @@ sub singletest_run {
# Default the tool to a unit test with the same name as the test spec
if($keywords{"unittest"} && !$tool) {
$tool="unit$testnum";
$tool_name="unit$testnum";
$tool = $tool_name;
}
if($tool =~ /^lib/) {
$CMDLINE="$LIBDIR/$tool";
if($bundle) {
$CMDLINE="$LIBDIR/libtests";
}
else {
$CMDLINE="$LIBDIR/$tool";
}
}
elsif($tool =~ /^unit/) {
$CMDLINE="$UNITDIR/$tool";
if($bundle) {
$CMDLINE="$UNITDIR/units";
}
else {
$CMDLINE="$UNITDIR/$tool";
}
}
if(! -f $CMDLINE) {
logmsg " $testnum: IGNORED: The tool set in the test case for this: '$tool' does not exist\n";
return (-1, 0, 0, "", "", 0);
}
if($bundle) {
$CMDLINE.=" $tool_name";
}
$DBGCURL=$CMDLINE;
}

View File

@@ -91,6 +91,11 @@ Provide a path to a curl binary to talk to APIs (currently only CI test APIs).
Display test results in automake style output (`PASS/FAIL: [number] [name]`).
## `-bundle`
Run tests via bundled test binaries. Bundled test binaries contain all tests,
and the test name passed as the first argument selects which test run.
## `-c\<curl\>`
Provide a path to a custom curl binary to run the tests with. Default is the

View File

@@ -869,8 +869,9 @@ sub checksystemfeatures {
"*\n");
}
logmsg sprintf("* Env: %s%s%s", $valgrind?"Valgrind ":"",
logmsg sprintf("* Env: %s%s%s%s", $valgrind?"Valgrind ":"",
$run_event_based?"event-based ":"",
$bundle?"bundle ":"",
$nghttpx_h3);
logmsg sprintf("%s\n", $libtool?"Libtool ":"");
logmsg ("* Seed: $randseed\n");
@@ -2240,6 +2241,10 @@ while(@ARGV) {
$ACURL=shell_quote($ARGV[1]);
shift @ARGV;
}
elsif ($ARGV[0] eq "-bundle") {
# use test bundles
$bundle=1;
}
elsif ($ARGV[0] eq "-d") {
# have the servers display protocol output
$debugprotocol=1;
@@ -2417,6 +2422,7 @@ Usage: runtests.pl [options] [test selection(s)]
-a continue even if a test fails
-ac path use this curl only to talk to APIs (currently only CI test APIs)
-am automake style output PASS/FAIL: [number] [name]
-bundle use test bundles
-c path use this curl executable
-d display server debug info
-e event-based execution

View File

@@ -3,3 +3,4 @@
# SPDX-License-Identifier: curl
/unit[0-9][0-9][0-9][0-9]
units.c

View File

@@ -22,13 +22,26 @@
#
###########################################################################
# Get 'UNITPROGS', 'UNITFILES' variables
# Get 'UNITPROGS', '*_SOURCES', 'FIRSTFILES' variables
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
if(CURL_TEST_BUNDLES)
add_custom_command(
OUTPUT "unit_bundle.c"
COMMAND ${PERL_EXECUTABLE} "${CURL_SOURCE_DIR}/tests/mk-bundle.pl" "${CMAKE_CURRENT_SOURCE_DIR}" > "unit_bundle.c"
DEPENDS
"${CURL_SOURCE_DIR}/tests/mk-bundle.pl" ${FIRSTFILES}
"${CMAKE_CURRENT_SOURCE_DIR}/Makefile.inc"
VERBATIM)
set(UNITPROGS "units")
set(units_SOURCES "unit_bundle.c")
endif()
foreach(_target IN LISTS UNITPROGS)
set(_target_name "${_target}")
add_executable(${_target_name} EXCLUDE_FROM_ALL "${_target}.c" ${UNITFILES})
add_executable(${_target_name} EXCLUDE_FROM_ALL ${${_target}_SOURCES})
add_dependencies(testdeps ${_target_name})
target_link_libraries(${_target_name} curltool curlu)
target_include_directories(${_target_name} PRIVATE
@@ -37,6 +50,9 @@ foreach(_target IN LISTS UNITPROGS)
"${CURL_SOURCE_DIR}/src"
"${CURL_SOURCE_DIR}/tests/libtest"
)
if(CURL_TEST_BUNDLES)
target_include_directories(${_target_name} PRIVATE "${CURL_SOURCE_DIR}/tests/unit")
endif()
set_target_properties(${_target_name} PROPERTIES
OUTPUT_NAME "${_target}"
PROJECT_LABEL "Test unit ${_target}")

View File

@@ -36,7 +36,8 @@ AM_CPPFLAGS = -I$(top_srcdir)/include \
-I$(top_builddir)/lib \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/src \
-I$(top_srcdir)/tests/libtest
-I$(top_srcdir)/tests/libtest \
-I$(top_srcdir)/tests/unit
EXTRA_DIST = CMakeLists.txt README.md
@@ -51,6 +52,23 @@ LDADD = $(top_builddir)/src/libcurltool.la \
AM_CPPFLAGS += -DCURL_STATICLIB -DUNITTESTS
if BUILD_UNITTESTS
if USE_TEST_BUNDLES
unit_bundle.c: $(top_srcdir)/tests/mk-bundle.pl
@PERL@ $(top_srcdir)/tests/mk-bundle.pl $(srcdir) > unit_bundle.c
noinst_PROGRAMS = units
nodist_units_SOURCES = unit_bundle.c
CLEANFILES = unit_bundle.c
else
# Makefile.inc provides neat definitions
include Makefile.inc
noinst_PROGRAMS = $(UNITPROGS)
endif
else
noinst_PROGRAMS =
endif
CHECKSRC = $(CS_$(V))
CS_0 = @echo " RUN " $@;
CS_1 =
@@ -58,12 +76,3 @@ CS_ = $(CS_0)
checksrc:
$(CHECKSRC)@PERL@ $(top_srcdir)/scripts/checksrc.pl $(srcdir)/*.[ch]
# Makefile.inc provides neat definitions
include Makefile.inc
if BUILD_UNITTESTS
noinst_PROGRAMS = $(UNITPROGS)
else
noinst_PROGRAMS =
endif

View File

@@ -24,9 +24,11 @@
# these files are used in every single unit test program
UNITFILES = curlcheck.h \
../libtest/test.h \
../libtest/first.c
FIRSTFILES = \
../libtest/first.c \
../libtest/first.h
UNITFILES = curlcheck.h $(FIRSTFILES)
# These are all unit test programs
UNITPROGS = unit1300 unit1302 unit1303 unit1304 unit1305 unit1307 \

View File

@@ -28,15 +28,15 @@
#include "curl_base64.h"
#include "memdebug.h" /* LAST include file */
static struct Curl_easy *data;
static struct Curl_easy *testdata;
static CURLcode unit_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
data = curl_easy_init();
if(!data) {
testdata = curl_easy_init();
if(!testdata) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
@@ -45,7 +45,7 @@ static CURLcode unit_setup(void)
static void unit_stop(void)
{
curl_easy_cleanup(data);
curl_easy_cleanup(testdata);
curl_global_cleanup();
}

View File

@@ -27,15 +27,15 @@
#include "connect.h"
#include "memdebug.h" /* LAST include file */
static struct Curl_easy *data;
static struct Curl_easy *testdata;
static CURLcode unit_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
data = curl_easy_init();
if(!data) {
testdata = curl_easy_init();
if(!testdata) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
@@ -44,7 +44,7 @@ static CURLcode unit_setup(void)
static void unit_stop(void)
{
curl_easy_cleanup(data);
curl_easy_cleanup(testdata);
curl_global_cleanup();
}
@@ -55,7 +55,8 @@ static void unit_stop(void)
/* macro to set the pretended current time */
#define NOW(x,y) now.tv_sec = x; now.tv_usec = y
/* macro to set the millisecond based timeouts to use */
#define TIMEOUTS(x,y) data->set.timeout = x; data->set.connecttimeout = y
#define TIMEOUTS(x,y) testdata->set.timeout = x; \
testdata->set.connecttimeout = y
/*
* To test:
@@ -136,16 +137,16 @@ UNITTEST_START
};
/* this is the pretended start time of the transfer */
data->progress.t_startsingle.tv_sec = BASE;
data->progress.t_startsingle.tv_usec = 0;
data->progress.t_startop.tv_sec = BASE;
data->progress.t_startop.tv_usec = 0;
testdata->progress.t_startsingle.tv_sec = BASE;
testdata->progress.t_startsingle.tv_usec = 0;
testdata->progress.t_startop.tv_sec = BASE;
testdata->progress.t_startop.tv_usec = 0;
for(i = 0; i < sizeof(run)/sizeof(run[0]); i++) {
timediff_t timeout;
NOW(run[i].now_s, run[i].now_us);
TIMEOUTS(run[i].timeout_ms, run[i].connecttimeout_ms);
timeout = Curl_timeleft(data, &now, run[i].connecting);
timeout = Curl_timeleft(testdata, &now, run[i].connecting);
if(timeout != run[i].result)
fail(run[i].comment);
}

View File

@@ -27,16 +27,16 @@
#ifndef CURL_DISABLE_NETRC
static char *login;
static char *password;
static char *s_login;
static char *s_password;
static CURLcode unit_setup(void)
{
password = strdup("");
login = strdup("");
if(!password || !login) {
Curl_safefree(password);
Curl_safefree(login);
s_password = strdup("");
s_login = strdup("");
if(!s_password || !s_login) {
Curl_safefree(s_password);
Curl_safefree(s_login);
return CURLE_OUT_OF_MEMORY;
}
return CURLE_OK;
@@ -44,8 +44,8 @@ static CURLcode unit_setup(void)
static void unit_stop(void)
{
Curl_safefree(password);
Curl_safefree(login);
Curl_safefree(s_password);
Curl_safefree(s_login);
}
UNITTEST_START
@@ -54,133 +54,133 @@ UNITTEST_START
/*
* Test a non existent host in our netrc file.
*/
result = Curl_parsenetrc("test.example.com", &login, &password, arg);
result = Curl_parsenetrc("test.example.com", &s_login, &s_password, arg);
fail_unless(result == 1, "Host not found should return 1");
abort_unless(password != NULL, "returned NULL!");
fail_unless(password[0] == 0, "password should not have been changed");
abort_unless(login != NULL, "returned NULL!");
fail_unless(login[0] == 0, "login should not have been changed");
abort_unless(s_password != NULL, "returned NULL!");
fail_unless(s_password[0] == 0, "password should not have been changed");
abort_unless(s_login != NULL, "returned NULL!");
fail_unless(s_login[0] == 0, "login should not have been changed");
/*
* Test a non existent login in our netrc file.
*/
free(login);
login = strdup("me");
abort_unless(login != NULL, "returned NULL!");
result = Curl_parsenetrc("example.com", &login, &password, arg);
free(s_login);
s_login = strdup("me");
abort_unless(s_login != NULL, "returned NULL!");
result = Curl_parsenetrc("example.com", &s_login, &s_password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(password[0] == 0, "password should not have been changed");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "me", 2) == 0,
abort_unless(s_password != NULL, "returned NULL!");
fail_unless(s_password[0] == 0, "password should not have been changed");
abort_unless(s_login != NULL, "returned NULL!");
fail_unless(strncmp(s_login, "me", 2) == 0,
"login should not have been changed");
/*
* Test a non existent login and host in our netrc file.
*/
free(login);
login = strdup("me");
abort_unless(login != NULL, "returned NULL!");
result = Curl_parsenetrc("test.example.com", &login, &password, arg);
free(s_login);
s_login = strdup("me");
abort_unless(s_login != NULL, "returned NULL!");
result = Curl_parsenetrc("test.example.com", &s_login, &s_password, arg);
fail_unless(result == 1, "Host not found should return 1");
abort_unless(password != NULL, "returned NULL!");
fail_unless(password[0] == 0, "password should not have been changed");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "me", 2) == 0,
abort_unless(s_password != NULL, "returned NULL!");
fail_unless(s_password[0] == 0, "password should not have been changed");
abort_unless(s_login != NULL, "returned NULL!");
fail_unless(strncmp(s_login, "me", 2) == 0,
"login should not have been changed");
/*
* Test a non existent login (substring of an existing one) in our
* netrc file.
*/
free(login);
login = strdup("admi");
abort_unless(login != NULL, "returned NULL!");
result = Curl_parsenetrc("example.com", &login, &password, arg);
free(s_login);
s_login = strdup("admi");
abort_unless(s_login != NULL, "returned NULL!");
result = Curl_parsenetrc("example.com", &s_login, &s_password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(password[0] == 0, "password should not have been changed");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "admi", 4) == 0,
abort_unless(s_password != NULL, "returned NULL!");
fail_unless(s_password[0] == 0, "password should not have been changed");
abort_unless(s_login != NULL, "returned NULL!");
fail_unless(strncmp(s_login, "admi", 4) == 0,
"login should not have been changed");
/*
* Test a non existent login (superstring of an existing one)
* in our netrc file.
*/
free(login);
login = strdup("adminn");
abort_unless(login != NULL, "returned NULL!");
result = Curl_parsenetrc("example.com", &login, &password, arg);
free(s_login);
s_login = strdup("adminn");
abort_unless(s_login != NULL, "returned NULL!");
result = Curl_parsenetrc("example.com", &s_login, &s_password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(password[0] == 0, "password should not have been changed");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "adminn", 6) == 0,
abort_unless(s_password != NULL, "returned NULL!");
fail_unless(s_password[0] == 0, "password should not have been changed");
abort_unless(s_login != NULL, "returned NULL!");
fail_unless(strncmp(s_login, "adminn", 6) == 0,
"login should not have been changed");
/*
* Test for the first existing host in our netrc file
* with login[0] = 0.
* with s_login[0] = 0.
*/
free(login);
login = strdup("");
abort_unless(login != NULL, "returned NULL!");
result = Curl_parsenetrc("example.com", &login, &password, arg);
free(s_login);
s_login = strdup("");
abort_unless(s_login != NULL, "returned NULL!");
result = Curl_parsenetrc("example.com", &s_login, &s_password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "passwd", 6) == 0,
abort_unless(s_password != NULL, "returned NULL!");
fail_unless(strncmp(s_password, "passwd", 6) == 0,
"password should be 'passwd'");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
abort_unless(s_login != NULL, "returned NULL!");
fail_unless(strncmp(s_login, "admin", 5) == 0, "login should be 'admin'");
/*
* Test for the first existing host in our netrc file
* with login[0] != 0.
* with s_login[0] != 0.
*/
free(password);
password = strdup("");
abort_unless(password != NULL, "returned NULL!");
result = Curl_parsenetrc("example.com", &login, &password, arg);
free(s_password);
s_password = strdup("");
abort_unless(s_password != NULL, "returned NULL!");
result = Curl_parsenetrc("example.com", &s_login, &s_password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "passwd", 6) == 0,
abort_unless(s_password != NULL, "returned NULL!");
fail_unless(strncmp(s_password, "passwd", 6) == 0,
"password should be 'passwd'");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
abort_unless(s_login != NULL, "returned NULL!");
fail_unless(strncmp(s_login, "admin", 5) == 0, "login should be 'admin'");
/*
* Test for the second existing host in our netrc file
* with login[0] = 0.
* with s_login[0] = 0.
*/
free(password);
password = strdup("");
abort_unless(password != NULL, "returned NULL!");
free(login);
login = strdup("");
abort_unless(login != NULL, "returned NULL!");
result = Curl_parsenetrc("curl.example.com", &login, &password, arg);
free(s_password);
s_password = strdup("");
abort_unless(s_password != NULL, "returned NULL!");
free(s_login);
s_login = strdup("");
abort_unless(s_login != NULL, "returned NULL!");
result = Curl_parsenetrc("curl.example.com", &s_login, &s_password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "none", 4) == 0,
abort_unless(s_password != NULL, "returned NULL!");
fail_unless(strncmp(s_password, "none", 4) == 0,
"password should be 'none'");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
abort_unless(s_login != NULL, "returned NULL!");
fail_unless(strncmp(s_login, "none", 4) == 0, "login should be 'none'");
/*
* Test for the second existing host in our netrc file
* with login[0] != 0.
* with s_login[0] != 0.
*/
free(password);
password = strdup("");
abort_unless(password != NULL, "returned NULL!");
result = Curl_parsenetrc("curl.example.com", &login, &password, arg);
free(s_password);
s_password = strdup("");
abort_unless(s_password != NULL, "returned NULL!");
result = Curl_parsenetrc("curl.example.com", &s_login, &s_password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "none", 4) == 0,
abort_unless(s_password != NULL, "returned NULL!");
fail_unless(strncmp(s_password, "none", 4) == 0,
"password should be 'none'");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
abort_unless(s_login != NULL, "returned NULL!");
fail_unless(strncmp(s_login, "none", 4) == 0, "login should be 'none'");
UNITTEST_STOP

View File

@@ -40,15 +40,15 @@
#include "memdebug.h" /* LAST include file */
static struct Curl_easy *data;
static struct Curl_easy *testdata;
static struct Curl_hash hp;
static char *data_key;
static struct Curl_dns_entry *data_node;
static CURLcode unit_setup(void)
{
data = curl_easy_init();
if(!data) {
testdata = curl_easy_init();
if(!testdata) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
@@ -66,7 +66,7 @@ static void unit_stop(void)
free(data_key);
Curl_hash_destroy(&hp);
curl_easy_cleanup(data);
curl_easy_cleanup(testdata);
curl_global_cleanup();
}

View File

@@ -21,10 +21,13 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#define CURL_NO_FMT_CHECKS
#include "curlcheck.h"
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
#endif
static CURLcode unit_setup(void) {return CURLE_OK;}
static void unit_stop(void) {}
@@ -182,3 +185,7 @@ rc = curl_msnprintf(output, 129,
fail_unless(rc == 128, "return code should be 128");
UNITTEST_STOP
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

View File

@@ -26,7 +26,7 @@
#include "speedcheck.h"
#include "urldata.h"
static CURL *easy;
static struct Curl_easy *easy;
static CURLcode unit_setup(void)
{

View File

@@ -21,20 +21,24 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#define CURL_NO_FMT_CHECKS
#include "curlcheck.h"
#include "urldata.h"
#include "sendf.h"
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wformat-zero-length"
#endif
/*
* This test hardcodes the knowledge of the buffer size which is internal to
* Curl_infof(). If that buffer is changed in size, this tests needs to be
* updated to still be valid.
*/
static struct Curl_easy *data;
static struct Curl_easy *testdata;
static char input[4096];
static char output[4096];
@@ -66,20 +70,20 @@ unit_setup(void)
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
data = curl_easy_init();
if(!data) {
testdata = curl_easy_init();
if(!testdata) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
curl_easy_setopt(data, CURLOPT_DEBUGFUNCTION, debugf_cb);
curl_easy_setopt(data, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(testdata, CURLOPT_DEBUGFUNCTION, debugf_cb);
curl_easy_setopt(testdata, CURLOPT_VERBOSE, 1L);
return res;
}
static void
unit_stop(void)
{
curl_easy_cleanup(data);
curl_easy_cleanup(testdata);
curl_global_cleanup();
}
@@ -96,24 +100,24 @@ UNITTEST_START
/* Injecting a simple short string via a format */
msnprintf(input, sizeof(input), "Simple Test");
Curl_infof(data, "%s", input);
Curl_infof(testdata, "%s", input);
fail_unless(verify(output, input) == 0, "Simple string test");
/* Injecting a few different variables with a format */
Curl_infof(data, "%s %u testing %lu", input, 42, 43L);
Curl_infof(testdata, "%s %u testing %lu", input, 42, 43L);
fail_unless(verify(output, "Simple Test 42 testing 43\n") == 0,
"Format string");
/* Variations of empty strings */
Curl_infof(data, "");
Curl_infof(testdata, "");
fail_unless(strlen(output) == 1, "Empty string");
Curl_infof(data, "%s", (char *)NULL);
Curl_infof(testdata, "%s", (char *)NULL);
fail_unless(verify(output, "(nil)") == 0, "Passing NULL as string");
/* A string just long enough to not be truncated */
memset(input, '\0', sizeof(input));
memset(input, 'A', 2047);
Curl_infof(data, "%s", input);
Curl_infof(testdata, "%s", input);
fail_unless(strlen(output) == 2048, "No truncation of infof input");
fail_unless(verify(output, input) == 0, "No truncation of infof input");
fail_unless(output[sizeof(output) - 1] == '\0',
@@ -121,22 +125,26 @@ fail_unless(output[sizeof(output) - 1] == '\0',
/* Just over the limit without newline for truncation via '...' */
memset(input + 2047, 'A', 4);
Curl_infof(data, "%s", input);
Curl_infof(testdata, "%s", input);
fail_unless(strlen(output) == 2051, "Truncation of infof input 1");
fail_unless(output[sizeof(output) - 1] == '\0', "Truncation of infof input 1");
/* Just over the limit with newline for truncation via '...' */
memset(input + 2047, 'A', 4);
memset(input + 2047 + 4, '\n', 1);
Curl_infof(data, "%s", input);
Curl_infof(testdata, "%s", input);
fail_unless(strlen(output) == 2051, "Truncation of infof input 2");
fail_unless(output[sizeof(output) - 1] == '\0', "Truncation of infof input 2");
/* Way over the limit for truncation via '...' */
memset(input, '\0', sizeof(input));
memset(input, 'A', sizeof(input) - 1);
Curl_infof(data, "%s", input);
Curl_infof(testdata, "%s", input);
fail_unless(strlen(output) == 2051, "Truncation of infof input 3");
fail_unless(output[sizeof(output) - 1] == '\0', "Truncation of infof input 3");
UNITTEST_STOP
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

View File

@@ -44,6 +44,7 @@ static CURLcode unit_setup(void)
static void unit_stop(void)
{
Curl_bufref_free(&bufref);
}
UNITTEST_START

View File

@@ -49,7 +49,7 @@ static void unit_stop(void)
}
static void test_parse(
const char *input,
const char *input_data,
const char *exp_dev,
const char *exp_iface,
const char *exp_host,
@@ -58,7 +58,7 @@ static void test_parse(
char *dev = NULL;
char *iface = NULL;
char *host = NULL;
CURLcode rc = Curl_parse_interface(input, &dev, &iface, &host);
CURLcode rc = Curl_parse_interface(input_data, &dev, &iface, &host);
fail_unless(rc == exp_rc, "Curl_parse_interface() failed");
fail_unless(!!exp_dev == !!dev, "dev expectation failed.");