Skip to content

SOFT-6671: Add unit tests for RPC device load functions#1095

Open
evgeny-boger wants to merge 12 commits into
masterfrom
feature/SOFT-6671-rpc-device-load-tests
Open

SOFT-6671: Add unit tests for RPC device load functions#1095
evgeny-boger wants to merge 12 commits into
masterfrom
feature/SOFT-6671-rpc-device-load-tests

Conversation

@evgeny-boger

Copy link
Copy Markdown
Member

Описание

Добавлены юнит-тесты для внутренних функций RPC загрузки устройств (rpc_device_load_task.cpp и rpc_device_load_config_task.cpp), которые ранее были скрыты в анонимных пространствах имён и не поддавались тестированию.

Изменения:

  • Анонимные пространства имён в rpc_device_load_task.cpp и rpc_device_load_config_task.cpp вынесены в именованные detail-пространства имён (rpc_device_load_detail, rpc_device_load_config_detail)
  • Созданы внутренние заголовочные файлы для экспорта функций деталей
  • Добавлено 19 новых юнит-тестов с использованием TFakeSerialPort + TModbusExpectationsBase
  • Тесты покрывают: SetContinuousRead, MarkUnsupported, ReadRegistersIntoJson, ExecRPCRequest, ReadWbRegister, ReadDeviceModel, CheckTemplate, MarkUnsupportedParameters

Тестирование

  • Все 294 теста проходят локально
  • Покрытие rpc_device_load_task.cpp увеличено с ~53% до ~70%+
  • Покрытие rpc_device_load_config_task.cpp увеличено с ~15% до ~30%+

evgeny-boger and others added 12 commits February 25, 2026 23:14
Move readonly filtering from CreateRegisterList() to callers so that
readonly parameters can be read for condition evaluation. In deviceLoad,
read condition-referenced parameters first, then filter channels by
their condition expressions before reading channel registers. This
avoids unnecessary serial I/O for channels that don't apply to the
current device configuration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Update CreateRegisterList test expectations to include readonly params
- Add ReadonlyParametersFiltered test verifying caller-side filtering
- Add GetConditionParametersRegisterList test for dependency extraction
- Add GetChannelsRegisterList tests for condition-based filtering
- Add device_load_conditions test template with conditional channels

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Document how to build and run tests using contactless/devenv Docker
image with QEMU user-mode emulation for ARM binaries.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix GetParametersRegisterList checking Channels instead of Parameters,
which silently skipped errors for unknown parameter names. Add missing
return after successful read/write in ReadModbusRegister and
WriteModbusRegister to avoid redundant retries on success.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify that requesting a non-existent parameter throws TRPCException.
This test caught a copy-paste bug where Channels was checked instead
of Parameters.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move ReadModbusRegister, WriteModbusRegister, and IsAllFFFE from
rpc_device_load_task.cpp and rpc_device_load_config_task.cpp into shared
rpc_helpers.h/.cpp, eliminating code duplication. Both callers now use
the shared versions via TRPCDeviceRequest& (the common base class).

Bug fixes included in the extraction:
- Add missing return after successful Modbus read/write in the
  rpc_device_load_config_task copy (registers were read/written 3x)
- Re-throw non-fatal TModbusExceptionError on last retry instead of
  silently returning with uninitialized value
- Use IsAllFFFE (handles string and multi-word registers) in
  MarkUnsupportedParameters instead of a 16-bit-only inline check
- Always restore continuous-read mode in MarkUnsupported, not only
  for devices loaded from config

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Refactor anonymous-namespace functions in rpc_device_load_task.cpp and
rpc_device_load_config_task.cpp into named detail namespaces to make them
testable. Add 19 modbus-level tests covering SetContinuousRead,
MarkUnsupported, ReadWbRegister, ReadDeviceModel, CheckTemplate, and
ExecRPCRequest. Also add 12 tests for ReadModbusRegister/WriteModbusRegister
retry and exception handling in rpc_helpers_test.cpp.

Coverage: rpc_device_load_task.cpp 53%→83%, rpc_device_load_config_task.cpp 15%→44%.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@evgeny-boger evgeny-boger changed the base branch from feature/device-view to feature/SOFT-6670-device-view March 1, 2026 11:52
@evgeny-boger evgeny-boger marked this pull request as ready for review March 1, 2026 21:49
Base automatically changed from feature/SOFT-6670-device-view to master March 10, 2026 07:58
@u236 u236 requested a review from a team as a code owner March 10, 2026 07:58
@u236

u236 commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

с учетом влитых пуллреквестов, думаю, этот проще закрыть и попросить Claude сделать новые тесты для непокрытого кода, а то как-то многовато конфликтов

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants