mirror of
https://github.com/curl/curl.git
synced 2026-08-25 09:53:32 +03:00
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:
parent
6a1dcdc5d2
commit
71cf0d1fca
86 changed files with 1008 additions and 497 deletions
1
tests/unit/.gitignore
vendored
1
tests/unit/.gitignore
vendored
|
|
@ -3,3 +3,4 @@
|
|||
# SPDX-License-Identifier: curl
|
||||
|
||||
/unit[0-9][0-9][0-9][0-9]
|
||||
units.c
|
||||
|
|
|
|||
|
|
@ -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}")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 \
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
#include "speedcheck.h"
|
||||
#include "urldata.h"
|
||||
|
||||
static CURL *easy;
|
||||
static struct Curl_easy *easy;
|
||||
|
||||
static CURLcode unit_setup(void)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ static CURLcode unit_setup(void)
|
|||
|
||||
static void unit_stop(void)
|
||||
{
|
||||
Curl_bufref_free(&bufref);
|
||||
}
|
||||
|
||||
UNITTEST_START
|
||||
|
|
|
|||
|
|
@ -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.");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue