aboutsummaryrefslogtreecommitdiff
path: root/src/testcurl/test_digestauth_concurrent.c
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-01-31 14:22:55 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-01-31 14:22:55 +0300
commit1c4e21f099a029200cacd50a6b7fb224c5550ccf (patch)
tree11821bfa3c7fe1ebccd3df3176da65169a8b2bff /src/testcurl/test_digestauth_concurrent.c
parent8c901963d7838497cc49e8f66aae48e8f7e33bff (diff)
downloadlibmicrohttpd-1c4e21f099a029200cacd50a6b7fb224c5550ccf.tar.gz
libmicrohttpd-1c4e21f099a029200cacd50a6b7fb224c5550ccf.zip
test_digestauth_concurrent: finish the test even if error is found
Diffstat (limited to 'src/testcurl/test_digestauth_concurrent.c')
-rw-r--r--src/testcurl/test_digestauth_concurrent.c119
1 files changed, 79 insertions, 40 deletions
diff --git a/src/testcurl/test_digestauth_concurrent.c b/src/testcurl/test_digestauth_concurrent.c
index f7d533dc..40f292bb 100644
--- a/src/testcurl/test_digestauth_concurrent.c
+++ b/src/testcurl/test_digestauth_concurrent.c
@@ -136,6 +136,7 @@ _externalErrorExit_func (const char *errDesc, const char *funcName, int lineNum)
136} 136}
137 137
138 138
139/* Not actually used in this test */
139static char libcurl_errbuf[CURL_ERROR_SIZE] = ""; 140static char libcurl_errbuf[CURL_ERROR_SIZE] = "";
140 141
141_MHD_NORETURN static void 142_MHD_NORETURN static void
@@ -188,6 +189,8 @@ _mhdErrorExit_func (const char *errDesc, const char *funcName, int lineNum)
188} 189}
189 190
190 191
192#if 0
193/* Function unused in this test */
191static void 194static void
192_checkCURLE_OK_func (CURLcode code, const char *curlFunc, 195_checkCURLE_OK_func (CURLcode code, const char *curlFunc,
193 const char *funcName, int lineNum) 196 const char *funcName, int lineNum)
@@ -217,6 +220,9 @@ _checkCURLE_OK_func (CURLcode code, const char *curlFunc,
217} 220}
218 221
219 222
223#endif
224
225
220/* Could be increased to facilitate debugging */ 226/* Could be increased to facilitate debugging */
221#define TIMEOUTS_VAL 5 227#define TIMEOUTS_VAL 5
222 228
@@ -346,7 +352,7 @@ ahc_echo (void *cls,
346 352
347 353
348static CURL * 354static CURL *
349setupCURL (void *cbc, int port) 355setupCURL (void *cbc, int port, char *errbuf)
350{ 356{
351 CURL *c; 357 CURL *c;
352 char url[512]; 358 char url[512];
@@ -368,7 +374,7 @@ setupCURL (void *cbc, int port)
368 374
369 if ((CURLE_OK != curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L)) || 375 if ((CURLE_OK != curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L)) ||
370 (CURLE_OK != curl_easy_setopt (c, CURLOPT_ERRORBUFFER, 376 (CURLE_OK != curl_easy_setopt (c, CURLOPT_ERRORBUFFER,
371 libcurl_errbuf)) || 377 errbuf)) ||
372 (CURLE_OK != curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, 378 (CURLE_OK != curl_easy_setopt (c, CURLOPT_WRITEFUNCTION,
373 &copyBuffer)) || 379 &copyBuffer)) ||
374 (CURLE_OK != curl_easy_setopt (c, CURLOPT_WRITEDATA, cbc)) || 380 (CURLE_OK != curl_easy_setopt (c, CURLOPT_WRITEDATA, cbc)) ||
@@ -445,12 +451,13 @@ struct curlWokerInfo
445 * The libcurl handle to run in thread 451 * The libcurl handle to run in thread
446 */ 452 */
447 CURL *c; 453 CURL *c;
454 char *libcurl_errbuf;
448 /** 455 /**
449 * Non-zero if worker is finished 456 * Non-zero if worker is finished
450 */ 457 */
451 volatile int finished; 458 volatile int finished;
452 /** 459 /**
453 * Non-zero if worker result is success 460 * The number of successful worker results
454 */ 461 */
455 volatile int success; 462 volatile int success;
456}; 463};
@@ -467,54 +474,81 @@ worker_func (void *param)
467 req_result = curl_easy_perform (w->c); 474 req_result = curl_easy_perform (w->c);
468 if (CURLE_OK != req_result) 475 if (CURLE_OK != req_result)
469 { 476 {
470 fprintf (stderr, "Worker %d: first request failed. ", w->workerNumber); 477 fflush (stdout);
471 checkCURLE_OK (req_result); 478 if (0 != w->libcurl_errbuf[0])
472 } 479 fprintf (stderr, "Worker %d: first request failed. "
473 if (w->cbc.pos != strlen (PAGE)) 480 "libcurl error: '%s'.\n"
474 { 481 "libcurl error description: '%s'.\n",
475 fprintf (stderr, "Worker %d: Got %u bytes ('%.*s'), expected %u bytes. ", 482 w->workerNumber, curl_easy_strerror (req_result),
476 w->workerNumber, 483 w->libcurl_errbuf);
477 (unsigned) w->cbc.pos, (int) w->cbc.pos, w->cbc.buf, 484 else
478 (unsigned) strlen (MHD_URI_BASE_PATH)); 485 fprintf (stderr, "Worker %d: first request failed. "
479 mhdErrorExitDesc ("Wrong returned data length"); 486 "libcurl error: '%s'.\n",
487 w->workerNumber, curl_easy_strerror (req_result));
488 fflush (stderr);
480 } 489 }
481 if (0 != strncmp (PAGE, w->cbc.buf, strlen (PAGE))) 490 else
482 { 491 {
483 fprintf (stderr, "Worker %d: Got invalid response '%.*s'. ", 492 if (w->cbc.pos != strlen (PAGE))
484 w->workerNumber, 493 {
485 (int) w->cbc.pos, w->cbc.buf); 494 fprintf (stderr, "Worker %d: Got %u bytes ('%.*s'), expected %u bytes. ",
486 mhdErrorExitDesc ("Wrong returned data"); 495 w->workerNumber,
496 (unsigned) w->cbc.pos, (int) w->cbc.pos, w->cbc.buf,
497 (unsigned) strlen (MHD_URI_BASE_PATH));
498 mhdErrorExitDesc ("Wrong returned data length");
499 }
500 if (0 != strncmp (PAGE, w->cbc.buf, strlen (PAGE)))
501 {
502 fprintf (stderr, "Worker %d: Got invalid response '%.*s'. ",
503 w->workerNumber,
504 (int) w->cbc.pos, w->cbc.buf);
505 mhdErrorExitDesc ("Wrong returned data");
506 }
507 if (verbose)
508 printf ("Worker %d: first request successful.\n", w->workerNumber);
509 w->success++;
487 } 510 }
488 if (verbose)
489 printf ("Worker %d: first request successful.\n", w->workerNumber);
490 511
491 /* Second request */ 512 /* Second request */
492 w->cbc.pos = 0; 513 w->cbc.pos = 0;
493 req_result = curl_easy_perform (w->c); 514 req_result = curl_easy_perform (w->c);
494 if (CURLE_OK != req_result) 515 if (CURLE_OK != req_result)
495 { 516 {
496 fprintf (stderr, "Worker %d: second request failed. ", w->workerNumber); 517 fflush (stdout);
497 checkCURLE_OK (req_result); 518 if (0 != w->libcurl_errbuf[0])
498 } 519 fprintf (stderr, "Worker %d: second request failed. "
499 if (w->cbc.pos != strlen (PAGE)) 520 "libcurl error: '%s'.\n"
500 { 521 "libcurl error description: '%s'.\n",
501 fprintf (stderr, "Worker %d: Got %u bytes ('%.*s'), expected %u bytes. ", 522 w->workerNumber, curl_easy_strerror (req_result),
502 w->workerNumber, 523 w->libcurl_errbuf);
503 (unsigned) w->cbc.pos, (int) w->cbc.pos, w->cbc.buf, 524 else
504 (unsigned) strlen (MHD_URI_BASE_PATH)); 525 fprintf (stderr, "Worker %d: second request failed. "
505 mhdErrorExitDesc ("Wrong returned data length"); 526 "libcurl error: '%s'.\n",
527 w->workerNumber, curl_easy_strerror (req_result));
528 fflush (stderr);
506 } 529 }
507 if (0 != strncmp (PAGE, w->cbc.buf, strlen (PAGE))) 530 else
508 { 531 {
509 fprintf (stderr, "Worker %d: Got invalid response '%.*s'. ", 532 if (w->cbc.pos != strlen (PAGE))
510 w->workerNumber, 533 {
511 (int) w->cbc.pos, w->cbc.buf); 534 fprintf (stderr, "Worker %d: Got %u bytes ('%.*s'), expected %u bytes. ",
512 mhdErrorExitDesc ("Wrong returned data"); 535 w->workerNumber,
536 (unsigned) w->cbc.pos, (int) w->cbc.pos, w->cbc.buf,
537 (unsigned) strlen (MHD_URI_BASE_PATH));
538 mhdErrorExitDesc ("Wrong returned data length");
539 }
540 if (0 != strncmp (PAGE, w->cbc.buf, strlen (PAGE)))
541 {
542 fprintf (stderr, "Worker %d: Got invalid response '%.*s'. ",
543 w->workerNumber,
544 (int) w->cbc.pos, w->cbc.buf);
545 mhdErrorExitDesc ("Wrong returned data");
546 }
547 if (verbose)
548 printf ("Worker %d: second request successful.\n", w->workerNumber);
549 w->success++;
513 } 550 }
514 if (verbose)
515 printf ("Worker %d: second request successful.\n", w->workerNumber);
516 551
517 w->success = ! 0;
518 w->finished = ! 0; 552 w->finished = ! 0;
519 return NULL; 553 return NULL;
520} 554}
@@ -573,7 +607,11 @@ testDigestAuth (void)
573 externalErrorExitDesc ("malloc() failed"); 607 externalErrorExitDesc ("malloc() failed");
574 w->cbc.size = CLIENT_BUF_SIZE; 608 w->cbc.size = CLIENT_BUF_SIZE;
575 w->cbc.pos = 0; 609 w->cbc.pos = 0;
576 w->c = setupCURL (&w->cbc, port); 610 w->libcurl_errbuf = malloc (CURL_ERROR_SIZE);
611 if (NULL == w->libcurl_errbuf)
612 externalErrorExitDesc ("malloc() failed");
613 w->libcurl_errbuf[0] = 0;
614 w->c = setupCURL (&w->cbc, port, w->libcurl_errbuf);
577 w->finished = 0; 615 w->finished = 0;
578 w->success = 0; 616 w->success = 0;
579 } 617 }
@@ -594,10 +632,11 @@ testDigestAuth (void)
594 if (0 != pthread_join (w->pid, NULL)) 632 if (0 != pthread_join (w->pid, NULL))
595 externalErrorExitDesc ("pthread_join() failed"); 633 externalErrorExitDesc ("pthread_join() failed");
596 curl_easy_cleanup (w->c); 634 curl_easy_cleanup (w->c);
635 free (w->libcurl_errbuf);
597 free (w->cbc.buf); 636 free (w->cbc.buf);
598 if (! w->finished) 637 if (! w->finished)
599 externalErrorExitDesc ("The worker thread did't signal 'finished' state"); 638 externalErrorExitDesc ("The worker thread did't signal 'finished' state");
600 ret += ! w->success; 639 ret += 2 - w->success;
601 } 640 }
602 641
603 MHD_stop_daemon (d); 642 MHD_stop_daemon (d);