memcg/functional: rewrite
PATCH 1/4 memcg/functional: rewrite
* Use the LTP API for shell tests
* Remove memcg_getpagesize binary, since its functionality can be provided by 'getconf PAGESIZE'
* Move common code to memcg_lib.sh
--- testcases/kernel/controllers/memcg/.gitignore | 1 - .../memcg/functional/memcg_function_test.sh | 56 +++------ .../memcg/functional/memcg_getpagesize.c | 30 ----- .../controllers/memcg/functional/memcg_lib.sh | 128 ++++++++++++++------ .../functional/memcg_max_usage_in_bytes_test.sh | 49 +------- .../functional/memcg_memsw_limit_in_bytes_test.sh | 54 ++------- .../memcg_move_charge_at_immigrate_test.sh | 40 +------ .../memcg/functional/memcg_stat_test.sh | 49 +------- .../memcg/functional/memcg_usage_in_bytes_test.sh | 47 +------ .../memcg/functional/memcg_use_hierarchy_test.sh | 39 +----- 10 files changed, 148 insertions(+), 345 deletions(-) delete mode 100644 testcases/kernel/controllers/memcg/functional/memcg_getpagesize.c
testcases/kernel/controllers/memcg/.gitignore +0 -1
@@ -1,5 +1,4 @@ /control/mem_process -/functional/memcg_getpagesize /functional/memcg_process /regression/memcg_test_1 /regression/memcg_test_2
testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +16 -40
81 lines not on this page · raw message
testcases/kernel/controllers/memcg/functional/memcg_getpagesize.c deleted +0 -30
@@ -1,30 +0,0 @@ -/******************************************************************************/ -/* */ -/* Copyright (c) 2009 FUJITSU LIMITED */ -/* */ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* */ -/* Author: Li Zefan <[email protected]> */ -/* */ -/******************************************************************************/ - -#include <unistd.h> -#include <stdio.h> - -int main (void ) -{ -printf ("%d\n" ,getpagesize ()); -return 0 ; -}
testcases/kernel/controllers/memcg/functional/memcg_lib.sh +93 -35
239 lines not on this page · raw message
testcases/kernel/controllers/memcg/functional/memcg_max_usage_in_bytes_test.sh +7 -42
73 lines not on this page · raw message
testcases/kernel/controllers/memcg/functional/memcg_memsw_limit_in_bytes_test.sh +9 -45
89 lines not on this page · raw message
testcases/kernel/controllers/memcg/functional/memcg_move_charge_at_immigrate_test.sh +5 -35
@@ -26,11 +26,10 @@ # History: 2012/01/16 - Created. # -export TCID="memcg_move_charge_at_immigrate_test" -export TST_TOTAL=4 -export TST_COUNT=0 +TCID="memcg_move_charge_at_immigrate_test" +TST_TOTAL=4 -. memcg_lib.sh || exit 1 +. memcg_lib.sh # Test disable moving charges testcase_1()
@@ -58,35 +57,6 @@ testcase_4() test_move_charge "--mmap-anon --shm" $PAGESIZE 3 $PAGESIZE $PAGESIZE 0 0 } -# Run all the test cases -for i in $(seq 1 $TST_TOTAL) -do - export TST_COUNT=$(( $TST_COUNT + 1 )) - cur_id=$i +run_tests - do_mount - if [ $? -ne 0 ]; then - echo "Cannot create memcg" - exit 1 - fi - - # prepare - mkdir /dev/memcg/$i 2> /dev/null - cd /dev/memcg/$i - - # run the case - testcase_$i - - # clean up - sleep 1 - cd $TEST_PATH - rmdir /dev/memcg/$i - - cleanup -done - -if [ $failed -ne 0 ]; then - exit $failed -else - exit 0 -fi +tst_exit
testcases/kernel/controllers/memcg/functional/memcg_stat_test.sh +7 -42
73 lines not on this page · raw message
testcases/kernel/controllers/memcg/functional/memcg_usage_in_bytes_test.sh +6 -41
65 lines not on this page · raw message
testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_test.sh +5 -34
@@ -26,11 +26,10 @@ # History: 2012/01/14 - Created. # -export TCID="memcg_use_hierarchy_test" -export TST_TOTAL=3 -export TST_COUNT=0 +TCID="memcg_use_hierarchy_test" +TST_TOTAL=3 -. memcg_lib.sh || exit 1 +. memcg_lib.sh # test if one of the ancestors goes over its limit, the proces will be killed testcase_1()
@@ -67,35 +66,7 @@ testcase_3() rmdir subgroup } -# Run all the test cases -for i in $(seq 1 $TST_TOTAL) -do - export TST_COUNT=$(( $TST_COUNT + 1 )) - cur_id=$i +run_tests - do_mount - if [ $? -ne 0 ]; then - echo "Cannot create memcg" - exit 1 - fi +tst_exit - # prepare - mkdir /dev/memcg/$i 2> /dev/null - cd /dev/memcg/$i - - # run the case - testcase_$i - - # clean up - sleep 1 - cd $TEST_PATH - rmdir /dev/memcg/$i - - cleanup -done - -if [ $failed -ne 0 ]; then - exit $failed -else - exit 0 -fi
Signature · 1 line
1.7.1
PATCH 2/4 memcg/functional/memcg_process: cleanup
--- .../controllers/memcg/functional/memcg_process.c | 49 ++++++++++---------- 1 files changed, 25 insertions(+), 24 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_process.c +25 -24
@@ -35,20 +35,20 @@#include <string.h> #include <unistd.h> -int fd; +static int fd; -int flag_exit; -int flag_allocated; +static volatile int flag_exit; +static volatile int flag_allocated; -int opt_mmap_anon; -int opt_mmap_file; -int opt_mmap_lock1; -int opt_mmap_lock2; -int opt_shm; -int opt_hugepage; +static int opt_mmap_anon; +static int opt_mmap_file; +static int opt_mmap_lock1; +static int opt_mmap_lock2; +static int opt_shm; +static int opt_hugepage; -int key_id;/* used with opt_shm */ -unsigned long memsize; +static int key_id;/* used with opt_shm */ +static unsigned long memsize;#define FILE_HUGEPAGE "/hugetlb/hugepagefile"
@@ -59,7 +59,7 @@ unsigned long memsize;#define SHM (SCHAR_MAX + 5)#define HUGEPAGE (SCHAR_MAX + 6) -const struct option long_opts[] = { +static const struct option long_opts[] = { {"mmap-anon" ,0 ,NULL ,MMAP_ANON }, {"mmap-file" ,0 ,NULL ,MMAP_FILE }, {"mmap-lock1" ,0 ,NULL ,MMAP_LOCK1 },
@@ -74,7 +74,7 @@ const struct option long_opts[] = {/* * process_options: read options from user input */ -void process_options (int argc,char *argv[]) +static void process_options (int argc,char *argv[]) {int c;char *end;
@@ -117,7 +117,7 @@ void process_options(int argc, char *argv[])/* * touch_memory: force allocating phy memory */ -void touch_memory (char *p,int size) +static void touch_memory (char *p,int size) {int i;int pagesize =getpagesize ();
@@ -126,7 +126,7 @@ void touch_memory(char *p, int size) p[i] =0xef ; } -void mmap_anon () +static void mmap_anon (void ) {static char *p;
@@ -142,7 +142,7 @@ void mmap_anon() } } -void mmap_file () +static void mmap_file (void ) {static char *p;static int fd_hugepage;
@@ -177,7 +177,7 @@ void mmap_file() } } -void mmap_lock1 () +static void mmap_lock1 (void ) {static char *p;
@@ -193,7 +193,7 @@ void mmap_lock1() } } -void mmap_lock2 () +static void mmap_lock2 (void ) {static char *p;
@@ -215,7 +215,7 @@ void mmap_lock2() } } -void shm () +static void shm (void ) {static char *p;static int shmid;
@@ -258,7 +258,7 @@ void shm()/* * sigint_handler: handle SIGINT by set the exit flag. */ -void sigint_handler (int __attribute__ ((unused)) signo) +static void sigint_handler (int __attribute__ ((unused)) signo) { flag_exit =1 ; }
@@ -272,7 +272,7 @@ void sigint_handler(int __attribute__ ((unused)) signo)* When we receive SIGUSR again, we will free all the allocated * memory. */ -void sigusr_handler (int __attribute__ ((unused)) signo) +static void sigusr_handler (int __attribute__ ((unused)) signo) {if (opt_mmap_anon)mmap_anon ();
@@ -303,14 +303,15 @@ int main(int argc, char *argv[])memset (&sigint_action,0 ,sizeof (sigint_action));memset (&sigusr_action,0 ,sizeof (sigusr_action)); -/* TODO: add error handling below. */ sigemptyset (&sigint_action.sa_mask); sigint_action.sa_handler = &sigint_handler; -sigaction (SIGINT , &sigint_action,NULL ); +if (sigaction (SIGINT , &sigint_action,NULL )) +err (1 ,"sigaction(SIGINT)" );sigemptyset (&sigusr_action.sa_mask); sigusr_action.sa_handler = &sigusr_handler; -sigaction (SIGUSR1 , &sigusr_action,NULL ); +if (sigaction (SIGUSR1 , &sigusr_action,NULL )) +err (1 ,"sigaction(SIGUSR1)" );process_options (argc, argv);
Signature · 1 line
1.7.1
PATCH 3/4 memcg/functional: use checkpoints
This patch implements the idea proposed in [1], [2], that we use the checkpoint interface to let memcg_process inform the parent process that it's ready.
In my enviroment it saves ~50 secs of time.
--- .../memcg/functional/memcg_function_test.sh | 4 ++-- .../controllers/memcg/functional/memcg_lib.sh | 15 ++++++++------- .../controllers/memcg/functional/memcg_process.c | 6 ++++++ 3 files changed, 16 insertions(+), 9 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_function_test.sh +2 -2
@@ -214,7 +214,7 @@ testcase_29() { memcg_process --mmap-anon -s $PAGESIZE & pid=$! - sleep 1 + TST_CHECKPOINT_WAIT 0 echo $pid > tasks kill -s USR1 $pid 2> /dev/null sleep 1
@@ -235,7 +235,7 @@ testcase_30() { memcg_process --mmap-lock2 -s $PAGESIZE & pid=$! - sleep 1 + TST_CHECKPOINT_WAIT 0 echo $pid > tasks kill -s USR1 $pid 2> /dev/null sleep 1
testcases/kernel/controllers/memcg/functional/memcg_lib.sh +8 -7
@@ -22,6 +22,7 @@ ## ## ################################################################################ +TST_NEEDS_CHECKPOINTS=1 . test.sh if [ "x$(grep -w memory /proc/cgroups | cut -f4)" != "x1" ]; then
@@ -137,7 +138,7 @@ test_mem_stat() { tst_resm TINFO "Running memcg_process $1 -s $2" memcg_process $1 -s $2 & - sleep 1 + TST_CHECKPOINT_WAIT 0 warmup $! if [ $? -ne 0 ]; then
@@ -170,7 +171,7 @@ test_max_usage_in_bytes() { tst_resm TINFO "Running memcg_process $1 -s $2" memcg_process $1 -s $2 & - sleep 1 + TST_CHECKPOINT_WAIT 0 warmup $! if [ $? -ne 0 ]; then
@@ -201,7 +202,7 @@ malloc_free_memory() { tst_resm TINFO "Running memcg_process $1 -s $2" memcg_process $1 -s $2 & - sleep 1 + TST_CHECKPOINT_WAIT 0 echo $! > tasks kill -s USR1 $! 2> /dev/null
@@ -246,7 +247,7 @@ test_proc_kill() memcg_process $2 -s $3 & pid=$! - sleep 1 + TST_CHECKPOINT_WAIT 0 echo $pid > tasks kill -s USR1 $pid 2> /dev/null
@@ -315,7 +316,7 @@ test_hugepage() echo $1 > /proc/sys/vm/nr_hugepages memcg_process $2 --hugepage -s $3 > $TMP_FILE 2>&1 & - sleep 1 + TST_CHECKPOINT_WAIT 0 kill -s USR1 $! 2> /dev/null sleep 1
@@ -363,7 +364,7 @@ test_subgroup() tst_resm TINFO "Running memcg_process --mmap-anon -s $PAGESIZE" memcg_process --mmap-anon -s $PAGESIZE & - sleep 1 + TST_CHECKPOINT_WAIT 0 warmup $! if [ $? -ne 0 ]; then
@@ -399,7 +400,7 @@ test_move_charge() tst_resm TINFO "Running memcg_process $1 -s $2" memcg_process $1 -s $2 & - sleep 1 + TST_CHECKPOINT_WAIT 0 warmup $! if [ $? -ne 0 ]; then rmdir subgroup_a
testcases/kernel/controllers/memcg/functional/memcg_process.c +6 -0
@@ -34,6 +34,8 @@#include <stdlib.h> #include <string.h> #include <unistd.h> +#define TST_NO_DEFAULT_MAIN +#include "tst_test.h" static int fd;
@@ -315,6 +317,10 @@ int main(int argc, char *argv[])process_options (argc, argv); +tst_reinit (); + +TST_CHECKPOINT_WAKE (0 ); +while (!flag_exit)sleep (1 );
Signature · 1 line
1.7.1
PATCH v3 4/4 memcg/functional: check several times if the process is killed
On some systems it may take slightly more than one second to kill the memcg_process. So let's check several times if the process is alive.
---
Changes since [1]:
* 'sleep 1' next to memcg_process & is substituted by patch 3 of the series
* use /proc/pid and /proc/pid/status to check wheter the process exists and if it exists whether it's in Z state
[1] http://lists.linux.it/pipermail/ltp/2016-May/001840.html
.../controllers/memcg/functional/memcg_lib.sh | 15 ++++++++++++--- 1 files changed, 12 insertions(+), 3 deletions(-)
testcases/kernel/controllers/memcg/functional/memcg_lib.sh +12 -3
@@ -251,10 +251,19 @@ test_proc_kill() echo $pid > tasks kill -s USR1 $pid 2> /dev/null - sleep 1 - ps -p $pid > /dev/null 2> /dev/null - if [ $? -ne 0 ]; then + tpk_pid_exists=1 + for tpk_iter in $(seq 20); do + if [ ! -d "/proc/$pid" ] || + grep -q 'Z (zombie)' "/proc/$pid/status"; then + tpk_pid_exists=0 + break + fi + + tst_sleep 250ms + done + + if [ $tpk_pid_exists -eq 0 ]; then wait $pid ret=$? if [ $ret -eq 1 ]; then
Signature · 1 line
1.7.1
PATCH v3 4/4 memcg/functional: check several times if the process is killed
Hi!
Looks good to me.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/4 memcg/functional: use checkpoints
In reply to Stanislav KholmanskikhHi!
Quoted 5 lines
This patch implements the idea proposed in [1], [2], that we use the checkpoint interface to let
memcg_processinform the parent process that it's ready.In my enviroment it saves ~50 secs of time.
Nice :)
BTW, we should also change the test so that the allocation is not done from the signal handlers, but that can be done later.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/4 memcg/functional: use checkpoints
In reply to Stanislav KholmanskikhHi!
Quoted 3 lines
This patch implements the idea proposed in [1], [2], that we use the checkpoint interface to let
memcg_processinform the parent process that it's ready.
Also you probably forget to add links for [1] and [2] here.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/4 memcg/functional/memcg_process: cleanup
In reply to Stanislav KholmanskikhHi!
This one is obviously OK.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/4 memcg/functional: rewrite
In reply to Stanislav KholmanskikhHi!
testcases/kernel/controllers/memcg/functional/memcg_lib.sh result() · line 85
Quoted 8 lines
# Record the test result of a test case
# $1 - The result of the test case, $PASS or $FAILtestcases/kernel/controllers/memcg/functional/memcg_lib.sh +0
-1@@ -55,7 +82,6 @@ result() tst_resm TPASS "$info" else tst_resm TFAIL "$info" - : $(( failed += 1 )) fi
Can we get rid of the result() function?
Since the failures are now counted in the test.sh library it does not make a sense to define special result reporting function.
Quoted 10 lines
testcases/kernel/controllers/memcg/functional/memcg_lib.sh +1
-1@@ -83,7 +109,7 @@ warmup() { pid=$1 - echo "Warming up for test: $cur_id, pid: $pid" + tst_resm TINFO "Warming up pid: $pid" kill -s USR1 $pid 2> /dev/null sleep 1 kill -s USR1 $pid 2> /dev/null
testcases/kernel/controllers/memcg/functional/memcg_lib.sh warmup() · line 120
Quoted 5 lines
testcases/kernel/controllers/memcg/functional/memcg_lib.sh +1
-1@@ -91,10 +117,10 @@ warmup() kill -0 $pid if [ $? -ne 0 ]; then - result $FAIL "cur_id=$cur_id" + result $FAIL ""
^
Shouldn't we print here something as:
"process died after warmup"
Or even better wait the pid and print the exit value as well.
Otherwise this looks fine.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/4 memcg/functional: rewrite
Hi!
Quoted 12 lines · Cyril Hrubis
Hi!
testcases/kernel/controllers/memcg/functional/memcg_lib.sh result() · line 85
Quoted 8 lines
# Record the test result of a test case
# $1 - The result of the test case, $PASS or $FAILtestcases/kernel/controllers/memcg/functional/memcg_lib.sh +0
-1@@ -55,7 +82,6 @@ result() tst_resm TPASS "$info" else tst_resm TFAIL "$info" - : $(( failed += 1 )) fiCan we get rid of the
result()function?
Quoted 2 lines
Since the failures are now counted in the
test.shlibrary it does not make a sense to define special result reporting function.
Yes, we can.
One thing to notice that in the current code there are many places like this:
echo 1.0 > memory.limit_in_bytes 2> /dev/null
result $(( !($? != 0) )) "return value is $?"
I don't think it will be a good idea to transform them all to:
echo 1.0 > memory.limit_in_bytes 2> /dev/null
if [ $? -ne 0 ]; then
tst_resm TPASS "return value is $?"
else
tst_resm TFAIL "return value is 0"
fi
A possible solution could be using help functions similar to ROD():
SHOULD_FAIL echo 1.0 \> memory.limit_in_bytes
which will output:
TPASS: echo 1.0 > memory.limit_in_bytes failed as expected
I have an RFC patch for that. I'll send it shortly.
Quoted 17 lines
Quoted 11 lines
testcases/kernel/controllers/memcg/functional/memcg_lib.sh +1
-1@@ -83,7 +109,7 @@ warmup() { pid=$1 - echo "Warming up for test: $cur_id, pid: $pid" + tst_resm TINFO "Warming up pid: $pid" kill -s USR1 $pid 2> /dev/null sleep 1 kill -s USR1 $pid 2> /dev/nulltestcases/kernel/controllers/memcg/functional/memcg_lib.sh warmup() · line 120
Quoted 5 lines
testcases/kernel/controllers/memcg/functional/memcg_lib.sh +1
-1@@ -91,10 +117,10 @@ warmup() kill -0 $pid if [ $? -ne 0 ]; then - result $FAIL "cur_id=$cur_id" + result $FAIL ""^
Quoted 5 lines
Shouldn't we print here something as:
"process died after warmup"
Or even better wait the pid and print the exit value as well.
Ok. Will do.
Quoted 4 lines
Otherwise this looks fine.