blob: de5c6df3d46ce2f3ad46bddda8f491f994aface7 [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 Pedrolee217b02020-05-04 19:06:47 +02005from osmo_gsm_tester.core import log, config, util, report
Pau Espin Pedrolf574a462020-05-05 12:18:35 +02006from osmo_gsm_tester.core import suite
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +02007from osmo_gsm_tester.core.schema import generate_schemas
Neels Hofmeyr3531a192017-03-28 14:30:28 +02008
Neels Hofmeyr17c139e2017-04-12 02:42:02 +02009config.ENV_CONF = './suite_test'
Neels Hofmeyr3531a192017-03-28 14:30:28 +020010
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020011example_trial_dir = os.path.join('test_trial_tmp')
12
13class FakeTrial(log.Origin):
14 def __init__(self):
15 super().__init__(log.C_TST, 'trial')
16 self.dir = util.Dir(example_trial_dir)
17 self._run_dir = None
18
19 def get_run_dir(self):
20 if self._run_dir is not None:
21 return self._run_dir
22 self._run_dir = util.Dir(self.dir.new_child('test_run'))
23 self._run_dir.mkdir()
24 return self._run_dir
25
Neels Hofmeyr3531a192017-03-28 14:30:28 +020026#log.style_change(trace=True)
27
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020028# Generate supported schemas dynamically from objects:
29generate_schemas()
30
Neels Hofmeyr3531a192017-03-28 14:30:28 +020031print('- non-existing suite dir')
32assert(log.run_logging_exceptions(suite.load, 'does_not_exist') == None)
33
34print('- no suite.conf')
35assert(log.run_logging_exceptions(suite.load, 'empty_dir') == None)
36
37print('- valid suite dir')
38example_suite_dir = os.path.join('test_suite')
39s_def = suite.load(example_suite_dir)
40assert(isinstance(s_def, suite.SuiteDefinition))
41print(config.tostr(s_def.conf))
42
43print('- run hello world test')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020044trial = FakeTrial()
Neels Hofmeyr6ccda112017-06-06 19:41:17 +020045s = suite.SuiteRun(trial, 'test_suite', s_def)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020046results = s.run_tests('hello_world.py')
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020047print(report.suite_to_text(s))
Neels Hofmeyr3531a192017-03-28 14:30:28 +020048
49log.style_change(src=True)
50#log.style_change(trace=True)
51print('\n- a test with an error')
52results = s.run_tests('test_error.py')
Pau Espin Pedrol0ffb4142017-05-15 18:24:35 +020053output = 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 failure')
57results = s.run_tests('test_fail.py')
58output = 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 raised failure')
62results = s.run_tests('test_fail_raise.py')
63output = report.suite_to_text(s)
Neels Hofmeyr6ccda112017-06-06 19:41:17 +020064print(output)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020065
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020066print('- test with half empty scenario')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020067trial = FakeTrial()
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020068scenario = config.Scenario('foo', 'bar')
Pau Espin Pedrolcbc72422017-09-14 15:55:49 +020069scenario['resources'] = { 'bts': [{'type': 'osmo-bts-trx'}] }
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020070s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
71results = s.run_tests('hello_world.py')
72print(report.suite_to_text(s))
73
74print('- test with scenario')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020075trial = FakeTrial()
Pau Espin Pedrol0b302792017-09-10 16:33:10 +020076scenario = config.Scenario('foo', 'bar')
77scenario['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 'sysmo'}] }
78s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
79results = s.run_tests('hello_world.py')
80print(report.suite_to_text(s))
81
Pau Espin Pedrolaab56922018-08-21 14:58:29 +020082print('- test with scenario and modifiers')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020083trial = FakeTrial()
Pau Espin Pedrolaab56922018-08-21 14:58:29 +020084scenario = config.Scenario('foo', 'bar')
85scenario['resources'] = { 'bts': [{ 'times': '2', 'type': 'osmo-bts-trx', 'trx_list': [{'nominal_power': '10'}, {'nominal_power': '12'}]}, {'type': 'sysmo'}] }
86scenario['modifiers'] = { 'bts': [{ 'times': '2', 'trx_list': [{'nominal_power': '20'}, {'nominal_power': '20'}]}, {'type': 'sysmo'}] }
87s = suite.SuiteRun(trial, 'test_suite', s_def, [scenario])
88s.reserve_resources()
89print(repr(s.reserved_resources))
90results = s.run_tests('hello_world.py')
91print(report.suite_to_text(s))
92
Neels Hofmeyr3531a192017-03-28 14:30:28 +020093print('\n- graceful exit.')
Pau Espin Pedrol9d489c82019-09-18 18:43:45 +020094#deleting generated tmp trial dir:
95shutil.rmtree(example_trial_dir, ignore_errors=True)
96
Neels Hofmeyr3531a192017-03-28 14:30:28 +020097# vim: expandtab tabstop=4 shiftwidth=4