1 /******************************************************************************/ 2 /* */ 3 /* Copyright (c) International Business Machines Corp., 2008 */ 4 /* */ 5 /* This program is free software; you can redistribute it and/or modify */ 6 /* it under the terms of the GNU General Public License as published by */ 7 /* the Free Software Foundation; either version 2 of the License, or */ 8 /* (at your option) any later version. */ 9 /* */ 10 /* This program is distributed in the hope that it will be useful, */ 11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ 13 /* the GNU General Public License for more details. */ 14 /* */ 15 /* You should have received a copy of the GNU General Public License */ 16 /* along with this program; if not, write to the Free Software */ 17 /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ 18 /* */ 19 /******************************************************************************/ 20 21 /******************************************************************************/ 22 /* */ 23 /* File: cpuctl_latency_test.c */ 24 /* */ 25 /* Description: This is a c program that runs a task which tries to keep cpu */ 26 /* busy in doing some calculations. The task will be used to */ 27 /* check the latency under group scheduling. */ 28 /* The file is to be used by script */ 29 /* */ 30 /* Total Tests: 2 */ 31 /* */ 32 /* Test Name: cpu_controller_latency_tests */ 33 /* */ 34 /* Test Assertion */ 35 /* Please refer to the file cpuctl_testplan.txt */ 36 /* */ 37 /* Author: Sudhir Kumar skumar@linux.vnet.ibm.com */ 38 /* */ 39 /* History: */ 40 /* Created- 26/11/2008 -Sudhir Kumar <skumar@linux.vnet.ibm.com> */ 41 /* */ 42 /******************************************************************************/ 43 44 #include <errno.h> 45 #include <err.h> 46 #include <signal.h> 47 #include <stdio.h> 48 #include <stdlib.h> 49 #include <string.h> 50 #include <unistd.h> 51 52 #include "../libcontrollers/libcontrollers.h" 53 54 char *TCID = "cpu_controller_latency_tests"; 55 int TST_TOTAL = 2; 56 57 void sighandler(int i) 58 { 59 exit(0); 60 } 61 62 int main(int argc, char *argv[]) 63 { 64 char mytaskfile[FILENAME_MAX]; 65 int test_num; 66 67 struct sigaction newaction, oldaction; 68 69 /* TODO (garrcoop): add error handling. */ 70 sigemptyset(&newaction.sa_mask); 71 sigaddset(&newaction.sa_mask, SIGUSR1); 72 newaction.sa_handler = &sighandler; 73 sigaction(SIGUSR1, &newaction, &oldaction); 74 75 if (argc < 2 || argc > 3) { 76 errx(EINVAL, "TBROK\t Invalid #args received from script" 77 " The test will run without any cpu load"); 78 } 79 80 /* Migrate the task to its group if applicable */ 81 test_num = atoi(argv[1]); 82 if (test_num < 0) { 83 errx(EINVAL, 84 "Invalid test number received from script. " 85 "Skipping load creation"); 86 } 87 88 if (test_num == 2) { 89 strncpy(mytaskfile, argv[2], FILENAME_MAX); 90 strncat(mytaskfile, "/tasks", 91 FILENAME_MAX - strlen(mytaskfile) - 1); 92 write_to_file(mytaskfile, "a", getpid()); 93 } 94 95 while (1) ; 96 97 return 0; 98 } 99