|
@@ -27,6 +27,7 @@ int send_crafted_request(modbus_t *ctx, int function,
|
|
|
uint16_t max_value, uint16_t bytes,
|
|
|
int backend_length, int backend_offset);
|
|
|
int equal_dword(uint16_t *tab_reg, const uint32_t value);
|
|
|
+int is_memory_equal(const void *s1, const void *s2, size_t size);
|
|
|
|
|
|
#define BUG_REPORT(_cond, _format, _args ...) \
|
|
|
printf("\nLine %d: assertion error for '%s': " _format "\n", __LINE__, # _cond, ## _args)
|
|
@@ -40,6 +41,11 @@ int equal_dword(uint16_t *tab_reg, const uint32_t value);
|
|
|
} \
|
|
|
};
|
|
|
|
|
|
+int is_memory_equal(const void *s1, const void *s2, size_t size)
|
|
|
+{
|
|
|
+ return (memcmp(s1, s2, size) == 0);
|
|
|
+}
|
|
|
+
|
|
|
int equal_dword(uint16_t *tab_reg, const uint32_t value) {
|
|
|
return ((tab_reg[0] == (value >> 16)) && (tab_reg[1] == (value & 0xFFFF)));
|
|
|
}
|
|
@@ -287,26 +293,26 @@ int main(int argc, char *argv[])
|
|
|
/** FLOAT **/
|
|
|
printf("1/4 Set/get float ABCD: ");
|
|
|
modbus_set_float_abcd(UT_REAL, tab_rp_registers);
|
|
|
- ASSERT_TRUE(equal_dword(tab_rp_registers, UT_IREAL_ABCD), "FAILED Set float ABCD");
|
|
|
- real = modbus_get_float_abcd(tab_rp_registers);
|
|
|
+ ASSERT_TRUE(is_memory_equal(tab_rp_registers, UT_IREAL_ABCD_SET, 4), "FAILED Set float ABCD");
|
|
|
+ real = modbus_get_float_abcd(UT_IREAL_ABCD_GET);
|
|
|
ASSERT_TRUE(real == UT_REAL, "FAILED (%f != %f)\n", real, UT_REAL);
|
|
|
|
|
|
printf("2/4 Set/get float DCBA: ");
|
|
|
modbus_set_float_dcba(UT_REAL, tab_rp_registers);
|
|
|
- ASSERT_TRUE(equal_dword(tab_rp_registers, UT_IREAL_DCBA), "FAILED Set float DCBA");
|
|
|
- real = modbus_get_float_dcba(tab_rp_registers);
|
|
|
+ ASSERT_TRUE(is_memory_equal(tab_rp_registers, UT_IREAL_DCBA_SET, 4), "FAILED Set float DCBA");
|
|
|
+ real = modbus_get_float_dcba(UT_IREAL_DCBA_GET);
|
|
|
ASSERT_TRUE(real == UT_REAL, "FAILED (%f != %f)\n", real, UT_REAL);
|
|
|
|
|
|
printf("3/4 Set/get float BADC: ");
|
|
|
modbus_set_float_badc(UT_REAL, tab_rp_registers);
|
|
|
- ASSERT_TRUE(equal_dword(tab_rp_registers, UT_IREAL_BADC), "FAILED Set float BADC");
|
|
|
- real = modbus_get_float_badc(tab_rp_registers);
|
|
|
+ ASSERT_TRUE(is_memory_equal(tab_rp_registers, UT_IREAL_BADC_SET, 4), "FAILED Set float BADC");
|
|
|
+ real = modbus_get_float_badc(UT_IREAL_BADC_GET);
|
|
|
ASSERT_TRUE(real == UT_REAL, "FAILED (%f != %f)\n", real, UT_REAL);
|
|
|
|
|
|
printf("4/4 Set/get float CDAB: ");
|
|
|
modbus_set_float_cdab(UT_REAL, tab_rp_registers);
|
|
|
- ASSERT_TRUE(equal_dword(tab_rp_registers, UT_IREAL_CDAB), "FAILED Set float CDAB");
|
|
|
- real = modbus_get_float_cdab(tab_rp_registers);
|
|
|
+ ASSERT_TRUE(is_memory_equal(tab_rp_registers, UT_IREAL_CDAB_SET, 4), "FAILED Set float CDAB");
|
|
|
+ real = modbus_get_float_cdab(UT_IREAL_CDAB_GET);
|
|
|
ASSERT_TRUE(real == UT_REAL, "FAILED (%f != %f)\n", real, UT_REAL);
|
|
|
|
|
|
printf("\nAt this point, error messages doesn't mean the test has failed\n");
|