unittests: cleanups

- make sure all UNITTEST prototypes mark in which unit test they are used,
  with "@unittest" markup

- make sure all UNITTEST functions do not use Curl_ prefix, as that is a
  prefix we use for global private functions and these functions are static
  and therefore not global and the prefix is wrong

- drop UNITTEST for functions not used in unit tests

- make the extract-unit-protos script highlight the above issues if found

- extract-unit-protos now also outputs the unit test number for all the
  generated protos in lib/unitprotos.h to aid readers. It also adds the source
  file and line number where the proto originates from.

- extract-unit-protos now exits with a non-zero value if any of the above
  warnings are triggered

- cf-dns: Curl_cf_dns_result => static cf_dns_result
- hostip: Curl_ipv6works => static ipv6works
- url: remove Curl_setup_conn() - not used anymore
- connect: Curl_timeleft_now_ms => UNITTEST timeleft_now_ms

Closes #21330
This commit is contained in:
Daniel Stenberg 2026-04-15 12:11:54 +02:00
parent 94f14c54b0
commit 7fd35f4c34
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
36 changed files with 248 additions and 216 deletions

View file

@ -69,7 +69,7 @@ static CURLcode test_unit1300(const char *arg)
"list initial size should be zero");
fail_unless(Curl_llist_head(&llist) == NULL,
"list head should initiate to NULL");
fail_unless(Curl_llist_tail(&llist) == NULL,
fail_unless(llist_tail(&llist) == NULL,
"list tail should initiate to NULL");
/**
@ -91,7 +91,7 @@ static CURLcode test_unit1300(const char *arg)
fail_unless(Curl_node_elem(Curl_llist_head(&llist)) == &unusedData_case1,
"head ptr should be first entry");
/* same goes for the list tail */
fail_unless(Curl_llist_tail(&llist) == Curl_llist_head(&llist),
fail_unless(llist_tail(&llist) == Curl_llist_head(&llist),
"tail and head should be the same");
/**
@ -108,7 +108,7 @@ static CURLcode test_unit1300(const char *arg)
fail_unless(Curl_node_elem(Curl_node_next(Curl_llist_head(&llist))) ==
&unusedData_case3,
"the node next to head is not getting set correctly");
fail_unless(Curl_node_elem(Curl_llist_tail(&llist)) == &unusedData_case3,
fail_unless(Curl_node_elem(llist_tail(&llist)) == &unusedData_case3,
"the list tail is not getting set correctly");
/**
@ -126,7 +126,7 @@ static CURLcode test_unit1300(const char *arg)
&unusedData_case2,
"the node next to head is not getting set correctly");
/* better safe than sorry, check that the tail is not corrupted */
fail_unless(Curl_node_elem(Curl_llist_tail(&llist)) != &unusedData_case2,
fail_unless(Curl_node_elem(llist_tail(&llist)) != &unusedData_case2,
"the list tail is not getting set correctly");
/* unit tests for Curl_node_remove */
@ -152,7 +152,7 @@ static CURLcode test_unit1300(const char *arg)
fail_unless(Curl_llist_head(&llist) == element_next,
"llist new head not modified properly");
abort_unless(Curl_llist_head(&llist), "llist.head is NULL");
fail_unless(Curl_node_prev(Curl_llist_head(&llist)) == NULL,
fail_unless(llist_node_prev(Curl_llist_head(&llist)) == NULL,
"new head previous not set to null");
/**
@ -173,12 +173,12 @@ static CURLcode test_unit1300(const char *arg)
to_remove = Curl_node_next(Curl_llist_head(&llist));
abort_unless(to_remove, "to_remove is NULL");
element_next = Curl_node_next(to_remove);
element_prev = Curl_node_prev(to_remove);
Curl_node_uremove(to_remove, NULL);
element_prev = llist_node_prev(to_remove);
Curl_node_remove(to_remove);
fail_unless(Curl_node_next(element_prev) == element_next,
"element previous->next is not being adjusted");
abort_unless(element_next, "element_next is NULL");
fail_unless(Curl_node_prev(element_next) == element_prev,
fail_unless(llist_node_prev(element_next) == element_prev,
"element next->previous is not being adjusted");
/**
@ -191,10 +191,10 @@ static CURLcode test_unit1300(const char *arg)
* 4: list->tail will be tail->previous
*/
to_remove = Curl_llist_tail(&llist);
element_prev = Curl_node_prev(to_remove);
to_remove = llist_tail(&llist);
element_prev = llist_node_prev(to_remove);
Curl_node_remove(to_remove);
fail_unless(Curl_llist_tail(&llist) == element_prev,
fail_unless(llist_tail(&llist) == element_prev,
"llist tail is not being adjusted when removing tail");
/**
@ -210,7 +210,7 @@ static CURLcode test_unit1300(const char *arg)
Curl_node_remove(to_remove);
fail_unless(Curl_llist_head(&llist) == NULL,
"llist head is not NULL while the llist is empty");
fail_unless(Curl_llist_tail(&llist) == NULL,
fail_unless(llist_tail(&llist) == NULL,
"llist tail is not NULL while the llist is empty");
/**
@ -228,7 +228,7 @@ static CURLcode test_unit1300(const char *arg)
fail_unless(Curl_node_elem(Curl_llist_head(&llist)) == &unusedData_case1,
"head ptr should be first entry");
/* same goes for the list tail */
fail_unless(Curl_llist_tail(&llist) == Curl_llist_head(&llist),
fail_unless(llist_tail(&llist) == Curl_llist_head(&llist),
"tail and head should be the same");
/**
@ -243,7 +243,7 @@ static CURLcode test_unit1300(const char *arg)
fail_unless(Curl_node_elem(Curl_node_next(Curl_llist_head(&llist))) ==
&unusedData_case2,
"the node next to head is not getting set correctly");
fail_unless(Curl_node_elem(Curl_llist_tail(&llist)) == &unusedData_case2,
fail_unless(Curl_node_elem(llist_tail(&llist)) == &unusedData_case2,
"the list tail is not getting set correctly");
/**
@ -258,7 +258,7 @@ static CURLcode test_unit1300(const char *arg)
fail_unless(Curl_node_elem(Curl_node_next(Curl_llist_head(&llist))) ==
&unusedData_case2,
"the node next to head did not stay the same");
fail_unless(Curl_node_elem(Curl_llist_tail(&llist)) == &unusedData_case3,
fail_unless(Curl_node_elem(llist_tail(&llist)) == &unusedData_case3,
"the list tail is not getting set correctly");
Curl_llist_destroy(&llist, NULL);

View file

@ -148,7 +148,7 @@ static CURLcode test_unit1303(const char *arg)
TIMEOUTS(run[i].timeout_ms, run[i].connecttimeout_ms);
easy->progress.now = now;
easy->mstate = run[i].connecting ? MSTATE_INIT : MSTATE_DO;
timeout = Curl_timeleft_now_ms(easy, &now);
timeout = timeleft_now_ms(easy, &now);
if(timeout != run[i].result)
fail(run[i].comment);
}

View file

@ -55,7 +55,7 @@ static CURLcode test_unit1608(const char *arg)
/* Shuffle repeatedly and make sure that the list changes */
for(i = 0; i < 10; i++) {
if(CURLE_OK != Curl_shuffle_addr(easy, &addrhead))
if(CURLE_OK != dns_shuffle_addr(easy, &addrhead))
break;
if(addrhead != addrs)
break;

View file

@ -156,7 +156,7 @@ static CURLcode test_unit1614(const char *arg)
{ NULL, NULL, FALSE }
};
for(i = 0; list4[i].a; i++) {
bool match = Curl_cidr4_match(list4[i].a, list4[i].n, list4[i].bits);
bool match = cidr4_match(list4[i].a, list4[i].n, list4[i].bits);
if(match != list4[i].match) {
curl_mfprintf(stderr, "%s in %s/%u should %smatch\n",
list4[i].a, list4[i].n, list4[i].bits,
@ -166,7 +166,7 @@ static CURLcode test_unit1614(const char *arg)
}
#ifdef USE_IPV6
for(i = 0; list6[i].a; i++) {
bool match = Curl_cidr6_match(list6[i].a, list6[i].n, list6[i].bits);
bool match = cidr6_match(list6[i].a, list6[i].n, list6[i].bits);
if(match != list6[i].match) {
curl_mfprintf(stderr, "%s in %s/%u should %smatch\n",
list6[i].a, list6[i].n, list6[i].bits,

View file

@ -26,14 +26,14 @@
#include "curl/urlapi.h"
#include "urlapi-int.h"
static CURLUcode parse_port(CURLU *url, const char *h, bool has_scheme)
static CURLUcode my_parse_port(CURLU *url, const char *h, bool has_scheme)
{
struct dynbuf host;
CURLUcode ret;
curlx_dyn_init(&host, 10000);
if(curlx_dyn_add(&host, h))
return CURLUE_OUT_OF_MEMORY;
ret = Curl_parse_port(url, &host, has_scheme);
ret = parse_port(url, &host, has_scheme);
curlx_dyn_free(&host);
return ret;
}
@ -55,7 +55,7 @@ static CURLcode test_unit1653(const char *arg)
ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15]");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
ret = my_parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
ret = curl_url_get(u, CURLUPART_PORT, &portnum, CURLU_NO_DEFAULT_PORT);
fail_unless(ret != CURLUE_OK, "curl_url_get portnum returned something");
@ -69,7 +69,7 @@ static CURLcode test_unit1653(const char *arg)
ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15|");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
ret = my_parse_port(u, ipv6port, FALSE);
fail_unless(ret != CURLUE_OK, "parse_port true on error");
curlx_safefree(ipv6port);
curl_url_cleanup(u);
@ -80,7 +80,7 @@ static CURLcode test_unit1653(const char *arg)
ipv6port = curlx_strdup("[fe80::250:56ff;fea7:da15]:808");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
ret = my_parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0);
fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error");
@ -97,7 +97,7 @@ static CURLcode test_unit1653(const char *arg)
ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15%25eth3]:80");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
ret = my_parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0);
fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error");
@ -113,7 +113,7 @@ static CURLcode test_unit1653(const char *arg)
ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15%25eth3]");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
ret = my_parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
curlx_safefree(ipv6port);
curl_url_cleanup(u);
@ -125,7 +125,7 @@ static CURLcode test_unit1653(const char *arg)
ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15]:81");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
ret = my_parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0);
fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error");
@ -141,7 +141,7 @@ static CURLcode test_unit1653(const char *arg)
ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15];81");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
ret = my_parse_port(u, ipv6port, FALSE);
fail_unless(ret != CURLUE_OK, "parse_port true on error");
curlx_safefree(ipv6port);
curl_url_cleanup(u);
@ -152,7 +152,7 @@ static CURLcode test_unit1653(const char *arg)
ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15]80");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
ret = my_parse_port(u, ipv6port, FALSE);
fail_unless(ret != CURLUE_OK, "parse_port true on error");
curlx_safefree(ipv6port);
curl_url_cleanup(u);
@ -165,7 +165,7 @@ static CURLcode test_unit1653(const char *arg)
ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15]:");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, TRUE);
ret = my_parse_port(u, ipv6port, TRUE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
curlx_safefree(ipv6port);
curl_url_cleanup(u);
@ -177,7 +177,7 @@ static CURLcode test_unit1653(const char *arg)
ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15!25eth3]:180");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
ret = my_parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0);
fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error");
@ -193,7 +193,7 @@ static CURLcode test_unit1653(const char *arg)
ipv6port = curlx_strdup("[fe80::250:56ff:fea7:da15%eth3]:80");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
ret = my_parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
curlx_safefree(ipv6port);
curl_url_cleanup(u);
@ -207,7 +207,7 @@ static CURLcode test_unit1653(const char *arg)
"aaaaaaaaaaaaaaaaaaaaaa:");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
ret = my_parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_BAD_PORT_NUMBER, "parse_port did wrong");
fail:
curlx_free(ipv6port);

