tests: check preloading of FPU registers
This commit is contained in:
parent
6ef611b8aa
commit
f3bef7cb8c
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*
|
||||
* PURPOSE: check that the FPU state is preloaded in the hardware as
|
||||
* expected when an EVL thread emerges, including when the attachement
|
||||
* follows a plain fork() [and no exec()]. If that action unexpectedly
|
||||
* triggers a FPU trap for which a transition to inband mode is
|
||||
* required, we would be notified via the SIGDEBUG handler (cause ==
|
||||
* SIGDEBUG_MIGRATE_FAULT).
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <evl/evl.h>
|
||||
#include <evl/thread.h>
|
||||
#include <uapi/evl/signal.h>
|
||||
#include "helpers.h"
|
||||
|
||||
static double get_float(void)
|
||||
{
|
||||
return 2277.55 * (double)rand();
|
||||
}
|
||||
|
||||
static void sigdebug_handler(int sig, siginfo_t *si, void *context)
|
||||
{
|
||||
evl_sigdebug_handler(sig, si, context);
|
||||
exit(1); /* bad */
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct sched_param param;
|
||||
struct sigaction sa;
|
||||
int tfd, ret;
|
||||
__u32 mode;
|
||||
double f;
|
||||
|
||||
srand(time(NULL));
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_sigaction = sigdebug_handler;
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
sigaction(SIGDEBUG, &sa, NULL);
|
||||
|
||||
param.sched_priority = 1;
|
||||
__Texpr_assert(pthread_setschedparam(pthread_self(),
|
||||
SCHED_FIFO, ¶m) == 0);
|
||||
__Tcall_assert(tfd, evl_attach_self("fpu-preload:%d", getpid()));
|
||||
|
||||
mode = T_WARN;
|
||||
__Tcall_assert(ret, oob_ioctl(tfd, EVL_THRIOC_SET_MODE, &mode));
|
||||
f = get_float() * get_float();
|
||||
__Tcall_assert(ret, oob_ioctl(tfd, EVL_THRIOC_CLEAR_MODE, &mode));
|
||||
if (fork() == 0) {
|
||||
__Tcall_assert(tfd, evl_attach_self("fpu-preload-child:%d", getpid()));
|
||||
__Tcall_assert(ret, oob_ioctl(tfd, EVL_THRIOC_SET_MODE, &mode));
|
||||
f = get_float() * get_float();
|
||||
}
|
||||
|
||||
return f == NAN;
|
||||
}
|
Loading…
Reference in New Issue