blob: 88eed283da44a547611731868393e92420c3e0a6 [file] [log] [blame]
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +02001#!/usr/bin/env python3
2
3# osmo_gsm_tester: invoke a single test run
4#
5# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
6#
7# Author: Neels Hofmeyr <neels@hofmeyr.de>
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU Affero General Public License as
11# published by the Free Software Foundation, either version 3 of the
12# License, or (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU Affero General Public License for more details.
18#
19# You should have received a copy of the GNU Affero General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22'''osmo_gsm_tester: invoke a single test run.
23
Neels Hofmeyr3531a192017-03-28 14:30:28 +020024Examples:
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020025
Neels Hofmeyr3531a192017-03-28 14:30:28 +020026./run_once.py ~/my_trial_package/ -s osmo_trx
27./run_once.py ~/my_trial_package/ -c sms_tests:dyn_ts+eu_band+bts_sysmo
28./run_once.py ~/my_trial_package/ -c sms_tests/mo_mt_sms:bts_trx
29
30(The names for test suite, scenario and series names used in these examples
31must be defined by the osmo-gsm-tester configuration.)
32
33A trial package contains binaries (usually built by a jenkins job) of GSM
34software, including the core network programs as well as binaries for the
35various BTS models.
36
37A test suite defines specific actions to be taken and verifies their outcome.
38Such a test suite may leave certain aspects of a setup undefined, e.g. it may
39be BTS model agnostic or does not care which voice codecs are chosen.
40
41A test scenario completes the picture in that it defines which specific choices
42shall be made to run a test suite. Any one test suite may thus run on any
43number of different scenarios, e.g. to test various voice codecs.
44
45Test scenarios may be combined. For example, one scenario may define a timeslot
46configuration to use, while another scenario may define the voice codec
47configuration.
48
49There may still be aspects that are neither required by a test suite nor
50strictly defined by a scenario, which will be resolved automatically, e.g. by
51choosing the first available item that matches the other constraints.
52
53A test run thus needs to define: a trial package containing built binaries, a
54combination of scenarios to run a suite in, and a test suite to launch in the
55given scenario with the given binaries.
56
57The osmo-gsm-tester configuration may define one or more series as a number of
58suite:scenario combinations. So instead of a specific suite:scenario
59combination, the name of such a series can be passed.
60
61If neither a combination or series is specified, the default series will be run
62as defined in the osmo-gsm-tester configuration.
63
64The scenarios and suites run for a given trial will be recorded in a trial
65package's directory: Upon launch, a 'test_package/run.<date>' directory will be
66created, which will collect logs and reports.
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020067'''
68
Neels Hofmeyr3531a192017-03-28 14:30:28 +020069from osmo_gsm_tester import trial, suite, log, __version__
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020070
71if __name__ == '__main__':
72 import argparse
73
Neels Hofmeyr3531a192017-03-28 14:30:28 +020074 parser = argparse.ArgumentParser(epilog=__doc__, formatter_class=argparse.RawTextHelpFormatter)
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020075 parser.add_argument('-V', '--version', action='store_true',
76 help='Show version')
Neels Hofmeyr3531a192017-03-28 14:30:28 +020077 parser.add_argument('trial_package', nargs='+',
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020078 help='Directory containing binaries to test')
Neels Hofmeyr3531a192017-03-28 14:30:28 +020079 parser.add_argument('-s', '--suite-scenario', dest='suite_scenario', action='append',
80 help='A suite-scenarios combination like suite:scenario+scenario')
81 parser.add_argument('-S', '--series', dest='series', action='append',
82 help='A series of suite-scenarios combinations as defined in the'
83 ' osmo-gsm-tester configuration')
84 parser.add_argument('-t', '--test', dest='test', action='append',
85 help='Run only tests matching this name')
86 parser.add_argument('-l', '--log-level', dest='log_level', choices=log.LEVEL_STRS.keys(),
87 default=None,
88 help='Set logging level for all categories (on stdout)')
89 parser.add_argument('-T', '--traceback', dest='trace', action='store_true',
90 help='Enable logging of tracebacks')
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020091 args = parser.parse_args()
92
93 if args.version:
Neels Hofmeyr3531a192017-03-28 14:30:28 +020094 print(__version__)
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +020095 exit(0)
96
Neels Hofmeyr3531a192017-03-28 14:30:28 +020097 print('combinations:', repr(args.suite_scenario))
98 print('series:', repr(args.series))
99 print('trials:', repr(args.trial_package))
100 print('tests:', repr(args.test))
101
102 if args.log_level:
103 log.set_all_levels(log.LEVEL_STRS.get(args.log_level))
104 log.style_change(origin_width=32)
105 if args.trace:
106 log.style_change(trace=True)
107
108 combination_strs = list(args.suite_scenario or [])
109 # for series in args.series:
110 # combination_strs.extend(config.get_series(series))
111
112 if not combination_strs:
113 raise RuntimeError('Need at least one suite:scenario or series to run')
114
115 suite_scenarios = []
116 for combination_str in combination_strs:
117 suite_scenarios.append(suite.load_suite_scenario_str(combination_str))
118
119 test_names = []
120 for test_name in (args.test or []):
121 found = False
122 for suite_run in suite_runs:
123 for test in suite_run.definition.tests:
124 if test_name in test.name():
125 found = True
126 test_names.append(test.name())
127 if not found:
128 raise RuntimeError('No test found for %r' % test_name)
129 if test_names:
130 print(repr(test_names))
131
132 trials = []
133 for trial_package in args.trial_package:
134 t = trial.Trial(trial_package)
135 t.verify()
136 trials.append(t)
137
138 for current_trial in trials:
139 with current_trial:
140 for suite_def, scenarios in suite_scenarios:
141 suite_run = suite.SuiteRun(current_trial, suite_def, scenarios)
142 suite_run.run_tests(test_names)
Neels Hofmeyrdae3d3c2017-03-28 12:16:58 +0200143
144# vim: expandtab tabstop=4 shiftwidth=4