Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,2 @@
# SPDX-License-Identifier: GPL-2.0+
test_fpu
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: GPL-2.0+
LDLIBS := -lm
TEST_GEN_PROGS := test_fpu
TEST_PROGS := run_test_fpu.sh
include ../lib.mk
+46
View File
@@ -0,0 +1,46 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Load kernel module for FPU tests
uid=$(id -u)
if [ $uid -ne 0 ]; then
echo "$0: Must be run as root"
exit 1
fi
if ! which modprobe > /dev/null 2>&1; then
echo "$0: You need modprobe installed"
exit 4
fi
if ! modinfo test_fpu > /dev/null 2>&1; then
echo "$0: You must have the following enabled in your kernel:"
echo "CONFIG_TEST_FPU=m"
exit 4
fi
NR_CPUS=$(getconf _NPROCESSORS_ONLN)
if [ ! $NR_CPUS ]; then
NR_CPUS=1
fi
modprobe test_fpu
if [ ! -e /sys/kernel/debug/selftest_helpers/test_fpu ]; then
mount -t debugfs none /sys/kernel/debug
if [ ! -e /sys/kernel/debug/selftest_helpers/test_fpu ]; then
echo "$0: Error mounting debugfs"
exit 4
fi
fi
echo "Running 1000 iterations on all CPUs... "
for i in $(seq 1 1000); do
for c in $(seq 1 $NR_CPUS); do
./test_fpu &
done
done
rmmod test_fpu
@@ -0,0 +1,61 @@
// 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;
}