Commit a4864a33 authored by George G. Davis's avatar George G. Davis Committed by Shuah Khan
Browse files

selftests: watchdog: Add optional file argument



Some systems have multiple watchdog devices where the first device
registered is assigned to the /dev/watchdog device file. In order
to test other watchdog devices, add an optional file argument for
selecting non-default watchdog devices for testing.

Tested-by: default avatarEugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: default avatarGeorge G. Davis <george_davis@mentor.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 88282297
Loading
Loading
Loading
Loading
+17 −3
Original line number Original line Diff line number Diff line
@@ -19,7 +19,7 @@


int fd;
int fd;
const char v = 'V';
const char v = 'V';
static const char sopts[] = "bdehp:t:Tn:NL";
static const char sopts[] = "bdehp:t:Tn:NLf:";
static const struct option lopts[] = {
static const struct option lopts[] = {
	{"bootstatus",          no_argument, NULL, 'b'},
	{"bootstatus",          no_argument, NULL, 'b'},
	{"disable",             no_argument, NULL, 'd'},
	{"disable",             no_argument, NULL, 'd'},
@@ -31,6 +31,7 @@ static const struct option lopts[] = {
	{"pretimeout",    required_argument, NULL, 'n'},
	{"pretimeout",    required_argument, NULL, 'n'},
	{"getpretimeout",       no_argument, NULL, 'N'},
	{"getpretimeout",       no_argument, NULL, 'N'},
	{"gettimeleft",		no_argument, NULL, 'L'},
	{"gettimeleft",		no_argument, NULL, 'L'},
	{"file",          required_argument, NULL, 'f'},
	{NULL,                  no_argument, NULL, 0x0}
	{NULL,                  no_argument, NULL, 0x0}
};
};


@@ -69,6 +70,8 @@ static void term(int sig)
static void usage(char *progname)
static void usage(char *progname)
{
{
	printf("Usage: %s [options]\n", progname);
	printf("Usage: %s [options]\n", progname);
	printf(" -f, --file          Open watchdog device file\n");
	printf("                     Default is /dev/watchdog\n");
	printf(" -b, --bootstatus    Get last boot status (Watchdog/POR)\n");
	printf(" -b, --bootstatus    Get last boot status (Watchdog/POR)\n");
	printf(" -d, --disable       Turn off the watchdog timer\n");
	printf(" -d, --disable       Turn off the watchdog timer\n");
	printf(" -e, --enable        Turn on the watchdog timer\n");
	printf(" -e, --enable        Turn on the watchdog timer\n");
@@ -92,14 +95,20 @@ int main(int argc, char *argv[])
	int ret;
	int ret;
	int c;
	int c;
	int oneshot = 0;
	int oneshot = 0;
	char *file = "/dev/watchdog";


	setbuf(stdout, NULL);
	setbuf(stdout, NULL);


	fd = open("/dev/watchdog", O_WRONLY);
	while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
		if (c == 'f')
			file = optarg;
	}

	fd = open(file, O_WRONLY);


	if (fd == -1) {
	if (fd == -1) {
		if (errno == ENOENT)
		if (errno == ENOENT)
			printf("Watchdog device not enabled.\n");
			printf("Watchdog device (%s) not found.\n", file);
		else if (errno == EACCES)
		else if (errno == EACCES)
			printf("Run watchdog as root.\n");
			printf("Run watchdog as root.\n");
		else
		else
@@ -108,6 +117,8 @@ int main(int argc, char *argv[])
		exit(-1);
		exit(-1);
	}
	}


	optind = 0;

	while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
	while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
		switch (c) {
		switch (c) {
		case 'b':
		case 'b':
@@ -190,6 +201,9 @@ int main(int argc, char *argv[])
			else
			else
				printf("WDIOC_GETTIMELEFT error '%s'\n", strerror(errno));
				printf("WDIOC_GETTIMELEFT error '%s'\n", strerror(errno));
			break;
			break;
		case 'f':
			/* Handled above */
			break;


		default:
		default:
			usage(argv[0]);
			usage(argv[0]);