blob: c4dd5bf800367a33b7c08e7576f71c966241fb75 [file] [log] [blame]
Neels Hofmeyr3531a192017-03-28 14:30:28 +02001#!/usr/bin/env python3
2import os
3import _prep
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +02004import shutil
Pau Espin Pedrole8bbcbf2020-04-10 19:51:31 +02005from osmo_gsm_tester.core import log, config, util
6from osmo_gsm_tester import suite, report
Neels Hofmeyr3531a192017-03-28 14:30:28 +02007
Neels Hofmeyr17c139e2017-04-12 02:42:02 +02008config.ENV_CONF = './suite_test'
Neels Hofmeyr3531a192017-03-28 14:30:28 +02009
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020010example_trial_dir = os.path.join('test_trial_tmp')
11
12class FakeTrial(log.Origin):
13 def __init__(self):
14 super().__init__(log.C_TST, 'trial')
15 self.dir = util.Dir(example_trial_dir)
16 self._run_dir = None
17
18 def get_run_dir(self):
19 if self._run_dir is not None:
20 return self._run_dir
21 self._run_dir = util.Dir(self.dir.new_child('test_run'))
22 self._run_dir.mkdir()
23 return self._run_dir
24
Neels Hofmeyr3531a192017-03-28 14:30:28 +020025#log.style_change(trace=True)
26
27print('- non-existing suite dir')
28assert(log.run_logging_exceptions(suite.load, 'does_not_exist') == None)
29
30print('- no suite.conf')
31assert(log.run_logging_exceptions(suite.load, 'empty_dir') == None)
32
33print('- valid suite dir')
34example_suite_dir = os.path.join('test_suite')
35s_def = suite.load(example_suite_dir)
36assert(isinstance(s_def, suite.SuiteDefinition))
37print(config.tostr(s_def.conf))
38
39print('- run hello world test')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020040trial = FakeTrial()
Neels Hofmeyr6ccda112017-06-06 19:41:17 +020041s = suite.SuiteRun(trial, 'test_suite', s_def)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020042results = s.run_tests('hello_world.py')
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020043print(report.suite_to_text(s))
Neels Hofmeyr3531a192017-03-28 14:30:28 +020044
45log.style_change(src=True)
46#log.style_change(trace=True)
47print('\n- a test with an error')
48results = s.run_tests('test_error.py')
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020049output = report.suite_to_text(s)
Neels Hofmeyr6ccda112017-06-06 19:41:17 +020050print(output)
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020051
52print('\n- a test with a failure')
53results = s.run_tests('test_fail.py')
54output = report.suite_to_text(s)
Neels Hofmeyr6ccda112017-06-06 19:41:17 +020055print(output)
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020056
57print('\n- a test with a raised failure')
58results = s.run_tests('test_fail_raise.py')
59output = report.suite_to_text(s)
Neels Hofmeyr6ccda112017-06-06 19:41:17 +020060print(output)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020061
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020062print('- test with half empty scenario')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020063trial = FakeTrial()
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020064scenario = config.Scenario('foo', 'bar')
Pau Espin Pedrolcbc72422017-09-14 15:55:49 +020065scenario['resources'] = { 'bts': [{'type': 'osmo-bts-trx'}] }
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020066s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
67results = s.run_tests('hello_world.py')
68print(report.suite_to_text(s))
69
70print('- test with scenario')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020071trial = FakeTrial()
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020072scenario = config.Scenario('foo', 'bar')
73scenario['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 'sysmo'}] }
74s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
75results = s.run_tests('hello_world.py')
76print(report.suite_to_text(s))
77
Pau Espin Pedrolaab56922018-08-21 14:58:29 +020078print('- test with scenario and modifiers')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020079trial = FakeTrial()
Pau Espin Pedrolaab56922018-08-21 14:58:29 +020080scenario = config.Scenario('foo', 'bar')
81scenario['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 'sysmo'}] }
82scenario['modifiers'] = { 'bts': [{ 'times': '2', 'trx_list': [{'nominal_power': '20'}, {'nominal_power': '20'}]}, {'type': 'sysmo'}] }
83s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
84s.reserve_resources()
85print(repr(s.reserved_resources))
86results = s.run_tests('hello_world.py')
87print(report.suite_to_text(s))
88
Neels Hofmeyr3531a192017-03-28 14:30:28 +020089print('\n- graceful exit.')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020090#deleting generated tmp trial dir:
91shutil.rmtree(example_trial_dir, ignore_errors=True)
92
Neels Hofmeyr3531a192017-03-28 14:30:28 +020093# vim: expandtab tabstop=4 shiftwidth=4