tools/testing/selftests/wireguard/qemu/init.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/wireguard/qemu/init.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/wireguard/qemu/init.c- Extension
.c- Size
- 6747 bytes
- Lines
- 281
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
unistd.herrno.hstring.hstdio.hstdlib.hstdbool.hfcntl.htime.hsys/wait.hsys/mount.hsys/stat.hsys/types.hsys/io.hsys/ioctl.hsys/reboot.hsys/utsname.hsys/sendfile.hsys/sysmacros.hsys/random.hlinux/random.hlinux/version.h
Detected Declarations
function Copyrightfunction panicfunction print_bannerfunction seed_rngfunction set_timefunction mount_filesystemsfunction enable_loggingfunction kmod_selftestsfunction launch_testsfunction ensure_consolefunction clear_leaksfunction check_leaksfunction main
Annotated Snippet
if (!pass || pass[6] != '\0') {
success = false;
printf(" \x1b[31m* %s\x1b[0m\n", start);
} else
printf(" \x1b[32m* %s\x1b[0m\n", start);
}
fclose(file);
if (!success) {
puts("\x1b[31m\x1b[1m[-] Tests failed! \u2639\x1b[0m");
poweroff();
}
}
static void launch_tests(void)
{
char cmdline[4096], *success_dev;
int status, fd;
pid_t pid;
pretty_message("[+] Launching tests...");
pid = fork();
if (pid == -1)
panic("fork");
else if (pid == 0) {
execl("/init.sh", "init", NULL);
panic("exec");
}
if (waitpid(pid, &status, 0) < 0)
panic("waitpid");
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
pretty_message("[+] Tests successful! :-)");
fd = open("/proc/cmdline", O_RDONLY);
if (fd < 0)
panic("open(/proc/cmdline)");
if (read(fd, cmdline, sizeof(cmdline) - 1) <= 0)
panic("read(/proc/cmdline)");
cmdline[sizeof(cmdline) - 1] = '\0';
for (success_dev = strtok(cmdline, " \n"); success_dev; success_dev = strtok(NULL, " \n")) {
if (strncmp(success_dev, "wg.success=", 11))
continue;
memcpy(success_dev + 11 - 5, "/dev/", 5);
success_dev += 11 - 5;
break;
}
if (!success_dev || !strlen(success_dev))
panic("Unable to find success device");
fd = open(success_dev, O_WRONLY);
if (fd < 0)
panic("open(success_dev)");
if (write(fd, "success\n", 8) != 8)
panic("write(success_dev)");
close(fd);
} else {
const char *why = "unknown cause";
int what = -1;
if (WIFEXITED(status)) {
why = "exit code";
what = WEXITSTATUS(status);
} else if (WIFSIGNALED(status)) {
why = "signal";
what = WTERMSIG(status);
}
printf("\x1b[31m\x1b[1m[-] Tests failed with %s %d! \u2639\x1b[0m\n", why, what);
}
}
static void ensure_console(void)
{
for (unsigned int i = 0; i < 1000; ++i) {
int fd = open("/dev/console", O_RDWR);
if (fd < 0) {
usleep(50000);
continue;
}
dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
close(fd);
if (write(1, "\0\0\0\0\n", 5) == 5)
return;
}
panic("Unable to open console device");
}
static void clear_leaks(void)
{
int fd;
Annotation
- Immediate include surface: `unistd.h`, `errno.h`, `string.h`, `stdio.h`, `stdlib.h`, `stdbool.h`, `fcntl.h`, `time.h`.
- Detected declarations: `function Copyright`, `function panic`, `function print_banner`, `function seed_rng`, `function set_time`, `function mount_filesystems`, `function enable_logging`, `function kmod_selftests`, `function launch_tests`, `function ensure_console`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.