xref: /openbmc/phosphor-modbus/tests/Readme.md (revision a32d241b08af236b5ea1d4e18a390bdc561b435b)
1*a32d241bSJagpal Singh Gill# Testing
2*a32d241bSJagpal Singh Gill
3*a32d241bSJagpal Singh Gill## Mocked Modbus Testing
4*a32d241bSJagpal Singh Gill
5*a32d241bSJagpal Singh GillThe `socat` command is utilized to create pseudo-terminals (PTYs), enabling the
6*a32d241bSJagpal Singh Gillsetup of virtual serial ports for communication between a Modbus client and
7*a32d241bSJagpal Singh Gillserver. In this testing framework, the Modbus client (implemented as a test
8*a32d241bSJagpal Singh Gillclient using gtest) sends Modbus commands to a test server, which processes
9*a32d241bSJagpal Singh Gillthese requests and returns responses. The test environment setup is responsible
10*a32d241bSJagpal Singh Gillfor configuring the pseudo-terminals and launching the test server instance. The
11*a32d241bSJagpal Singh Gillserver logic resides in `modbus_server_tester.cpp::ServerTester`, with further
12*a32d241bSJagpal Singh Gilldetails provided in the following sections.
13*a32d241bSJagpal Singh Gill
14*a32d241bSJagpal Singh Gill### ServerTester
15*a32d241bSJagpal Singh Gill
16*a32d241bSJagpal Singh Gill`ServerTester` acts as a mock Modbus server, intercepting Modbus messages and
17*a32d241bSJagpal Singh Gillgenerating appropriate responses. The replies are determined by the mocked
18*a32d241bSJagpal Singh GillModbus addresses, allowing targeted code paths to be exercised on the client
19*a32d241bSJagpal Singh Gillside. `ServerTester` is capable of handling both single and segmented response
20*a32d241bSJagpal Singh Gillscenarios, and also provides error responses to facilitate negative testing. The
21*a32d241bSJagpal Singh Gilltest server currently handles the following Modbus command:
22*a32d241bSJagpal Singh Gill
23*a32d241bSJagpal Singh Gill- ReadHoldingRegisters
24