Hi,
The following patch adds the stat check test case for memory controller
testcases.

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



Index: ltp-full-20080430/testcases/kernel/controllers/memctl/run_memctl_test.sh
===================================================================
--- 
ltp-full-20080430.orig/testcases/kernel/controllers/memctl/run_memctl_test.sh
+++ ltp-full-20080430/testcases/kernel/controllers/memctl/run_memctl_test.sh
@@ -94,6 +94,17 @@ case ${TEST_NUM} in
        MEM_TASK=`expr $CHUNK_SIZE \* $NUM_CHUNKS`;     # memory allocated by a 
task
        TEST_NAME=" FAILCNT CHECK TEST:";
        ;;
+"4" )
+       NUM_GROUPS=1;
+       MEMLIMIT_GROUP_1=100M;                          # MEM_TASK > 
MEMLIMIT_GROUP_1
+       CHUNK_SIZE=6291456;                             # malloc n chunks of 
size m(6M)
+       NUM_CHUNKS=10;                                  # (say)60 MB 
memory(6*10)
+       TOTAL_TASKS=1;                                  # num of tasks in a 
group(1)
+       MEM_TASK=`expr $CHUNK_SIZE \* $NUM_CHUNKS`;     # memory allocated by a 
task
+       MEM_TOTAL=`expr $MEM_TASK \* $TOTAL_TASKS`;     # total memory 
allocated in a group
+       TEST_NAME=" STATS CHECK TEST:";
+       SECOND_READ=0;
+       ;;
 *  )   usage;
        exit -1
                ;;
@@ -269,6 +280,94 @@ case $TEST_NUM in
                exit -1;
        fi;
                ;;
+"4" )
+       setmemlimits;
+       if [ -f memctl_test01 ]
+       then
+               MYGROUP=/dev/memctl/group_1;
+               cp memctl_test01 memctl_task_1 # 2>/dev/null;
+               chmod +x memctl_task_1;
+               TEST_NUM=$TEST_NUM MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID 
CHUNK_SIZE=$CHUNK_SIZE \
+                       NUM_CHUNKS=$NUM_CHUNKS ./memctl_task_$i &
+               if [ $? -ne 0 ]
+               then
+                       echo "Error: Could not run ./memctl_task_1"
+                       cleanup;
+                       exit -1;
+               else
+                       PID[1]=$!;
+               fi
+
+               # Wait untill tasks allocate memory from group1
+               while [ 1 -gt 0 ]
+               do
+                       sleep 1;
+                       GRP1_MEMUSAGE=`cat 
/dev/memctl/group_1/memory.usage_in_bytes`;
+                       MEMLIMIT_GROUP_1=`echo $MEMLIMIT_GROUP_1 | cut -d"M" 
-f1`;
+                       if [ $GRP1_MEMUSAGE -gt $MEM_TOTAL ]
+                       then
+                               if [ $GRP1_MEMUSAGE -eq $SECOND_READ ]
+                               then
+                               # seems memory allocation is over now
+                                       break;
+                               fi;
+                               sleep 5;
+                               SECOND_READ=`cat 
/dev/memctl/group_1/memory.usage_in_bytes`;
+                       fi
+               done
+
+               # now we can check the memory usage from both files
+               USAGE_FROM_STAT=`cat /dev/memctl/group_1/memory.stat | grep -w 
"active" | cut -d" " -f2`;
+               if [ $GRP1_MEMUSAGE -eq $USAGE_FROM_STAT ]
+               then
+                       echo "memory.usage_in_bytes=$GRP1_MEMUSAGE";
+                       echo "memory.stat=$USAGE_FROM_STAT";
+                       echo "TINFO   Memory Resource Controller: stat check 
test passes first step";
+                       echo Test continues to run the second step.
+                       FIRST_STEP_PASS=1;
+               else
+                       echo "TINFO   Memory Resource Controller: stat check 
test fails in first step";
+                       FIRST_STEP_PASS=0;
+               fi;
+               kill -SIGUSR2 ${PID[1]};
+
+               # just a second run of the test with different memory 
allocations
+               # Wait untill tasks allocate memory from group1
+               while [ 1 -gt 0 ]
+               do
+                       sleep 1;
+                       GRP1_MEMUSAGE=`cat 
/dev/memctl/group_1/memory.usage_in_bytes`;
+
+                       if [ $GRP1_MEMUSAGE -gt $MEM_TOTAL ]
+                       then
+                               if [ $GRP1_MEMUSAGE -eq $SECOND_READ ]
+                               then
+                               # seems memory allocation is over now
+                                       break;
+                               fi;
+                               sleep 5;
+                               SECOND_READ=`cat 
/dev/memctl/group_1/memory.usage_in_bytes`;
+                       fi
+               done
+
+               # now we can check the memory usage from both files
+               USAGE_FROM_STAT=`cat /dev/memctl/group_1/memory.stat | grep -w 
"active" | cut -d" " -f2`;
+               if [ $GRP1_MEMUSAGE -eq $USAGE_FROM_STAT ] && [ 
$FIRST_STEP_PASS -eq 1 ]
+               then
+                       # Now we can signal the task to finish and do the 
cleanup
+                       kill -SIGUSR1 ${PID[1]};
+                       echo "memory.usage_in_bytes=$GRP1_MEMUSAGE";
+                       echo "memory.stat=$USAGE_FROM_STAT";
+                       echo "TPASS   Memory Resource Controller: stat check 
test PASSED";
+               else
+                       echo "TFAIL   Memory Resource Controller: stat check 
test FAILED";
+               fi;
+       else
+               echo "Source file not compiled..Please check Makefile...Exiting 
test"
+               cleanup;
+               exit -1;
+       fi;
+               ;;
        "*" )
                usage;
                exit -1;
Index: ltp-full-20080430/testcases/kernel/controllers/memctl/memctl_test01.c
===================================================================
--- ltp-full-20080430.orig/testcases/kernel/controllers/memctl/memctl_test01.c
+++ ltp-full-20080430/testcases/kernel/controllers/memctl/memctl_test01.c
@@ -153,6 +153,11 @@ void signal_handler_sigusr2 (int signal)
        for (i=0; i< num_of_chunks; ++i)
                free(array_of_chunks[i]);
        free(array_of_chunks);
+       if (test_num == 4){
+               /* Allocate different amount of memory for second step */
+               chunk_size=5242880;     /* 5 MB chunks */
+               num_of_chunks=15;
+       }
        allocate_memory();
 }
 
Index: ltp-full-20080430/testcases/kernel/controllers/test_controllers.sh
===================================================================
--- ltp-full-20080430.orig/testcases/kernel/controllers/test_controllers.sh
+++ ltp-full-20080430/testcases/kernel/controllers/test_controllers.sh
@@ -62,6 +62,7 @@ then
                $LTPROOT/testcases/bin/run_memctl_test.sh 1;
                $LTPROOT/testcases/bin/run_memctl_test.sh 2;
                $LTPROOT/testcases/bin/run_memctl_test.sh 3;
+               $LTPROOT/testcases/bin/run_memctl_test.sh 4;
        else
                echo "CONTROLLERS TESTCASES: WARNING";
                echo "Kernel does not support for memory controller";


Thanks
Sudhir

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to