nvttest: Enable specifying device
Also check that the device file exists.
This commit is contained in:
+14
-2
@@ -7,6 +7,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
@@ -20,6 +21,7 @@
|
||||
static const char help_text[] =
|
||||
"Usage: nvttest OPTIONS...\n"
|
||||
"OPTIONS:\n"
|
||||
" -D name : Specify device name (/dev/name, default /dev/ttyNVT0)\n"
|
||||
" -d : Enable debug\n"
|
||||
" -n loops : Test loops per thread\n"
|
||||
" -q : Quiet\n"
|
||||
@@ -28,7 +30,7 @@ static const char help_text[] =
|
||||
;
|
||||
/**INDENT-ON**/
|
||||
|
||||
static const char *dev = "/dev/ttyNVT0";
|
||||
static char dev[64] = "/dev/ttyNVT0";
|
||||
|
||||
typedef struct {
|
||||
int nthread;
|
||||
@@ -126,18 +128,22 @@ int main(int argc, char **argv)
|
||||
topts_t topts = { }, *popts;
|
||||
pthread_t *ptids;
|
||||
int debug, quiet;
|
||||
struct stat st;
|
||||
|
||||
debug = quiet = 0;
|
||||
nthr = 1;
|
||||
topts.nloop = 1;
|
||||
|
||||
while ((opt = getopt(argc, argv, "dn:qrt:")) != -1)
|
||||
while ((opt = getopt(argc, argv, "D:dn:qrt:")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
default: /* '?' */
|
||||
_usage(1);
|
||||
break;
|
||||
case 'D':
|
||||
snprintf(dev, sizeof(dev), "/dev/%s", optarg);
|
||||
break;
|
||||
case 'd':
|
||||
debug += 1;
|
||||
break;
|
||||
@@ -156,6 +162,12 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (stat(dev, &st) || !S_ISCHR(st.st_mode))
|
||||
{
|
||||
fprintf(stderr, "Invalid device file: '%s'\n", dev);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
nvt_log_level(quiet, debug);
|
||||
nvt_log_dest(NVT_LOG_STDOUT);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user