/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * Test that the process that is the head of the highest priority list preempt * the process calling sched_setparam() when the calling process sets its own * priority lower than that of one or more other non-empty process lists. * * There is no portable way to get the number of CPUs but the test should work * for most of UNIX system (including but not limited to: Linux, Solaris, AIX, * HPUX, *BSD). * This test used shared memory. * Steps: * 1. Create a share memory segment. * 2. Change the policy to SCHED_FIFO. * 3. Create nb_cpu children processes which shall have the same priority * and policy than the father (cf specs of fork). * 4. Call sched_setparam with a priority smaller than those of children. * 5. Check if the shared value has been changed by a child process. If not, * the test fail. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include "posixtest.h" #ifdef BSD # include # include # include #endif #ifdef HPUX # include # include #endif /* Max number of loop for child_process */ #define NB_LOOP 100000 int nb_cpu; int *shmptr; /* shared memory */ /* Get the number of CPUs */ int get_ncpu() { int ncpu = -1; /* This syscall is not POSIX but it should work on many system */ #ifdef _SC_NPROCESSORS_ONLN ncpu = sysconf(_SC_NPROCESSORS_ONLN); #else # ifdef BSD int mib[2]; size_t len = sizeof(ncpu); mib[0] = CTL_HW; mib[1] = HW_NCPU; sysctl(mib, 2, &ncpu, &len, NULL, 0); # else # ifdef HPUX struct pst_dynamic psd; pstat_getdynamic(&psd, sizeof(psd), 1, 0); ncpu = (int)psd.psd_proc_cnt; # endif /* HPUX */ # endif /* BSD */ #endif /* _SC_NPROCESSORS_ONLN */ return ncpu; } void child_process(){ alarm(2); while(1) { (*shmptr)++; sched_yield(); } } void kill_children(int *child_pid){ int i; for(i=0; i