int main()
{
  {
    m.lock();
    boost::thread t(f1);
    time_point t2 = Clock::now();
    boost::this_thread::sleep_for(ms(250));
    time_point t3 = Clock::now();
    m.unlock();
    t.join();

    ns sleep_time = t3 - t2;
    ns d_ns = t1 - t0 - sleep_time;
    ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
    // BOOST_TEST_GE(d_ms.count(), 0);
    BOOST_THREAD_TEST_IT(d_ms, max_diff);
    BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
  }
  {
    m.lock();
    boost::thread t(f2);
    boost::this_thread::sleep_for(ms(750));
    m.unlock();
    t.join();
  }

  return boost::report_errors();
}
Exemple #2
0
TEST(UAVObjManager, bind_connect_disconneect)
{
	boost::system_time t;
	AccessoryDesired::DataFields data;
	AccessoryDesired *obj1 = AccessoryDesired::GetInstance(objMngr, 0);

	ASSERT_NE(obj1, (void*)NULL);

	bind_updated = 0;
	obj1->objectUpdated.connect(boost::bind(bind_objUpdated, _1));

	data = obj1->getData();
	data.AccessoryVal++;
	obj1->setData(data);

	t = boost::get_system_time() +
		boost::posix_time::milliseconds(100);
	mutex.timed_lock(t);

	EXPECT_EQ(bind_updated, 1);

	obj1->objectUpdated.disconnect(boost::bind(bind_objUpdated, _1));

	data = obj1->getData();
	data.AccessoryVal++;
	obj1->setData(data);

	t = boost::get_system_time() +
		boost::posix_time::milliseconds(100);
	mutex.timed_lock(t);

	EXPECT_EQ(bind_updated, 1);
}
void f1()
{
  t0 = Clock::now();
  BOOST_TEST(m.try_lock_for(ms(750)) == true);
  t1 = Clock::now();
  BOOST_TEST(m.try_lock());
  m.unlock();
  m.unlock();
}
Exemple #4
0
void f1()
{
  time_point t0 = Clock::now();
  // This test is spurious as it depends on the time the thread system switches the threads
  BOOST_TEST(m.try_lock_until(Clock::now() + ms(300) + ms(1000)) == true);
  time_point t1 = Clock::now();
  m.unlock();
  ns d = t1 - t0 - ms(250);
  BOOST_TEST(d < ns(5000000)+ms(1000)); // within 5ms
}
Exemple #5
0
int main()
{
  m.lock();
  boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
  boost::this_thread::sleep_for(ms(250));
#else
#endif
  m.unlock();
  t.join();

  return boost::report_errors();
}
Exemple #6
0
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
  time_point t0 = Clock::now();
  BOOST_TEST(!m.try_lock());
  BOOST_TEST(!m.try_lock());
  BOOST_TEST(!m.try_lock());
  while (!m.try_lock())
    ;
  time_point t1 = Clock::now();
  BOOST_TEST(m.try_lock());
  m.unlock();
  m.unlock();
  ns d = t1 - t0 - ms(250);
  // This test is spurious as it depends on the time the thread system switches the threads
  BOOST_TEST(d < ns(50000000)+ms(1000)); // within 50ms
#else
  //time_point t0 = Clock::now();
  //BOOST_TEST(!m.try_lock());
  //BOOST_TEST(!m.try_lock());
  //BOOST_TEST(!m.try_lock());
  while (!m.try_lock())
    ;
  //time_point t1 = Clock::now();
  BOOST_TEST(m.try_lock());
  m.unlock();
  m.unlock();
  //ns d = t1 - t0 - ms(250);
  // This test is spurious as it depends on the time the thread system switches the threads
  //BOOST_TEST(d < ns(50000000)+ms(1000)); // within 50ms
#endif
}
void f2()
{
  time_point t0 = Clock::now();
  BOOST_TEST(m.try_lock_for(ms(250)) == false);
  time_point t1 = Clock::now();
  ns d = t1 - t0 - ms(250);
  BOOST_THREAD_TEST_IT(d, ns(max_diff));
}
void f2()
{
  time_point t0 = Clock::now();
  BOOST_TEST(m.try_lock_for(ms(250)) == false);
  time_point t1 = Clock::now();
  ns d = t1 - t0 - ms(250);
  // This test is spurious as it depends on the time the thread system switches the threads
  BOOST_TEST(d < ns(5000000)+ms(1000)); // within 5ms
}
int main()
{
  {
    m.lock();
    boost::thread t(f1);
    boost::this_thread::sleep_for(ms(250));
    m.unlock();
    t.join();
  }
  {
    m.lock();
    boost::thread t(f2);
    boost::this_thread::sleep_for(ms(400));
    m.unlock();
    t.join();
  }

  return boost::report_errors();
}
Exemple #10
0
TEST(UAVObjManager, registerTwo)
{
	boost::system_time t;
	objMngr = new UAVObjectManager();

	newobj = 0;
	newinst = 0;

	objMngr->newObject.connect(newObject);
	objMngr->newInstance.connect(newInstance);

	AccessoryDesired *obj1 = new AccessoryDesired();
	obj1->objectUpdated.connect(objUpdated);
	obj1->objectUpdatedAuto.connect(objUpdatedAuto);
	obj1->objectUpdatedManual.connect(objUpdatedManual);
	obj1->updateRequested.connect(updRequested);

	objMngr->registerObject(obj1);

	t = boost::get_system_time() +
		boost::posix_time::milliseconds(100);
	mutex.timed_lock(t);
	EXPECT_GT(newobj, 0);

	AccessoryDesired *obj2 = new AccessoryDesired();
	obj2->objectUpdated.connect(objUpdated);
	obj2->objectUpdatedAuto.connect(objUpdatedAuto);
	obj2->objectUpdatedManual.connect(objUpdatedManual);
	obj2->updateRequested.connect(updRequested);

	objMngr->registerObject(obj2);

	t = boost::get_system_time() +
		boost::posix_time::milliseconds(100);
	mutex.timed_lock(t);
	EXPECT_GT(newinst, 0);
}