This commit is contained in:
admin
2026-06-22 15:35:18 +08:00
commit 74e4f32cdf
6014 changed files with 589981 additions and 0 deletions
@@ -0,0 +1,30 @@
Copyright (c) 2008-2014 by Stéphane Raimbault
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* The names of the contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,52 @@
EXTRA_DIST = README.md unit-tests.sh LICENSE
noinst_PROGRAMS = \
bandwidth-server-one \
bandwidth-server-many-up \
bandwidth-client \
random-test-server \
random-test-client \
unit-test-server \
unit-test-client \
version
common_ldflags = \
$(top_builddir)/src/libmodbus.la
bandwidth_server_one_SOURCES = bandwidth-server-one.c
bandwidth_server_one_LDADD = $(common_ldflags)
bandwidth_server_many_up_SOURCES = bandwidth-server-many-up.c
bandwidth_server_many_up_LDADD = $(common_ldflags)
bandwidth_client_SOURCES = bandwidth-client.c
bandwidth_client_LDADD = $(common_ldflags)
random_test_server_SOURCES = random-test-server.c
random_test_server_LDADD = $(common_ldflags)
random_test_client_SOURCES = random-test-client.c
random_test_client_LDADD = $(common_ldflags)
unit_test_server_SOURCES = unit-test-server.c unit-test.h
unit_test_server_LDADD = $(common_ldflags)
unit_test_client_SOURCES = unit-test-client.c unit-test.h
unit_test_client_LDADD = $(common_ldflags)
version_SOURCES = version.c
version_LDADD = $(common_ldflags)
AM_CPPFLAGS = \
-include $(top_builddir)/config.h \
-DSYSCONFDIR=\""$(sysconfdir)"\" \
-DLIBEXECDIR=\""$(libexecdir)"\" \
-I${top_srcdir}/src \
-I${top_builddir}/src
AM_CFLAGS = ${my_CFLAGS}
CLEANFILES = *~ *.log
noinst_SCRIPTS=unit-tests.sh
TESTS=./unit-tests.sh
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,27 @@
# License
Test programs of this directory are provided under BSD license (see associated
LICENSE file).
# Compilation
After installation, you can use pkg-config to compile these tests.
For example, to compile random-test-server run:
gcc random-test-server.c -o random-test-server `pkg-config --libs --cflags libmodbus`
- `random-test-server` is necessary to launch a server before running
random-test-client. By default, it receives and replies to Modbus query on the
localhost and port 1502.
- `random-test-client` sends many different queries to a large range of
addresses and values to test the communication between the client and the
server.
- `unit-test-server` and `unit-test-client` run a full unit test suite. These
programs are essential to test the Modbus protocol implementation and libmodbus
behavior.
- `bandwidth-server-one`, `bandwidth-server-many-up` and `bandwidth-client`
return very useful information about the performance of transfer rate between
the server and the client. `bandwidth-server-one` can only handles one
connection at once with a client whereas `bandwidth-server-many-up` opens a
connection for each new clients (with a limit).
@@ -0,0 +1,71 @@
/*
* Copyright © 2008-2014 Stéphane Raimbault <stephane.raimbault@gmail.com>
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _UNIT_TEST_H_
#define _UNIT_TEST_H_
/* Constants defined by configure.ac */
#define HAVE_INTTYPES_H @HAVE_INTTYPES_H@
#define HAVE_STDINT_H @HAVE_STDINT_H@
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
# ifndef _MSC_VER
# include <stdint.h>
# else
# include "stdint.h"
# endif
#endif
#define SERVER_ID 17
#define INVALID_SERVER_ID 18
const uint16_t UT_BITS_ADDRESS = 0x130;
const uint16_t UT_BITS_NB = 0x25;
const uint8_t UT_BITS_TAB[] = { 0xCD, 0x6B, 0xB2, 0x0E, 0x1B };
const uint16_t UT_INPUT_BITS_ADDRESS = 0x1C4;
const uint16_t UT_INPUT_BITS_NB = 0x16;
const uint8_t UT_INPUT_BITS_TAB[] = { 0xAC, 0xDB, 0x35 };
const uint16_t UT_REGISTERS_ADDRESS = 0x160;
const uint16_t UT_REGISTERS_NB = 0x3;
const uint16_t UT_REGISTERS_NB_MAX = 0x20;
const uint16_t UT_REGISTERS_TAB[] = { 0x022B, 0x0001, 0x0064 };
/* Raise a manual exception when this address is used for the first byte */
const uint16_t UT_REGISTERS_ADDRESS_SPECIAL = 0x170;
/* The response of the server will contains an invalid TID or slave */
const uint16_t UT_REGISTERS_ADDRESS_INVALID_TID_OR_SLAVE = 0x171;
/* The server will wait for 1 second before replying to test timeout */
const uint16_t UT_REGISTERS_ADDRESS_SLEEP_500_MS = 0x172;
/* The server will wait for 5 ms before sending each byte */
const uint16_t UT_REGISTERS_ADDRESS_BYTE_SLEEP_5_MS = 0x173;
/* If the following value is used, a bad response is sent.
It's better to test with a lower value than
UT_REGISTERS_NB_POINTS to try to raise a segfault. */
const uint16_t UT_REGISTERS_NB_SPECIAL = 0x2;
const uint16_t UT_INPUT_REGISTERS_ADDRESS = 0x108;
const uint16_t UT_INPUT_REGISTERS_NB = 0x1;
const uint16_t UT_INPUT_REGISTERS_TAB[] = { 0x000A };
const float UT_REAL = 123456.00;
const uint32_t UT_IREAL_ABCD = 0x0020F147;
const uint32_t UT_IREAL_DCBA = 0x47F12000;
const uint32_t UT_IREAL_BADC = 0x200047F1;
const uint32_t UT_IREAL_CDAB = 0xF1470020;
/* const uint32_t UT_IREAL_ABCD = 0x47F12000);
const uint32_t UT_IREAL_DCBA = 0x0020F147;
const uint32_t UT_IREAL_BADC = 0xF1470020;
const uint32_t UT_IREAL_CDAB = 0x200047F1;*/
#endif /* _UNIT_TEST_H_ */
@@ -0,0 +1,19 @@
#!/bin/sh
client_log=unit-test-client.log
server_log=unit-test-server.log
rm -f $client_log $server_log
echo "Starting server"
./unit-test-server > $server_log 2>&1 &
sleep 1
echo "Starting client"
./unit-test-client > $client_log 2>&1
rc=$?
killall unit-test-server
exit $rc
Binary file not shown.