Test: add file based synchronization point for python test app
[lttng-tools.git] / tests / regression / ust / python-logging / test.py
1 # Copyright (C) 2015 - Philippe Proulx <pproulx@efficios.com>
2 # Copyright (C) 2014 - David Goulet <dgoulet@efficios.com>
3 #
4 # This library is free software; you can redistribute it and/or modify it under
5 # the terms of the GNU Lesser General Public License as published by the Free
6 # Software Foundation; version 2.1 of the License.
7 #
8 # This library is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 # details.
12 #
13 # You should have received a copy of the GNU Lesser General Public License
14 # along with this library; if not, write to the Free Software Foundation, Inc.,
15 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17 from __future__ import unicode_literals, print_function
18 import logging
19 import time
20 import sys
21 import argparse
22 import os
23
24
25 def _perror(msg):
26 print(msg, file=sys.stderr)
27 sys.exit(1)
28
29
30 try:
31 import lttngust
32 except (ImportError) as e:
33 _perror('lttngust package not found: {}'.format(e))
34
35
36 def _main():
37 ev1 = logging.getLogger('python-ev-test1');
38 ev2 = logging.getLogger('python-ev-test2');
39
40 logging.basicConfig()
41
42 parser = argparse.ArgumentParser()
43 parser.add_argument('-n', '--nr-iter', required=True)
44 parser.add_argument('-s', '--wait', required=True)
45 parser.add_argument('-d', '--fire-debug-event', action="store_true")
46 parser.add_argument('-e', '--fire-second-event', action="store_true")
47 parser.add_argument('-r', '--ready-file')
48 parser.add_argument('-g', '--go-file')
49 args = parser.parse_args()
50
51 nr_iter = int(args.nr_iter)
52 wait_time = float(args.wait)
53 fire_debug_ev = args.fire_debug_event
54 fire_second_ev = args.fire_second_event
55
56 ready_file = args.ready_file
57 go_file = args.go_file
58
59 if ready_file is not None and os.path.exists(ready_file):
60 raise ValueError('Ready file already exist')
61
62 if go_file is not None and os.path.exists(go_file):
63 raise ValueError('Go file already exist. Review synchronization')
64
65 if (ready_file is None) != (go_file is None):
66 raise ValueError('--go-file and --ready-file need each others, review'
67 'synchronization')
68
69
70 # Inform that we are ready, if necessary
71 if ready_file is not None:
72 open(ready_file, 'a').close()
73
74 # Wait for go, if necessary
75 while go_file is not None and not os.path.exists(go_file):
76 time.sleep(0.5)
77
78 for i in range(nr_iter):
79 ev1.info('{} fired [INFO]'.format(ev1.name))
80
81 if fire_debug_ev:
82 ev1.debug('{} fired [DEBUG]'.format(ev1.name))
83
84 time.sleep(wait_time)
85
86 if fire_second_ev:
87 ev2.info('{} fired [INFO]'.format(ev2.name))
88
89 if ready_file is not None:
90 try:
91 os.unlink(ready_file)
92 except:
93 print("Unexpected error on ready file unlink:", sys.exc_info()[0])
94 raise
95
96
97 if __name__ == '__main__':
98 _main()
This page took 0.030389 seconds and 4 git commands to generate.