fix issues in test logic

This commit is contained in:
Christian Grothoff
2024-07-21 17:04:25 +02:00
parent fcb47a6a1c
commit cd8a44ac17
4 changed files with 76 additions and 8 deletions
+23 -6
View File
@@ -278,6 +278,10 @@ run_single_client (void *cls)
struct ClientContext *cc = cls;
const char *err;
fprintf (stderr,
"Client %u started in phase %s\n",
cc->pc.client_id,
cc->phase->label);
err = cc->phase->client_cb (cc->phase->client_cb_cls,
&cc->pc);
if (NULL != err)
@@ -300,6 +304,10 @@ run_single_client (void *cls)
write (cc->p2,
"s",
1));
fprintf (stderr,
"Client %u finished in phase %s\n",
cc->pc.client_id,
cc->phase->label);
return NULL;
}
@@ -367,12 +375,20 @@ run_client_phase (const struct MHDT_Phase *phase,
for (i = phase->timeout_ms - 1; i>0; i--)
{
struct timespec ms = {
.tv_nsec = 1000 * 1000
.tv_nsec = 1000 * 1000,
.tv_sec = 1000 // for debugging...
};
struct timespec rem;
char c;
nanosleep (&ms,
NULL);
if (0 != nanosleep (&ms,
&rem))
{
fprintf (stderr,
"nanosleep() interrupted (%s), trying again\n",
strerror (errno));
i++;
}
/* This is a non-blocking read */
while (1 == read (p[0],
&c,
@@ -537,10 +553,11 @@ MHDT_test (MHDT_ServerSetup ss_cb,
strerror (errno));
return 77;
}
// FIXME: start some thread to run the actual server!
for (i = 0; NULL == phases[i].label; i++)
for (i = 0; NULL != phases[i].label; i++)
{
fprintf (stderr,
"Running test phase %s\n",
phases[i].label);
if (! run_client_phase (&phases[i],
&pc))
{
+15
View File
@@ -314,6 +314,21 @@ typedef void
struct MHD_Daemon *d);
/**
* Function that starts an MHD daemon with the
* simple #MHD_daemon_start() method until
* a read() against @a finsig succeeds.
*
* @param cls closure
* @param finsig fd to read from to detect termination request
* @param[in,out] d daemon to run
*/
void
MHDT_server_run_minimal (void *cls,
int finsig,
struct MHD_Daemon *d);
/**
* Function that runs an MHD daemon in blocking mode until
* a read() against @a finsig succeeds.
+37
View File
@@ -46,6 +46,38 @@ MHDT_server_setup_minimal (void *cls,
}
void
MHDT_server_run_minimal (void *cls,
int finsig,
struct MHD_Daemon *d)
{
fd_set r;
FD_ZERO (&r);
FD_SET (finsig, &r);
while (1)
{
if ( (-1 ==
select (finsig + 1,
&r,
NULL,
NULL,
NULL)) &&
(EAGAIN != errno) )
{
fprintf (stderr,
"Failure waiting on termination signal: %s\n",
strerror (errno));
break;
}
if (FD_ISSET (finsig,
&r))
break;
}
}
#if FUTURE
void
MHDT_server_run_blocking (void *cls,
int finsig,
@@ -77,6 +109,9 @@ MHDT_server_run_blocking (void *cls,
}
#endif
const struct MHD_Action *
MHDT_server_reply_text (
void *cls,
@@ -223,6 +258,8 @@ MHDT_server_reply_check_header (
enum MHD_HTTP_Method method,
uint_fast64_t upload_size)
{
if (1)
return NULL; // force failure...
// FIXME: actual check logic missing...
return MHD_action_from_response (
request,
+1 -2
View File
@@ -38,7 +38,6 @@ main (int argc, char *argv[])
.client_cb = &MHDT_client_get_root,
.client_cb_cls = "Hello world",
.timeout_ms = 5,
.num_clients = 10
},
// Basic upload
// HTTP client header
@@ -83,7 +82,7 @@ main (int argc, char *argv[])
//
return MHDT_test (&MHDT_server_setup_minimal,
NULL,
&MHDT_server_run_blocking,
&MHDT_server_run_minimal,
NULL,
phases);
}