HI,
This patch adds the fourth testcase for cpu controller.
Signed-off-by: Sudhir Kumar <[EMAIL PROTECTED]>
Index: ltp-full-20080131/testcases/kernel/controllers/cpuctl/cpuctl_test02.c
===================================================================
--- /dev/null
+++ ltp-full-20080131/testcases/kernel/controllers/cpuctl/cpuctl_test02.c
@@ -0,0 +1,171 @@
+/******************************************************************************/
+/*
*/
+/* Copyright (c) International Business Machines Corp., 2007
*/
+/*
*/
+/* This program is free software; you can redistribute it and/or modify
*/
+/* it under the terms of the GNU General Public License as published by
*/
+/* the Free Software Foundation; either version 2 of the License, or
*/
+/* (at your option) any later version.
*/
+/*
*/
+/* 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.
*/
+/*
*/
+/* You should have received a copy of the GNU General Public License
*/
+/* along with this program; if not, write to the Free Software
*/
+/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+/*
*/
+/******************************************************************************/
+
+/******************************************************************************/
+/*
*/
+/* File: cpuctl_test02.c
*/
+/*
*/
+/* Description: This is a c program that tests the cpucontroller fairness of
*/
+/* scheduling the tasks according to their group shares. This
*/
+/* testcase tests the ability of the cpu controller to provide
*/
+/* fairness for share values (absolute).
*/
+/*
*/
+/* Total Tests: 1
*/
+/*
*/
+/* Test Name: cpu_controller_test02
*/
+/*
*/
+/* Test Assertion
*/
+/* Please refer to the file cpuctl_testplan.txt
*/
+/*
*/
+/* Author: Sudhir Kumar [EMAIL PROTECTED] */
+/*
*/
+/* History:
*/
+/* Created- 20/12/2007 -Sudhir Kumar [EMAIL PROTECTED] */
+/*
*/
+/******************************************************************************/
+
+/* Standard Include Files */
+#include <unistd.h>
+#include <math.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/resource.h>
+#include <sys/syscall.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "test.h" /* LTP harness APIs*/
+
+#define TIME_INTERVAL 60 /* Time interval in seconds*/
+#define NUM_INTERVALS 4 /* How many iterations of TIME_INTERVAL */
+
+extern int Tst_count;
+char *TCID = "cpu_controller_test04";
+int TST_TOTAL = 1;
+pid_t scriptpid;
+extern void
+cleanup()
+{
+ kill (scriptpid, SIGUSR1);/* Inform the shell to do cleanup*/
+ tst_exit (); /* Report exit status*/
+}
+
+int write_to_file (char * file, const char* mode, unsigned int value);
+void signal_handler_alarm (int signal );
+int timer_expired = 0;
+
+int main(int argc, char* argv[])
+{
+
+ int num_cpus; /* To calculate cpu time in %*/
+ char mygroup[32], mytaskfile[32], ch;
+ pid_t pid;
+ int my_group_num, /* A number attached with a group*/
+ fd, /* A descriptor to open a fifo for
synchronized start*/
+ counter =0; /* To take n number of readings*/
+ double total_cpu_time, /* Accumulated cpu time*/
+ delta_cpu_time, /* Time the task could run on cpu(s)
(in an interval)*/
+ prev_cpu_time=0;
+ struct rusage cpu_usage;
+ time_t current_time, prev_time, delta_time;
+ struct sigaction newaction, oldaction;
+ /* Signal handling for alarm*/
+ sigemptyset (&newaction.sa_mask);
+ newaction.sa_handler = signal_handler_alarm;
+ newaction.sa_flags=0;
+ sigaction (SIGALRM, &newaction, &oldaction);
+
+ /* Check if all parameters passed are correct*/
+ if ((argc < 5) || ((my_group_num = atoi(argv[1])) <= 0) || ((scriptpid
= atoi(argv[3])) <= 0) || ((num_cpus = atoi(argv[4])) <= 0))
+ {
+ tst_brkm (TBROK, cleanup, "Invalid input parameters\n");
+ }
+
+ sprintf(mygroup,"%s", argv[2]);
+ sprintf(mytaskfile, "%s", mygroup);
+ strcat (mytaskfile,"/tasks");
+ pid = getpid();
+ write_to_file (mytaskfile, "a", pid); /* Assign the task to it's
group*/
+
+ fd = open ("./myfifo", 0);
+ if (fd == -1)
+ {
+ tst_brkm (TBROK, cleanup, "Could not open fifo for
synchronization");
+ }
+
+ read (fd, &ch, 1); /* To block all tasks here and fire
them up at the same time*/
+ prev_time = time (NULL); /* Note down the time*/
+
+ while (1)
+ {
+ /* Need to run some cpu intensive task, which also frequently
checks the timer value*/
+ double f = 274.345, mytime; /*just a float number to take
sqrt*/
+ alarm (TIME_INTERVAL);
+ timer_expired = 0;
+ while (!timer_expired) /* Let the task run on cpu for
TIME_INTERVAL*/
+ f = sqrt (f*f); /* Time of this operation should not be
high otherwise we can
+ * exceed the TIME_INTERVAL to measure
cpu usage
+ */
+ current_time = time (NULL);
+ delta_time = current_time - prev_time; /* Duration in case its
not exact TIME_INTERVAL*/
+
+ getrusage (0, &cpu_usage);
+ total_cpu_time = (cpu_usage.ru_utime.tv_sec +
cpu_usage.ru_utime.tv_usec * 1e-6 + /* user time*/
+ cpu_usage.ru_stime.tv_sec +
cpu_usage.ru_stime.tv_usec * 1e-6) ; /* system time*/
+ delta_cpu_time = total_cpu_time - prev_cpu_time;
+
+ prev_cpu_time = total_cpu_time;
+ prev_time = current_time;
+ if (delta_time > TIME_INTERVAL)
+ mytime = (delta_cpu_time * 100) / (delta_time *
num_cpus);
+ else
+ mytime = (delta_cpu_time * 100) / (TIME_INTERVAL *
num_cpus);
+
+ fprintf (stdout,"PID: %u\tgroup-%d:cpu time --->
%6.3f\%(%fs)\tinterval:%lu\n",getpid(),my_group_num, mytime, delta_cpu_time,
delta_time);
+ counter++;
+
+ if (counter >= NUM_INTERVALS) /* Take n sets of readings for
each shares value*/
+ exit (0); /* This task is done with its
job*/
+
+ }/* end while*/
+}/* end main*/
+
+
+int write_to_file (char *file, const char *mode, unsigned int value)
+{
+ FILE *fp;
+ fp = fopen (file, mode);
+ if (fp == NULL)
+ {
+ tst_brkm (TBROK, cleanup, "Could not open file %s for writing",
file);
+ }
+ fprintf (fp, "%u\n", value);
+ fclose (fp);
+ return 0;
+}
+
+void signal_handler_alarm (int signal)
+{
+ timer_expired = 1;
+}
Index: ltp-full-20080131/testcases/kernel/controllers/cpuctl/run_cpuctl_test.sh
===================================================================
---
ltp-full-20080131.orig/testcases/kernel/controllers/cpuctl/run_cpuctl_test.sh
+++ ltp-full-20080131/testcases/kernel/controllers/cpuctl/run_cpuctl_test.sh
@@ -51,7 +51,10 @@ export TST_COUNT=1;
RC=0; # return code from functions
NUM_CPUS=1; # at least 1 cpu is there
NUM_GROUPS=2; # min number of groups
-TEST_NUM=$1; # To run the desired test (1 or 2)
+TEST_NUM=$1; # To run the desired test (1 or 2)
+TASK_NUM=0; # The serial number of a task
+TOTAL_TASKS=0; # Total num of tasks in any test
+TASKS_IN_GROUP=0 # Total num of tasks in a group
PWD=`pwd`
cd $LTPROOT/testcases/bin/
@@ -136,26 +139,17 @@ setup ()
}
########################## main #######################
- if [ -z $TEST_NUM ]
- then
- echo "Could not start cpu controller test";
+ case ${TEST_NUM} in
+ "1" ) get_num_groups;;
+ "2" ) NUM_GROUPS=`expr 2 \* $NUM_CPUS`;;
+ "3" ) NUM_GROUPS=$NUM_CPUS;;
+ * ) echo "Could not start cpu controller test";
echo "usage: run_cpuctl_test.sh test_num";
echo "Skipping the test...";
- exit -1;
- fi;
+ exit -1;;
+ esac
echo "TEST $TEST_NUM: CPU CONTROLLER TESTING";
echo "RUNNING SETUP.....";
- if [ ${TEST_NUM} -eq 1 ]
- then
- get_num_groups;
- elif [ ${TEST_NUM} -eq 2 ]
- then
- NUM_GROUPS=`expr 2 \* $NUM_CPUS`;
- else
- echo "Invalid test number";
- exit -1;
- fi;
-
setup;
# Trap the signal from any abnormaly terminated task
@@ -164,8 +158,11 @@ setup ()
echo "TEST STARTED: Please avoid using system while this test executes";
#Check if c source file has been compiled and then run it in
different groups
- if [ -f cpuctl_test01 ]
- then
+
+ case $TEST_NUM in
+ "1" | "2" )
+ if [ -f cpuctl_test01 ]
+ then
echo `date` >> $LTPROOT/output/cpuctl_results_$TEST_NUM.txt;
for i in $(seq 1 $NUM_GROUPS)
do
@@ -182,17 +179,65 @@ setup ()
fi
i=`expr $i + 1`
done
- else
- echo "Source file not compiled..Plz check Makefile...Exiting
test"
- cleanup;
- exit -1;
- fi
+ else
+ echo "Source file not compiled..Plz check
Makefile...Exiting test"
+ cleanup;
+ exit -1;
+ fi;
+ TOTAL_TASKS=$NUM_GROUPS;
+ ;;
+ "3" )
+ if [ -f cpuctl_test02 ]
+ then
+ echo `date` >> $LTPROOT/output/cpuctl_results_$TEST_NUM.txt;
+ for i in $(seq 1 $NUM_GROUPS)
+ do
+ TASKS_IN_GROUP=`expr $i \* 2`;
+ for j in $(seq 1 $TASKS_IN_GROUP)
+ do
+ TASK_NUM=`expr $TASK_NUM + 1`;
+ cp cpuctl_test02 cpuctl_task_$TASK_NUM 2>/dev/null;
+ chmod +x cpuctl_task_$TASK_NUM;
+ if [ $j -eq 1 ] # Renice 1 task in each group
+ then
+ NICELEVEL=-15;
+ else
+ NICELEVEL=0;
+ fi;
+
+ nice -n $NICELEVEL ./cpuctl_task_$TASK_NUM $i
/dev/cpuctl/group_$i $$ $NUM_CPUS
>>$LTPROOT/output/cpuctl_results_$TEST_NUM.txt 2>/dev/null &
+ if [ $? -ne 0 ]
+ then
+ echo "Error: Could not run
./cpuctl_task_$TASK_NUM"
+ cleanup;
+ exit -1;
+ else
+ PID[$TASK_NUM]=$!;
+ fi;
+ j=`expr $j + 1`
+ done; # end j loop
+ i=`expr $i + 1`
+ done; # end i loop
+ else
+ echo "Source file not compiled..Plz check
Makefile...Exiting test"
+ cleanup;
+ exit -1;
+ fi;
+ TOTAL_TASKS=$TASK_NUM;
+ ;;
+ * )
+ echo "Could not start cpu controller test";
+ echo "usage: run_cpuctl_test.sh test_num";
+ echo "Skipping the test...";
+ exit -1;;
+ esac
+
sleep 3
echo TASKS FIRED
echo helloworld > myfifo;
#wait for the tasks to finish for cleanup and status report to pan
- for i in $(seq 1 $NUM_GROUPS)
+ for i in $(seq 1 $TOTAL_TASKS)
do
wait ${PID[$i]};
RC=$?; # Return status of the task being waited
Index: ltp-full-20080131/testcases/kernel/controllers/test_controllers.sh
===================================================================
--- ltp-full-20080131.orig/testcases/kernel/controllers/test_controllers.sh
+++ ltp-full-20080131/testcases/kernel/controllers/test_controllers.sh
@@ -41,6 +41,7 @@ then
then
$LTPROOT/testcases/bin/run_cpuctl_test.sh 1;
$LTPROOT/testcases/bin/run_cpuctl_test.sh 2;
+ $LTPROOT/testcases/bin/run_cpuctl_test.sh 3;
else
echo "CONTROLLERS TESTCASES: WARNING";
echo "Kernel does not support for cpu controller";
Thanks,
Sudhir Kumar
LTC, ISTL
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list