tools/testing/selftests/fpu/test_fpu.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/fpu/test_fpu.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/fpu/test_fpu.c- Extension
.c- Size
- 1576 bytes
- Lines
- 62
- 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.
Dependency Surface
stdio.herrno.hstring.hfenv.hunistd.hfcntl.h
Detected Declarations
function main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0+
/* This testcase operates with the test_fpu kernel driver.
* It modifies the FPU control register in user mode and calls the kernel
* module to perform floating point operations in the kernel. The control
* register value should be independent between kernel and user mode.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <fenv.h>
#include <unistd.h>
#include <fcntl.h>
const char *test_fpu_path = "/sys/kernel/debug/selftest_helpers/test_fpu";
int main(void)
{
char dummy[1];
int fd = open(test_fpu_path, O_RDONLY);
if (fd < 0) {
printf("[SKIP]\tcan't access %s: %s\n",
test_fpu_path, strerror(errno));
return 0;
}
if (read(fd, dummy, 1) < 0) {
printf("[FAIL]\taccess with default rounding mode failed\n");
return 1;
}
fesetround(FE_DOWNWARD);
if (read(fd, dummy, 1) < 0) {
printf("[FAIL]\taccess with downward rounding mode failed\n");
return 2;
}
if (fegetround() != FE_DOWNWARD) {
printf("[FAIL]\tusermode rounding mode clobbered\n");
return 3;
}
/* Note: the tests up to this point are quite safe and will only return
* an error. But the exception mask setting can cause misbehaving kernel
* to crash.
*/
feclearexcept(FE_ALL_EXCEPT);
feenableexcept(FE_ALL_EXCEPT);
if (read(fd, dummy, 1) < 0) {
printf("[FAIL]\taccess with fpu exceptions unmasked failed\n");
return 4;
}
if (fegetexcept() != FE_ALL_EXCEPT) {
printf("[FAIL]\tusermode fpu exception mask clobbered\n");
return 5;
}
printf("[OK]\ttest_fpu\n");
return 0;
}
Annotation
- Immediate include surface: `stdio.h`, `errno.h`, `string.h`, `fenv.h`, `unistd.h`, `fcntl.h`.
- Detected declarations: `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.