[lttng-dev] [PATCH lttng-tools 1/2] Test: add file based synchronization point for python test app
Jérémie Galarneau
jeremie.galarneau at efficios.com
Tue Nov 14 00:26:05 UTC 2017
Merged, thanks!
Jérémie
On 28 August 2017 at 17:50, Jonathan Rajotte
<jonathan.rajotte-julien at efficios.com> wrote:
> test.py is responsible for the cleanup of the "ready" file while the
> cleanup of the "go" file is left to the external controller.
>
> Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
> ---
> tests/regression/ust/python-logging/test.py | 59 ++++++++++++++++------
> .../ust/python-logging/test_python_logging.in | 11 +++-
> 2 files changed, 53 insertions(+), 17 deletions(-)
>
> diff --git a/tests/regression/ust/python-logging/test.py b/tests/regression/ust/python-logging/test.py
> index d08e623c..cd6b724c 100644
> --- a/tests/regression/ust/python-logging/test.py
> +++ b/tests/regression/ust/python-logging/test.py
> @@ -18,6 +18,8 @@ from __future__ import unicode_literals, print_function
> import logging
> import time
> import sys
> +import argparse
> +import os
>
>
> def _perror(msg):
> @@ -37,23 +39,41 @@ def _main():
>
> logging.basicConfig()
>
> - try:
> - nr_iter = int(sys.argv[1])
> - wait_time = float(sys.argv[2])
> - fire_debug_ev = False
> - fire_second_ev = False
> - except (IndexError) as e:
> - _perror('missing arguments: {}'.format(e))
> - except (ValueError) as e:
> - _perror('invalid arguments: {}'.format(e))
> + parser = argparse.ArgumentParser()
> + parser.add_argument('-n', '--nr-iter', required=True)
> + parser.add_argument('-s', '--wait', required=True)
> + parser.add_argument('-d', '--fire-debug-event', action="store_true")
> + parser.add_argument('-e', '--fire-second-event', action="store_true")
> + parser.add_argument('-r', '--ready-file')
> + parser.add_argument('-g', '--go-file')
> + args = parser.parse_args()
>
> - try:
> - if len(sys.argv) > 3:
> - fire_debug_ev = int(sys.argv[3])
> - if len(sys.argv) > 4:
> - fire_second_ev = int(sys.argv[4])
> - except (ValueError) as e:
> - _perror('invalid arguments: {}'.format(e))
> + nr_iter = int(args.nr_iter)
> + wait_time = float(args.wait)
> + fire_debug_ev = args.fire_debug_event
> + fire_second_ev = args.fire_second_event
> +
> + ready_file = args.ready_file
> + go_file = args.go_file
> +
> + if ready_file is not None and os.path.exists(ready_file):
> + raise ValueError('Ready file already exist')
> +
> + if go_file is not None and os.path.exists(go_file):
> + raise ValueError('Go file already exist. Review synchronization')
> +
> + if (ready_file is None) != (go_file is None):
> + raise ValueError('--go-file and --ready-file need each others, review'
> + 'synchronization')
> +
> +
> + # Inform that we are ready, if necessary
> + if ready_file is not None:
> + open(ready_file, 'a').close()
> +
> + # Wait for go, if necessary
> + while go_file is not None and not os.path.exists(go_file):
> + time.sleep(0.5)
>
> for i in range(nr_iter):
> ev1.info('{} fired [INFO]'.format(ev1.name))
> @@ -66,6 +86,13 @@ def _main():
> if fire_second_ev:
> ev2.info('{} fired [INFO]'.format(ev2.name))
>
> + if ready_file is not None:
> + try:
> + os.unlink(ready_file)
> + except:
> + print("Unexpected error on ready file unlink:", sys.exc_info()[0])
> + raise
> +
>
> if __name__ == '__main__':
> _main()
> diff --git a/tests/regression/ust/python-logging/test_python_logging.in b/tests/regression/ust/python-logging/test_python_logging.in
> index 90abc116..42c30572 100755
> --- a/tests/regression/ust/python-logging/test_python_logging.in
> +++ b/tests/regression/ust/python-logging/test_python_logging.in
> @@ -46,8 +46,17 @@ function run_app
> local python=$1
> local debug_tp=$2
> local fire_second_tp=$3
> + local opt=""
>
> - $python $TESTAPP_PATH/$TESTAPP_BIN $NR_ITER $NR_SEC_WAIT $debug_tp $fire_second_tp
> + if [[ -n "$debug_tp" ]] && [ "$debug_tp" -eq "1" ]; then
> + opt="${opt} -d"
> + fi
> +
> + if [[ -n "$fire_second_tp" ]] && [ "$fire_second_tp" -eq "1" ]; then
> + opt="${opt} -e"
> + fi
> +
> + $python $TESTAPP_PATH/$TESTAPP_BIN -n $NR_ITER -s $NR_SEC_WAIT $opt
> }
>
> function run_app_background
> --
> 2.11.0
>
--
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
More information about the lttng-dev
mailing list