aboutsummaryrefslogtreecommitdiffstats
path: root/tests/linus_stress/run_tests.py
blob: 22e67e8daf83fa70d4621a64e4cd7c519c1cdbad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pytest
import subprocess
import pathlib

from plugins.agl_test_base import AGLBaseTest

class LinusStressBase(AGLBaseTest):
    def __init__(self):
        super().__init__(name="linus_stress")

    def run_test_fun(self):
        log_file = self.get_logfile()
        cwd_buf = self.get_temp_logdir()
        workdir = self.get_workdir()
        run_test_cmd = workdir + '/linus_stress'

        with open(log_file, 'w') as log_f:
            output = subprocess.run(run_test_cmd, shell=True,
                     cwd=cwd_buf, stdout=log_f, stderr=log_f)
        log_f.close()

        if (output.returncode == 0):
            self.case_info_list = {'test_linus_stress': ['test_linus_stress',
                                   '', 'passed']}
        else:
            self.case_info_list = {'test_linus_stress': ['test_linus_stress',
                                   '', 'failed']}

    def precheck(self):
        test_location = self.get_workdir() + "/linus_stress"
        pathObj = pathlib.Path(test_location)
        return super().precheck() and pathObj.is_file()

@pytest.fixture(scope='module')
def testbase():
    #init instance for test
    instance = LinusStressBase()

    yield instance

    #package log files and make report file
    instance.log_report()

def precheck():
    instance = LinusStressBase()
    output = instance.precheck()
    if(output == False):
        #write test suite info to file
        instance.write_skip_info()
    return output

skip_msg = "The current environment does not match the test requirements."
pytestmark = pytest.mark.skipif(precheck() == False, reason = skip_msg)

def test_linus_stress(testbase: LinusStressBase):
    testbase.run_test_fun()
    #write test suite info to file
    testbase.write_run_info()
    assert testbase.case_info_list['test_linus_stress'][2] == 'passed'

if __name__ == '__main__':
    pytest.main("-s run_tests")