Hi,

This patch adds the sixth to eigth testcase for cpu controller.
These are the stress test cases.
<cpuctl-stress1.patch>

Signed-off-by: Sudhir Kumar <[EMAIL PROTECTED]>

Index: ltp-full-20080131/testcases/kernel/controllers/cpuctl/cpuctl_test03.c
===================================================================
--- /dev/null
+++ ltp-full-20080131/testcases/kernel/controllers/cpuctl/cpuctl_test03.c
@@ -0,0 +1,206 @@
+/******************************************************************************/
+/*                                                                            
*/
+/* 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_test03.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  2       /* How many iterations of TIME_INTERVAL */
+
+extern int Tst_count;
+char *TCID = "cpu_controller_test06";
+int TST_TOTAL = 3;
+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 test_num, task_num, num_cpus;       /* To calculate cpu time in %*/
+       char mygroup[32], mytaskfile[32], ch;
+       /* Following variables are to capture parameters from script*/
+       char *group_num_p, *mygroup_p, *script_pid_p, *num_cpus_p, *test_num_p, 
*task_num_p;
+       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);
+
+       /* Collect the parameters passed by the script */
+       group_num_p     = getenv("GROUP_NUM");
+       mygroup_p       = getenv("MYGROUP");
+       script_pid_p    = getenv("SCRIPT_PID");
+       num_cpus_p      = getenv("NUM_CPUS");
+       test_num_p      = getenv("TEST_NUM");
+       task_num_p      = getenv("TASK_NUM");
+       /* Check if all of them are valid */
+       if ((test_num_p != NULL) && (((test_num = atoi(test_num_p)) <= 3) && 
((test_num =atoi(test_num_p)) >= 1)))
+       {
+               if ((group_num_p != NULL) && (mygroup_p != NULL) && \
+                       (script_pid_p != NULL) && (num_cpus_p != NULL) && 
(task_num_p != NULL))
+               {
+                       my_group_num     = atoi(group_num_p);
+                       scriptpid        = atoi(script_pid_p);
+                       num_cpus         = atoi (num_cpus_p);
+                       task_num         = atoi (task_num_p);
+                       sprintf(mygroup,"%s", mygroup_p);
+               }
+               else
+               {
+                       tst_brkm (TBROK, cleanup, "Invalid other input 
parameters\n");
+               }
+       }
+       else
+       {
+               tst_brkm (TBROK, cleanup, "Invalid test number passed\n");
+       }
+
+       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-%3d  task_num: %3d :cpu time 
---> %6.3f\%(%fs)\tinterval:%lu\n",getpid(),my_group_num, task_num, mytime, 
delta_cpu_time, delta_time);
+               counter++;
+
+               if (counter >= NUM_INTERVALS)    /* Take n sets of readings for 
each shares value*/
+               {
+               switch (test_num)
+                       {
+                       case 1:
+                       case 2:
+                       case 3:
+                               exit (0);               /* This task is done 
with its job*/
+                               break;
+                       default:
+                               tst_brkm (TBROK, cleanup, "Invalid test number 
passed\n");
+                               break;
+
+                       }       /* end switch*/
+               }       /* end if*/
+        }      /* 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_stress_test.sh
===================================================================
--- /dev/null
+++ 
ltp-full-20080131/testcases/kernel/controllers/cpuctl/run_cpuctl_stress_test.sh
@@ -0,0 +1,181 @@
+#!/bin/bash
+# usage ./runcpuctl_stress_test.sh test_num
+
+#################################################################################
+#  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     
 #
+#                                                                              
 #
+#################################################################################
+# Name Of File: run_cpuctl_stress_test.sh                                      
 #
+#                                                                              
 #
+# Description:  This file runs the setup for testing cpucontroller.            
 #
+#               After setup it runs some of the tasks in different groups.     
 #
+#               setup includes creating controller device, mounting it with    
 #
+#               cgroup filesystem with option cpu and creating groups in it.   
 #
+#                                                                              
 #
+# Functions:    get_num_groups(): decides num of groups based on num of cpus   
 #
+#               setup(): creaes /dev/cpuctl, mounts cgroup fs on it, creates   
 #
+#               groups in that, creates fifo to fire tasks at one time.        
 #
+#                                                                              
 #
+# Precaution:   Avoid system use by other applications/users to get fair and   
 #
+#               appropriate results                                            
 #
+#                                                                              
 #
+# Author:       Sudhir Kumar   <[EMAIL PROTECTED]>                    #
+#                                                                              
 #
+# History:                                                                     
 #
+#                                                                              
 #
+#  DATE         NAME           EMAIL                           DESC            
 #
+#                                                                              
 #
+#  20/12/07  Sudhir Kumar <[EMAIL PROTECTED]>   Created this test     #
+#                                                                              
 #
+#################################################################################
+
+
+export TCID="cpuctl_test06";
+export TST_TOTAL=3;
+export TST_COUNT=1;    # how to tell here ??
+
+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)
+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
+SCRIPT_PID=$$;
+FILE="stress-123";     # suffix for results file
+
+NUM_CPUS=`cat /proc/cpuinfo | grep -w processor | wc -l`
+N=$NUM_CPUS;           # Default total num of groups (classes)
+M=10;                  # Default total num of tasks in a group
+
+PWD=`pwd`
+cd $LTPROOT/testcases/bin/
+
+. parameters.sh
+
+usage ()
+{
+       echo "Could not start cpu controller stress test";
+       echo "Check entry in file 
$LTPROOT/testcases/kernel/controllers/test_controllers.sh";
+       echo "usage: run_cpuctl_stress_test.sh test_num";
+       echo "Skipping the test...";
+       exit -1;
+}
+##########################  main   #######################
+               # For testcase 1, 2 & 3 N--> $NUM_CPUS
+               # i,2 & 3 are not heavy stress test
+
+       case ${TEST_NUM} in
+
+       "1" )   # N X M (N groups with M tasks each)
+               NUM_GROUPS=$N;
+               TASKS_IN_GROUP=$M;
+               echo `date` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
+               ;;
+       "2" )   # N*M X 1 (N*M groups with 1 task each)
+               NUM_GROUPS=`expr $N \* $M`;
+               TASKS_IN_GROUP=1;
+               ;;
+       "3" )   # 1 X N*M (1 group with N*M tasks)
+               NUM_GROUPS=1;
+               TASKS_IN_GROUP=`expr $N \* $M`;
+               ;;
+         * )
+               usage;
+               ;;
+       esac
+
+       echo "TEST $TEST_NUM: CPU CONTROLLER STRESS TESTING";
+       echo "RUNNING SETUP.....";
+       setup;
+
+       # Trap the signal from any abnormaly terminated task
+       # and kill all others and let cleanup be called
+       trap 'echo "signal caught from task"; killall cpuctl_task_*;' SIGUSR1;
+
+       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
+
+       case $TEST_NUM in
+
+       "1" | "2" | "3" )
+
+               if [ -f cpuctl_test03 ]
+               then
+               echo Test $TEST_NUM: NUM_GROUPS=$NUM_GROUPS >> 
$LTPROOT/output/cpuctl_results_$FILE.txt;
+               echo Test $TEST_NUM: TASKS PER GROUP=$TASKS_IN_GROUP >> 
$LTPROOT/output/cpuctl_results_$FILE.txt;
+               echo "==========================" >> 
$LTPROOT/output/cpuctl_results_$FILE.txt;
+               for i in $(seq 1 $NUM_GROUPS)
+               do
+                       MYGROUP=/dev/cpuctl/group_$i
+                       for j in $(seq 1 $TASKS_IN_GROUP)
+                       do
+                       TASK_NUM=`expr $TASK_NUM + 1`;
+                       cp cpuctl_test03 cpuctl_task_$TASK_NUM 2>/dev/null;
+                       chmod +x cpuctl_task_$TASK_NUM;
+
+                       GROUP_NUM=$i MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID 
NUM_CPUS=$NUM_CPUS \
+                       TEST_NUM=$TEST_NUM TASK_NUM=$TASK_NUM 
./cpuctl_task_$TASK_NUM \
+                       >>$LTPROOT/output/cpuctl_results_$FILE.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;
+               ;;
+         * )
+               usage;
+               ;;
+       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 $TOTAL_TASKS)
+       do
+               wait ${PID[$i]};
+               RC=$?;  # Return status of the task being waited
+               # In abnormal termination of anyone trap will kill all others
+               # and they will return non zero exit status. So Test broke!!
+               if [ $RC -ne 0 ]
+               then
+                       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_$FILE.txt"
+       cleanup;
+       cd $PWD
+       exit 0;         #to let PAN reprt success of test
Index: ltp-full-20080131/testcases/kernel/controllers/cpuctl/Makefile
===================================================================
--- ltp-full-20080131.orig/testcases/kernel/controllers/cpuctl/Makefile
+++ ltp-full-20080131/testcases/kernel/controllers/cpuctl/Makefile
@@ -12,5 +12,5 @@ clean:
        rm -f $(TARGETS) *.o
 
 install:
-       @set -e; for i in $(TARGETS) run_cpuctl_test.sh parameters.sh ; do ln 
-f $$i ../../../bin/$$i ; chmod +x $$i ; done
+       @set -e; for i in $(TARGETS) run_cpuctl_test.sh 
run_cpuctl_stress_test.sh parameters.sh ; do ln -f $$i ../../../bin/$$i ; chmod 
+x $$i ; done
 
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
@@ -43,6 +43,9 @@ then
                $LTPROOT/testcases/bin/run_cpuctl_test.sh 2;
                $LTPROOT/testcases/bin/run_cpuctl_test.sh 3;
                $LTPROOT/testcases/bin/run_cpuctl_test.sh 4;
+               $LTPROOT/testcases/bin/run_cpuctl_stress_test.sh 1;
+               $LTPROOT/testcases/bin/run_cpuctl_stress_test.sh 2;
+               $LTPROOT/testcases/bin/run_cpuctl_stress_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

Reply via email to