Commit a6485982 authored by Pavel Vainerman's avatar Pavel Vainerman

(SM): немного переделал тест на "потерю сообщений"

parent ce4fa6e8
......@@ -6,7 +6,7 @@ ulimit -Sc 10000000000
./uniset2-start.sh -f ./uniset2-smemory --smemory-id SharedMemory \
--confile test-lost.xml --datfile test-lost.xml --ulog-add-levels crit,warn,system,level1 \
--sm-log-add-levels any $* --sm-run-logserver --activate-timeout 320000
--sm-log-add-levels any $* --sm-run-logserver --activator-run-httpserver --activate-timeout 320000
#--pulsar-id DO_C --pulsar-iotype DO --pulsar-msec 100
......
#include <iomanip>
#include "Exceptions.h"
#include "LostPassiveTestProc.h"
// -----------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
// -----------------------------------------------------------------------------
LostPassiveTestProc::LostPassiveTestProc( UniSetTypes::ObjectId id, xmlNode* confnode ):
LostTestProc_SK( id, confnode )
{
auto conf = uniset_conf();
UniXML::iterator cit(confnode);
string f_field = conf->getArgParam("--" + argprefix + "filter-field", cit.getProp("filterField"));
string f_value = conf->getArgParam("--" + argprefix + "filter-value", cit.getProp("filterValue"));
xmlNode* snode = conf->getXMLSensorsSection();
if( !snode )
throw SystemError(myname + "(init): Not found <sensors> section?!");
UniXML::iterator it(snode);
if( !it.goChildren() )
throw SystemError(myname + "(init): Section <sensors> empty?!");
for( ; it; it++ )
{
if( !UniSetTypes::check_filter(it, f_field, f_value) )
continue;
if( it.getProp("iotype") != "AI" )
continue;
slist.emplace(it.getIntProp("id"),0);
}
setMaxSizeOfMessageQueue(slist.size()*2+500);
smTestID = slist.begin()->first;
}
// -----------------------------------------------------------------------------
LostPassiveTestProc::~LostPassiveTestProc()
{
}
// -----------------------------------------------------------------------------
bool LostPassiveTestProc::emptyQueue()
{
return ( countMessages() == 0 );
}
// -----------------------------------------------------------------------------
long LostPassiveTestProc::checkValue( ObjectId sid )
{
std::lock_guard<std::mutex> lock(mut);
auto s = slist.find(sid);
if( s == slist.end() )
{
ostringstream err;
err << myname << "(checkValue): NOT FOUND?!! sensor ID=" << sid;
throw UniSetTypes::SystemError(err.str());
}
return s->second;
}
// -----------------------------------------------------------------------------
LostPassiveTestProc::LostPassiveTestProc()
{
cerr << ": init failed!!!!!!!!!!!!!!!" << endl;
throw UniSetTypes::Exception(myname+"(init): FAILED..");
}
// -----------------------------------------------------------------------------
void LostPassiveTestProc::askSensors(UniversalIO::UIOCommand cmd)
{
for( const auto& s: slist )
askSensor(s.first,cmd);
}
// -----------------------------------------------------------------------------
void LostPassiveTestProc::sensorInfo(const SensorMessage* sm)
{
std::lock_guard<std::mutex> lock(mut);
auto s = slist.find(sm->id);
if( s == slist.end() )
{
mycrit << myname << "(sensorInfo): ERROR: message from UNKNOWN SENSOR sm->id=" << sm->id << endl;
UniSetTypes::SimpleInfo_var i = getInfo();
mycrit << i->info << endl;
std::abort();
}
s->second = sm->value;
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
#ifndef LostPassiveTestProc_H_
#define LostPassiveTestProc_H_
// -----------------------------------------------------------------------------
#include <unordered_map>
#include "Debug.h"
#include "LostTestProc_SK.h"
// -----------------------------------------------------------------------------
/* Пассивный процесс, который только заказывает датчики, но не выставляет */
class LostPassiveTestProc:
public LostTestProc_SK
{
public:
LostPassiveTestProc( UniSetTypes::ObjectId id, xmlNode* confnode = UniSetTypes::uniset_conf()->getNode("LostPassiveTestProc") );
virtual ~LostPassiveTestProc();
bool emptyQueue();
long checkValue( UniSetTypes::ObjectId sid );
protected:
LostPassiveTestProc();
virtual void askSensors( UniversalIO::UIOCommand cmd ) override;
virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override;
std::mutex mut;
std::unordered_map<UniSetTypes::ObjectId,long> slist;
private:
};
// -----------------------------------------------------------------------------
#endif // LostPassiveTestProc_H_
// -----------------------------------------------------------------------------
......@@ -6,36 +6,8 @@ using namespace std;
using namespace UniSetTypes;
// -----------------------------------------------------------------------------
LostTestProc::LostTestProc( UniSetTypes::ObjectId id, xmlNode* confnode ):
LostTestProc_SK( id, confnode )
LostPassiveTestProc( id, confnode )
{
auto conf = uniset_conf();
UniXML::iterator cit(confnode);
string f_field = conf->getArgParam("--" + argprefix + "filter-field", cit.getProp("filterField"));
string f_value = conf->getArgParam("--" + argprefix + "filter-value", cit.getProp("filterValue"));
xmlNode* snode = conf->getXMLSensorsSection();
if( !snode )
throw SystemError(myname + "(init): Not found <sensors> section?!");
UniXML::iterator it(snode);
if( !it.goChildren() )
throw SystemError(myname + "(init): Section <sensors> empty?!");
for( ; it; it++ )
{
if( !UniSetTypes::check_filter(it, f_field, f_value) )
continue;
if( it.getProp("iotype") != "AI" )
continue;
slist.emplace(it.getIntProp("id"),0);
}
setMaxSizeOfMessageQueue(slist.size()+500);
vmonit(ncycle);
vmonit(waitEmpty);
}
......@@ -44,6 +16,11 @@ LostTestProc::~LostTestProc()
{
}
// -----------------------------------------------------------------------------
void LostTestProc::setChildPassiveProc( const std::shared_ptr<LostPassiveTestProc>& lp )
{
child = lp;
}
// -----------------------------------------------------------------------------
LostTestProc::LostTestProc()
{
cerr << ": init failed!!!!!!!!!!!!!!!" << endl;
......@@ -73,26 +50,6 @@ void LostTestProc::sysCommand( const UniSetTypes::SystemMessage* sm )
}
}
// -----------------------------------------------------------------------------
void LostTestProc::askSensors(UniversalIO::UIOCommand cmd)
{
for( const auto& s: slist )
askSensor(s.first,cmd);
}
// -----------------------------------------------------------------------------
void LostTestProc::sensorInfo(const SensorMessage* sm)
{
auto s = slist.find(sm->id);
if( s == slist.end() )
{
mycrit << myname << "(sensorInfo): ERROR: message from UNKNOWN SENSOR sm->id=" << sm->id << endl;
UniSetTypes::SimpleInfo_var i = getInfo();
mycrit << i->info << endl;
std::abort();
}
s->second = sm->value;
}
// -----------------------------------------------------------------------------
string LostTestProc::getMonitInfo()
{
ostringstream inf;
......@@ -104,16 +61,23 @@ void LostTestProc::timerInfo( const TimerMessage* tm )
{
if( tm->id == tmCheck )
{
if( countMessages() > 0 )
if( countMessages() > 0 )
{
mylog1 << myname << ": [WAIT]: count of messages " << countMessages() << endl;
waitEmpty = true;
return;
}
if( child && !child->emptyQueue() )
{
mylog1 << myname << ": [WAIT]: wait empty queue for " << child->getName() << endl;
waitEmpty = true;
return;
}
waitEmpty = false;
myinfo << myname << ": [OK]: empty queue. UPDATE VALUE... " << endl;
myinfo << myname << ": [OK]: empty queue. CHECK VALUE... " << endl;
for( auto&& s: slist )
{
try
......@@ -121,19 +85,57 @@ void LostTestProc::timerInfo( const TimerMessage* tm )
long smValue = ui->getValue(s.first);
if( smValue != s.second )
{
cerr << myname << "(check): ERROR!! smValue=" << smValue << " != " << s.second << endl;
cerr << myname << "(check): ERROR!! sid=" << s.first << " smValue=" << smValue << " != " << s.second << endl;
UniSetTypes::SimpleInfo_var i = getInfo();
cerr << i->info << endl;
std::abort();
}
// cerr << "sm_value=" << smValue << " save " << (in_sensor_s+1) << endl;
if( child )
{
long childValue = child->checkValue(s.first);
if( smValue != childValue )
{
cerr << myname << "(check): ERROR!! sid=" << s.first << " smValue=" << smValue << " != " << childValue
<< " FOR CHILD: " << child->getName()
<< endl;
UniSetTypes::SimpleInfo_var i = getInfo();
cerr << i->info << endl;
cerr << "=============== CHILD INFO: ==============" << endl;
UniSetTypes::SimpleInfo_var i2 = child->getInfo();
cerr << i2->info << endl;
// cerr << "JSON: " << endl;
// Poco::URI::QueryParameters p;
// auto j = httpGet(p);
// cerr << j.dump() << endl;
// cerr << "-------------------------" << endl;
// auto j2 = child->httpGet(p);
// cerr << j2.dump() << endl;
std::abort();
}
}
}
catch( std::exception& ex )
{
mycrit << myname << "(check): " << ex.what() << endl;
}
}
myinfo << myname << ": [OK]: UPDATE VALUE... " << endl;
for( auto&& s: slist )
{
try
{
// Выставляем новое значение
ui->setValue(s.first, s.second+1);
// проверяем что сохранилось
smValue = ui->getValue(s.first);
long smValue = ui->getValue(s.first);
if(ui->getValue(s.first) != (s.second+1) )
{
......
......@@ -4,18 +4,22 @@
// -----------------------------------------------------------------------------
#include <unordered_map>
#include "Debug.h"
#include "LostTestProc_SK.h"
#include "LostPassiveTestProc.h"
// -----------------------------------------------------------------------------
/* Цель: поймать расхождение значения в SM и в in_-переменной в процессе.
* Тест: Каждые checkTime проверяем текущее значение в SM и в процессе, меняем в SM и опять проверяем.
*
* Заодно если инициализирован child то проверяем что у него тоже все входы совпадают со значениями в SM.
*/
class LostTestProc:
public LostTestProc_SK
public LostPassiveTestProc
{
public:
LostTestProc( UniSetTypes::ObjectId id, xmlNode* confnode = UniSetTypes::uniset_conf()->getNode("LostTestProc") );
virtual ~LostTestProc();
void setChildPassiveProc( const std::shared_ptr<LostPassiveTestProc>& lp );
protected:
LostTestProc();
......@@ -26,14 +30,13 @@ class LostTestProc:
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override;
virtual void sysCommand( const UniSetTypes::SystemMessage* sm ) override;
virtual void askSensors( UniversalIO::UIOCommand cmd ) override;
virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override;
virtual std::string getMonitInfo() override;
std::unordered_map<UniSetTypes::ObjectId,long> slist;
size_t ncycle = { 0 };
bool waitEmpty = { false };
std::shared_ptr<LostPassiveTestProc> child;
private:
};
// -----------------------------------------------------------------------------
......
......@@ -25,7 +25,7 @@ sm_lostmessage_test_CPPFLAGS = -I$(top_builddir)/include \
-I$(top_builddir)/extensions/include \
-I$(top_builddir)/extensions/SharedMemory \
$(SIGC_CFLAGS) $(POCO_CFLAGS)
sm_lostmessage_test_SOURCES = LostTestProc_SK.cc LostTestProc.cc sm-lostmessage-test.cc
sm_lostmessage_test_SOURCES = LostTestProc_SK.cc LostTestProc.cc LostPassiveTestProc.cc sm-lostmessage-test.cc
clean-local:
......
<?xml version="1.0" encoding="utf-8"?>
<!--
name - название класса
msgcount - сколько сообщений обрабатывается за один раз
sleep_msec - пауза между итерациями в работе процесса
type
====
in - входные регистры (только для чтения)
out - выходные регистры (запись)
-->
<LostTestProc>
<settings>
<set name="class-name" val="LostTestProc"/>
<set name="msg-count" val="30"/>
<set name="sleep-msec" val="150"/>
</settings>
<variables>
<item name="checkTime" type="int" default="200" min="0" comment="check Working time" const="1" public="1" />
</variables>
<smap>
</smap>
<msgmap>
</msgmap>
</LostTestProc>
......@@ -25,6 +25,14 @@ int main(int argc, const char** argv)
int num = conf->getArgPInt("--numproc", 1);
int max = 10;
if( num > max )
{
cerr << "'num' must be < " << max << endl;
return 1;
}
for( int i = 1; i <= num; i++ )
{
ostringstream s;
......@@ -32,8 +40,15 @@ int main(int argc, const char** argv)
cout << "..create " << s.str() << endl;
auto tp = make_shared<LostTestProc>( conf->getObjectID(s.str()));
// tp->init_dlog(dlog());
act->add(tp);
ostringstream sp;
sp << "TestProc" << (i+max);
cout << "..create passive " << sp.str() << endl;
auto child = make_shared<LostPassiveTestProc>( conf->getObjectID(sp.str()));
tp->setChildPassiveProc(child);
act->add(child);
}
SystemMessage sm(SystemMessage::StartUp);
......
......@@ -18,6 +18,18 @@ ${START} -f ./sm-lostmessage-test --confile ./test-lost.xml \
--TestProc3-filter-value 3 \
--TestProc3-sleep-msec 50 \
--TestProc3-log-add-levels $LOGLEVEL \
--TestProc11-filter-field losttest \
--TestProc11-filter-value 1 \
--TestProc11-sleep-msec 50 \
--TestProc11-log-add-levels $LOGLEVEL \
--TestProc12-filter-field losttest \
--TestProc12-filter-value 2 \
--TestProc12-sleep-msec 50 \
--TestProc12-log-add-levels $LOGLEVEL \
--TestProc13-filter-field losttest \
--TestProc13-filter-value 3 \
--TestProc13-sleep-msec 50 \
--TestProc13-log-add-levels $LOGLEVEL \
--ulog-add-levels crit $*
# --uniset-abort-script ./abort-script-example.sh
#--ulog-add-levels crit,warn,info
......
......@@ -194,6 +194,8 @@ extensions/tests/SMemoryTest/TestProc.h
extensions/tests/SMemoryTest/testproc.src.xml
extensions/tests/SMemoryTest/LostTestProc.cc
extensions/tests/SMemoryTest/LostTestProc.h
extensions/tests/SMemoryTest/LostPassiveTestProc.cc
extensions/tests/SMemoryTest/LostPassiveTestProc.h
extensions/tests/SMemoryTest/losttestproc.src.xml
extensions/tests/SMemoryTest/sm-lostmessage-test.cc
extensions/tests/SMemoryTest/Makefile.am
......
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