Debian Codegraph @

tests/unit-test.h.in

raw
1 /*
2 * Copyright © Stéphane Raimbault <[email protected]>
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #ifndef _UNIT_TEST_H_
8 #define _UNIT_TEST_H_
9
10 /* Constants defined by configure.ac */
11 #define HAVE_INTTYPES_H @HAVE_INTTYPES_H@
12 #define HAVE_STDINT_H @HAVE_STDINT_H@
13
14 // clang-format off
15 #ifdef HAVE_INTTYPES_H
16 #include <inttypes.h>
17 #endif
18 #ifdef HAVE_STDINT_H
19 # ifndef _MSC_VER
20 # include <stdint.h>
21 # else
22 # include "stdint.h"
23 # endif
24 #endif
25 // clang-format on
26
27 #define SERVER_ID 17
28 #define INVALID_SERVER_ID 18
29
30 #define UT_BITS_NB 0x25
31 const uint16_t UT_BITS_ADDRESS = 0x130;
32 const uint8_t UT_BITS_TAB[] = { 0xCD, 0x6B, 0xB2, 0x0E, 0x1B };
33 const uint16_t UT_BITS_ADDRESS_INVALID_REQUEST_LENGTH = UT_BITS_ADDRESS + 2;
34
35 const uint16_t UT_INPUT_BITS_ADDRESS = 0x1C4;
36 const uint16_t UT_INPUT_BITS_NB = 0x16;
37 const uint8_t UT_INPUT_BITS_TAB[] = { 0xAC, 0xDB, 0x35 };
38
39 const uint16_t UT_REGISTERS_ADDRESS = 0x160;
40 const uint16_t UT_REGISTERS_NB = 0x3;
41 const uint16_t UT_REGISTERS_NB_MAX = 0x20;
42 const uint16_t UT_REGISTERS_TAB[] = { 0x022B, 0x0001, 0x0064 };
43
44 /* Raise a manual exception when this address is used for the first byte */
45 const uint16_t UT_REGISTERS_ADDRESS_SPECIAL = 0x170;
46 /* The response of the server will contains an invalid TID or slave */
47 const uint16_t UT_REGISTERS_ADDRESS_INVALID_TID_OR_SLAVE = 0x171;
48 /* The server will wait for 1 second before replying to test timeout */
49 const uint16_t UT_REGISTERS_ADDRESS_SLEEP_500_MS = 0x172;
50 /* The server will wait for 5 ms before sending each byte */
51 const uint16_t UT_REGISTERS_ADDRESS_BYTE_SLEEP_5_MS = 0x173;
52
53 /* If the following value is used, a bad response is sent.
54 It's better to test with a lower value than
55 UT_REGISTERS_NB_POINTS to try to raise a segfault. */
56 const uint16_t UT_REGISTERS_NB_SPECIAL = 0x2;
57
58 const uint16_t UT_INPUT_REGISTERS_ADDRESS = 0x108;
59 const uint16_t UT_INPUT_REGISTERS_NB = 0x1;
60 const uint16_t UT_INPUT_REGISTERS_TAB[] = { 0x000A };
61
62 /*
63 * This float value is 0x47F12000 (in big-endian format).
64 * In Little-endian(intel) format, it will be stored in memory as follows:
65 * 0x00 0x20 0xF1 0x47
66 *
67 * You can check this with the following code:
68
69 float fl = UT_REAL;
70 uint8_t *inmem = (uint8_t*)&fl;
71 int x;
72 for(x = 0; x < 4; x++){
73 printf("0x%02X ", inmem[ x ]);
74 }
75 printf("\n");
76 */
77 const float UT_REAL = 123456.00;
78
79 /*
80 * libmodbus will convert all words to processor-endianness as they come in and also converts them
81 * back to big endian as they are sent out.
82 * The memory layout in modbus_mapping_t.tab_registers is thus processor-endianess.
83 * Hence we define the comparison constants to check against the content of modbus_mapping_t.tab_registers
84 * in terms of 16 bit integer values, that are likewise stored in memory in processor-endianess.
85 */
86 const uint16_t UT_IREAL_ABCD[] = {0x47F1, 0x2000};
87 const uint16_t UT_IREAL_DCBA[] = {0x0020, 0xF147};
88 const uint16_t UT_IREAL_BADC[] = {0xF147, 0x0020};
89 const uint16_t UT_IREAL_CDAB[] = {0x2000, 0x47F1};
90
91 #endif /* _UNIT_TEST_H_ */