Fix UMP logger boot initialization and configurable protocol build
This commit is contained in:
56
tests/ump_logger/init_test.c
Normal file
56
tests/ump_logger/init_test.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "../../Source/Internal/log_to_mem.c"
|
||||
|
||||
struct mock_gpio GpioDataRegs;
|
||||
int READY = 1, Desk = 6, Mode = 5;
|
||||
int modbus[128], CanTimeOutErrorTR;
|
||||
unsigned long IMPowse, WAKEpowse;
|
||||
unsigned int ADC_table[4];
|
||||
#define CHECK(x) if (!(x)) return __LINE__
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned int i;
|
||||
/* Simulate COFF boot with dirty RAM, including a stale active bank. */
|
||||
ump_state = ump_count = ump_cursor = ump_next = 0xA5A5;
|
||||
ump_period = ump_divider = 0xA5A5;
|
||||
ump_time = ump_sequence = 0xA5A5A5A5UL;
|
||||
ump_bank = ump_archive_bank = 0xA5A5;
|
||||
ump_archive_count = ump_archive_next = ump_generation = 0xA5A5;
|
||||
ump_source = ump_post = ump_post_dropped = 0xA5A5;
|
||||
ump_can_header = ump_can_count = 0xA5A5;
|
||||
for (i = 0; i < 3; i++) ump_can_data[i] = 0xA5A5;
|
||||
for (i = 0; i < 2; i++) ump_pm67_voltage[i] = 0xA5A5;
|
||||
ump_prev_commands = ump_prev_inputs = ump_prev_outputs = 0xA5A5;
|
||||
ump_dac_ramp = ump_dac_duration = ump_dac_go10 = 0xA5A5;
|
||||
ump_dac_stop10 = ump_dac_position = 0xA5A5;
|
||||
|
||||
ump_log_init();
|
||||
CHECK(ump_log_read(UMP_LOG_BASE) == 0x554D);
|
||||
CHECK(ump_log_read(UMP_LOG_BASE+1) == 3);
|
||||
CHECK(ump_log_read(UMP_LOG_BASE+2) == 0);
|
||||
CHECK(ump_log_read(UMP_LOG_BASE+3) == 0);
|
||||
CHECK(ump_log_read(UMP_LOG_BASE+6) == 20);
|
||||
for (i = 7; i <= 8; i++) CHECK(ump_log_read(UMP_LOG_BASE+i) == 0);
|
||||
for (i = 12; i <= 15; i++) CHECK(ump_log_read(UMP_LOG_BASE+i) == 0);
|
||||
CHECK(ump_bank == 0 && ump_archive_bank == 1);
|
||||
CHECK(ump_cursor == 0 && ump_next == 0 && ump_archive_next == 0);
|
||||
CHECK(ump_divider == 0 && ump_sequence == 0 && ump_post_dropped == 0);
|
||||
CHECK(ump_can_header == 0 && ump_can_count == 0);
|
||||
for (i = 0; i < 3; i++) CHECK(ump_can_data[i] == 0);
|
||||
for (i = 0; i < 2; i++) CHECK(ump_pm67_voltage[i] == 0);
|
||||
CHECK(ump_prev_commands == 0 && ump_prev_inputs == 0 && ump_prev_outputs == 0);
|
||||
CHECK(ump_dac_ramp == 0 && ump_dac_duration == 0 && ump_dac_go10 == 0);
|
||||
CHECK(ump_dac_stop10 == 0 && ump_dac_position == 0);
|
||||
CHECK(ump_log_write(UMP_LOG_BASE+1, 20));
|
||||
CHECK(ump_log_write(UMP_LOG_BASE, 1));
|
||||
CHECK(ump_state == 1 && ump_count == 1);
|
||||
ump_log_tick();
|
||||
CHECK(ump_time == 1);
|
||||
CHECK(ump_log_write(UMP_LOG_BASE, 0));
|
||||
ump_archive_count = 7; ump_generation = 2;
|
||||
ump_pm67_voltage[0] = 123;
|
||||
CHECK(ump_log_write(UMP_LOG_BASE, 1));
|
||||
CHECK(ump_time == 1 && ump_archive_count == 7 && ump_generation == 2);
|
||||
CHECK(ump_word(0, 0, 40) == 123);
|
||||
return 0;
|
||||
}
|
||||
@@ -14,6 +14,7 @@ __declspec(dllexport) int run_tests(void)
|
||||
unsigned int i, generation, archived, error, length;
|
||||
uint16_t reply[UMP_CAN_MAX_WORDS];
|
||||
unsigned long sequence;
|
||||
ump_log_init();
|
||||
CHECK(!ump_log_write(UMP_LOG_BASE+1, 0));
|
||||
CHECK(!ump_log_write(UMP_LOG_BASE+1, 1001));
|
||||
CHECK(ump_log_write(UMP_LOG_BASE+1, 1));
|
||||
|
||||
35
tests/ump_logger/run_init_test.py
Normal file
35
tests/ump_logger/run_init_test.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""Boot regression independent of the external shared protocol checkout.
|
||||
|
||||
Run with GCC in PATH: python tests/ump_logger/run_init_test.py
|
||||
The negative control must fail without the boot initialization call.
|
||||
"""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
source = root / 'tests/ump_logger/init_test.c'
|
||||
compiler = os.environ.get('CC', 'gcc')
|
||||
with tempfile.TemporaryDirectory(prefix='ump-init-') as directory:
|
||||
directory = Path(directory)
|
||||
text = source.read_text().replace(
|
||||
'../../Source/Internal/log_to_mem.c',
|
||||
(root / 'Source/Internal/log_to_mem.c').as_posix(),
|
||||
)
|
||||
for initialize in (False, True):
|
||||
case = directory / 'init_test.c'
|
||||
case.write_text(text if initialize else text.replace('ump_log_init();', ';'))
|
||||
executable = directory / 'init_test.exe'
|
||||
subprocess.run([
|
||||
compiler, '-Wno-unknown-pragmas', '-Wno-int-to-pointer-cast',
|
||||
'-I' + str(root / 'tests/ump_logger/stubs'),
|
||||
'-I' + str(root / 'Source/Internal/Include'),
|
||||
str(case), '-o', str(executable),
|
||||
], check=True)
|
||||
result = subprocess.run([str(executable)])
|
||||
if initialize:
|
||||
assert result.returncode == 0, f'Initialization failed: {result.returncode}'
|
||||
else:
|
||||
assert result.returncode != 0, 'Negative control unexpectedly passed'
|
||||
print(f'{"Initialized boot" if initialize else "Dirty RAM negative control"}: PASS')
|
||||
@@ -1,21 +1,28 @@
|
||||
"""Сборка и запуск исходного регистратора с подменой GPIO/IRQ на Windows.
|
||||
|
||||
Нужны Clang и lld-link в PATH. Проверяется алгоритм, но не ABI и тайминги TI.
|
||||
Нужны GCC либо Clang и lld-link в PATH. TEMPLATES_ROOT задаёт библиотеку. Проверяется алгоритм, но не ABI и тайминги TI.
|
||||
DLL создаётся во временной папке; исходные .out/.hex прошивки не затрагиваются.
|
||||
"""
|
||||
import ctypes
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
templates = Path(os.environ.get('TEMPLATES_ROOT', root.parent / 'newProject/SETGUI/third_party/templates'))
|
||||
protocol = templates / 'c/set-protocol'
|
||||
compiler = os.environ.get('CC') or shutil.which('clang') or shutil.which('gcc')
|
||||
if not compiler:
|
||||
raise SystemExit('Clang or GCC is required in PATH')
|
||||
link_flags = [] if 'gcc' in Path(compiler).name else ['-nostdlib', '-fuse-ld=lld', '-Wl,/noentry,/nodefaultlib']
|
||||
with tempfile.TemporaryDirectory(prefix='ump-recorder-') as directory:
|
||||
library = Path(directory) / 'recorder_test.dll'
|
||||
subprocess.run([
|
||||
'clang', '-shared', '-nostdlib', '-fuse-ld=lld',
|
||||
'-Wl,/noentry,/nodefaultlib', '-Wno-unknown-pragmas', '-Wno-int-to-pointer-cast',
|
||||
compiler, '-shared', *link_flags, '-Wno-unknown-pragmas', '-Wno-int-to-pointer-cast',
|
||||
'-Itests/ump_logger/stubs', '-ISource/Internal/Include',
|
||||
'-I' + str(protocol), '-I' + str(protocol / 'ports/tms320f28335'),
|
||||
'tests/ump_logger/recorder_test.c', 'Source/Internal/shared_ump.c', '-o', str(library),
|
||||
], cwd=root, check=True)
|
||||
# Отдельный процесс освобождает DLL до удаления временной папки Windows.
|
||||
|
||||
Reference in New Issue
Block a user