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 <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@
|
|||||||
static const char help_text[] =
|
static const char help_text[] =
|
||||||
"Usage: nvttest OPTIONS...\n"
|
"Usage: nvttest OPTIONS...\n"
|
||||||
"OPTIONS:\n"
|
"OPTIONS:\n"
|
||||||
|
" -D name : Specify device name (/dev/name, default /dev/ttyNVT0)\n"
|
||||||
" -d : Enable debug\n"
|
" -d : Enable debug\n"
|
||||||
" -n loops : Test loops per thread\n"
|
" -n loops : Test loops per thread\n"
|
||||||
" -q : Quiet\n"
|
" -q : Quiet\n"
|
||||||
@@ -28,7 +30,7 @@ static const char help_text[] =
|
|||||||
;
|
;
|
||||||
/**INDENT-ON**/
|
/**INDENT-ON**/
|
||||||
|
|
||||||
static const char *dev = "/dev/ttyNVT0";
|
static char dev[64] = "/dev/ttyNVT0";
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int nthread;
|
int nthread;
|
||||||
@@ -126,18 +128,22 @@ int main(int argc, char **argv)
|
|||||||
topts_t topts = { }, *popts;
|
topts_t topts = { }, *popts;
|
||||||
pthread_t *ptids;
|
pthread_t *ptids;
|
||||||
int debug, quiet;
|
int debug, quiet;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
debug = quiet = 0;
|
debug = quiet = 0;
|
||||||
nthr = 1;
|
nthr = 1;
|
||||||
topts.nloop = 1;
|
topts.nloop = 1;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "dn:qrt:")) != -1)
|
while ((opt = getopt(argc, argv, "D:dn:qrt:")) != -1)
|
||||||
{
|
{
|
||||||
switch (opt)
|
switch (opt)
|
||||||
{
|
{
|
||||||
default: /* '?' */
|
default: /* '?' */
|
||||||
_usage(1);
|
_usage(1);
|
||||||
break;
|
break;
|
||||||
|
case 'D':
|
||||||
|
snprintf(dev, sizeof(dev), "/dev/%s", optarg);
|
||||||
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
debug += 1;
|
debug += 1;
|
||||||
break;
|
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_level(quiet, debug);
|
||||||
nvt_log_dest(NVT_LOG_STDOUT);
|
nvt_log_dest(NVT_LOG_STDOUT);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user