#include <dpl/shared_object.h>
#include <dpl/shared_property.h>
#include <memory>
+#include <mutex>
RUNNER_TEST_GROUP_INIT(DPL)
void Wait(DPL::WaitableEvent& event, bool expectedTimeout = false)
{
- LogDebug("WaitForSingleHandle...");
+ WrtLogD("WaitForSingleHandle...");
DPL::WaitableHandleIndexList list = DPL::WaitForSingleHandle(
event.GetHandle(),
expectedTimeout ?
EXPECTED_WAITABLE_TIMEOUT : UNEXPECTED_WAITABLE_TIMEOUT);
if (list.size() == 0) {
- LogDebug("...timeout.");
+ WrtLogD("...timeout.");
} else {
- LogDebug("...signaled.");
+ WrtLogD("...signaled.");
event.Reset();
}
OnEvent(event);
m_waitable->Signal();
} else if (event == DESTROY_EVENT) {
- LogDebug("Destroying shared object");
+ WrtLogD("Destroying shared object");
OnEvent(event);
// deregister, destroy ad notify main thread
m_so.Reset();
- LogDebug("4");
+ WrtLogD("4");
m_waitable->Signal();
- LogDebug("5");
+ WrtLogD("5");
} else {
OnEvent(event);
}
~TestSharedObject4()
{
- LogDebug("dtor");
+ WrtLogD("dtor");
}
protected:
void EnumTestSO1::PropertyChanged(size_t propertyEnum)
{
if (propertyEnum == 1) {
- LogDebug("Property enum " << propertyEnum << " correctly set");
+ WrtLogD("Property enum %i correctly set", propertyEnum);
g_enumTestCorrect = true;
}
if (propertyEnum == 4) {
// This is bad. We only have 4 types
- LogError("Property enum " << propertyEnum << " should be skipped");
+ WrtLogE("Property enum %i should be skipped", propertyEnum);
g_enumTestIncorrect = true;
}
// confirm property change notification
// create listening controller and wait until it registers
EnumController controller(&waitable);
Wait(waitable);
- LogDebug("Listening controller created");
+ WrtLogD("Listening controller created");
// create writing shared object
std::shared_ptr<EnumTestSO2> sho2 =
m_so = SharedObjectFactory<MultiThreadSO>::Create(SHM_KEY, SEM_NAME);
PostEvent(2);
} else if (event == DESTROY_EVENT) {
- LogDebug("Destroying shared object");
+ WrtLogD("Destroying shared object");
// deregister, destroy ad notify main thread
m_so.Reset();
m_waitable->Signal();
m_so->TestAndSetProperty();
m_counter++;
if (m_counter >= TEST_AND_SET_REPEATS) {
- LogDebug("Max tests reached. Finishing thread");
+ WrtLogD("Max tests reached. Finishing thread");
PostEvent(DESTROY_EVENT);
return;
}
}
int value = sho->GetProperty<0, int>();
- LogDebug("Final value is " << value << ", expected " <<
- MAX_THREADS * TEST_AND_SET_REPEATS);
+ WrtLogD("Final value is %i, expected %i",
+ value, MAX_THREADS * TEST_AND_SET_REPEATS);
RUNNER_ASSERT(value == MAX_THREADS * TEST_AND_SET_REPEATS);
}
// change back
m_model->boolValue.Set(false);
} else {
- LogError("Expected value = true, got false");
+ WrtLogE("Expected value = true, got false");
}
m_waitable->Signal();
return;
}
- LogDebug("[1] Value changed to " << event.value);
+ WrtLogD("[1] Value changed to %s", event.value);
m_repeats++;
m_model1->counter.Set(event.value + 1);
}
return;
}
- LogDebug("[2] Value changed to " << event.value);
+ WrtLogD("[2] Value changed to %i", event.value);
m_repeats++;
m_model2->counter.Set(event.value + 1);
}
int value = sho->GetProperty<0, int>();
- LogDebug("final value: " << value);
+ WrtLogD("final value: %i", value);
// check value
RUNNER_ASSERT(value == SINGLE_PROCESS_REPEATS);
const int& value,
const void* /*info*/)
{
- LogDebug("ValueChanged(int) " << propertyEnum << " " << value);
+ WrtLogD("ValueChanged(int) %u %i", propertyEnum, value);
if ((propertyEnum == 0 &&
value == 1) || (propertyEnum == 1 && value == 2))
{
const char& value,
const void* /*info*/)
{
- LogDebug("ValueChanged(char) " << propertyEnum << " " << value);
+ WrtLogD("ValueChanged(char) %u %i", propertyEnum, value);
if (propertyEnum == 2 && value == 'c') {
g_values[propertyEnum]++;
if (g_values[propertyEnum] == 3) {
const int(&value)[64],
const void* /*info*/)
{
- LogDebug("ValueChanged(int[64]) " << propertyEnum << " " << value[5]);
+ WrtLogD("ValueChanged(int[64]) %u %i", propertyEnum, value[5]);
if (propertyEnum == 3 && value[5] == 5) {
g_values[propertyEnum]++;
if (g_values[propertyEnum] == 3) {
bool SetCondition(const int& readValue, int& setValue);
bool SetCondition(const int& readValue, int& setValue)
{
- LogDebug("Condition delegate called with read value = " << readValue <<
- " and set value = " << setValue);
+ WrtLogD("Condition delegate called with read value = %i and set value = %i",
+ readValue, setValue);
if (readValue > 3) {
- LogDebug("Condition is false");
+ WrtLogD("Condition is false");
return false;
}
- LogDebug("Condition is true");
+ WrtLogD("Condition is true");
if (4 == setValue) {
setValue = 10;
- LogDebug("Changing set value to " << setValue);
+ WrtLogD("Changing set value to %i", setValue);
}
return true;
}
void SetDelegate(const int& readValue);
void SetDelegate(const int& readValue)
{
- LogDebug("Set delegate called " << readValue);
+ WrtLogD("Set delegate called %i", readValue);
g_delegateCalls++;
}
private:
static MTSharedObjectPtr m_sho;
- static DPL::Mutex m_mutex;
+ static std::mutex m_mutex;
};
MTSharedObjectPtr SharedObjectSingleton::m_sho;
-DPL::Mutex SharedObjectSingleton::m_mutex;
+std::mutex SharedObjectSingleton::m_mutex;
MTSharedObjectPtr SharedObjectSingleton::Instance()
{
- DPL::Mutex::ScopedLock lock(&m_mutex);
+ std::lock_guard<std::mutex> lock(m_mutex);
if (!m_sho) {
m_sho = SharedObjectFactory<MTSharedObject>::Create(SHM_KEY, SEM_NAME);
}
void SharedObjectSingleton::Destroy()
{
- DPL::Mutex::ScopedLock lock(&m_mutex);
+ std::lock_guard<std::mutex> lock(m_mutex);
m_sho.Reset();
}
const int& value,
const void* /*info*/)
{
- LogDebug("ValueChanged(int) " << propertyEnum << " " << value);
+ WrtLogD("ValueChanged(int) %u %i", propertyEnum, value);
if ((propertyEnum == 0 && value == 1) ||
(propertyEnum == 1 && value == 11))
{
const char& value,
const void* /*info*/)
{
- LogDebug("ValueChanged(char) " << propertyEnum << " " << value);
+ WrtLogD("ValueChanged(char) %u %i", propertyEnum, value);
if (propertyEnum == 2 && value == 'a') {
m_waitable->Signal();
}
const int(&value)[64],
const void* /*info*/)
{
- LogDebug("ValueChanged(int[64]) " << propertyEnum << " " << value[5]);
+ WrtLogD("ValueChanged(int[64]) %u %i", propertyEnum, value[5]);
if (propertyEnum == 3 && value[0] == 0 && value[1] == 1 && value[2] == 2) {
m_waitable->Signal();
}
break;
case DESTROY_EVENT:
- LogDebug("Destroying shared object");
+ WrtLogD("Destroying shared object");
// deregister, destroy and notify main thread
m_so.Reset();
m_waitable->Signal();
break;
default:
- LogError("Unsupported event received: " << event);
+ WrtLogE("Unsupported event received: %i", event);
}
}
#define LISTENER_ASSERT(property) \
Try { \
singleton->RemoveListener<(property)>(controller[i]); \
- LogError("Controller " << i << " is still listening for property " \
- << #property); \
+ WrtLogE("Controller %i is still listening for property %s" \
+ i, #property); \
RUNNER_ASSERT_MSG(false, "No listeners expected"); \
} \
Catch(MTSharedObject::Exception::ListenerNotFound) { \
// Create and wait for notification. Make sure that the thread/controller 0
// is created first
- LogDebug("Creating controllers");
+ WrtLogD("Creating controllers");
for (size_t i = 0; i < MAX_THREADS; ++i) {
controller[i] = new ShmController4(&waitable[i]);
Wait(waitable[i]);
MTSharedObjectPtr singleton = SharedObjectSingleton::Instance();
for (size_t repeats = 0; repeats < SINGLETON_TEST_REPEATS; ++repeats) {
- LogDebug("%%%%%%%%%%%%%%%%%%%%%");
- LogDebug("Iteration " << repeats + 1 << " of " << SINGLETON_TEST_REPEATS);
+ WrtLogD("%%%%%%%%%%%%%%%%%%%%%");
+ WrtLogD("Iteration %u of %u", repeats + 1, SINGLETON_TEST_REPEATS);
singleton->Clear();
// add listeners
- LogDebug("Adding listeners");
+ WrtLogD("Adding listeners");
for (size_t i = 0; i < MAX_THREADS; ++i) {
controller[i]->PostEvent(ShmController4::ADD_LISTENERS);
}
RUNNER_ASSERT(checkArray[2] == 0);
// change
- LogDebug("Setting property 0");
+ WrtLogD("Setting property 0");
sho->SetProperty<0>(1);
// wait for confirmations
MultipleWait(waitable);
// change
- LogDebug("Setting property 1");
+ WrtLogD("Setting property 1");
sho->SetProperty<1>(11);
// wait for confirmations
MultipleWait(waitable);
// change
- LogDebug("Setting property 2");
+ WrtLogD("Setting property 2");
sho->SetProperty<2>('a');
// wait for confirmations
MultipleWait(waitable);
// change
- LogDebug("Setting property 3");
+ WrtLogD("Setting property 3");
sho->SetProperty<3>(array);
// wait for confirmations
MultipleWait(waitable);
// remove listeners
- LogDebug("Removing listeners");
+ WrtLogD("Removing listeners");
for (size_t i = 0; i < MAX_THREADS; ++i) {
controller[i]->PostEvent(ShmController4::REMOVE_LISTENERS);
}
MultipleWait(waitable);
// check if listeners array is empty
- LogDebug("Checking listeners");
+ WrtLogD("Checking listeners");
for (size_t i = 0; i < MAX_THREADS; ++i) {
LISTENER_ASSERT(0);
LISTENER_ASSERT(1);
// Destroy controllers and wait for confirmation. Make sure that
// thread/controller 0 is destroyed in the end
- LogDebug("Destroying controllers");
+ WrtLogD("Destroying controllers");
for (int i = MAX_THREADS - 1; i >= 0; --i) {
controller[i]->PostEvent(DESTROY_EVENT);
Wait(waitable[i]);
* This is to properly close all waitable handles opened by
* SharedObject in thread 0.
*/
- LogDebug("Destroying singleton");
+ WrtLogD("Destroying singleton");
controller[i]->PostEvent(ShmController4::DESTROY_SINGLETON);
Wait(waitable[i]);
}