Hi,

This patch adds the library routines in cpu controller stress test cases 4 & 5.
It also does minor cleanup.
<addlibrary-stress45.patch>

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

Index: ltp-full-20080131/testcases/kernel/controllers/cpuctl/cpuctl_test04.c
===================================================================
--- ltp-full-20080131.orig/testcases/kernel/controllers/cpuctl/cpuctl_test04.c
+++ ltp-full-20080131/testcases/kernel/controllers/cpuctl/cpuctl_test04.c
@@ -55,6 +55,7 @@
 #include <time.h>
 #include <unistd.h>
 
+#include "../libcontrollers/libcontrollers.h"
 #include "test.h"              /* LTP harness APIs*/
 
 #define TIME_INTERVAL  200     /* Time interval in seconds*/
@@ -64,6 +65,8 @@ extern int Tst_count;
 char *TCID = "cpu_controller_test06";
 int TST_TOTAL = 2;
 pid_t scriptpid;
+char path[] = "/dev/cpuctl";
+
 extern void
 cleanup()
 {
@@ -71,14 +74,12 @@ 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 %*/
+       int test_num, task_num, len, num_cpus;  /* num_cpus to calculate cpu 
time in %*/
        char mygroup[64], mytaskfile[64], mysharesfile[64], 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;
@@ -88,9 +89,11 @@ int main(int argc, char* argv[])
        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;
+       double exp_cpu_time;            /* Expected time in % as obtained by 
shares calculation */
        struct rusage cpu_usage;
        unsigned long int mygroup_shares;
        time_t current_time, prev_time, delta_time;
+       unsigned int fmyshares, num_tasks;/* f-> from file. num_tasks is tasks 
in this group*/
        struct sigaction newaction, oldaction;
        /* Signal handling for alarm*/
        sigemptyset (&newaction.sa_mask);
@@ -145,6 +148,31 @@ int main(int argc, char* argv[])
        }
 
        read (fd, &ch, 1);               /* To block all tasks here and fire 
them up at the same time*/
+
+       /*
+        * We now calculate the expected % cpu time of this task by getting
+        * it's group's shares, the total shares of all the groups and the
+        * number of tasks in this group.
+        */
+       FLAG = 0;
+       total_shares = 0;
+       shares_pointer = &total_shares;
+       len = strlen (path);
+       if (!strncpy (fullpath, path, len))
+               tst_brkm (TBROK, cleanup, "Could not copy directory path %s ", 
path);
+
+       if (scan_shares_files() != 0)
+               tst_brkm (TBROK, cleanup, "From function scan_shares_files in 
%s ", fullpath);
+
+       /* return val: -1 in case of function error, else 2 is min share value 
*/
+       if ((fmyshares = read_shares_file(mysharesfile)) < 2)
+               tst_brkm (TBROK, cleanup, "in reading shares files  %s ", 
mysharesfile);
+
+       if ((read_file (mytaskfile, GET_TASKS, &num_tasks)) < 0)
+               tst_brkm (TBROK, cleanup, "in reading tasks files  %s ", 
mytaskfile);
+
+       exp_cpu_time = (double)(fmyshares * 100) /(total_shares * num_tasks);
+
        prev_time = time (NULL);         /* Note down the time*/
 
        while (1)
@@ -172,8 +200,10 @@ int main(int argc, char* argv[])
                else
                        mytime =  (delta_cpu_time * 100) / (TIME_INTERVAL * 
num_cpus);
 
-               fprintf (stdout,"Group-%3d:Shares-%4u: task_num:%3d cpu time--> 
%6.3f\%(%6.3fs)\tinterval:%lu\n",
-               mygroup_num, mygroup_shares, task_num, mytime, delta_cpu_time, 
delta_time);
+                fprintf (stdout,"Grp:-%3d task-%3d:CPU TIME{calc:-%6.2f(s)i.e. 
%6.2f(\%) exp:-%6.2f(\%)}\
+with %lu shares in %lu (s) INTERVAL\n",mygroup_num, task_num, delta_cpu_time, 
mytime,\
+exp_cpu_time, fmyshares, delta_time);
+
                counter++;
 
                if (counter >= NUM_INTERVALS)    /* Take n sets of readings for 
each shares value*/
@@ -195,20 +225,3 @@ int main(int argc, char* argv[])
         }      /* 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;
-}

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