blob: abc5e548e013aef1b6dcfe6f52665e46642bb68e [file] [log] [blame]
Holger Hans Peter Freytherc490cde2018-02-25 21:24:30 +00001# osmo_ms_driver: Main test runner
2#
3# Copyright (C) 2018 by Holger Hans Peter Freyther
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as
7# published by the Free Software Foundation, either version 3 of the
8# License, or (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18# Local modules
19from .event_server import EventServer
20from .simple_loop import SimpleLoop
21from .location_update_test import MassUpdateLocationTest
Holger Hans Peter Freyther0f0ebd82018-06-23 14:40:42 +010022from .cdf import ease_in_out_duration, linear_with_duration, cdfs
Holger Hans Peter Freytherc490cde2018-02-25 21:24:30 +000023from osmo_gsm_tester import log
24
25# System modules
Holger Hans Peter Freyther0f0ebd82018-06-23 14:40:42 +010026import argparse
Holger Hans Peter Freyther94da0452018-06-23 14:41:27 +010027import atexit
Holger Hans Peter Freytherc490cde2018-02-25 21:24:30 +000028import datetime
29import subprocess
30import signal
31import tempfile
32import os.path
Holger Hans Peter Freyther0f0ebd82018-06-23 14:40:42 +010033import os
Holger Hans Peter Freytherc490cde2018-02-25 21:24:30 +000034
Holger Hans Peter Freyther0f0ebd82018-06-23 14:40:42 +010035def parser():
36 parser = argparse.ArgumentParser(epilog=__doc__, formatter_class=argparse.RawTextHelpFormatter)
37 parser.add_argument('-s', '--launch-duration', dest='launch_duration',
38 default=60, type=int,
39 help="Time launching applications should take in seconds")
40 parser.add_argument('-i', '--launch-interval', dest='launch_interval',
41 default=100, type=int,
42 help="Time between launching in milliseconds")
43 parser.add_argument('-d', '--distribution', dest="cdf_name",
44 choices=cdfs.keys(), default="ease_in_out",
45 help="Curve to use for starting within launch duration")
46 parser.add_argument('-m', '--number-ms', dest="num_ms",
47 default=10, type=int,
48 help="Number of MobileStations to simulate")
49 return parser
Holger Hans Peter Freytherc490cde2018-02-25 21:24:30 +000050
51def main():
52 # Create a default log to stdout
53 log.LogTarget().style(src=False)
54
Holger Hans Peter Freyther0f0ebd82018-06-23 14:40:42 +010055 args = parser().parse_args()
56
Holger Hans Peter Freytherc490cde2018-02-25 21:24:30 +000057 # We don't care what is happening to child processes we spawn!
58 signal.signal(signal.SIGCHLD, signal.SIG_IGN)
59
60 loop = SimpleLoop()
61
Holger Hans Peter Freytherc490cde2018-02-25 21:24:30 +000062 tmp_dir = tempfile.mkdtemp(suffix="osmo-ms-driver")
63 log.log("Going to store files in ", tmp_dir=tmp_dir)
64
65 # How long should starting all apps take
Holger Hans Peter Freyther0f0ebd82018-06-23 14:40:42 +010066 time_start=datetime.timedelta(seconds=args.launch_duration)
Holger Hans Peter Freytherc490cde2018-02-25 21:24:30 +000067 # In which steps to start processes
Holger Hans Peter Freyther0f0ebd82018-06-23 14:40:42 +010068 time_step=datetime.timedelta(milliseconds=args.launch_interval)
Holger Hans Peter Freytherc490cde2018-02-25 21:24:30 +000069
70 # Event server path
71 event_server_path = os.path.join(tmp_dir, "osmo_ms_driver.unix")
72
73 # The function that decides when to start something
Holger Hans Peter Freyther0f0ebd82018-06-23 14:40:42 +010074 cdf = cdfs[args.cdf_name](time_start, time_step)
Holger Hans Peter Freytherc490cde2018-02-25 21:24:30 +000075
76 # Event server to handle MS->test events
77 ev_server = EventServer("ev_server", event_server_path)
78 ev_server.listen(loop)
Holger Hans Peter Freytherc490cde2018-02-25 21:24:30 +000079
80 # Just a single test for now.
Holger Hans Peter Freyther0f0ebd82018-06-23 14:40:42 +010081 test = MassUpdateLocationTest("lu_test", args.num_ms, cdf, ev_server, tmp_dir)
Holger Hans Peter Freyther94da0452018-06-23 14:41:27 +010082 atexit.register(test.stop_all)
Holger Hans Peter Freytherc490cde2018-02-25 21:24:30 +000083
84 # Run until everything has been launched
85 test.launch(loop)
86
87 # Wait for it to complete
88 test.wait_for_result(loop)
89
90 # Print stats
91 test.print_stats()
92
93if __name__ == '__main__':
94 main()