blob: cf91a85392e8e94e1d784c7de4c8e13eb0c2416c [file] [log] [blame]
Neels Hofmeyr3531a192017-03-28 14:30:28 +02001#!/usr/bin/env python3
2
Neels Hofmeyr3531a192017-03-28 14:30:28 +02003import _prep
Pau Espin Pedrol6e0b6fb2020-05-25 19:49:29 +02004
5import time
Neels Hofmeyr3531a192017-03-28 14:30:28 +02006import os
Pau Espin Pedrol6e0b6fb2020-05-25 19:49:29 +02007
Pau Espin Pedrole8bbcbf2020-04-10 19:51:31 +02008from osmo_gsm_tester.core import util
Pau Espin Pedrolf574a462020-05-05 12:18:35 +02009from osmo_gsm_tester.core.trial import Trial
Neels Hofmeyr3531a192017-03-28 14:30:28 +020010
11workdir = util.get_tempdir()
12
13trials_dir = util.Dir(workdir)
14
15print('- make a few trials dirs')
16print(trials_dir.mkdir('first'))
17time.sleep(1)
18print(trials_dir.mkdir('second'))
19time.sleep(1)
20print(trials_dir.mkdir('third'))
21
22print('- fetch trial dirs in order')
23t = Trial.next(trials_dir)
24print(t)
25print(repr(sorted(t.dir.children())))
26print(Trial.next(trials_dir))
27print(Trial.next(trials_dir))
28
29print('- no more trial dirs left')
30print(repr(Trial.next(trials_dir)))
31
32print('- test checksum verification')
33d = util.Dir('trial_test')
34t = Trial(d.child('valid_checksums'))
35t.verify()
36
37print('- detect wrong checksum')
38t = Trial(d.child('invalid_checksum'))
39try:
40 t.verify()
41except RuntimeError as e:
Pau Espin Pedrolafa2fc32020-05-06 17:29:50 +020042 print('ok, got RuntimeError: %s' % str(e))
Neels Hofmeyr3531a192017-03-28 14:30:28 +020043
44print('- detect missing file')
45t = Trial(d.child('missing_file'))
46try:
47 t.verify()
48except RuntimeError as e:
Pau Espin Pedrolafa2fc32020-05-06 17:29:50 +020049 print('ok, got RuntimeError: %s' % str(e))
Neels Hofmeyr3531a192017-03-28 14:30:28 +020050
Pau Espin Pedrol6e0b6fb2020-05-25 19:49:29 +020051print('- Verify trials based on run_label')
52d = util.Dir('trial_test')
53t = Trial(d.child('run_label'))
54t.verify()
55inst = util.Dir(t.get_inst('sample', 'foobar'))
56print('inst: ' + str(inst))
57with open(inst.child('file2'), 'r') as f:
58 print('content file2: %s' % f.read())
59inst = util.Dir( t.get_inst('sample'))
60print('inst: ' + str(inst))
61with open(inst.child('file1'), 'r') as f:
62 print('content file1: %s' % f.read())
63
Neels Hofmeyr3531a192017-03-28 14:30:28 +020064# vim: expandtab tabstop=4 shiftwidth=4