public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Bernhard Voelker <mail@bernhard-voelker.de>
To: Sami Kerola <kerolasa@iki.fi>, util-linux@vger.kernel.org
Subject: Re: [PATCH 4/7] tests: check kill is converting signals names correctly
Date: Mon, 14 Apr 2014 00:22:19 +0200	[thread overview]
Message-ID: <534B0E1B.4040208@bernhard-voelker.de> (raw)
In-Reply-To: <1397298524-3364-5-git-send-email-kerolasa@iki.fi>

On 04/12/2014 12:28 PM, Sami Kerola wrote:
> +	$TS_HELPER_SIGRECEIVE &
> +	TEST_PID=$(jobs -p)
> +	# test_sigreceive needs time to start up
> +	sleep 0.01
> +	$TS_CMD_KILL -$SIG ${TS_HELPER_SIGRECEIVE##*/} >> $TS_OUTPUT 2>&1
> +	wait $TEST_PID
> +	if [ $? -ne $EXPECTED ]; then
> +		echo "$SIG returned $? while $EXPECTED was expected" >> $TS_OUTPUT
> +		all_ok=false
> +	fi

This is racy. Although this might work in most cases, one can not
determine that the SIGRECEIVE process had enough time to startup
and register all signal handlers before the signal arrives.
Usually this would fail more likely with high system load,
e.g. on build servers with massive parallel builds.

The only chance is that the SIGRECEIVE program indicates that it
has fully come up, e.g. by creating a file which did not exist
beforehand. The second part of avoiding unwanted behavior is to
wait for such a witness file to appear in the parent test script
... but avoiding to wait infinitely (because other unknown reasons
may have prevented the creation of the witness file).

In the test-suite of coreutils, there are a few complex (and yet
necessary) snippets to do this:
a) test case waiting for the inspected program to be ready:
  http://git.savannah.gnu.org/cgit/coreutils.git/tree/tests/tail-2/retry.sh#n45
b) utility function to retry with increasing delay until a
maximum number has reached:
  http://git.savannah.gnu.org/cgit/coreutils.git/tree/init.cfg#n597

Maybe a solution like the above is too heavy for this situation (unless
it could be reused in other tests), so something like the following may
suffice here - assuming that $TS_HELPER_SIGRECEIVE will successfully
perform a 'creat("witnessfile", mode)':

  rm -f witnessfile   || fail=1
  test -f witnessfile && fail=1
  $TS_HELPER_SIGRECEIVE & TEST_PID=$!
  up=0
  while i in 0.01 0.1 1 2 ; do
    test -f witnessfile && { up=1; break; }
    sleep $i
  done
  test $up = 1 || fail=1
  $TS_CMD_KILL -$SIG ${TS_HELPER_SIGRECEIVE##*/} >> $TS_OUTPUT 2>&1
  ...

WDYT?

Thank you & have a nice day,
Berny

  reply	other threads:[~2014-04-13 22:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-12 10:28 [PATCH 0/7] kill: add regression tests Sami Kerola
2014-04-12 10:28 ` [PATCH 1/7] kill: make options --pid and --queue mutually exclusive Sami Kerola
2014-04-12 15:57   ` Bernhard Voelker
2014-04-12 16:35     ` Sami Kerola
2014-04-12 10:28 ` [PATCH 2/7] kill: remove unnecessary indirection Sami Kerola
2014-04-12 10:28 ` [PATCH 3/7] tests: add signal receiver program Sami Kerola
2014-04-12 10:28 ` [PATCH 4/7] tests: check kill is converting signals names correctly Sami Kerola
2014-04-13 22:22   ` Bernhard Voelker [this message]
2014-04-14  7:42     ` Sami Kerola
2014-04-14 15:13       ` Sami Kerola
2014-04-14 16:14         ` Bernhard Voelker
2014-04-14 19:00           ` Sami Kerola
2014-04-15  9:09             ` Bernhard Voelker
2014-04-15 11:08               ` Sami Kerola
2014-04-12 10:28 ` [PATCH 5/7] tests: check various ways to specify kill signal Sami Kerola
2014-04-12 10:28 ` [PATCH 6/7] tests: check kill print pid option Sami Kerola
2014-04-12 10:28 ` [PATCH 7/7] tests: check kill all user processes Sami Kerola

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=534B0E1B.4040208@bernhard-voelker.de \
    --to=mail@bernhard-voelker.de \
    --cc=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox