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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hstdio.hstdlib.hstring.hunistd.hfcntl.hsignal.hgetopt.hsys/ioctl.hlinux/types.hlinux/watchdog.h
Detected Declarations
struct wdiof_statusfunction keep_alivefunction termfunction usagefunction print_statusfunction print_boot_statusfunction main
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
- Immediate include surface: `errno.h`, `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`, `fcntl.h`, `signal.h`, `getopt.h`.
- Detected declarations: `struct wdiof_status`, `function keep_alive`, `function term`, `function usage`, `function print_status`, `function print_boot_status`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.