unit-test.h.in 3.3 KB

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