Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | import os |
Pau Espin Pedrol | 3063730 | 2020-05-06 21:11:02 +0200 | [diff] [blame] | 3 | import sys |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 4 | import _prep |
Pau Espin Pedrol | 9d489c8 | 2019-09-18 18:43:45 +0200 | [diff] [blame] | 5 | import shutil |
Pau Espin Pedrol | 4e6b507 | 2020-05-11 15:12:07 +0200 | [diff] [blame] | 6 | from osmo_gsm_tester.core import log |
| 7 | from osmo_gsm_tester.core import config |
| 8 | from osmo_gsm_tester.core import util |
| 9 | from osmo_gsm_tester.core import report |
| 10 | from osmo_gsm_tester.core import scenario |
Pau Espin Pedrol | f574a46 | 2020-05-05 12:18:35 +0200 | [diff] [blame] | 11 | from osmo_gsm_tester.core import suite |
Pau Espin Pedrol | 3063730 | 2020-05-06 21:11:02 +0200 | [diff] [blame] | 12 | from osmo_gsm_tester.core.schema import generate_schemas, get_all_schema |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 13 | |
Pau Espin Pedrol | 6c6c0e8 | 2020-05-11 18:30:58 +0200 | [diff] [blame] | 14 | config.override_conf = os.path.join(os.path.dirname(sys.argv[0]), 'paths.conf') |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 15 | |
Pau Espin Pedrol | 9d489c8 | 2019-09-18 18:43:45 +0200 | [diff] [blame] | 16 | example_trial_dir = os.path.join('test_trial_tmp') |
| 17 | |
| 18 | class 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 Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 31 | #log.style_change(trace=True) |
| 32 | |
Pau Espin Pedrol | ea8c3d4 | 2020-05-04 12:05:05 +0200 | [diff] [blame] | 33 | # Generate supported schemas dynamically from objects: |
| 34 | generate_schemas() |
| 35 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 36 | print('- non-existing suite dir') |
| 37 | assert(log.run_logging_exceptions(suite.load, 'does_not_exist') == None) |
| 38 | |
| 39 | print('- no suite.conf') |
| 40 | assert(log.run_logging_exceptions(suite.load, 'empty_dir') == None) |
| 41 | |
| 42 | print('- valid suite dir') |
| 43 | example_suite_dir = os.path.join('test_suite') |
| 44 | s_def = suite.load(example_suite_dir) |
| 45 | assert(isinstance(s_def, suite.SuiteDefinition)) |
| 46 | print(config.tostr(s_def.conf)) |
| 47 | |
| 48 | print('- run hello world test') |
Pau Espin Pedrol | 9d489c8 | 2019-09-18 18:43:45 +0200 | [diff] [blame] | 49 | trial = FakeTrial() |
Neels Hofmeyr | 6ccda11 | 2017-06-06 19:41:17 +0200 | [diff] [blame] | 50 | s = suite.SuiteRun(trial, 'test_suite', s_def) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 51 | results = s.run_tests('hello_world.py') |
Pau Espin Pedrol | 0ffb414 | 2017-05-15 18:24:35 +0200 | [diff] [blame] | 52 | print(report.suite_to_text(s)) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 53 | |
| 54 | log.style_change(src=True) |
| 55 | #log.style_change(trace=True) |
| 56 | print('\n- a test with an error') |
| 57 | results = s.run_tests('test_error.py') |
Pau Espin Pedrol | 0ffb414 | 2017-05-15 18:24:35 +0200 | [diff] [blame] | 58 | output = report.suite_to_text(s) |
Neels Hofmeyr | 6ccda11 | 2017-06-06 19:41:17 +0200 | [diff] [blame] | 59 | print(output) |
Pau Espin Pedrol | 0ffb414 | 2017-05-15 18:24:35 +0200 | [diff] [blame] | 60 | |
| 61 | print('\n- a test with a failure') |
| 62 | results = s.run_tests('test_fail.py') |
| 63 | output = report.suite_to_text(s) |
Neels Hofmeyr | 6ccda11 | 2017-06-06 19:41:17 +0200 | [diff] [blame] | 64 | print(output) |
Pau Espin Pedrol | 0ffb414 | 2017-05-15 18:24:35 +0200 | [diff] [blame] | 65 | |
| 66 | print('\n- a test with a raised failure') |
| 67 | results = s.run_tests('test_fail_raise.py') |
| 68 | output = report.suite_to_text(s) |
Neels Hofmeyr | 6ccda11 | 2017-06-06 19:41:17 +0200 | [diff] [blame] | 69 | print(output) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 70 | |
Pau Espin Pedrol | 0b30279 | 2017-09-10 16:33:10 +0200 | [diff] [blame] | 71 | print('- test with half empty scenario') |
Pau Espin Pedrol | 9d489c8 | 2019-09-18 18:43:45 +0200 | [diff] [blame] | 72 | trial = FakeTrial() |
Pau Espin Pedrol | 4e6b507 | 2020-05-11 15:12:07 +0200 | [diff] [blame] | 73 | sc = scenario.Scenario('foo', 'bar') |
| 74 | sc['resources'] = { 'bts': [{'type': 'osmo-bts-trx'}] } |
| 75 | s = suite.SuiteRun(trial, 'test_suite', s_def, [sc]) |
Pau Espin Pedrol | 0b30279 | 2017-09-10 16:33:10 +0200 | [diff] [blame] | 76 | results = s.run_tests('hello_world.py') |
| 77 | print(report.suite_to_text(s)) |
| 78 | |
| 79 | print('- test with scenario') |
Pau Espin Pedrol | 9d489c8 | 2019-09-18 18:43:45 +0200 | [diff] [blame] | 80 | trial = FakeTrial() |
Pau Espin Pedrol | 4e6b507 | 2020-05-11 15:12:07 +0200 | [diff] [blame] | 81 | sc = scenario.Scenario('foo', 'bar') |
| 82 | sc['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 'sysmo'}] } |
| 83 | s = suite.SuiteRun(trial, 'test_suite', s_def, [sc]) |
Pau Espin Pedrol | 0b30279 | 2017-09-10 16:33:10 +0200 | [diff] [blame] | 84 | results = s.run_tests('hello_world.py') |
| 85 | print(report.suite_to_text(s)) |
| 86 | |
Pau Espin Pedrol | aab5692 | 2018-08-21 14:58:29 +0200 | [diff] [blame] | 87 | print('- test with scenario and modifiers') |
Pau Espin Pedrol | 9d489c8 | 2019-09-18 18:43:45 +0200 | [diff] [blame] | 88 | trial = FakeTrial() |
Pau Espin Pedrol | 4e6b507 | 2020-05-11 15:12:07 +0200 | [diff] [blame] | 89 | sc = scenario.Scenario('foo', 'bar') |
| 90 | sc['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 'sysmo'}] } |
| 91 | sc['modifiers'] = { 'bts': [{ 'times': '2', 'trx_list': [{'nominal_power': '20'}, {'nominal_power': '20'}]}, {'type': 'sysmo'}] } |
| 92 | s = suite.SuiteRun(trial, 'test_suite', s_def, [sc]) |
Pau Espin Pedrol | aab5692 | 2018-08-21 14:58:29 +0200 | [diff] [blame] | 93 | s.reserve_resources() |
| 94 | print(repr(s.reserved_resources)) |
| 95 | results = s.run_tests('hello_world.py') |
| 96 | print(report.suite_to_text(s)) |
| 97 | |
Pau Espin Pedrol | 3063730 | 2020-05-06 21:11:02 +0200 | [diff] [blame] | 98 | print('- test with suite-specific config') |
| 99 | trial = FakeTrial() |
Pau Espin Pedrol | 4e6b507 | 2020-05-11 15:12:07 +0200 | [diff] [blame] | 100 | sc = scenario.Scenario('foo', 'bar') |
| 101 | sc['config'] = {'suite': {s.name(): { 'some_suite_global_param': 'heyho', 'test_suite_params': {'one_bool_parameter': 'true', 'second_list_parameter': ['23', '45']}}}} |
| 102 | s = suite.SuiteRun(trial, 'test_suite', s_def, [sc]) |
Pau Espin Pedrol | 3063730 | 2020-05-06 21:11:02 +0200 | [diff] [blame] | 103 | s.reserve_resources() |
| 104 | print(repr(s.reserved_resources)) |
Pau Espin Pedrol | c3cf682 | 2020-06-12 17:54:55 +0200 | [diff] [blame] | 105 | results = s.run_tests(['test_suite_params.py', 'test_timeout.py']) |
Pau Espin Pedrol | 3063730 | 2020-05-06 21:11:02 +0200 | [diff] [blame] | 106 | print(report.suite_to_text(s)) |
| 107 | |
Pau Espin Pedrol | 166dc10 | 2020-06-04 18:44:42 +0200 | [diff] [blame] | 108 | print('- test with template overlay') |
| 109 | trial = FakeTrial() |
| 110 | s_def = suite.load('suiteC') |
| 111 | s = suite.SuiteRun(trial, 'suiteC', s_def) |
| 112 | results = s.run_tests('test_template_overlay.py') |
| 113 | print(report.suite_to_text(s)) |
| 114 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 115 | print('\n- graceful exit.') |
Pau Espin Pedrol | 9d489c8 | 2019-09-18 18:43:45 +0200 | [diff] [blame] | 116 | #deleting generated tmp trial dir: |
| 117 | shutil.rmtree(example_trial_dir, ignore_errors=True) |
| 118 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 119 | # vim: expandtab tabstop=4 shiftwidth=4 |