Hi,
This patch adds the third testcase for cpu controller.
Signed-off-by: Sudhir Kumar <[EMAIL PROTECTED]>
Index:
ltp-full-20071130-tested/testcases/kernel/controllers/cpuctl/cpuctl_test01.c
===================================================================
---
ltp-full-20071130-tested.orig/testcases/kernel/controllers/cpuctl/cpuctl_test01.c
+++ ltp-full-20071130-tested/testcases/kernel/controllers/cpuctl/cpuctl_test01.c
@@ -27,7 +27,7 @@
/* testcase tests the ability of the cpu controller to provide
*/
/* fairness for share values (absolute).
*/
/*
*/
-/* Total Tests: 2
*/
+/* Total Tests: 3
*/
/*
*/
/* Test Name: cpu_controller_test01
*/
/*
*/
@@ -61,7 +61,7 @@
#define NUM_INTERVALS 3 /* How many iterations of TIME_INTERVAL */
#define NUM_SETS 7 /* How many share values (with same ratio)*/
#define MULTIPLIER 10 /* decides the rate at which share value gets
multiplied*/
-
+#define GRANULARITY 5 /* % value by which shares of a group changes */
extern int Tst_count;
char *TCID = "cpu_controller_test01";
int TST_TOTAL = 1;
@@ -80,7 +80,7 @@ int timer_expired = 0;
int main(int argc, char* argv[])
{
- int num_cpus; /* To calculate cpu time in %*/
+ int num_cpus, test_num; /* To calculate cpu time in %*/
char mygroup[32], mytaskfile[32], mysharesfile[32], ch;
pid_t pid;
int my_group_num, /* A number attached with a group*/
@@ -92,7 +92,7 @@ int main(int argc, char* argv[])
prev_cpu_time=0;
struct rusage cpu_usage;
time_t current_time, prev_time, delta_time;
- unsigned long int myshares = 1; /* Simply the base value to start with*/
+ unsigned long int myshares = 1, baseshares = 1000; /* Simply the
base value to start with*/
struct sigaction newaction, oldaction;
/* Signal handling for alarm*/
sigemptyset (&newaction.sa_mask);
@@ -101,12 +101,20 @@ int main(int argc, char* argv[])
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))
+ if ((argc < 5) || ((my_group_num = atoi(argv[1])) <= 0) || ((scriptpid
= atoi(argv[3])) <= 0) || ((num_cpus = atoi(argv[4])) <= 0) || (test_num =
atoi(argv[5])) <= 0)
{
tst_brkm (TBROK, cleanup, "Invalid input parameters\n");
}
- myshares *= my_group_num;
+ if (test_num == 1)
+ myshares *= my_group_num;
+ else if (test_num == 2)
+ myshares = baseshares;
+ else
+ {
+ tst_brkm (TBROK, cleanup, "Wrong Test number passed. Exiting
Test...\n");
+ }
+
sprintf(mygroup,"%s", argv[2]);
sprintf(mytaskfile, "%s", mygroup);
sprintf(mysharesfile, "%s", mygroup);
@@ -137,7 +145,7 @@ int main(int argc, char* argv[])
* exceed the TIME_INTERVAL to measure
cpu usage
*/
current_time = time (NULL);
- delta_time = current_time - prev_time; /* Duration in
case it is not exact TIME_INTERVAL*/
+ 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*/
@@ -160,7 +168,21 @@ int main(int argc, char* argv[])
second_counter++;
if (second_counter >= NUM_SETS)
exit (0); /* This task is
done with its job*/
- myshares = MULTIPLIER * myshares; /* Keep
same ratio but change values*/
+
+ /* Change share values depending on the
test_num */
+ if (test_num ==1)
+ {
+ /* Keep same ratio but change values*/
+ myshares = MULTIPLIER * myshares;
+ }
+ else
+ {
+ /* Increase for odd task and decrease
for even task*/
+ if (my_group_num % 2)
+ myshares += baseshares *
GRANULARITY / 100;
+ else
+ myshares -= baseshares *
GRANULARITY / 100;
+ }
write_to_file (mysharesfile, "w", myshares);
fprintf(stdout,"\ntask-%d
SHARES=%lu\n",my_group_num, myshares);
}/* end if*/
Index:
ltp-full-20071130-tested/testcases/kernel/controllers/cpuctl/run_cpuctl_test.sh
===================================================================
---
ltp-full-20071130-tested.orig/testcases/kernel/controllers/cpuctl/run_cpuctl_test.sh
+++
ltp-full-20071130-tested/testcases/kernel/controllers/cpuctl/run_cpuctl_test.sh
@@ -51,13 +51,14 @@ 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)
PWD=`pwd`
cd $LTPROOT/testcases/bin/
+NUM_CPUS=`cat /proc/cpuinfo | grep -w processor | wc -l`
get_num_groups() # Number of tasks should be >= number of cpu's (to
check scheduling fairness)
{
- NUM_CPUS=`cat /proc/cpuinfo | grep -w processor | wc -l`
num_grps=$(echo "$NUM_CPUS * 1.5"|bc) # temp variable num_grps
int_part=`echo $num_grps | cut -d"." -f1`
dec_part=`echo $num_grps | cut -d"." -f2`
@@ -120,7 +121,7 @@ setup ()
# Create different groups
i=1;
- while [ $i -le $NUM_GROUPS ]
+ while [ "$i" -le "$NUM_GROUPS" ]
do
group=group_$i;
mkdir /dev/cpuctl/$group;# 2>/dev/null
@@ -135,13 +136,25 @@ setup ()
}
########################## main #######################
- echo "TEST: CPU CONTROLLER TESTING";
+ if [ -z $TEST_NUM ]
+ then
+ echo "Could not start cpu controller test";
+ echo "usage: run_cpuctl_test.sh test_num";
+ echo "Skipping the test...";
+ exit -1;
+ fi;
+ echo "TEST $TEST_NUM: CPU CONTROLLER TESTING";
echo "RUNNING SETUP.....";
- get_num_groups;
- if [ $NUM_GROUPS -lt 2 ]
+ if [ ${TEST_NUM} -eq 1 ]
then
- NUM_GROUPS=2; # min num of groups for testing
- fi
+ get_num_groups;
+ elif [ ${TEST_NUM} -eq 2 ]
+ then
+ NUM_GROUPS=`expr 2 \* $NUM_CPUS`;
+ else
+ echo "Invalid test number";
+ exit -1;
+ fi;
setup;
@@ -153,12 +166,12 @@ setup ()
#Check if c source file has been compiled and then run it in
different groups
if [ -f cpuctl_test01 ]
then
- echo `date` >> $LTPROOT/output/cpuctl_results.txt;
+ echo `date` >> $LTPROOT/output/cpuctl_results_$TEST_NUM.txt;
for i in $(seq 1 $NUM_GROUPS)
do
cp cpuctl_test01 cpuctl_task_$i 2>/dev/null;
chmod +x cpuctl_task_$i;
- ./cpuctl_task_$i $i /dev/cpuctl/group_$i $$ $NUM_CPUS
>>$LTPROOT/output/cpuctl_results.txt 2>/dev/null &
+ ./cpuctl_task_$i $i /dev/cpuctl/group_$i $$ $NUM_CPUS
$TEST_NUM >>$LTPROOT/output/cpuctl_results_$TEST_NUM.txt 2>/dev/null &
if [ $? -ne 0 ]
then
echo "Error: Could not run ./cpuctl_task_$i"
@@ -187,14 +200,14 @@ setup ()
# and they will return non zero exit status. So Test broke!!
if [ $RC -ne 0 ]
then
- echo "Task $i exited abnormalywith return value: $RC";
+ echo "Task $i exited abnormaly with return value: $RC";
tst_resm TINFO "Test could not execute for the expected
duration";
cleanup;
exit -1;
fi
done
echo "Cpu controller test executed successfully.Results written to
file";
- echo "Please review the results in $LTPROOT/output/cpuctl_results.txt"
+ echo "Please review the results in
$LTPROOT/output/cpuctl_results_$TEST_NUM.txt"
cleanup;
cd $PWD
exit 0; #to let PAN reprt success of test
Index: ltp-full-20071130-tested/testcases/kernel/controllers/test_controllers.sh
===================================================================
---
ltp-full-20071130-tested.orig/testcases/kernel/controllers/test_controllers.sh
+++ ltp-full-20071130-tested/testcases/kernel/controllers/test_controllers.sh
@@ -39,7 +39,8 @@ then
CPU_CONTROLLER=`grep -w cpu /proc/cgroups | cut -f1`;
if [ "$CPU_CONTROLLER" = "cpu" ]
then
- $LTPROOT/testcases/bin/run_cpuctl_test.sh;
+ $LTPROOT/testcases/bin/run_cpuctl_test.sh 1;
+ $LTPROOT/testcases/bin/run_cpuctl_test.sh 2;
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