Fixed concurrent tests
git-svn-id: svn://db.shs.com.ru/pip@892 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -1,7 +1,3 @@
|
|||||||
//
|
|
||||||
// Created by fomenko on 23.09.2019.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "piblockingdequeue.h"
|
#include "piblockingdequeue.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
//
|
|
||||||
// Created by fomenko on 26.09.2019.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
|
|
||||||
@@ -16,27 +12,27 @@ public:
|
|||||||
|
|
||||||
TEST_F(ConditionLock, lock_is_protect) {
|
TEST_F(ConditionLock, lock_is_protect) {
|
||||||
m->lock();
|
m->lock();
|
||||||
bool isProtect = true;
|
bool* isProtect = new bool(true);
|
||||||
|
|
||||||
createThread([&](){
|
createThread([&](){
|
||||||
m->lock();
|
m->lock();
|
||||||
isProtect = false;
|
*isProtect = false;
|
||||||
});
|
});
|
||||||
ASSERT_TRUE(isProtect);
|
EXPECT_FALSE(thread->waitForFinish(WAIT_THREAD_TIME_MS));
|
||||||
|
ASSERT_TRUE(*isProtect);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ConditionLock, unlock_is_release) {
|
TEST_F(ConditionLock, unlock_is_release) {
|
||||||
m->lock();
|
m->lock();
|
||||||
volatile bool isReleased = false;
|
bool* isReleased = new bool(false);
|
||||||
m->unlock();
|
m->unlock();
|
||||||
|
|
||||||
createThread([&](){
|
createThread([&](){
|
||||||
m->lock();
|
m->lock();
|
||||||
isReleased = true;
|
*isReleased = true;
|
||||||
m->unlock();
|
m->unlock();
|
||||||
});
|
});
|
||||||
EXPECT_TRUE(thread->waitForFinish(WAIT_THREAD_TIME_MS));
|
ASSERT_TRUE(*isReleased);
|
||||||
ASSERT_TRUE(isReleased);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ConditionLock, tryLock_is_false_when_locked) {
|
TEST_F(ConditionLock, tryLock_is_false_when_locked) {
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
//
|
|
||||||
// Created by fomenko on 24.09.2019.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "piconditionvar.h"
|
#include "piconditionvar.h"
|
||||||
#include "pithread.h"
|
#include "pithread.h"
|
||||||
@@ -14,10 +10,8 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
isRunning = false;
|
|
||||||
variable = new PIConditionVariable();
|
variable = new PIConditionVariable();
|
||||||
adapterFunctionDefault = [&](){
|
adapterFunctionDefault = [&](){
|
||||||
isRunning = true;
|
|
||||||
m.lock();
|
m.lock();
|
||||||
variable->wait(m);
|
variable->wait(m);
|
||||||
m.unlock();
|
m.unlock();
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
//
|
|
||||||
// Created by fomenko on 24.09.2019.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "executor.h"
|
#include "executor.h"
|
||||||
#include "pimutex.h"
|
#include "pimutex.h"
|
||||||
@@ -51,8 +47,8 @@ TEST(ExcutorIntegrationTest, execute_is_awaitTermination_wait) {
|
|||||||
});
|
});
|
||||||
executorService.shutdown();
|
executorService.shutdown();
|
||||||
PITimeMeasurer measurer;
|
PITimeMeasurer measurer;
|
||||||
ASSERT_TRUE(executorService.awaitTermination(4 * WAIT_THREAD_TIME_MS));
|
ASSERT_TRUE(executorService.awaitTermination(3 * WAIT_THREAD_TIME_MS));
|
||||||
double waitTime = measurer.elapsed_m();
|
double waitTime = measurer.elapsed_m();
|
||||||
ASSERT_GE(waitTime, WAIT_THREAD_TIME_MS);
|
ASSERT_GE(waitTime, WAIT_THREAD_TIME_MS);
|
||||||
ASSERT_LE(waitTime, 3 * WAIT_THREAD_TIME_MS);
|
ASSERT_LE(waitTime, 4 * WAIT_THREAD_TIME_MS);
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,3 @@
|
|||||||
//
|
|
||||||
// Created by fomenko on 27.09.2019.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef AWRCANFLASHER_TESTUTIL_H
|
#ifndef AWRCANFLASHER_TESTUTIL_H
|
||||||
#define AWRCANFLASHER_TESTUTIL_H
|
#define AWRCANFLASHER_TESTUTIL_H
|
||||||
|
|
||||||
@@ -20,13 +16,16 @@ PIOBJECT(TestUtil)
|
|||||||
public:
|
public:
|
||||||
double threadStartTime;
|
double threadStartTime;
|
||||||
PIThread* thread = new PIThread();
|
PIThread* thread = new PIThread();
|
||||||
volatile bool isRunning;
|
volatile bool isRunning = false;
|
||||||
std::function<void()> adapterFunctionDefault;
|
std::function<void()> adapterFunctionDefault;
|
||||||
|
|
||||||
bool createThread(const std::function<void()>& fun = nullptr, PIThread* thread_ = nullptr) {
|
bool createThread(const std::function<void()>& fun = nullptr, PIThread* thread_ = nullptr) {
|
||||||
std::function<void()> actualFun = fun == nullptr ? adapterFunctionDefault : fun;
|
std::function<void()> actualFun = fun == nullptr ? adapterFunctionDefault : fun;
|
||||||
if (thread_ == nullptr) thread_ = thread;
|
if (thread_ == nullptr) thread_ = thread;
|
||||||
thread_->startOnce([=](void*){ actualFun(); });
|
thread_->startOnce([=](void*){
|
||||||
|
isRunning = true;
|
||||||
|
actualFun();
|
||||||
|
});
|
||||||
return waitThread(thread_);
|
return waitThread(thread_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +35,7 @@ public:
|
|||||||
while (!isRunning) {
|
while (!isRunning) {
|
||||||
isTimeout = WAIT_THREAD_TIME_MS <= measurer.elapsed_m();
|
isTimeout = WAIT_THREAD_TIME_MS <= measurer.elapsed_m();
|
||||||
if (isTimeout) break;
|
if (isTimeout) break;
|
||||||
piMSleep(1);
|
piUSleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
threadStartTime = measurer.elapsed_m();
|
threadStartTime = measurer.elapsed_m();
|
||||||
|
|||||||
Reference in New Issue
Block a user