tools/testing/selftests/watchdog/watchdog-test.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/watchdog/watchdog-test.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/watchdog/watchdog-test.c
Extension
.c
Size
9489 bytes
Lines
366
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

struct wdiof_status {
	int flag;
	const char *status_str;
};

#define WDIOF_NUM_STATUS 8

static const struct wdiof_status wdiof_status[WDIOF_NUM_STATUS] = {
	{WDIOF_SETTIMEOUT,  "Set timeout (in seconds)"},
	{WDIOF_MAGICCLOSE,  "Supports magic close char"},
	{WDIOF_PRETIMEOUT,  "Pretimeout (in seconds), get/set"},
	{WDIOF_ALARMONLY,  "Watchdog triggers a management or other external alarm not a reboot"},
	{WDIOF_KEEPALIVEPING,  "Keep alive ping reply"},
	{WDIOS_DISABLECARD,  "Turn off the watchdog timer"},
	{WDIOS_ENABLECARD,  "Turn on the watchdog timer"},
	{WDIOS_TEMPPANIC,  "Kernel panic on temperature trip"},
};

static void print_status(int flags)
{
	int wdiof = 0;

	if (flags == WDIOS_UNKNOWN) {
		printf("Unknown status error from WDIOC_GETSTATUS\n");
		return;
	}

	for (wdiof = 0; wdiof < WDIOF_NUM_STATUS; wdiof++) {
		if (flags & wdiof_status[wdiof].flag)
			printf("Support/Status: %s\n",
				wdiof_status[wdiof].status_str);
	}
}

#define WDIOF_NUM_BOOTSTATUS 7

static const struct wdiof_status wdiof_bootstatus[WDIOF_NUM_BOOTSTATUS] = {
	{WDIOF_OVERHEAT, "Reset due to CPU overheat"},
	{WDIOF_FANFAULT, "Fan failed"},
	{WDIOF_EXTERN1, "External relay 1"},
	{WDIOF_EXTERN2, "External relay 2"},
	{WDIOF_POWERUNDER, "Power bad/power fault"},
	{WDIOF_CARDRESET, "Card previously reset the CPU"},
	{WDIOF_POWEROVER,  "Power over voltage"},
};

static void print_boot_status(int flags)
{
	int wdiof = 0;

	if (flags == WDIOF_UNKNOWN) {
		printf("Unknown flag error from WDIOC_GETBOOTSTATUS\n");
		return;
	}

	if (flags == 0) {
		printf("Last boot is caused by: Power-On-Reset\n");
		return;
	}

	for (wdiof = 0; wdiof < WDIOF_NUM_BOOTSTATUS; wdiof++) {
		if (flags & wdiof_bootstatus[wdiof].flag)
			printf("Last boot is caused by: %s\n",
				wdiof_bootstatus[wdiof].status_str);
	}
}

int main(int argc, char *argv[])
{
	int flags;
	unsigned int ping_rate = DEFAULT_PING_RATE;
	int ret;
	int c;
	int oneshot = 0;
	char *file = "/dev/watchdog";
	struct watchdog_info info;
	int temperature;

	setbuf(stdout, NULL);

	while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
		if (c == 'f')
			file = optarg;
	}

	fd = open(file, O_WRONLY);

	if (fd == -1) {
		if (errno == ENOENT)
			printf("Watchdog device (%s) not found.\n", file);

Annotation

Implementation Notes