nvttest: Return error if anything fails

This commit is contained in:
Kim Woelders
2024-11-10 12:42:34 +01:00
parent da027d4de1
commit cd5de2fe5d
+14 -4
View File
@@ -42,6 +42,7 @@ typedef struct {
typedef struct {
pthread_t thr;
topts_t opts;
int errors;
} thr_t;
@@ -68,6 +69,7 @@ static void *_worker(void *arg)
if (fd < 0)
{
nvt_log(LOG_ERR, "Open '%s' failed: %m\n", dev);
thr->errors++;
break;
}
@@ -76,12 +78,14 @@ static void *_worker(void *arg)
if (err != 0)
{
nvt_log(LOG_ERR, "ioctl(TCGETS) failed: %m\n");
thr->errors++;
break;
}
err = ioctl(fd, TCSETS, &ios);
if (err != 0)
{
nvt_log(LOG_ERR, "ioctl(TCSETS) failed: %m\n");
thr->errors++;
break;
}
close(fd);
@@ -98,6 +102,7 @@ static void *_worker(void *arg)
if (fd < 0)
{
nvt_log(LOG_ERR, "Open '%s' failed: %m\n", dev);
thr->errors++;
break;
}
@@ -108,11 +113,13 @@ static void *_worker(void *arg)
if (nw < 0)
{
nvt_log(LOG_ERR, "write failed: %m\n");
thr->errors++;
break;
}
if (nw < len)
{
nvt_log(LOG_ERR, "write short: %u/%u\n", nw, len);
thr->errors++;
break;
}
}
@@ -128,7 +135,7 @@ static void *_worker(void *arg)
int main(int argc, char **argv)
{
int err;
int err, errors;
int opt;
int ithr, nthr;
thr_t *threads, *thr;
@@ -179,7 +186,7 @@ int main(int argc, char **argv)
topts.nthread = nthr;
threads = malloc(nthr * sizeof(thr_t));
threads = calloc(nthr, sizeof(thr_t));
for (ithr = 0; ithr < nthr; ithr++)
{
@@ -197,14 +204,17 @@ int main(int argc, char **argv)
}
}
errors = 0;
for (ithr = 0; ithr < nthr; ithr++)
{
thr = &threads[ithr];
if (thr->thr == 0)
break;
pthread_join(thr->thr, NULL);
nvt_log(LOG_INFO, "Joined worker thread %d/%d\n", ithr + 1, nthr);
errors += thr->errors;
nvt_log(LOG_INFO, "Joined worker thread %d/%d (err=%d)\n",
ithr + 1, nthr, thr->errors);
}
return 0;
return errors ? 1 : 0;
}