1*39281709SNamhyung Kim /* SPDX-License-Identifier: GPL-2.0 */ 2*39281709SNamhyung Kim #include <math.h> 3*39281709SNamhyung Kim #include <signal.h> 4*39281709SNamhyung Kim #include <stdlib.h> 5*39281709SNamhyung Kim #include <unistd.h> 6*39281709SNamhyung Kim #include <linux/compiler.h> 7*39281709SNamhyung Kim #include <sys/wait.h> 8*39281709SNamhyung Kim #include "../tests.h" 9*39281709SNamhyung Kim 10*39281709SNamhyung Kim static volatile sig_atomic_t done; 11*39281709SNamhyung Kim 12*39281709SNamhyung Kim static void sighandler(int sig __maybe_unused) 13*39281709SNamhyung Kim { 14*39281709SNamhyung Kim done = 1; 15*39281709SNamhyung Kim } 16*39281709SNamhyung Kim 17*39281709SNamhyung Kim static int __sqrtloop(int sec) 18*39281709SNamhyung Kim { 19*39281709SNamhyung Kim signal(SIGALRM, sighandler); 20*39281709SNamhyung Kim alarm(sec); 21*39281709SNamhyung Kim 22*39281709SNamhyung Kim while (!done) 23*39281709SNamhyung Kim (void)sqrt(rand()); 24*39281709SNamhyung Kim return 0; 25*39281709SNamhyung Kim } 26*39281709SNamhyung Kim 27*39281709SNamhyung Kim static int sqrtloop(int argc, const char **argv) 28*39281709SNamhyung Kim { 29*39281709SNamhyung Kim int sec = 1; 30*39281709SNamhyung Kim 31*39281709SNamhyung Kim if (argc > 0) 32*39281709SNamhyung Kim sec = atoi(argv[0]); 33*39281709SNamhyung Kim 34*39281709SNamhyung Kim switch (fork()) { 35*39281709SNamhyung Kim case 0: 36*39281709SNamhyung Kim return __sqrtloop(sec); 37*39281709SNamhyung Kim case -1: 38*39281709SNamhyung Kim return -1; 39*39281709SNamhyung Kim default: 40*39281709SNamhyung Kim wait(NULL); 41*39281709SNamhyung Kim } 42*39281709SNamhyung Kim return 0; 43*39281709SNamhyung Kim } 44*39281709SNamhyung Kim 45*39281709SNamhyung Kim DEFINE_WORKLOAD(sqrtloop); 46