All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 3/4] memcg_stress_test.sh: rewrite
Date: Wed, 11 May 2016 17:01:08 +0200	[thread overview]
Message-ID: <20160511150108.GI24701@rei.lan> (raw)
In-Reply-To: <1461338590-1309-3-git-send-email-stanislav.kholmanskikh@oracle.com>

Hi!
> -cd $LTPROOT/testcases/bin
> -export TCID="memcg_stress_test"
> -export TST_TOTAL=2
> -export TST_COUNT=0
> +TCID=memcg_stress_test
> +TST_TOTAL=2
> +. test.sh
>  
>  if [ "x$(grep -w memory /proc/cgroups | cut -f4)" != "x1" ]; then
> -        echo "WARNING:";
> -        echo "Either Kernel does not support for memory resource controller or feature not enabled";
> -        echo "Skipping all memcgroup testcases....";
> -        exit 0
> +	tst_brkm TCONF "Kernel does not support the memory resource controller"
>  fi
>  
>  RUN_TIME=$(( 60 * 60 ))
>  
> +children=""
> +nr_children=0
> +memcg_path=/dev/memcg
> +memcg_created=0
> +
>  cleanup()
>  {
> -	if [ -e /dev/memcg ]; then
> -		umount /dev/memcg 2>/dev/null
> -		rmdir /dev/memcg 2>/dev/null
> +	for child in $children; do
> +		kill -s KILL $child 2> /dev/null
> +	done
> +	wait
> +
> +	if [ "$memcg_created" -ne 0 ]; then
> +		for i in $(seq 0 $(( $nr_children - 1 ))); do
> +			rmdir "$memcg_path/$i" 2> /dev/null
> +		done
> +		umount "$memcg_path"
> +		rmdir "$memcg_path"
>  	fi
>  }
> +TST_CLEANUP=cleanup
>  
> +do_unmount()
> +{
> +	ROD umount "$memcg_path"
> +	ROD rmdir "$memcg_path"
> +	memcg_created=0
> +}
>  
>  do_mount()
>  {
> -	cleanup;
> -
> -	mkdir /dev/memcg 2> /dev/null
> -	mount -t cgroup -omemory memcg /dev/memcg
> +	ROD mkdir "$memcg_path"
> +	memcg_created=1
> +	ROD mount -t cgroup -omemory memcg "$memcg_path"
>  }
>  
> +is_int()
> +{
> +	[ "$1" -eq "$1" ] 2> /dev/null
> +	return $?
> +}
>  
>  # Run the stress test
>  #
> @@ -65,33 +85,41 @@ do_mount()
>  # $4 - How long does this test run ? in second
>  run_stress()
>  {
> -	do_mount;
> +	nr_children=0
> +	children=""
> +
> +	do_mount
>  
> -	for i in $(seq 0 $(($1-1)))
> -	do
> -		mkdir /dev/memcg/$i 2> /dev/null
> +	for i in $(seq 0 $(( $1 - 1 ))); do
> +		ROD mkdir "$memcg_path/$i"
>  		./memcg_process_stress $2 $3 &

We should drop the ./ here since the binary is in $PATH

> -		eval pid$i=$!
> +		child=$!
>  
> -		eval echo \$pid$i > /dev/memcg/$i/tasks
> +		nr_children=$(( $nr_children + 1 ))
> +		children="$children $child"
> +
> +		ROD echo $child \> "$memcg_path/$i/tasks"
>  	done
>  
> -	for i in $(seq 0 $(($1-1)))
> -	do
> -		eval /bin/kill -s SIGUSR1 \$pid$i 2> /dev/null
> +	for child in $children; do
> +		ROD /bin/kill -s SIGUSR1 $child

Here drop the /bin/ and remove the SIG from the signal name.

>  	done
>  
>  	sleep $4
>  
> -	for i in $(seq 0 $(($1-1)))
> -	do
> -		eval /bin/kill -s SIGKILL \$pid$i 2> /dev/null
> -		eval wait \$pid$i
> +	for child in $children; do
> +		ROD /bin/kill -s SIGINT $child

Here as well.

> +	done
> +
> +	for child in $children; do
> +		ROD wait $child
> +	done
>  
> -		rmdir /dev/memcg/$i 2> /dev/null
> +	for i in $(seq 0 $(( $nr_children - 1 ))); do
> +		ROD rmdir "$memcg_path/$i"
>  	done
>  
> -	cleanup;
> +	do_unmount
>  }
>  
>  testcase_1()
> @@ -108,19 +136,23 @@ testcase_2()
>  	tst_resm TPASS "stress test 2 passed"
>  }
>  
> -echo 3 > /proc/sys/vm/drop_caches
> +ROD echo 3 \> /proc/sys/vm/drop_caches
>  sleep 2
> +
>  mem_free=`cat /proc/meminfo | grep MemFree | awk '{ print $2 }'`

mem_free=$(awk '/MemFree/ {print $2}' /proc/meminfo)

> +is_int "$mem_free" || tst_brkm TBROK "Unable to determine mem_free"
> +
>  swap_free=`cat /proc/meminfo | grep SwapFree | awk '{ print $2 }'`

Here as well.

> +is_int "$swap_free" || tst_brkm TBROK "Unable to determine swap_free"
>  
>  mem=$(( $mem_free + $swap_free / 2 ))
> -mem=$(( mem / 1024 ))
> +mem=$(( $mem / 1024 ))
> +[ "$mem" -gt 0 ] || tst_brkm TBROK "mem is negative: $mem"
>  
>  date
> -export TST_COUNT=$(( $TST_COUNT + 1 ))
>  testcase_1
> -export TST_COUNT=$(( $TST_COUNT + 1 ))
> +date
>  testcase_2
>  date
>  
> -exit 0
> +tst_exit

The rest looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

  parent reply	other threads:[~2016-05-11 15:01 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-22 15:23 [LTP] [PATCH 1/4] memcg_process_stress: cleanup Stanislav Kholmanskikh
2016-04-22 15:23 ` [LTP] [PATCH 2/4] memcg_process_stress: allocate memory not in the signal handler Stanislav Kholmanskikh
2016-04-22 15:23   ` [LTP] [PATCH 3/4] memcg_stress_test.sh: rewrite Stanislav Kholmanskikh
2016-04-22 15:23     ` [LTP] [RFC PATCH 4/4] memcg_stress_test.sh: allocate less than CommitLimit bytes Stanislav Kholmanskikh
2016-05-12 13:42       ` Cyril Hrubis
2016-05-17 12:52         ` Stanislav Kholmanskikh
2016-05-17 13:02           ` Stanislav Kholmanskikh
2016-05-18 14:39           ` Cyril Hrubis
2016-05-18 17:29             ` Stanislav Kholmanskikh
2016-05-19 13:38               ` Cyril Hrubis
2016-05-23 11:12                 ` Stanislav Kholmanskikh
2016-05-24 16:46                   ` Cyril Hrubis
2016-05-19  9:17             ` Michal Hocko
2016-05-19 12:56               ` Cyril Hrubis
2016-05-19 19:21                 ` Michal Hocko
2016-05-24 16:21                   ` Cyril Hrubis
2016-05-11 15:01     ` Cyril Hrubis [this message]
2016-05-11 14:39   ` [LTP] [PATCH 2/4] memcg_process_stress: allocate memory not in the signal handler Cyril Hrubis
2016-05-12 11:09     ` Stanislav Kholmanskikh
2016-05-12 11:26       ` Cyril Hrubis
2016-05-11 14:16 ` [LTP] [PATCH 1/4] memcg_process_stress: cleanup Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160511150108.GI24701@rei.lan \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.