blob: 115d76ef7d952a713be39858141fb4e9fecf0c0e [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
5from osmo_gsm_tester import log, suite, config, report, util
Neels Hofmeyr3531a192017-03-28 14:30:28 +02006
Neels Hofmeyr17c139e2017-04-12 02:42:02 +02007config.ENV_CONF = './suite_test'
Neels Hofmeyr3531a192017-03-28 14:30:28 +02008
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +02009example_trial_dir = os.path.join('test_trial_tmp')
10
11class FakeTrial(log.Origin):
12 def __init__(self):
13 super().__init__(log.C_TST, 'trial')
14 self.dir = util.Dir(example_trial_dir)
15 self._run_dir = None
16
17 def get_run_dir(self):
18 if self._run_dir is not None:
19 return self._run_dir
20 self._run_dir = util.Dir(self.dir.new_child('test_run'))
21 self._run_dir.mkdir()
22 return self._run_dir
23
Neels Hofmeyr3531a192017-03-28 14:30:28 +020024#log.style_change(trace=True)
25
26print('- non-existing suite dir')
27assert(log.run_logging_exceptions(suite.load, 'does_not_exist') == None)
28
29print('- no suite.conf')
30assert(log.run_logging_exceptions(suite.load, 'empty_dir') == None)
31
32print('- valid suite dir')
33example_suite_dir = os.path.join('test_suite')
34s_def = suite.load(example_suite_dir)
35assert(isinstance(s_def, suite.SuiteDefinition))
36print(config.tostr(s_def.conf))
37
38print('- run hello world test')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020039trial = FakeTrial()
Neels Hofmeyr6ccda112017-06-06 19:41:17 +020040s = suite.SuiteRun(trial, 'test_suite', s_def)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020041results = s.run_tests('hello_world.py')
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020042print(report.suite_to_text(s))
Neels Hofmeyr3531a192017-03-28 14:30:28 +020043
44log.style_change(src=True)
45#log.style_change(trace=True)
46print('\n- a test with an error')
47results = s.run_tests('test_error.py')
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020048output = report.suite_to_text(s)
Neels Hofmeyr6ccda112017-06-06 19:41:17 +020049print(output)
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020050
51print('\n- a test with a failure')
52results = s.run_tests('test_fail.py')
53output = report.suite_to_text(s)
Neels Hofmeyr6ccda112017-06-06 19:41:17 +020054print(output)
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020055
56print('\n- a test with a raised failure')
57results = s.run_tests('test_fail_raise.py')
58output = report.suite_to_text(s)
Neels Hofmeyr6ccda112017-06-06 19:41:17 +020059print(output)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020060
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020061print('- test with half empty scenario')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020062trial = FakeTrial()
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020063scenario = config.Scenario('foo', 'bar')
Pau Espin Pedrolcbc72422017-09-14 15:55:49 +020064scenario['resources'] = { 'bts': [{'type': 'osmo-bts-trx'}] }
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020065s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
66results = s.run_tests('hello_world.py')
67print(report.suite_to_text(s))
68
69print('- test with scenario')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020070trial = FakeTrial()
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020071scenario = config.Scenario('foo', 'bar')
72scenario['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 'sysmo'}] }
73s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
74results = s.run_tests('hello_world.py')
75print(report.suite_to_text(s))
76
Pau Espin Pedrolaab56922018-08-21 14:58:29 +020077print('- test with scenario and modifiers')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020078trial = FakeTrial()
Pau Espin Pedrolaab56922018-08-21 14:58:29 +020079scenario = config.Scenario('foo', 'bar')
80scenario['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 'sysmo'}] }
81scenario['modifiers'] = { 'bts': [{ 'times': '2', 'trx_list': [{'nominal_power': '20'}, {'nominal_power': '20'}]}, {'type': 'sysmo'}] }
82s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
83s.reserve_resources()
84print(repr(s.reserved_resources))
85results = s.run_tests('hello_world.py')
86print(report.suite_to_text(s))
87
Neels Hofmeyr3531a192017-03-28 14:30:28 +020088print('\n- graceful exit.')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020089#deleting generated tmp trial dir:
90shutil.rmtree(example_trial_dir, ignore_errors=True)
91
Neels Hofmeyr3531a192017-03-28 14:30:28 +020092# vim: expandtab tabstop=4 shiftwidth=4