blob: 752041b83105b1be72c1aaa26af0b7bb73602ab1 [file] [log] [blame]
Aastha Grover5948ab62020-05-11 15:38:37 -07001#!/usr/bin/env python3
2# Copyright (c) 2020 Intel Corporation
3#
4# SPDX-License-Identifier: Apache-2.0
Aastha Grovercf72fe82020-06-01 16:08:20 -07005
Anas Nashif9318e6c2020-12-07 12:29:36 -05006'''Common fixtures for use in testing the twister tool.'''
Aastha Grover5948ab62020-05-11 15:38:37 -07007
8import os
9import sys
10import pytest
11
12ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
Anas Nashif9318e6c2020-12-07 12:29:36 -050013sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister"))
14from twisterlib import TestSuite, TestInstance
Aastha Grover5948ab62020-05-11 15:38:37 -070015
16@pytest.fixture(name='test_data')
17def _test_data():
18 """ Pytest fixture to load the test data directory"""
Anas Nashif9318e6c2020-12-07 12:29:36 -050019 data = ZEPHYR_BASE + "/scripts/tests/twister/test_data/"
Aastha Grover5948ab62020-05-11 15:38:37 -070020 return data
21
Aastha Grovercf72fe82020-06-01 16:08:20 -070022@pytest.fixture(name='testcases_dir')
23def testcases_directory():
Aastha Grover5948ab62020-05-11 15:38:37 -070024 """ Pytest fixture to load the test data directory"""
Anas Nashif9318e6c2020-12-07 12:29:36 -050025 return ZEPHYR_BASE + "/scripts/tests/twister/test_data/testcases"
Aastha Grover5948ab62020-05-11 15:38:37 -070026
Aastha Grovercf72fe82020-06-01 16:08:20 -070027@pytest.fixture(name='class_testsuite')
28def testsuite_obj(test_data, testcases_dir, tmpdir_factory):
Aastha Grover5948ab62020-05-11 15:38:37 -070029 """ Pytest fixture to initialize and return the class TestSuite object"""
30 board_root = test_data +"board_config/1_level/2_level/"
31 testcase_root = [testcases_dir + '/tests', testcases_dir + '/samples']
Aastha Grovercf72fe82020-06-01 16:08:20 -070032 outdir = tmpdir_factory.mktemp("sanity_out_demo")
Aastha Grover5948ab62020-05-11 15:38:37 -070033 suite = TestSuite(board_root, testcase_root, outdir)
34 return suite
Spoorthy Priya Yerabolu9ac30b52020-05-21 04:17:40 -070035
Aastha Grover8213a152020-06-16 12:15:47 -070036@pytest.fixture(name='all_testcases_dict')
37def testcases_dict(class_testsuite):
38 """ Pytest fixture to call add_testcase function of
39 Testsuite class and return the dictionary of testcases"""
Spoorthy Priya Yerabolu9ac30b52020-05-21 04:17:40 -070040 class_testsuite.SAMPLE_FILENAME = 'test_sample_app.yaml'
41 class_testsuite.TESTCASE_FILENAME = 'test_data.yaml'
42 class_testsuite.add_testcases()
43 return class_testsuite.testcases
44
Aastha Grover8213a152020-06-16 12:15:47 -070045@pytest.fixture(name='platforms_list')
46def all_platforms_list(test_data, class_testsuite):
47 """ Pytest fixture to call add_configurations function of
48 Testsuite class and return the Platforms list"""
Spoorthy Priya Yerabolu9ac30b52020-05-21 04:17:40 -070049 class_testsuite.board_roots = os.path.abspath(test_data + "board_config")
50 suite = TestSuite(class_testsuite.board_roots, class_testsuite.roots, class_testsuite.outdir)
51 suite.add_configurations()
52 return suite.platforms
Aastha Grover8213a152020-06-16 12:15:47 -070053
54@pytest.fixture
55def instances_fixture(class_testsuite, platforms_list, all_testcases_dict, tmpdir_factory):
56 """ Pytest fixture to call add_instances function of Testsuite class
57 and return the instances dictionary"""
58 class_testsuite.outdir = tmpdir_factory.mktemp("sanity_out_demo")
59 class_testsuite.platforms = platforms_list
60 platform = class_testsuite.get_platform("demo_board_2")
61 instance_list = []
62 for _, testcase in all_testcases_dict.items():
63 instance = TestInstance(testcase, platform, class_testsuite.outdir)
64 instance_list.append(instance)
65 class_testsuite.add_instances(instance_list)
66 return class_testsuite.instances