View file

@ -175,7 +175,7 @@ static CURLcode cf_test_create(struct Curl_cfilter **pcf,
CURL_LOG_LVL_NONE,
cf_test_destroy,
cf_test_connect,
Curl_cf_def_close,
cf_def_close,
Curl_cf_def_shutdown,
cf_test_adjust_pollset,
Curl_cf_def_data_pending,
@ -315,7 +315,7 @@ static void test_connect(CURL *easy, const struct test_case *tc)
struct test_result tr;
struct curl_slist *list = NULL;
Curl_debug_set_transport_provider(TRNSPRT_TCP, cf_test_create);
debug_set_transport_provider(TRNSPRT_TCP, cf_test_create);
current_tc = tc;
current_tr = &tr;

View file

@ -42,7 +42,7 @@ static CURLcode test_unit2602(const char *arg)
fail_if(Curl_dynhds_add(&hds, "test2", 5, "456", 3), "add failed");
/* remove and add without exceeding limits */
for(i = 0; i < 100; ++i) {
if(Curl_dynhds_remove(&hds, "test2", 5) != 1) {
if(dynhds_remove(&hds, "test2", 5) != 1) {
fail_if(TRUE, "should");
break;
}
@ -54,7 +54,7 @@ static CURLcode test_unit2602(const char *arg)
fail_unless(Curl_dynhds_count(&hds) == 2, "should hold 2");
/* set, replacing previous entry without exceeding limits */
for(i = 0; i < 100; ++i) {
if(Curl_dynhds_set(&hds, "test2", 5, "456", 3)) {
if(dynhds_set(&hds, "test2", 5, "456", 3)) {
fail_if(TRUE, "add failed");
break;
}
@ -64,16 +64,16 @@ static CURLcode test_unit2602(const char *arg)
result = Curl_dynhds_add(&hds, "test3", 5, "789", 3);
fail_unless(result, "add should have failed");
fail_unless(Curl_dynhds_count_name(&hds, "test", 4) == 0, "false positive");
fail_unless(Curl_dynhds_count_name(&hds, "test1", 4) == 0, "false positive");
fail_unless(dynhds_count_name(&hds, "test", 4) == 0, "false positive");
fail_unless(dynhds_count_name(&hds, "test1", 4) == 0, "false positive");
fail_if(Curl_dynhds_get(&hds, "test1", 4), "false positive");
fail_unless(Curl_dynhds_get(&hds, "test1", 5), "false negative");
fail_unless(Curl_dynhds_count_name(&hds, "test1", 5) == 1, "should");
fail_unless(Curl_dynhds_ccount_name(&hds, "test2") == 1, "should");
fail_unless(dynhds_count_name(&hds, "test1", 5) == 1, "should");
fail_unless(dynhds_ccount_name(&hds, "test2") == 1, "should");
fail_unless(Curl_dynhds_cget(&hds, "test2"), "should");
fail_unless(Curl_dynhds_ccount_name(&hds, "TEST2") == 1, "should");
fail_unless(Curl_dynhds_ccontains(&hds, "TesT2"), "should");
fail_unless(Curl_dynhds_contains(&hds, "TeSt2", 5), "should");
fail_unless(dynhds_ccount_name(&hds, "TEST2") == 1, "should");
fail_unless(dynhds_ccontains(&hds, "TesT2"), "should");
fail_unless(dynhds_contains(&hds, "TeSt2", 5), "should");
Curl_dynhds_free(&hds);
/* add header exceeding max overall length */
@ -89,14 +89,14 @@ static CURLcode test_unit2602(const char *arg)
fail_if(Curl_dynhds_add(&hds, "test1", 5, "123", 3), "add failed");
fail_if(Curl_dynhds_cadd(&hds, "blablabla", "thingies"), "add failed");
fail_if(Curl_dynhds_h1_cadd_line(&hds, "blablabla: thingies"), "add failed");
fail_unless(Curl_dynhds_ccount_name(&hds, "blablabla") == 2, "should");
fail_unless(Curl_dynhds_cremove(&hds, "blablabla") == 2, "should");
fail_if(Curl_dynhds_ccontains(&hds, "blablabla"), "should not");
fail_unless(dynhds_ccount_name(&hds, "blablabla") == 2, "should");
fail_unless(dynhds_cremove(&hds, "blablabla") == 2, "should");
fail_if(dynhds_ccontains(&hds, "blablabla"), "should not");
result = Curl_dynhds_h1_cadd_line(&hds, "blablabla thingies");
fail_unless(result, "add should have failed");
if(!result) {
fail_unless(Curl_dynhds_ccount_name(&hds, "bLABlaBlA") == 0, "should");
fail_unless(dynhds_ccount_name(&hds, "bLABlaBlA") == 0, "should");
fail_if(Curl_dynhds_cadd(&hds, "Bla-Bla", "thingies"), "add failed");
curlx_dyn_init(&dbuf, 32 * 1024);

View file

@ -37,7 +37,7 @@ static void check_set(const char *name, uint32_t capacity,
name, capacity, slen);
Curl_uint32_bset_init(&bset);
fail_unless(!Curl_uint32_bset_resize(&bset, capacity), "bset resize failed");
c = Curl_uint32_bset_capacity(&bset);
c = uint32_bset_capacity(&bset);
fail_unless(c == (((capacity + 63) / 64) * 64), "wrong capacity");
Curl_uint32_bset_clear(&bset);
@ -68,7 +68,7 @@ static void check_set(const char *name, uint32_t capacity,
}
/* Adding capacity number does not work (0 - capacity-1) */
c = Curl_uint32_bset_capacity(&bset);
c = uint32_bset_capacity(&bset);
fail_unless(!Curl_uint32_bset_add(&bset, c), "add out of range worked");
/* The count it correct */
c = Curl_uint32_bset_count(&bset);
@ -109,7 +109,7 @@ static void check_set(const char *name, uint32_t capacity,
fail_unless(!Curl_uint32_bset_resize(&bset, capacity / 2),
"resize half failed");
/* halved the size, what numbers remain in set? */
c = Curl_uint32_bset_capacity(&bset);
c = uint32_bset_capacity(&bset);
n = 0;
for(i = 0; i < slen; ++i) {
if(s[i] < c)

View file

@ -104,7 +104,7 @@ static CURLcode test_unit3212(const char *arg)
"does not contain dummy");
}
/* clear */
Curl_uint32_tbl_clear(&tbl);
uint32_tbl_clear(&tbl);
fail_unless(!Curl_uint32_tbl_count(&tbl), "count not 0 after clear");
for(i = 0; i < TBL_SIZE / 2; ++i) {
fail_unless(!Curl_uint32_tbl_contains(&tbl, i),
@ -118,7 +118,7 @@ static CURLcode test_unit3212(const char *arg)
fail_unless(Curl_uint32_tbl_add(&tbl, &dummy, &key), "failed to add");
fail_unless(key == 1, "unexpected key assigned");
/* clear, fill, remove one, add, should get the removed key again */
Curl_uint32_tbl_clear(&tbl);
uint32_tbl_clear(&tbl);
for(i = 0; i < Curl_uint32_tbl_capacity(&tbl); ++i)
fail_unless(Curl_uint32_tbl_add(&tbl, &dummy, &key), "failed to add");
fail_unless(!Curl_uint32_tbl_add(&tbl, &dummy, &key), "add on full");

View file

@ -36,7 +36,7 @@ static void check_spbset(const char *name, const uint32_t *s, size_t slen)
Curl_uint32_spbset_init(&bset);
Curl_uint32_spbset_clear(&bset);
uint32_spbset_clear(&bset);
c = Curl_uint32_spbset_count(&bset);
fail_unless(c == 0, "set count is not 0");
@ -75,7 +75,7 @@ static void check_spbset(const char *name, const uint32_t *s, size_t slen)
c = Curl_uint32_spbset_count(&bset);
fail_unless(c == slen / 2, "set count is wrong");
Curl_uint32_spbset_clear(&bset);
uint32_spbset_clear(&bset);
c = Curl_uint32_spbset_count(&bset);
fail_unless(c == 0, "set count is not 0");
for(i = 0; i < slen; i++) { /* none present any longer */