blob: 4b32439ad181c8a53935428644a52289f6a6722c [file] [log] [blame]
Neels Hofmeyr3531a192017-03-28 14:30:28 +02001#!/usr/bin/env python3
2import os
Pau Espin Pedrol30637302020-05-06 21:11:02 +02003import sys
Neels Hofmeyr3531a192017-03-28 14:30:28 +02004import _prep
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +02005import shutil
Pau Espin Pedrol4e6b5072020-05-11 15:12:07 +02006from osmo_gsm_tester.core import log
7from osmo_gsm_tester.core import config
8from osmo_gsm_tester.core import util
9from osmo_gsm_tester.core import report
10from osmo_gsm_tester.core import scenario
Pau Espin Pedrolf574a462020-05-05 12:18:35 +020011from osmo_gsm_tester.core import suite
Pau Espin Pedrol30637302020-05-06 21:11:02 +020012from osmo_gsm_tester.core.schema import generate_schemas, get_all_schema
Neels Hofmeyr3531a192017-03-28 14:30:28 +020013
Pau Espin Pedrol6c6c0e82020-05-11 18:30:58 +020014config.override_conf = os.path.join(os.path.dirname(sys.argv[0]), 'paths.conf')
Neels Hofmeyr3531a192017-03-28 14:30:28 +020015
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020016example_trial_dir = os.path.join('test_trial_tmp')
17
18class FakeTrial(log.Origin):
19 def __init__(self):
20 super().__init__(log.C_TST, 'trial')
21 self.dir = util.Dir(example_trial_dir)
22 self._run_dir = None
23
24 def get_run_dir(self):
25 if self._run_dir is not None:
26 return self._run_dir
27 self._run_dir = util.Dir(self.dir.new_child('test_run'))
28 self._run_dir.mkdir()
29 return self._run_dir
30
Neels Hofmeyr3531a192017-03-28 14:30:28 +020031#log.style_change(trace=True)
32
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020033# Generate supported schemas dynamically from objects:
34generate_schemas()
35
Neels Hofmeyr3531a192017-03-28 14:30:28 +020036print('- non-existing suite dir')
37assert(log.run_logging_exceptions(suite.load, 'does_not_exist') == None)
38
39print('- no suite.conf')
40assert(log.run_logging_exceptions(suite.load, 'empty_dir') == None)
41
42print('- valid suite dir')
43example_suite_dir = os.path.join('test_suite')
44s_def = suite.load(example_suite_dir)
45assert(isinstance(s_def, suite.SuiteDefinition))
46print(config.tostr(s_def.conf))
47
48print('- run hello world test')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020049trial = FakeTrial()
Neels Hofmeyr6ccda112017-06-06 19:41:17 +020050s = suite.SuiteRun(trial, 'test_suite', s_def)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020051results = s.run_tests('hello_world.py')
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020052print(report.suite_to_text(s))
Neels Hofmeyr3531a192017-03-28 14:30:28 +020053
54log.style_change(src=True)
55#log.style_change(trace=True)
56print('\n- a test with an error')
57results = s.run_tests('test_error.py')
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020058output = report.suite_to_text(s)
Neels Hofmeyr6ccda112017-06-06 19:41:17 +020059print(output)
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020060
61print('\n- a test with a failure')
62results = s.run_tests('test_fail.py')
63output = report.suite_to_text(s)
Neels Hofmeyr6ccda112017-06-06 19:41:17 +020064print(output)
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020065
66print('\n- a test with a raised failure')
67results = s.run_tests('test_fail_raise.py')
68output = report.suite_to_text(s)
Neels Hofmeyr6ccda112017-06-06 19:41:17 +020069print(output)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020070
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020071print('- test with half empty scenario')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020072trial = FakeTrial()
Pau Espin Pedrol4e6b5072020-05-11 15:12:07 +020073sc = scenario.Scenario('foo', 'bar')
74sc['resources'] = { 'bts': [{'type': 'osmo-bts-trx'}] }
75s = suite.SuiteRun(trial, 'test_suite', s_def, [sc])
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020076results = s.run_tests('hello_world.py')
77print(report.suite_to_text(s))
78
79print('- test with scenario')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020080trial = FakeTrial()
Pau Espin Pedrol4e6b5072020-05-11 15:12:07 +020081sc = scenario.Scenario('foo', 'bar')
82sc['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 'sysmo'}] }
83s = suite.SuiteRun(trial, 'test_suite', s_def, [sc])
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020084results = s.run_tests('hello_world.py')
85print(report.suite_to_text(s))
86
Pau Espin Pedrolaab56922018-08-21 14:58:29 +020087print('- test with scenario and modifiers')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020088trial = FakeTrial()
Pau Espin Pedrol4e6b5072020-05-11 15:12:07 +020089sc = scenario.Scenario('foo', 'bar')
90sc['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 'sysmo'}] }
91sc['modifiers'] = { 'bts': [{ 'times': '2', 'trx_list': [{'nominal_power': '20'}, {'nominal_power': '20'}]}, {'type': 'sysmo'}] }
92s = suite.SuiteRun(trial, 'test_suite', s_def, [sc])
Pau Espin Pedrolaab56922018-08-21 14:58:29 +020093s.reserve_resources()
94print(repr(s.reserved_resources))
95results = s.run_tests('hello_world.py')
96print(report.suite_to_text(s))
97
Pau Espin Pedrol30637302020-05-06 21:11:02 +020098print('- test with suite-specific config')
99trial = FakeTrial()
Pau Espin Pedrol4e6b5072020-05-11 15:12:07 +0200100sc = scenario.Scenario('foo', 'bar')
101sc['config'] = {'suite': {s.name(): { 'some_suite_global_param': 'heyho', 'test_suite_params': {'one_bool_parameter': 'true', 'second_list_parameter': ['23', '45']}}}}
102s = suite.SuiteRun(trial, 'test_suite', s_def, [sc])
Pau Espin Pedrol30637302020-05-06 21:11:02 +0200103s.reserve_resources()
104print(repr(s.reserved_resources))
105results = s.run_tests('test_suite_params.py')
106print(report.suite_to_text(s))
107
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200108print('\n- graceful exit.')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +0200109#deleting generated tmp trial dir:
110shutil.rmtree(example_trial_dir, ignore_errors=True)
111
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200112# vim: expandtab tabstop=4 shiftwidth=4