Commit 3338255d authored by Pavel Vainerman's avatar Pavel Vainerman

(SM): добавил тест на проверку отсутствия потери сообщений SensorMessage

и на отсутствие их перемешивания.
parent dc4e5d6c
...@@ -10,7 +10,7 @@ TestObject_SK.cc TestObject_SK.h: testobject.src.xml ...@@ -10,7 +10,7 @@ TestObject_SK.cc TestObject_SK.h: testobject.src.xml
tests_SOURCES = TestObject_SK.cc NullSM.cc TestObject.cc test_sm.cc tests.cc tests_SOURCES = TestObject_SK.cc NullSM.cc TestObject.cc test_sm.cc tests.cc
tests_LDADD = $(top_builddir)/lib/libUniSet2.la $(top_builddir)/extensions/lib/libUniSet2Extensions.la \ tests_LDADD = $(top_builddir)/lib/libUniSet2.la $(top_builddir)/extensions/lib/libUniSet2Extensions.la \
$(top_builddir)/extensions/SharedMemory/libUniSet2SharedMemory.la \ $(top_builddir)/extensions/SharedMemory/libUniSet2SharedMemory.la \
$(SIGC_LIBS) $(POCO_LIBS) $(SIGC_LIBS) $(POCO_LIBS) -lpthread
tests_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions/include \ tests_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions/include \
-I$(top_builddir)/extensions/SharedMemory $(SIGC_CFLAGS) $(POCO_CFLAGS) -I$(top_builddir)/extensions/SharedMemory $(SIGC_CFLAGS) $(POCO_CFLAGS)
......
...@@ -36,6 +36,26 @@ void TestObject::sysCommand( const uniset::SystemMessage* sm ) ...@@ -36,6 +36,26 @@ void TestObject::sysCommand( const uniset::SystemMessage* sm )
evntIsOK = true; evntIsOK = true;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void TestObject::sensorInfo( const SensorMessage* sm )
{
if( sm->id == monotonic_s )
{
if( (sm->value - lastValue) < 0 )
monitonicFailed = true;
if( (sm->value - lastValue) > 1 )
{
cerr << "LOST: sm->value=" << sm->value << " last=" << lastValue
<< " lost: " << (sm->value - lastValue)
<< endl;
lostMessages = true;
}
lastValue = sm->value;
}
}
// -----------------------------------------------------------------------------
void TestObject::stopHeartbeat() void TestObject::stopHeartbeat()
{ {
maxHeartBeat = 0; maxHeartBeat = 0;
...@@ -46,3 +66,40 @@ void TestObject::runHeartbeat( int max ) ...@@ -46,3 +66,40 @@ void TestObject::runHeartbeat( int max )
maxHeartBeat = max; maxHeartBeat = max;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void TestObject::askMonotonic()
{
askSensor(monotonic_s, UniversalIO::UIONotify);
}
// -----------------------------------------------------------------------------
void TestObject::startMonitonicTest()
{
monitonicFailed = false;
lostMessages = false;
lastValue = in_monotonic_s;
}
// -----------------------------------------------------------------------------
bool TestObject::isMonotonicTestOK() const
{
return !monitonicFailed;
}
// -----------------------------------------------------------------------------
bool TestObject::isLostMessages() const
{
return lostMessages;
}
long TestObject::getLastValue() const
{
return lastValue;
}
bool TestObject::isEmptyQueue()
{
return ( countMessages() == 0 );
}
bool TestObject::isFullQueue()
{
return (getCountOfLostMessages() > 0);
}
// -----------------------------------------------------------------------------
...@@ -27,13 +27,28 @@ class TestObject: ...@@ -27,13 +27,28 @@ class TestObject:
return ptHeartBeat.getInterval(); return ptHeartBeat.getInterval();
} }
// тест на последовательность SensorMessage
void askMonotonic();
void startMonitonicTest();
bool isMonotonicTestOK() const;
bool isLostMessages() const;
long getLastValue() const;
bool isEmptyQueue();
bool isFullQueue();
protected: protected:
TestObject(); TestObject();
virtual void sysCommand( const uniset::SystemMessage* sm ) override; virtual void sysCommand( const uniset::SystemMessage* sm ) override;
virtual void sensorInfo( const uniset::SensorMessage* sm ) override;
private: private:
bool evntIsOK = { false }; bool evntIsOK = { false };
bool monitonicFailed = { false };
bool lostMessages = { false };
long lastValue = { 0 };
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#endif // _TestObject_H_ #endif // _TestObject_H_
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
<item node="localhost" name="ReservSharedMemory"/> <item node="localhost" name="ReservSharedMemory"/>
</ReservList> </ReservList>
</SharedMemory> </SharedMemory>
<TestObject name="TestObject" sensor_s="DI2_S" output_c="AO2_C" dependDI_s="DependDI_S" dependAI_s="DependAI_S" heartbeat_id="TO_Heartbeat_Counter" heartbeatTime="500" heartbeat_max="5"/> <TestObject name="TestObject" sensor_s="DI2_S" output_c="AO2_C" dependDI_s="DependDI_S" dependAI_s="DependAI_S" monotonic_s="MonotonicAI_S" heartbeat_id="TO_Heartbeat_Counter" heartbeatTime="500" heartbeat_max="5"/>
</settings> </settings>
<ObjectsMap idfromfile="1"> <ObjectsMap idfromfile="1">
<nodes port="2809" unet_broadcast_ip="192.168.1.255" unet_broadcast_ip2="192.168.122.255"> <nodes port="2809" unet_broadcast_ip="192.168.1.255" unet_broadcast_ip2="192.168.122.255">
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
<item id="513" iotype="DI" name="DependDI_S" depend="Depend_BlockSensor_S" depend_value="0" depend_off_value="0" priority="Medium" textname="Depend DI sesnor"/> <item id="513" iotype="DI" name="DependDI_S" depend="Depend_BlockSensor_S" depend_value="0" depend_off_value="0" priority="Medium" textname="Depend DI sesnor"/>
<item id="514" iotype="DI" name="Depend_BlockSensor_S" priority="Medium" textname="Block Sensor for depend"/> <item id="514" iotype="DI" name="Depend_BlockSensor_S" priority="Medium" textname="Block Sensor for depend"/>
<item id="515" iotype="DI" name="Threshold2_S" priority="Medium" textname="Threshold 2"/> <item id="515" iotype="DI" name="Threshold2_S" priority="Medium" textname="Threshold 2"/>
<item id="516" iotype="AI" name="MonotonicAI_S" priority="Medium" textname="monitonic AI"/>
</sensors> </sensors>
<thresholds name="thresholds"> <thresholds name="thresholds">
<sensor name="AI1_AS"> <sensor name="AI1_AS">
......
#include <catch.hpp> #include <catch.hpp>
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <memory> #include <memory>
#include <future>
#include "UniSetTypes.h" #include "UniSetTypes.h"
#include "UInterface.h" #include "UInterface.h"
#include "DelayTimer.h"
#include "TestObject.h" #include "TestObject.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
using namespace std; using namespace std;
...@@ -256,3 +258,51 @@ TEST_CASE("[SM]: depend test", "[sm][depend]") ...@@ -256,3 +258,51 @@ TEST_CASE("[SM]: depend test", "[sm][depend]")
REQUIRE( obj->in_dependDI_s == 1 ); REQUIRE( obj->in_dependDI_s == 1 );
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TEST_CASE("[SM]: monitonic sensor message", "[sm][monitonic]")
{
InitTest();
// Проверка корректной последовательности прихода SensorMessage.
// Тест заключается в том, что параллельно вызывается setValue()
// и askSensors() и сообщения должны приходить в правильном порядке.
// Для проверки этого датчик монотонно увеличивается на +1
// сама проверка см. TestObject::sensorInfo()
auto conf = uniset_conf();
const long max = uniset::getArgInt("--monotonic-max-value", conf->getArgc(),conf->getArgv(),"1000");
auto&& write_worker = [&max]
{
try
{
for( long val=0; val<=max; val++ )
ui->setValue(516, val);
}
catch( std::exception& ex )
{
return false;
}
return true;
};
obj->startMonitonicTest();
// std::thread t(write_worker);
auto ret = std::async(std::launch::async, write_worker);
for( long n=0; n <= max; n++ )
obj->askMonotonic();
// t.join();
REQUIRE( ret.get() );
DelayTimer dt(2000,0);
while( !dt.check(obj->isEmptyQueue()) )
msleep(500);
REQUIRE( obj->isMonotonicTestOK() );
REQUIRE_FALSE( obj->isLostMessages() );
REQUIRE_FALSE( obj->isFullQueue() );
REQUIRE( obj->getLastValue() == max );
}
// -----------------------------------------------------------------------------
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<item name="output_c" vartype="out" iotype="AO" comment="Test output"/> <item name="output_c" vartype="out" iotype="AO" comment="Test output"/>
<item name="dependDI_s" vartype="in" iotype="DI" comment="Test input"/> <item name="dependDI_s" vartype="in" iotype="DI" comment="Test input"/>
<item name="dependAI_s" vartype="in" iotype="AI" comment="Test input"/> <item name="dependAI_s" vartype="in" iotype="AI" comment="Test input"/>
<item name="monotonic_s" vartype="in" iotype="AI" comment="Test analog input"/>
</smap> </smap>
<msgmap> <msgmap>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
./uniset2-start.sh -f ./tests $* -- --confile ./sm-configure.xml --pulsar-id Pulsar_S --pulsar-msec 1000 --e-filter evnt_test \ ./uniset2-start.sh -f ./tests $* -- --confile ./sm-configure.xml --pulsar-id Pulsar_S --pulsar-msec 1000 --e-filter evnt_test \
--heartbeat-node localhost --heartbeat-check-time 1000 --TestObject-startup-timeout 0 --heartbeat-node localhost --heartbeat-check-time 1000 --TestObject-startup-timeout 0 --uniset-object-size-message-queue 2000000
#--sm-log-add-levels any --ulog-add-levels level4,warn,crit \ #--sm-log-add-levels any --ulog-add-levels level4,warn,crit \
#--TestObject-log-add-levels any #--TestObject-log-add-levels any
#--dlog-add-levels any #--dlog-add-levels any
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