nvttest: Use nvt_log for printing output
This commit is contained in:
@@ -5,3 +5,5 @@ nvttest_SOURCES = \
|
|||||||
nvttest.c
|
nvttest.c
|
||||||
|
|
||||||
nvttest_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir) $(CFLAGS_WARN)
|
nvttest_CPPFLAGS = -I$(top_builddir) -I$(top_srcdir) $(CFLAGS_WARN)
|
||||||
|
|
||||||
|
nvttest_LDADD = $(top_builddir)/lib/libnvt.la
|
||||||
|
|||||||
+30
-14
@@ -13,6 +13,11 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <asm/termbits.h>
|
#include <asm/termbits.h>
|
||||||
|
|
||||||
|
#include "lib/nvt_log.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define HELP \
|
||||||
|
"Usage: nvttest -dqr [-n loops] [-t threads]\n"
|
||||||
|
|
||||||
static const char *dev = "/dev/ttyNVT0";
|
static const char *dev = "/dev/ttyNVT0";
|
||||||
|
|
||||||
@@ -32,13 +37,13 @@ static void *_worker(void *arg)
|
|||||||
|
|
||||||
for (iloop = 0; iloop < topts->nloop; iloop++)
|
for (iloop = 0; iloop < topts->nloop; iloop++)
|
||||||
{
|
{
|
||||||
printf("Thread %d/%d run %d/%d\n",
|
nvt_log(LOG_INFO, "Thread %d/%d run %d/%d\n",
|
||||||
topts->ithread, topts->nthread, iloop + 1, topts->nloop);
|
topts->ithread, topts->nthread, iloop + 1, topts->nloop);
|
||||||
{
|
{
|
||||||
fd = open(dev, O_RDWR);
|
fd = open(dev, O_RDWR);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
printf("Open '%s' failed: %m\n", dev);
|
nvt_log(LOG_ERR, "Open '%s' failed: %m\n", dev);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,13 +51,13 @@ static void *_worker(void *arg)
|
|||||||
err = ioctl(fd, TCGETS, &ios);
|
err = ioctl(fd, TCGETS, &ios);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
{
|
{
|
||||||
printf("ioctl(TCGETS) failed: %m\n");
|
nvt_log(LOG_ERR, "ioctl(TCGETS) failed: %m\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
err = ioctl(fd, TCSETS, &ios);
|
err = ioctl(fd, TCSETS, &ios);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
{
|
{
|
||||||
printf("ioctl(TCSETS) failed: %m\n");
|
nvt_log(LOG_ERR, "ioctl(TCSETS) failed: %m\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
@@ -68,7 +73,7 @@ static void *_worker(void *arg)
|
|||||||
fd = open(dev, O_RDWR);
|
fd = open(dev, O_RDWR);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
printf("Open '%s' failed: %m\n", dev);
|
nvt_log(LOG_ERR, "Open '%s' failed: %m\n", dev);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,12 +83,12 @@ static void *_worker(void *arg)
|
|||||||
nw = write(fd, buf, len);
|
nw = write(fd, buf, len);
|
||||||
if (nw < 0)
|
if (nw < 0)
|
||||||
{
|
{
|
||||||
printf("write failed: %m\n");
|
nvt_log(LOG_ERR, "write failed: %m\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (nw < len)
|
if (nw < len)
|
||||||
{
|
{
|
||||||
printf("write short: %u/%u\n", nw, len);
|
nvt_log(LOG_ERR, "write short: %u/%u\n", nw, len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,36 +109,47 @@ int main(int argc, char **argv)
|
|||||||
int ithr, nthr;
|
int ithr, nthr;
|
||||||
topts_t topts = { }, *popts;
|
topts_t topts = { }, *popts;
|
||||||
pthread_t *ptids;
|
pthread_t *ptids;
|
||||||
|
int debug, quiet;
|
||||||
|
|
||||||
|
debug = quiet = 0;
|
||||||
nthr = 1;
|
nthr = 1;
|
||||||
topts.nloop = 1;
|
topts.nloop = 1;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "n:rt:")) != -1)
|
while ((opt = getopt(argc, argv, "dn:qrt:")) != -1)
|
||||||
{
|
{
|
||||||
switch (opt)
|
switch (opt)
|
||||||
{
|
{
|
||||||
|
default: /* '?' */
|
||||||
|
fprintf(stderr, HELP);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
case 'd':
|
||||||
|
debug += 1;
|
||||||
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
topts.nloop = atoi(optarg);
|
topts.nloop = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'q':
|
||||||
|
quiet = 1;
|
||||||
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
topts.opt_rand_delay = true;
|
topts.opt_rand_delay = true;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
nthr = atoi(optarg);
|
nthr = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
default: /* '?' */
|
|
||||||
fprintf(stderr, "Usage: %s [-n nloop]\n", argv[0]);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvt_log_level(quiet, debug);
|
||||||
|
nvt_log_dest(NVT_LOG_STDOUT);
|
||||||
|
|
||||||
topts.nthread = nthr;
|
topts.nthread = nthr;
|
||||||
|
|
||||||
ptids = malloc(nthr * sizeof(pthread_t));
|
ptids = malloc(nthr * sizeof(pthread_t));
|
||||||
|
|
||||||
for (ithr = 0; ithr < nthr; ithr++)
|
for (ithr = 0; ithr < nthr; ithr++)
|
||||||
{
|
{
|
||||||
printf("Create worker thread %d/%d\n", ithr + 1, nthr);
|
nvt_log(LOG_INFO, "Create worker thread %d/%d\n", ithr + 1, nthr);
|
||||||
|
|
||||||
popts = malloc(sizeof(topts_t));
|
popts = malloc(sizeof(topts_t));
|
||||||
*popts = topts;
|
*popts = topts;
|
||||||
@@ -142,7 +158,7 @@ int main(int argc, char **argv)
|
|||||||
err = pthread_create(&ptids[ithr], NULL, _worker, popts);
|
err = pthread_create(&ptids[ithr], NULL, _worker, popts);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
printf("Failed to create thread %d/%d\n", ithr, nthr);
|
nvt_log(LOG_ERR, "Failed to create thread %d/%d\n", ithr, nthr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,7 +168,7 @@ int main(int argc, char **argv)
|
|||||||
if (ptids[ithr] == 0)
|
if (ptids[ithr] == 0)
|
||||||
break;
|
break;
|
||||||
pthread_join(ptids[ithr], NULL);
|
pthread_join(ptids[ithr], NULL);
|
||||||
printf("Joined worker thread %d/%d\n", ithr + 1, nthr);
|
nvt_log(LOG_INFO, "Joined worker thread %d/%d\n", ithr + 1, nthr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user