-
Notifications
You must be signed in to change notification settings - Fork 15
/
test_generate_stm_mcu.py
64 lines (50 loc) · 1.96 KB
/
test_generate_stm_mcu.py
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
63
64
from typing import Any, Dict
import pytest
from generate_stm_mcu import MCU
def _make_empty_info(flash_size: int = 0) -> Dict[str, Any]:
return {
'names': {
'name': 'STM32F3xxxx',
'ref': '',
'family': 'STM32F3',
},
'package': '',
'gpio_version': '',
'info': {
'flash': flash_size,
'ram': '',
'io': '',
'frequency': '',
},
}
@pytest.mark.parametrize(['mcu_ref', 'expected', 'flash_size'], [
('STM32F429NEHx', 'STM32F429NxHx', 512),
('STM32L552CETxP', 'STM32L552CxTxP', 512),
('STM32MP153CADx', 'STM32MP153CADx', 0),
])
def test_mcu_ref_without_flash(mcu_ref, expected, flash_size):
mcu = MCU(ref=mcu_ref, info=_make_empty_info(flash_size), pins=[])
assert mcu.ref_without_flash == expected
def test_mcu_ref_for_flash_variants_multiple():
mcu = MCU(ref='STM32F429IGHx', info=_make_empty_info(), pins=[])
assert mcu.ref_for_flash_variants(['STM32F429IEHx', 'STM32F429IGHx', 'STM32F429IIHx']) == 'STM32F429I[EGI]Hx'
def test_mcu_ref_for_flash_variants_single():
mcu = MCU(ref='STM32F429IGHx', info=_make_empty_info(), pins=[])
assert mcu.ref_for_flash_variants(['STM32F429IGHx']) == 'STM32F429IGHx'
@pytest.mark.parametrize(['pin_name', 'expected'], [
# Oscillator normalization
('PC14OSC32_IN', 'PC14-OSC32_IN'),
('PC3 / OSC', 'PC3-OSC'),
('PC3/ OSC', 'PC3-OSC'),
# Everything after a space is stripped out
('PH3-BOOT0 (BOOT0)', 'PH3-BOOT0'),
('PC15-OSC32_OUT (OSC32_OUT)', 'PC15-OSC32_OUT'),
('PA13 (JTMS/SWDIO)', 'PA13'),
])
def test_cleanup_pin_name(pin_name, expected):
mcu = MCU(ref='STM32L071KBTx', info=_make_empty_info(), pins=[])
assert mcu._cleanup_pin_name(pin_name) == expected
def test_signal_name_validation():
mcu = MCU(ref='STM32L071KBTx', info=_make_empty_info(), pins=[])
with pytest.raises(AssertionError):
mcu._cleanup_pin_name('Hel(lo world')