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

Добавил тесты для проверки "производительности" (SM)

parent e2cbeb0b
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--) {
shm->getValue(11);
}
};
auto&& w_worker = [&shm,bound] {
int num = bound;
while (num--) {
shm->setValue(11,123);
}
};
std::vector<std::thread> threads;
for (std::size_t i = 0; i < concurrency; ++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
#include <map>
#include <unordered_map>
#include <vector>
#include <iostream>
#include <iomanip>
#include "Configuration.h"
using namespace std;
std::map< UniSetTypes::ObjectId, int > std_m;
std::unordered_map< UniSetTypes::ObjectId, int > std_un;
std::vector< UniSetTypes::ObjectId > values;
const int N = 10000000;
int main( int argc, char* argv[] )
{
auto conf = UniSetTypes::uniset_init(argc,argv);
auto ind = conf->oind;
int t1, t2;
for ( int i = 0; i < N; i++ )
values.push_back( rand() * rand() );
#if 0
std::cout << "insert:" << std::endl;
for ( int k = 0; k < 5; k++ ) {
t1 = clock();
for ( int i = 0; i < N; i++ )
std_m[ values[ i ] ] = i;
t2 = clock();
std::cout << "std : " << std::setw( 8 ) << (t2 - t1) / (double)CLOCKS_PER_SEC * 1000 << " ms." << std::endl;
}
for ( int k = 0; k < 5; k++ ) {
t1 = clock();
for ( int i = 0; i < N; i++ )
std_un[ values[ i ] ] = i;
t2 = clock();
std::cout << "std_un: " << std::setw( 8 ) << (t2 - t1) / (double)CLOCKS_PER_SEC * 1000 << " ms." << std::endl;
}
#endif
std::cout << "find:" << std::endl;
{
t1 = clock();
for ( int k = 0; k < N; k++ )
{
auto v = std_m.find( rand() );
}
t2 = clock();
std::cout << "std : " << std::setw( 8 ) << (t2 - t1) / (double)CLOCKS_PER_SEC * 1000 << " ms." << std::endl;
}
{
t1 = clock();
for ( int k = 0; k < N; k++ )
{
auto v = std_un.find( rand() );
}
t2 = clock();
std::cout << "std_un: " << std::setw( 8 ) << (t2 - t1) / (double)CLOCKS_PER_SEC * 1000 << " ms." << std::endl;
}
return 0;
}
#!/bin/sh
# '--' - нужен для отделения аоргументов catch, от наших..
./perf_test $* -- --confile tests_with_conf.xml --prop-id2 -10 --ulog-no-debug && exit 0 || exit 1
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