Commit 5a71c135 authored by Pavel Vainerman's avatar Pavel Vainerman

добавил тест быстродействия для SM

parent 23537ae4
SUBDIR=SMemoryTest SUBDIR=SMemoryTest
if HAVE_TESTS if HAVE_TESTS
noinst_PROGRAMS = tests tests_with_conf tests_with_sm noinst_PROGRAMS = tests tests_with_conf tests_with_sm sm_perf_test
tests_SOURCES = tests.cc test_digitalfilter.cc test_vtypes.cc tests_SOURCES = tests.cc test_digitalfilter.cc test_vtypes.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
...@@ -18,6 +18,13 @@ tests_with_sm_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions ...@@ -18,6 +18,13 @@ tests_with_sm_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions
-I$(top_builddir)/extensions/SharedMemory $(SIGC_CFLAGS) $(COMCPP_CFLAGS) -I$(top_builddir)/extensions/SharedMemory $(SIGC_CFLAGS) $(COMCPP_CFLAGS)
sm_perf_test_SOURCES = sm_perf_test.cc
sm_perf_test_LDADD = $(top_builddir)/lib/libUniSet2.la $(top_builddir)/extensions/lib/libUniSet2Extensions.la \
$(top_builddir)/extensions/SharedMemory/libUniSet2SharedMemory.la $(SIGC_LIBS) $(COMCPP_LIBS)
sm_perf_test_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 include $(top_builddir)/testsuite/testsuite-common.mk
check-local: atconfig package.m4 $(TESTSUITE) check-local: atconfig package.m4 $(TESTSUITE)
......
#include <memory>
#include <string>
#include "Debug.h"
#include "UniSetActivator.h"
#include "PassiveTimer.h"
#include "SharedMemory.h"
#include "SMInterface.h"
#include "Extensions.h"
// --------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
using namespace UniSetExtensions;
// --------------------------------------------------------------------------
static shared_ptr<SMInterface> smi;
static shared_ptr<SharedMemory> shm;
static shared_ptr<UInterface> ui;
static ObjectId myID = 6000;
// --------------------------------------------------------------------------
shared_ptr<SharedMemory> shmInstance()
{
if( !shm )
throw SystemError("SharedMemory don`t initialize..");
return shm;
}
// --------------------------------------------------------------------------
shared_ptr<SMInterface> smiInstance()
{
if( smi == nullptr )
{
if( shm == nullptr )
throw SystemError("SharedMemory don`t initialize..");
if( ui == nullptr )
ui = make_shared<UInterface>();
smi = make_shared<SMInterface>(shm->getId(), ui, myID, shm );
}
return smi;
}
// --------------------------------------------------------------------------
void run_test(std::size_t concurrency, int bound, shared_ptr<SharedMemory>& shm )
{
auto&& r_worker = [&shm,bound] {
int num = bound;
while (num--) {
int v = shm->getValue(11);
}
};
auto&& w_worker = [&shm,bound] {
int num = bound;
while (num--) {
shm->setValue(11,num);
}
};
std::vector<std::thread> threads;
for (std::size_t i = 0; i < concurrency-1; ++i) {
threads.emplace_back(r_worker);
}
threads.emplace_back(w_worker);
for (auto&& thread : threads) {
thread.join();
}
}
// --------------------------------------------------------------------------
int main(int argc, char* argv[] )
{
try
{
auto conf = uniset_init(argc,argv);
shm = SharedMemory::init_smemory(argc, argv);
if( !shm )
return 1;
auto act = UniSetActivator::Instance();
act->add(shm);
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;
}
run_test(8, 1000000,shm);
return 0;
}
catch( const SystemError& err )
{
cerr << "(tests_with_sm): " << err << endl;
}
catch( const Exception& ex )
{
cerr << "(tests_with_sm): " << ex << endl;
}
catch( const std::exception& e )
{
cerr << "(tests_with_sm): " << e.what() << endl;
}
catch(...)
{
cerr << "(tests_with_sm): catch(...)" << endl;
}
return 1;
}
#!/bin/sh
# '--' - нужен для отделения аргументов catch, от наших..
cd ../../Utilities/Admin/
./create_links.sh
./uniset2-start.sh -f ./create
./uniset2-start.sh -f ./exist | grep -q UNISET_PLC/Controllers || exit 1
cd -
time -p ./uniset2-start.sh -f ./sm_perf_test $* --confile tests_with_sm.xml --e-startup-pause 10
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