cpuctl_latency_test.c revision 6c4d1c6d4b3c116ff88f9209b4860940fb8659a8
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 54extern int Tst_count; 55char *TCID = "cpu_controller_latency_tests"; 56int TST_TOTAL = 2; 57 58void sighandler(int i) 59{ 60 exit(0); 61} 62 63int main(int argc, char *argv[]) 64{ 65 char mytaskfile[FILENAME_MAX]; 66 int test_num; 67 68 struct sigaction newaction, oldaction; 69 70 /* TODO (garrcoop): add error handling. */ 71 sigemptyset(&newaction.sa_mask); 72 sigaddset(&newaction.sa_mask, SIGUSR1); 73 newaction.sa_handler = &sighandler; 74 sigaction(SIGUSR1, &newaction, &oldaction); 75 76 if (argc < 2 || argc > 3) { 77 errx(EINVAL, "TBROK\t Invalid #args received from script" 78 " The test will run without any cpu load"); 79 } 80 81 /* Migrate the task to its group if applicable */ 82 test_num = atoi(argv[1]); 83 if (test_num < 0) { 84 errx(EINVAL, 85 "Invalid test number received from script. " 86 "Skipping load creation"); 87 } 88 89 if (test_num == 2) { 90 strncpy(mytaskfile, argv[2], FILENAME_MAX); 91 strncat(mytaskfile, "/tasks", 92 FILENAME_MAX - strlen(mytaskfile) - 1); 93 write_to_file(mytaskfile, "a", getpid()); 94 } 95 96 while (1) ; 97 98 return 0; 99} 100