Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
4a406f56
Commit
4a406f56
authored
Jan 06, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(ModbusTCPMaster): Добавил скелет теста
parent
89382a0f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
273 additions
and
10 deletions
+273
-10
configure.ac
configure.ac
+5
-3
Makefile.am
extensions/Makefile.am
+1
-1
MBTCPMaster.cc
extensions/ModbusMaster/MBTCPMaster.cc
+6
-0
MBTCPMaster.h
extensions/ModbusMaster/MBTCPMaster.h
+1
-0
MBTCPMultiMaster.cc
extensions/ModbusMaster/MBTCPMultiMaster.cc
+24
-2
MBTCPMultiMaster.h
extensions/ModbusMaster/MBTCPMultiMaster.h
+1
-0
Makefile.am
extensions/ModbusMaster/tests/Makefile.am
+27
-0
mbmaster-test-configure.xml
extensions/ModbusMaster/tests/mbmaster-test-configure.xml
+0
-0
mbmaster-tests.at
extensions/ModbusMaster/tests/mbmaster-tests.at
+7
-0
test_mbtcpmaster.cc
extensions/ModbusMaster/tests/test_mbtcpmaster.cc
+37
-0
test_mbtcpmultimaster.cc
extensions/ModbusMaster/tests/test_mbtcpmultimaster.cc
+37
-0
tests_with_sm.cc
extensions/ModbusMaster/tests/tests_with_sm.cc
+88
-0
tests_with_sm.sh
extensions/ModbusMaster/tests/tests_with_sm.sh
+14
-0
testsuite.at
extensions/ModbusMaster/tests/testsuite.at
+7
-0
uniset2-functions.sh
extensions/ModbusMaster/tests/uniset2-functions.sh
+2
-0
uniset2-smemory
extensions/ModbusMaster/tests/uniset2-smemory
+2
-0
uniset2-start.sh
extensions/ModbusMaster/tests/uniset2-start.sh
+2
-0
MBSlave.cc
extensions/ModbusSlave/MBSlave.cc
+9
-2
MBSlave.h
extensions/ModbusSlave/MBSlave.h
+1
-0
test_mbslave.cc
extensions/ModbusSlave/tests/test_mbslave.cc
+1
-1
tests_with_sm.sh
extensions/ModbusSlave/tests/tests_with_sm.sh
+1
-1
No files found.
configure.ac
View file @
4a406f56
...
...
@@ -165,11 +165,11 @@ AM_CONDITIONAL(DISABLE_PYTHON, test ${buildpython} = false)
# check Doxygen
DOXYGEN=""
doc=
tru
e
doc=
fals
e
dox=
AC_MSG_CHECKING([Generate docs])
AC_ARG_ENABLE(docs,AC_HELP_STRING([--
disable-docs], [dis
able build docs]),
[ if test $enableval = yes; then doc=true; else doc=false; fi],[ doc=
tru
e; ])
AC_ARG_ENABLE(docs,AC_HELP_STRING([--
enable-docs], [en
able build docs]),
[ if test $enableval = yes; then doc=true; else doc=false; fi],[ doc=
fals
e; ])
if test ${doc} = true; then
AC_MSG_RESULT([yes])
...
...
@@ -219,6 +219,7 @@ if test ${buildtests} = true; then
AC_CONFIG_TESTDIR(extensions/tests)
AC_CONFIG_TESTDIR(extensions/LogicProcessor/tests)
AC_CONFIG_TESTDIR(extensions/ModbusSlave/tests)
AC_CONFIG_TESTDIR(extensions/ModbusMaster/tests)
AC_CONFIG_TESTDIR(extensions/UNetUDP/tests)
TESTSUITE_DIR="\$(top_builddir)/testsuite"
...
...
@@ -328,6 +329,7 @@ AC_CONFIG_FILES([Makefile
extensions/ModbusMaster/Makefile
extensions/ModbusMaster/libUniSet2RTU.pc
extensions/ModbusMaster/libUniSet2MBTCPMaster.pc
extensions/ModbusMaster/tests/Makefile
extensions/ModbusSlave/Makefile
extensions/ModbusSlave/libUniSet2MBSlave.pc
extensions/ModbusSlave/tests/Makefile
...
...
extensions/Makefile.am
View file @
4a406f56
...
...
@@ -4,7 +4,7 @@
if
HAVE_EXTENTIONS
SUBDIRS
=
lib include SharedMemory IOControl LogicProcessor
\
ModbusMaster ModbusSlave SMViewer UniNetwork UNetUDP UNetUDP/tests DBServer-MySQL DBServer-SQLite
\
ModbusMaster Modbus
Master/tests Modbus
Slave SMViewer UniNetwork UNetUDP UNetUDP/tests DBServer-MySQL DBServer-SQLite
\
RRDServer SharedMemoryPlus tests ModbusSlave/tests
#SMDBServer
...
...
extensions/ModbusMaster/MBTCPMaster.cc
View file @
4a406f56
...
...
@@ -70,6 +70,7 @@ pollThread(0)
ic
->
addReadItem
(
sigc
::
mem_fun
(
this
,
&
MBTCPMaster
::
readItem
)
);
pollThread
=
new
ThreadCreator
<
MBTCPMaster
>
(
this
,
&
MBTCPMaster
::
poll_thread
);
pollThread
->
setFinalAction
(
this
,
&
MBTCPMaster
::
final_thread
);
if
(
dlog
.
is_info
()
)
printMap
(
rmap
);
...
...
@@ -140,6 +141,11 @@ void MBTCPMaster::sysCommand( const UniSetTypes::SystemMessage *sm )
pollThread
->
start
();
}
// -----------------------------------------------------------------------------
void
MBTCPMaster
::
final_thread
()
{
setProcActive
(
false
);
}
// -----------------------------------------------------------------------------
void
MBTCPMaster
::
poll_thread
()
{
{
...
...
extensions/ModbusMaster/MBTCPMaster.h
View file @
4a406f56
...
...
@@ -215,6 +215,7 @@ class MBTCPMaster:
int
port
;
void
poll_thread
();
void
final_thread
();
bool
force_disconnect
;
private
:
...
...
extensions/ModbusMaster/MBTCPMultiMaster.cc
View file @
4a406f56
...
...
@@ -142,7 +142,9 @@ checkThread(0)
ic
->
addReadItem
(
sigc
::
mem_fun
(
this
,
&
MBTCPMultiMaster
::
readItem
)
);
pollThread
=
new
ThreadCreator
<
MBTCPMultiMaster
>
(
this
,
&
MBTCPMultiMaster
::
poll_thread
);
pollThread
->
setFinalAction
(
this
,
&
MBTCPMultiMaster
::
final_thread
);
checkThread
=
new
ThreadCreator
<
MBTCPMultiMaster
>
(
this
,
&
MBTCPMultiMaster
::
check_thread
);
checkThread
->
setFinalAction
(
this
,
&
MBTCPMultiMaster
::
final_thread
);
// Т.к. при "многоканальном" доступе к slave, смена канала должна происходит сразу после
...
...
@@ -155,8 +157,22 @@ checkThread(0)
// -----------------------------------------------------------------------------
MBTCPMultiMaster
::~
MBTCPMultiMaster
()
{
delete
pollThread
;
delete
checkThread
;
if
(
pollThread
)
{
pollThread
->
stop
();
if
(
pollThread
->
isRunning
()
)
pollThread
->
join
();
delete
pollThread
;
}
if
(
checkThread
)
{
checkThread
->
stop
();
if
(
checkThread
->
isRunning
()
)
checkThread
->
join
();
delete
checkThread
;
}
for
(
auto
&
it
:
mblist
)
{
it
.
mbtcp
=
nullptr
;
...
...
@@ -216,6 +232,12 @@ std::shared_ptr<ModbusClient> MBTCPMultiMaster::initMB( bool reopen )
return
0
;
}
// -----------------------------------------------------------------------------
void
MBTCPMultiMaster
::
final_thread
()
{
setProcActive
(
false
);
}
// -----------------------------------------------------------------------------
bool
MBTCPMultiMaster
::
MBSlaveInfo
::
check
()
{
return
mbtcp
->
checkConnection
(
ip
,
port
);
...
...
extensions/ModbusMaster/MBTCPMultiMaster.h
View file @
4a406f56
...
...
@@ -232,6 +232,7 @@ class MBTCPMultiMaster:
virtual
std
::
shared_ptr
<
ModbusClient
>
initMB
(
bool
reopen
=
false
)
override
;
void
poll_thread
();
void
check_thread
();
void
final_thread
();
UniSetTypes
::
uniset_rwmutex
mbMutex
;
bool
force_disconnect
;
...
...
extensions/ModbusMaster/tests/Makefile.am
0 → 100644
View file @
4a406f56
if
HAVE_TESTS
noinst_PROGRAMS
=
tests-with-sm
tests_with_sm_SOURCES
=
tests_with_sm.cc test_mbtcpmaster.cc test_mbtcpmultimaster.cc
tests_with_sm_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(top_builddir)
/extensions/lib/libUniSet2Extensions.la
\
$(top_builddir)
/extensions/ModbusMaster/libUniSet2MBTCPMaster.la
\
$(top_builddir)
/extensions/SharedMemory/libUniSet2SharedMemory.la
\
$(SIGC_LIBS)
$(COMCPP_LIBS)
tests_with_sm_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
\
-I
$(top_builddir)
/extensions/ModbusMaster
\
-I
$(top_builddir)
/extensions/SharedMemory
$(SIGC_CFLAGS)
$(COMCPP_CFLAGS)
include
$(top_builddir)/testsuite/testsuite-common.mk
check-local
:
atconfig package.m4 $(TESTSUITE) mbmaster-tests.at
$(SHELL)
$(TESTSUITE)
$(TESTSUITEFLAGS)
clean-local
:
rm
-rf
$(CLEANFILES)
rm
-rf
$(COVERAGE_REPORT_DIR)
if
HAVE_COVERAGE
include
$(top_builddir)/testsuite/testsuite-coverage-common.mk
endif
endif
extensions/ModbusMaster/tests/mbmaster-test-configure.xml
0 → 100644
View file @
4a406f56
This diff is collapsed.
Click to expand it.
extensions/ModbusMaster/tests/mbmaster-tests.at
0 → 100644
View file @
4a406f56
AT_SETUP([ModbusTCPMaster tests (with SM)])
AT_CHECK([$abs_top_builddir/testsuite/at-test-launch.sh $abs_top_builddir/extensions/ModbusMaster/tests tests_with_sm.sh],[0],[ignore],[ignore])
AT_CLEANUP
AT_SETUP([ModbusTCPMaster tests (Apart)])
AT_CHECK([$abs_top_builddir/testsuite/at-test-launch.sh $abs_top_builddir/extensions/ModbusMaster/tests tests_with_sm_apart.sh],[0],[ignore],[ignore])
AT_CLEANUP
extensions/ModbusMaster/tests/test_mbtcpmaster.cc
0 → 100644
View file @
4a406f56
#include <catch.hpp>
// -----------------------------------------------------------------------------
#include <time.h>
#include <limits>
#include "UniSetTypes.h"
#include "MBTCPMultiMaster.h"
// -----------------------------------------------------------------------------
using
namespace
std
;
using
namespace
UniSetTypes
;
// -----------------------------------------------------------------------------
static
ModbusRTU
::
ModbusAddr
slaveaddr
=
0x01
;
// conf->getArgInt("--mbs-my-addr");
static
int
port
=
20048
;
// conf->getArgInt("--mbs-inet-port");
static
string
addr
(
"127.0.0.1"
);
// conf->getArgParam("--mbs-inet-addr");
static
ObjectId
slaveID
=
6004
;
// conf->getObjectID( conf->getArgParam("--mbs-name"));
static
ModbusTCPMaster
*
mb
=
nullptr
;
static
UInterface
*
ui
=
nullptr
;
// -----------------------------------------------------------------------------
static
void
InitTest
()
{
auto
conf
=
uniset_conf
();
CHECK
(
conf
!=
nullptr
);
if
(
ui
==
nullptr
)
{
ui
=
new
UInterface
();
// UI понадобиться для проверки записанных в SM значений.
CHECK
(
ui
->
getObjectIndex
()
!=
nullptr
);
CHECK
(
ui
->
getConf
()
==
conf
);
CHECK
(
ui
->
waitReady
(
slaveID
,
5000
)
);
}
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"MBTCPMaster"
,
"[modbus][mbmaster][mbtcpmaster]"
)
{
FAIL
(
"Tests for MBTCPMaster not yet"
);
}
extensions/ModbusMaster/tests/test_mbtcpmultimaster.cc
0 → 100644
View file @
4a406f56
#include <catch.hpp>
// -----------------------------------------------------------------------------
#include <time.h>
#include <limits>
#include "UniSetTypes.h"
#include "MBTCPMultiMaster.h"
// -----------------------------------------------------------------------------
using
namespace
std
;
using
namespace
UniSetTypes
;
// -----------------------------------------------------------------------------
static
ModbusRTU
::
ModbusAddr
slaveaddr
=
0x01
;
// conf->getArgInt("--mbs-my-addr");
static
int
port
=
20048
;
// conf->getArgInt("--mbs-inet-port");
static
string
addr
(
"127.0.0.1"
);
// conf->getArgParam("--mbs-inet-addr");
static
ObjectId
slaveID
=
6004
;
// conf->getObjectID( conf->getArgParam("--mbs-name"));
static
ModbusTCPMaster
*
mb
=
nullptr
;
static
UInterface
*
ui
=
nullptr
;
// -----------------------------------------------------------------------------
static
void
InitTest
()
{
auto
conf
=
uniset_conf
();
CHECK
(
conf
!=
nullptr
);
if
(
ui
==
nullptr
)
{
ui
=
new
UInterface
();
// UI понадобиться для проверки записанных в SM значений.
CHECK
(
ui
->
getObjectIndex
()
!=
nullptr
);
CHECK
(
ui
->
getConf
()
==
conf
);
CHECK
(
ui
->
waitReady
(
slaveID
,
5000
)
);
}
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"MBTCPMultiMaster"
,
"[modbus][mbmaster][mbtcpmultimaster]"
)
{
FAIL
(
"Tests for MBTCPMaster not yet"
);
}
extensions/ModbusMaster/tests/tests_with_sm.cc
0 → 100644
View file @
4a406f56
#define CATCH_CONFIG_RUNNER
#include <catch.hpp>
#include <string>
#include "Debug.h"
#include "UniSetActivator.h"
#include "PassiveTimer.h"
#include "SharedMemory.h"
#include "Extensions.h"
#include "MBTCPMaster.h"
// --------------------------------------------------------------------------
using
namespace
std
;
using
namespace
UniSetTypes
;
using
namespace
UniSetExtensions
;
// --------------------------------------------------------------------------
int
main
(
int
argc
,
char
*
argv
[]
)
{
Catch
::
Session
session
;
if
(
argc
>
1
&&
(
strcmp
(
argv
[
1
],
"--help"
)
==
0
||
strcmp
(
argv
[
1
],
"-h"
)
==
0
)
)
{
cout
<<
"--confile - Использовать указанный конф. файл. По умолчанию configure.xml"
<<
endl
;
SharedMemory
::
help_print
(
argc
,
argv
);
cout
<<
endl
<<
endl
<<
"--------------- CATCH HELP --------------"
<<
endl
;
session
.
showHelp
(
"test_with_sm"
);
return
0
;
}
int
returnCode
=
session
.
applyCommandLine
(
argc
,
argv
,
Catch
::
Session
::
OnUnusedOptions
::
Ignore
);
if
(
returnCode
!=
0
)
// Indicates a command line error
return
returnCode
;
try
{
auto
conf
=
uniset_init
(
argc
,
argv
);
conf
->
initDebug
(
dlog
,
"dlog"
);
bool
apart
=
findArgParam
(
"--apart"
,
argc
,
argv
)
!=
-
1
;
auto
shm
=
SharedMemory
::
init_smemory
(
argc
,
argv
);
if
(
!
shm
)
return
1
;
/*
auto mbs = MBSlave::init_mbslave(argc,argv,shm->getId(), (apart ? nullptr : shm ));
if( !mbs )
return 1;
*/
auto
act
=
UniSetActivator
::
Instance
();
act
->
addObject
(
shm
);
// act->addObject(mbs);
SystemMessage
sm
(
SystemMessage
::
StartUp
);
act
->
broadcast
(
sm
.
transport_msg
()
);
act
->
run
(
true
);
int
tout
=
6000
;
PassiveTimer
pt
(
tout
);
while
(
!
pt
.
checkTime
()
&&
!
act
->
exist
()
)
msleep
(
100
);
if
(
!
act
->
exist
()
)
{
cerr
<<
"(tests_with_sm): SharedMemory not exist! (timeout="
<<
tout
<<
")"
<<
endl
;
return
1
;
}
return
session
.
run
();
}
catch
(
SystemError
&
err
)
{
cerr
<<
"(tests_with_sm): "
<<
err
<<
endl
;
}
catch
(
Exception
&
ex
)
{
cerr
<<
"(tests_with_sm): "
<<
ex
<<
endl
;
}
catch
(
std
::
exception
&
e
)
{
cerr
<<
"(tests_with_sm): "
<<
e
.
what
()
<<
endl
;
}
catch
(...)
{
cerr
<<
"(tests_with_sm): catch(...)"
<<
endl
;
}
return
1
;
}
extensions/ModbusMaster/tests/tests_with_sm.sh
0 → 100755
View file @
4a406f56
#!/bin/sh
# '--' - нужен для отделения аргументов catch, от наших..
cd
../../../Utilities/Admin/
./uniset2-start.sh
-f
./create_links.sh
./uniset2-start.sh
-f
./create
./uniset2-start.sh
-f
./exist |
grep
-q
UNISET_PLC/Controllers
||
exit
1
cd
-
./uniset2-start.sh
-g
./tests-with-sm
$*
--
--confile
mbmaster-test-configure.xml
--e-startup-pause
10
\
--mbs-name
MBSlave1
--mbs-type
TCP
--mbs-inet-addr
127.0.0.1
--mbs-inet-port
20048
--mbs-my-addr
0x01
\
--mbs-askcount-id
SVU_AskCount_AS
--mbs-respond-id
RespondRTU_S
--mbs-respond-invert
1
\
--mbs-filter-field
mbs
--mbs-filter-value
1
--ulog-add-levels
any
extensions/ModbusMaster/tests/testsuite.at
0 → 100644
View file @
4a406f56
m4_include(package.m4)
AT_COLOR_TESTS
AT_INIT([ModbusMaster tests])
m4_include(mbmaster-tests.at)
extensions/ModbusMaster/tests/uniset2-functions.sh
0 → 120000
View file @
4a406f56
../../../Utilities/scripts/uniset2-functions.sh
\ No newline at end of file
extensions/ModbusMaster/tests/uniset2-smemory
0 → 120000
View file @
4a406f56
/home/pv/Projects.com/uniset-2.0/extensions/SharedMemory/uniset2-smemory
\ No newline at end of file
extensions/ModbusMaster/tests/uniset2-start.sh
0 → 120000
View file @
4a406f56
../../../Utilities/scripts/uniset2-start.sh
\ No newline at end of file
extensions/ModbusSlave/MBSlave.cc
View file @
4a406f56
...
...
@@ -98,7 +98,7 @@ prefix(prefix)
mbslot
=
rs
;
thr
=
new
ThreadCreator
<
MBSlave
>
(
this
,
&
MBSlave
::
execute_rtu
);
thr
->
setFinalAction
(
this
,
&
MBSlave
::
finalThread
);
dinfo
<<
myname
<<
"(init): type=RTU myaddr="
<<
ModbusRTU
::
addr2str
(
addr
)
<<
" dev="
<<
dev
<<
" speed="
<<
speed
<<
endl
;
}
...
...
@@ -121,6 +121,7 @@ prefix(prefix)
mbslot
=
mbtcp
;
thr
=
new
ThreadCreator
<
MBSlave
>
(
this
,
&
MBSlave
::
execute_tcp
);
thr
->
setFinalAction
(
this
,
&
MBSlave
::
finalThread
);
dinfo
<<
myname
<<
"(init): init TCP connection ok. "
<<
" inet="
<<
iaddr
<<
" port="
<<
port
<<
endl
;
if
(
dlog
.
debugging
(
Debug
::
LEVEL9
)
)
...
...
@@ -367,7 +368,7 @@ MBSlave::~MBSlave()
if
(
thr
&&
thr
->
isRunning
()
)
{
thr
->
stop
();
thr
->
join
();
//
thr->join();
}
delete
thr
;
...
...
@@ -375,6 +376,12 @@ MBSlave::~MBSlave()
delete
shm
;
}
// -----------------------------------------------------------------------------
void
MBSlave
::
finalThread
()
{
activated
=
false
;
cancelled
=
true
;
}
// -----------------------------------------------------------------------------
void
MBSlave
::
waitSMReady
()
{
// waiting for SM is ready...
...
...
extensions/ModbusSlave/MBSlave.h
View file @
4a406f56
...
...
@@ -386,6 +386,7 @@ class MBSlave:
// действия при завершении работы
virtual
void
sigterm
(
int
signo
)
override
;
virtual
void
finalThread
();
virtual
void
initIterators
();
bool
initItem
(
UniXML
::
iterator
&
it
);
...
...
extensions/ModbusSlave/tests/test_mbslave.cc
View file @
4a406f56
...
...
@@ -16,7 +16,7 @@ static ObjectId slaveID = 6004; // conf->getObjectID( conf->getArgParam("--mbs-n
static
ModbusTCPMaster
*
mb
=
nullptr
;
static
UInterface
*
ui
=
nullptr
;
// -----------------------------------------------------------------------------
void
InitTest
()
static
void
InitTest
()
{
auto
conf
=
uniset_conf
();
CHECK
(
conf
!=
nullptr
);
...
...
extensions/ModbusSlave/tests/tests_with_sm.sh
View file @
4a406f56
...
...
@@ -8,7 +8,7 @@ cd ../../../Utilities/Admin/
./uniset2-start.sh
-f
./exist |
grep
-q
UNISET_PLC/Controllers
||
exit
1
cd
-
./uniset2-start.sh
-
f
./tests-with-sm
$*
--
--confile
mbslave-test-configure.xml
--e-startup-pause
10
\
./uniset2-start.sh
-
g
./tests-with-sm
$*
--
--confile
mbslave-test-configure.xml
--e-startup-pause
10
\
--mbs-name
MBSlave1
--mbs-type
TCP
--mbs-inet-addr
127.0.0.1
--mbs-inet-port
20048
--mbs-my-addr
0x01
\
--mbs-askcount-id
SVU_AskCount_AS
--mbs-respond-id
RespondRTU_S
--mbs-respond-invert
1
\
--mbs-filter-field
mbs
--mbs-filter-value
1
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment