1#!/usr/bin/env python3 2# Copyright (c) 2023 Intel Corporation 3# 4# SPDX-License-Identifier: Apache-2.0 5 6''' 7This test file contains tests for platform.py module of twister 8''' 9import sys 10import os 11import mock 12import pytest 13 14ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") 15sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister")) 16 17from twisterlib.platform import Platform, Simulator 18 19 20TESTDATA_1 = [ 21 ( 22"""\ 23identifier: dummy empty 24arch: arc 25""", 26 { 27 'name': 'dummy empty', 28 'arch': 'arc', 29 'twister': True, 30 'ram': 128, 31 'timeout_multiplier': 1.0, 32 'ignore_tags': [], 33 'only_tags': [], 34 'default': False, 35 'binaries': [], 36 'flash': 512, 37 'supported': set(), 38 'vendor': '', 39 'tier': -1, 40 'type': 'na', 41 'simulators': [], 42 'supported_toolchains': [], 43 'env': [], 44 'env_satisfied': True 45 }, 46 '<dummy empty on arc>' 47 ), 48 ( 49"""\ 50identifier: dummy full 51arch: riscv 52twister: true 53ram: 1024 54testing: 55 timeout_multiplier: 2.0 56 ignore_tags: 57 - tag1 58 - tag2 59 only_tags: 60 - tag3 61 default: true 62 binaries: 63 - dummy.exe 64 - dummy.bin 65flash: 4096 66supported: 67 - ble 68 - netif:openthread 69 - gpio 70vendor: vendor1 71tier: 1 72type: unit 73simulation: 74- name: nsim 75 exec: nsimdrv 76toolchain: 77 - zephyr 78 - llvm 79env: 80 - dummynonexistentvar 81""", 82 { 83 'name': 'dummy full', 84 'arch': 'riscv', 85 'twister': True, 86 'ram': 1024, 87 'timeout_multiplier': 2.0, 88 'ignore_tags': ['tag1', 'tag2'], 89 'only_tags': ['tag3'], 90 'default': True, 91 'binaries': ['dummy.exe', 'dummy.bin'], 92 'flash': 4096, 93 'supported': set(['ble', 'netif', 'openthread', 'gpio']), 94 'vendor': 'vendor1', 95 'tier': 1, 96 'type': 'unit', 97 'simulators': [Simulator({'name': 'nsim', 'exec': 'nsimdrv'})], 98 'supported_toolchains': ['zephyr', 'llvm', 'cross-compile'], 99 'env': ['dummynonexistentvar'], 100 'env_satisfied': False 101 }, 102 '<dummy full on riscv>' 103 ), 104] 105 106# This test is disabled because the Platform loading was changed significantly. 107# The test should be updated to reflect the new implementation. 108 109@pytest.mark.parametrize( 110 'platform_text, expected_data, expected_repr', 111 TESTDATA_1, 112 ids=['almost empty specification', 'full specification'] 113) 114def xtest_platform_load(platform_text, expected_data, expected_repr): 115 platform = Platform() 116 117 with mock.patch('builtins.open', mock.mock_open(read_data=platform_text)): 118 platform.load('dummy.yaml') 119 120 for k, v in expected_data.items(): 121 if not hasattr(platform, k): 122 assert False, f'No key {k} in platform {platform}' 123 att = getattr(platform, k) 124 if isinstance(v, list) and not isinstance(att, list): 125 assert False, f'Value mismatch in key {k} in platform {platform}' 126 if isinstance(v, list): 127 assert sorted(att) == sorted(v) 128 else: 129 assert att == v 130 131 assert platform.__repr__() == expected_repr 132