Commit e2cbeb0b authored by Pavel Vainerman's avatar Pavel Vainerman

(SharedMemory): заложил основу для тестов,

в IONotifyController сделал Restorer shared_ptr
parent 40a0da8d
......@@ -18,11 +18,11 @@ dumpingToDB(_dumpingToDB)
{
restorer = NULL;
NCRestorer_XML* askd = new NCRestorer_XML(askdump);
shared_ptr<NCRestorer_XML> askd = make_shared<NCRestorer_XML>(askdump);
askd->setItemFilter(s_filterField, s_filterValue);
askd->setConsumerFilter(c_filterField, c_filterValue);
restorer = askd;
restorer = std::static_pointer_cast<NCRestorer>(askd);
/*
// askd->setReadItem( sigc::mem_fun(this,&NullController::readSItem) );
......@@ -33,16 +33,9 @@ dumpingToDB(_dumpingToDB)
}
// --------------------------------------------------------------------------------
NullController::~NullController()
{
if( restorer != NULL )
{
delete restorer;
restorer=NULL;
}
}
// --------------------------------------------------------------------------------
void NullController::dumpToDB()
{
......
......@@ -221,6 +221,7 @@ if test ${buildtests} = true; then
AC_CONFIG_TESTDIR(extensions/ModbusSlave/tests)
AC_CONFIG_TESTDIR(extensions/ModbusMaster/tests)
AC_CONFIG_TESTDIR(extensions/UNetUDP/tests)
AC_CONFIG_TESTDIR(extensions/SharedMemory/tests)
TESTSUITE_DIR="\$(top_builddir)/testsuite"
AC_SUBST(TESTSUITE_DIR)
......@@ -345,6 +346,7 @@ AC_CONFIG_FILES([Makefile
extensions/UNetUDP/libUniSet2UNetUDP.pc
extensions/UNetUDP/tests/Makefile
extensions/SharedMemory/Makefile
extensions/SharedMemory/tests/Makefile
extensions/SharedMemory/libUniSet2SharedMemory.pc
extensions/SharedMemoryPlus/Makefile
extensions/RRDServer/Makefile
......
......@@ -3,7 +3,7 @@
############################################################################
if HAVE_EXTENTIONS
SUBDIRS = lib include SharedMemory IOControl LogicProcessor \
SUBDIRS = lib include SharedMemory SharedMemory/tests IOControl LogicProcessor \
ModbusMaster ModbusSlave SMViewer UniNetwork UNetUDP UNetUDP/tests DBServer-MySQL DBServer-SQLite \
RRDServer SharedMemoryPlus tests ModbusMaster/tests ModbusSlave/tests
......
......@@ -61,8 +61,7 @@ SharedMemory::SharedMemory( ObjectId id, const std::string& datafile, const std:
for( auto i=hist.begin(); i!=hist.end(); ++i )
histmap[i->fuse_id].push_back(i);
// ----------------------
restorer = NULL;
NCRestorer_XML* rxml = new NCRestorer_XML(datafile);
auto rxml = make_shared<NCRestorer_XML>(datafile);
string s_field(conf->getArgParam("--s-filter-field"));
string s_fvalue(conf->getArgParam("--s-filter-value"));
......@@ -85,7 +84,7 @@ SharedMemory::SharedMemory( ObjectId id, const std::string& datafile, const std:
rxml->setConsumerFilter(c_field, c_fvalue);
rxml->setThresholdsFilter(t_field, t_fvalue);
restorer = rxml;
restorer = std::static_pointer_cast<NCRestorer>(rxml);
rxml->setReadItem( sigc::mem_fun(this,&SharedMemory::readItem) );
string wdt_dev = conf->getArgParam("--wdt-device");
......@@ -123,11 +122,6 @@ SharedMemory::SharedMemory( ObjectId id, const std::string& datafile, const std:
SharedMemory::~SharedMemory()
{
if( restorer )
{
delete restorer;
restorer = NULL;
}
}
// --------------------------------------------------------------------------------
......@@ -834,8 +828,8 @@ bool SharedMemory::initFromSM( UniSetTypes::ObjectId sm_id, UniSetTypes::ObjectI
IOController_i::SensorIOInfo& ii(amap[i]);
try
{
#if 0
// Вариант через setValue...
#if 1
// Вариант через setValue...(заодно внтури проверяются пороги)
setValue(ii.si.id,ii.value,getId());
#else
......@@ -848,6 +842,13 @@ bool SharedMemory::initFromSM( UniSetTypes::ObjectId sm_id, UniSetTypes::ObjectI
}
io->second->init(ii);
// проверка порогов
try
{
checkThreshold(io,ii.si.id,true);
}
catch(...){}
#endif
}
catch( const Exception& ex )
......
if HAVE_TESTS
noinst_PROGRAMS = tests
tests_SOURCES = tests.cc NullSM.cc test_sm.cc
tests_LDADD = $(top_builddir)/lib/libUniSet2.la $(top_builddir)/extensions/lib/libUniSet2Extensions.la \
$(top_builddir)/extensions/SharedMemory/libUniSet2SharedMemory.la \
$(SIGC_LIBS) $(COMCPP_LIBS)
tests_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions/include \
-I$(top_builddir)/extensions/SharedMemory $(SIGC_CFLAGS) $(COMCPP_CFLAGS)
include $(top_builddir)/testsuite/testsuite-common.mk
check-local: atconfig package.m4 $(TESTSUITE) sm-tests.at
$(SHELL) $(TESTSUITE) $(TESTSUITEFLAGS)
clean-local:
rm -rf $(CLEANFILES)
rm -rf $(COVERAGE_REPORT_DIR)
endif
#include <memory>
#include "Configuration.h"
#include "NCRestorer.h"
#include "NullSM.h"
#include "PassiveTimer.h"
// --------------------------------------------------------------------------------
using namespace UniSetTypes;
using namespace std;
// --------------------------------------------------------------------------------
NullSM::NullSM( ObjectId id, const std::string& datfile ):
IONotifyController(id)
{
shared_ptr<NCRestorer_XML> r = make_shared<NCRestorer_XML>(datfile);
restorer = std::static_pointer_cast<NCRestorer>(r);
}
// --------------------------------------------------------------------------------
NullSM::~NullSM()
{
}
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------
#ifndef NullSM_H_
#define NullSM_H_
// --------------------------------------------------------------------------
#include <string>
#include "IONotifyController.h"
#include "NCRestorer.h"
// --------------------------------------------------------------------------
class NullSM:
public IONotifyController
{
public:
NullSM( UniSetTypes::ObjectId id, const std::string& datfile );
virtual ~NullSM();
protected:
virtual void loggingInfo( UniSetTypes::SensorMessage& sm ) override {};
virtual void dumpOrdersList( const UniSetTypes::ObjectId sid, const IONotifyController::ConsumerListInfo& lst ) override {};
virtual void dumpThresholdList( const UniSetTypes::ObjectId sid, const IONotifyController::ThresholdExtList& lst ) override {};
virtual void readDump() override {};
private:
};
// --------------------------------------------------------------------------
#endif // NullSM_H_
// --------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<UNISETPLC xmlns:xi="http://www.w3.org/2001/XInclude">
<UserData/>
<!-- Общие(стартовые) параметры по UniSet -->
<UniSet>
<NameService host="localhost" port="2809"/>
<LocalNode name="localhost"/>
<RootSection name="UNISET_SM"/>
<CountOfNet name="1"/>
<RepeatCount name="3"/>
<RepeatTimeoutMS name="50"/>
<WatchDogTime name="0"/>
<PingNodeTime name="0"/>
<AutoStartUpTime name="1"/>
<DumpStateTime name="10"/>
<SleepTickMS name="500"/>
<UniSetDebug levels="" name="ulog"/>
<ConfDir name="./"/>
<DataDir name="./"/>
<BinDir name="./"/>
<LogDir name="./"/>
<DocDir name="./"/>
<LockDir name="./"/>
<Services/>
</UniSet>
<dlog name="dlog"/>
<settings>
<ReservSharedMemory name="ReservSharedMemory" shmID="ReservSharedMemory"/>
</settings>
<ObjectsMap idfromfile="1">
<nodes port="2809" unet_broadcast_ip="192.168.1.255" unet_broadcast_ip2="192.168.122.255">
<item id="3000" dbserver="DBServer1" infserver="InfoServer" ip="127.0.0.1" name="localhost" textname="Локальный узел" unet_ignore="0" unet_port="2048"/>
</nodes>
<!-- ************************ Датчики ********************** -->
<sensors name="Sensors">
<item id="500" iotype="AI" name="AI_AS" priority="Medium" textname="AI" default="-50"/>
<item id="501" iotype="DI" name="DI_S" priority="Medium" textname="Digital input" default="1"/>
<item id="502" iotype="DO" name="DO_C" priority="Medium" textname="Digital output"/>
<item id="503" iotype="AI" name="AI1_AS" priority="Medium" textname="AI" default="390"/>
<item id="504" iotype="DI" name="Threshold1_S" priority="Medium" textname="Threshold"/>
</sensors>
<thresholds name="thresholds">
<sensor iotype="AI" name="AI1_AS">
<threshold hilimit="376" id="1" lowlimit="374" name="t1" sensibility="0" sid="Threshold1_S"/>
</sensor>
</thresholds>
<controllers name="Controllers">
<item id="5000" name="SharedMemory1"/>
<item id="5003" name="SharedMemory"/>
<item id="5001" name="UniExchange"/>
<item id="5002" name="UniExchange2"/>
<item id="5004" name="ReservSharedMemory"/>
</controllers>
<!-- ******************* Идентификаторы сервисов ***************** -->
<services name="Services">
<item id="5010" name="InfoServer"/>
<item id="5011" name="DBServer1"/>
<item id="5012" name="PrintServer"/>
<item id="5013" name="TimeService"/>
</services>
<!-- ******************* Идентификаторы объектов ***************** -->
<objects name="UniObjects">
<item id="6000" name="TestProc"/>
</objects>
</ObjectsMap>
<messages idfromfile="1" name="messages">
</messages>
<Calibrations name="Calibrations">
</Calibrations>
</UNISETPLC>
<?xml version="1.0" encoding="utf-8"?>
<UNISETPLC xmlns:xi="http://www.w3.org/2001/XInclude">
<UserData/>
<!-- Общие(стартовые) параметры по UniSet -->
<UniSet>
<NameService host="localhost" port="2809"/>
<LocalNode name="localhost"/>
<RootSection name="UNISET_SM"/>
<CountOfNet name="1"/>
<RepeatCount name="3"/>
<RepeatTimeoutMS name="50"/>
<WatchDogTime name="0"/>
<PingNodeTime name="0"/>
<AutoStartUpTime name="1"/>
<DumpStateTime name="10"/>
<SleepTickMS name="500"/>
<UniSetDebug levels="" name="ulog"/>
<ConfDir name="./"/>
<DataDir name="./"/>
<BinDir name="./"/>
<LogDir name="./"/>
<DocDir name="./"/>
<LockDir name="./"/>
<Services/>
</UniSet>
<dlog name="dlog"/>
<settings>
<SharedMemory name="SharedMemory" shmID="SharedMemory">
<ReservList>
<item node="localhost" name="ReservSharedMemory"/>
</ReservList>
</SharedMemory>
</settings>
<ObjectsMap idfromfile="1">
<nodes port="2809" unet_broadcast_ip="192.168.1.255" unet_broadcast_ip2="192.168.122.255">
<item id="3000" dbserver="DBServer1" infserver="InfoServer" ip="127.0.0.1" name="localhost" textname="Локальный узел" unet_ignore="0" unet_port="2048"/>
</nodes>
<!-- ************************ Датчики ********************** -->
<sensors name="Sensors">
<item id="500" iotype="AI" name="AI_AS" priority="Medium" textname="AI"/>
<item id="501" iotype="DI" name="DI_S" priority="Medium" textname="Digital input"/>
<item id="502" iotype="DO" name="DO_C" priority="Medium" textname="Digital output"/>
<item id="503" iotype="AI" name="AI1_AS" priority="Medium" textname="AI"/>
<item id="504" iotype="DI" name="Threshold1_S" priority="Medium" textname="Threshold"/>
</sensors>
<thresholds name="thresholds">
<sensor iotype="AI" name="AI1_AS">
<threshold hilimit="376" id="1" lowlimit="374" name="t1" sensibility="0" sid="Threshold1_S"/>
</sensor>
</thresholds>
<controllers name="Controllers">
<item id="5000" name="SharedMemory1"/>
<item id="5003" name="SharedMemory"/>
<item id="5001" name="UniExchange"/>
<item id="5002" name="UniExchange2"/>
<item id="5004" name="ReservSharedMemory"/>
</controllers>
<!-- ******************* Идентификаторы сервисов ***************** -->
<services name="Services">
<item id="5010" name="InfoServer"/>
<item id="5011" name="DBServer1"/>
<item id="5012" name="PrintServer"/>
<item id="5013" name="TimeService"/>
</services>
<!-- ******************* Идентификаторы объектов ***************** -->
<objects name="UniObjects">
<item id="6000" name="TestProc"/>
</objects>
</ObjectsMap>
<messages idfromfile="1" name="messages">
</messages>
<Calibrations name="Calibrations">
</Calibrations>
</UNISETPLC>
AT_SETUP([SharedMemory tests])
AT_CHECK([$abs_top_builddir/testsuite/at-test-launch.sh $abs_top_builddir/extensions/SharedMemory/tests tests.sh],[0],[ignore],[ignore])
AT_CLEANUP
#include <catch.hpp>
// -----------------------------------------------------------------------------
#include <memory>
#include "UniSetTypes.h"
#include "UInterface.h"
// -----------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
// -----------------------------------------------------------------------------
static shared_ptr<UInterface> ui;
// -----------------------------------------------------------------------------
void InitTest()
{
auto conf = uniset_conf();
CHECK( conf!=nullptr );
if( !ui )
{
ui = make_shared<UInterface>();
CHECK( ui->getObjectIndex() != nullptr );
CHECK( ui->getConf() == conf );
}
}
// -----------------------------------------------------------------------------
TEST_CASE("[SM]: init from reserv","[sm][reserv]")
{
InitTest();
/*
CHECK( ui->getValue(500) == -50 );
CHECK( ui->getValue(501) == 1 );
CHECK( ui->getValue(502) == 390 );
CHECK( ui->getValue(503) == 1 );
*/
}
// -----------------------------------------------------------------------------
#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 "NullSM.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("tests");
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);
auto shm = SharedMemory::init_smemory(argc, argv);
if( !shm )
return 1;
auto act = UniSetActivator::Instance();
act->add(shm);
ObjectId ns_id = conf->getControllerID("ReservSharedMemory");
if( ns_id == DefaultObjectId )
{
cerr << "Not found ID for 'ReservSharedMemory'" << endl;
return 1;
}
auto nullsm = make_shared<NullSM>(ns_id,"reserv-sm-configure.xml");
act->add(nullsm);
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): SharedMemory not exist! (timeout=" << tout << ")" << endl;
return 1;
}
return session.run();
}
catch( const SystemError& err )
{
cerr << "(tests): " << err << endl;
}
catch( const Exception& ex )
{
cerr << "(tests): " << ex << endl;
}
catch( const std::exception& e )
{
cerr << "(tests): " << e.what() << endl;
}
catch(...)
{
cerr << "(tests): catch(...)" << endl;
}
return 1;
}
#!/bin/sh
./uniset2-start.sh -f ./uniset2-admin --confile ./sm-configure.xml --create
./uniset2-start.sh -f ./uniset2-admin --confile ./sm-configure.xml --exist | grep -q UNISET_SM/Controllers || exit 1
./uniset2-start.sh -f ./uniset2-admin --confile ./reserv-sm-configure.xml --create
./uniset2-start.sh -f ./uniset2-admin --confile ./reserv-sm-configure.xml --exist | grep -q UNISET_SM/Controllers || exit 1
./uniset2-start.sh -f ./tests $* -- --confile ./sm-configure.xml --dlog-add-levels any
m4_include(package.m4)
AT_COLOR_TESTS
AT_INIT([SharedMemory tests])
m4_include(sm-tests.at)
../../../Utilities/Admin/uniset2-admin
\ No newline at end of file
../../../Utilities/scripts/uniset2-functions.sh
\ No newline at end of file
../../SharedMemory/uniset2-smemory
\ No newline at end of file
../../../Utilities/scripts/uniset2-start.sh
\ No newline at end of file
......@@ -25,6 +25,7 @@
#ifndef IONotifyController_H_
#define IONotifyController_H_
//---------------------------------------------------------------------------
#include <memory>
#include <unordered_map>
#include <list>
#include <string>
......@@ -131,8 +132,8 @@ class IONotifyController:
{
public:
IONotifyController(const std::string& name, const std::string& section, NCRestorer* dumper=0);
IONotifyController(const UniSetTypes::ObjectId id, NCRestorer* dumper=0);
IONotifyController(const std::string& name, const std::string& section, std::shared_ptr<NCRestorer> dumper= nullptr );
IONotifyController(const UniSetTypes::ObjectId id, std::shared_ptr<NCRestorer> dumper=nullptr );
virtual ~IONotifyController();
......@@ -302,7 +303,7 @@ class IONotifyController:
/*! чтение dump-файла */
virtual void readDump();
NCRestorer* restorer;
std::shared_ptr<NCRestorer> restorer;
void onChangeUndefinedState( std::shared_ptr<USensorInfo>& it, IOController* ic );
......
......@@ -39,7 +39,6 @@ using namespace UniSetTypes;
using namespace std;
// ------------------------------------------------------------------------------------------
IONotifyController::IONotifyController():
restorer(NULL),
askIOMutex("askIOMutex"),
trshMutex("trshMutex"),
maxAttemtps(uniset_conf()->getPIntField("ConsumerMaxAttempts", 5))
......@@ -47,7 +46,7 @@ maxAttemtps(uniset_conf()->getPIntField("ConsumerMaxAttempts", 5))
}
IONotifyController::IONotifyController(const string& name, const string& section, NCRestorer* d ):
IONotifyController::IONotifyController(const string& name, const string& section, std::shared_ptr<NCRestorer> d ):
IOController(name, section),
restorer(d),
askIOMutex(name+"askIOMutex"),
......@@ -58,7 +57,7 @@ IONotifyController::IONotifyController(const string& name, const string& section
addIOFilter( sigc::mem_fun(this,&IONotifyController::myIOFilter) );
}
IONotifyController::IONotifyController( ObjectId id, NCRestorer* d ):
IONotifyController::IONotifyController( ObjectId id, std::shared_ptr<NCRestorer> d ):
IOController(id),
restorer(d),
askIOMutex(string(uniset_conf()->oind->getMapName(id))+"_askIOMutex"),
......
......@@ -151,6 +151,11 @@ extensions/SharedMemory/SharedMemory.cc
extensions/SharedMemory/SharedMemory.h
extensions/SharedMemory/smemory.cc
extensions/SharedMemory/test.xml
extensions/SharedMemory/tests/Makefile.am
extensions/SharedMemory/tests/test_sm.cc
extensions/SharedMemory/tests/tests.cc
extensions/SharedMemory/tests/NullSM.cc
extensions/SharedMemory/tests/NullSM.h
extensions/SharedMemoryPlus/Makefile.am
extensions/SharedMemoryPlus/smemory-plus.cc
extensions/SharedMemoryPlus/test.xml
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment