Commits

Jose Luis Rivero committed 9eaaeec

Use QBENCHMARK for get durations in QTest based tests

  • Participants
  • Parent commits df55d43
  • Branches qtest_timing

Comments (0)

Files changed (3)

gazebo/gui/DataLogger_TEST.cc

 /////////////////////////////////////////////////
 void DataLogger_TEST::RecordButton()
 {
-  this->Load("worlds/empty.world");
+  QBENCHMARK
+  {
+    this->Load("worlds/empty.world");
 
-  // Create a new data logger widget
-  gazebo::gui::DataLogger *dataLogger = new gazebo::gui::DataLogger;
-  dataLogger->show();
-  QCoreApplication::processEvents();
+    // Create a new data logger widget
+    gazebo::gui::DataLogger *dataLogger = new gazebo::gui::DataLogger;
+    dataLogger->show();
+    QCoreApplication::processEvents();
 
-  // Get the record button
-  QToolButton *recordButton = dataLogger->findChild<QToolButton*>(
-      "dataLoggerRecordButton");
+    // Get the record button
+    QToolButton *recordButton = dataLogger->findChild<QToolButton*>(
+        "dataLoggerRecordButton");
 
-  // Get the destination label
-  QLineEdit *destPathLabel = dataLogger->findChild<QLineEdit*>(
-      "dataLoggerDestnationPathLabel");
+    // Get the destination label
+    QLineEdit *destPathLabel = dataLogger->findChild<QLineEdit*>(
+        "dataLoggerDestnationPathLabel");
 
-  // Get the time label
-  QLabel *timeLabel = dataLogger->findChild<QLabel*>("dataLoggerTimeLabel");
+    // Get the time label
+    QLabel *timeLabel = dataLogger->findChild<QLabel*>("dataLoggerTimeLabel");
 
-  // Get the status label
-  QLabel *statusLabel = dataLogger->findChild<QLabel*>("dataLoggerStatusLabel");
+    // Get the status label
+    QLabel *statusLabel = dataLogger->findChild<QLabel*>("dataLoggerStatusLabel");
 
-  // Get the size label
-  QLabel *sizeLabel = dataLogger->findChild<QLabel*>("dataLoggerSizeLabel");
+    // Get the size label
+    QLabel *sizeLabel = dataLogger->findChild<QLabel*>("dataLoggerSizeLabel");
 
-  QVERIFY(recordButton != NULL);
-  QVERIFY(destPathLabel != NULL);
-  QVERIFY(sizeLabel != NULL);
-  QVERIFY(timeLabel != NULL);
-  QVERIFY(statusLabel != NULL);
+    QVERIFY(recordButton != NULL);
+    QVERIFY(destPathLabel != NULL);
+    QVERIFY(sizeLabel != NULL);
+    QVERIFY(timeLabel != NULL);
+    QVERIFY(statusLabel != NULL);
 
-  // Toggle the record button, which starts logging.
-  recordButton->toggle();
+    // Toggle the record button, which starts logging.
+    recordButton->toggle();
 
-  // Wait for a log status return message
-  while (destPathLabel->text().toStdString().empty())
-  {
-    // The following line tell QT to process its events. This is vital for
-    // all tests, but it must be run in the main thread.
-    QCoreApplication::processEvents();
-    gazebo::common::Time::MSleep(100);
+    // Wait for a log status return message
+    while (destPathLabel->text().toStdString().empty())
+    {
+      // The following line tell QT to process its events. This is vital for
+      // all tests, but it must be run in the main thread.
+      QCoreApplication::processEvents();
+      gazebo::common::Time::MSleep(100);
+    }
+
+    std::string txt;
+
+    // Make sure the destination log file is correct.
+    txt = destPathLabel->text().toStdString();
+    QVERIFY(txt.find("test/state.log") != std::string::npos);
+
+    // Make sure the initial size is zero
+    txt = sizeLabel->text().toStdString();
+    QVERIFY(txt == "0.00 B");
+
+    // Make sure the initial time is zero
+    txt = timeLabel->text().toStdString();
+    QVERIFY(txt == "00:00:00.000");
+
+    // Make sure the status label says "Recording"
+    txt = statusLabel->text().toStdString();
+    QVERIFY(txt == "Recording");
+
+
+    // Toggle the record button, which stops logging.
+    recordButton->toggle();
+
+    // Make sure the initial size is zero
+    txt = sizeLabel->text().toStdString();
+    QVERIFY(txt == "0.00 B");
+
+    // Make sure the initial time is zero
+    txt = timeLabel->text().toStdString();
+    QVERIFY(txt == "00:00:00.000");
+
+
+    // Make sure the status label says "Ready"
+    txt = statusLabel->text().toStdString();
+    QVERIFY(txt == "Ready");
+
+    dataLogger->hide();
   }
-
-  std::string txt;
-
-  // Make sure the destination log file is correct.
-  txt = destPathLabel->text().toStdString();
-  QVERIFY(txt.find("test/state.log") != std::string::npos);
-
-  // Make sure the initial size is zero
-  txt = sizeLabel->text().toStdString();
-  QVERIFY(txt == "0.00 B");
-
-  // Make sure the initial time is zero
-  txt = timeLabel->text().toStdString();
-  QVERIFY(txt == "00:00:00.000");
-
-  // Make sure the status label says "Recording"
-  txt = statusLabel->text().toStdString();
-  QVERIFY(txt == "Recording");
-
-
-  // Toggle the record button, which stops logging.
-  recordButton->toggle();
-
-  // Make sure the initial size is zero
-  txt = sizeLabel->text().toStdString();
-  QVERIFY(txt == "0.00 B");
-
-  // Make sure the initial time is zero
-  txt = timeLabel->text().toStdString();
-  QVERIFY(txt == "00:00:00.000");
-
-
-  // Make sure the status label says "Ready"
-  txt = statusLabel->text().toStdString();
-  QVERIFY(txt == "Ready");
-
-  dataLogger->hide();
 }
 
 /////////////////////////////////////////////////
 void DataLogger_TEST::StressTest()
 {
-  // Cleanup test directory.
-  boost::filesystem::remove_all("/tmp/gazebo_test");
+  QBENCHMARK
+  {
+    // Cleanup test directory.
+    boost::filesystem::remove_all("/tmp/gazebo_test");
 
-  this->Load("worlds/empty.world");
+    this->Load("worlds/empty.world");
 
-  gazebo::transport::NodePtr node;
-  gazebo::transport::PublisherPtr pub;
+    gazebo::transport::NodePtr node;
+    gazebo::transport::PublisherPtr pub;
 
-  // Create a node from communication.
-  node = gazebo::transport::NodePtr(new gazebo::transport::Node());
-  node->Init();
-  pub = node->Advertise<gazebo::msgs::LogControl>("~/log/control");
+    // Create a node from communication.
+    node = gazebo::transport::NodePtr(new gazebo::transport::Node());
+    node->Init();
+    pub = node->Advertise<gazebo::msgs::LogControl>("~/log/control");
 
-  gazebo::msgs::LogControl msg;
-  msg.set_base_path("/tmp/gazebo_test");
-  pub->Publish(msg);
+    gazebo::msgs::LogControl msg;
+    msg.set_base_path("/tmp/gazebo_test");
+    pub->Publish(msg);
 
-  // Create a new data logger widget
-  gazebo::gui::DataLogger *dataLogger = new gazebo::gui::DataLogger;
+    // Create a new data logger widget
+    gazebo::gui::DataLogger *dataLogger = new gazebo::gui::DataLogger;
 
-  // Get the record button
-  QToolButton *recordButton = dataLogger->findChild<QToolButton*>(
-      "dataLoggerRecordButton");
+    // Get the record button
+    QToolButton *recordButton = dataLogger->findChild<QToolButton*>(
+        "dataLoggerRecordButton");
 
-  unsigned int count = 100;
+    unsigned int count = 100;
 
-  // Toggle the record button many times with sleeps
-  for (unsigned int i = 0; i < count; ++i)
-  {
-    recordButton->toggle();
+    // Toggle the record button many times with sleeps
+    for (unsigned int i = 0; i < count; ++i)
+    {
+      recordButton->toggle();
 
-    // Sleep for random times
-    gazebo::common::Time::MSleep(gazebo::math::Rand::GetIntUniform(10, 500));
+      // Sleep for random times
+      gazebo::common::Time::MSleep(gazebo::math::Rand::GetIntUniform(10, 500));
+    }
+
+    // There should be (count * 0.5) log directories in /tmp/gazebo_test
+    // due to the record button being toggled.
+    unsigned int dirCount = 0;
+    for (boost::filesystem::directory_iterator iter("/tmp/gazebo_test");
+         iter != boost::filesystem::directory_iterator(); ++iter, ++dirCount)
+    {
+    }
+
+    QVERIFY(dirCount == count / 2);
+
+    // Cleanup after ourselves.
+    boost::filesystem::remove_all("/tmp/gazebo_test");
   }
-
-  // There should be (count * 0.5) log directories in /tmp/gazebo_test
-  // due to the record button being toggled.
-  unsigned int dirCount = 0;
-  for (boost::filesystem::directory_iterator iter("/tmp/gazebo_test");
-       iter != boost::filesystem::directory_iterator(); ++iter, ++dirCount)
-  {
-  }
-
-  QVERIFY(dirCount == count / 2);
-
-  // Cleanup after ourselves.
-  boost::filesystem::remove_all("/tmp/gazebo_test");
 }
 
 // Generate a main function for the test

gazebo/gui/TimePanel_TEST.cc

 /////////////////////////////////////////////////
 void TimePanel_TEST::ValidTimes()
 {
-  this->Load("empty.world");
+  QBENCHMARK
+  {
+    this->Load("empty.world");
 
-  // Create a new data logger widget
-  gazebo::gui::TimePanel *timePanel = new gazebo::gui::TimePanel;
+    // Create a new data logger widget
+    gazebo::gui::TimePanel *timePanel = new gazebo::gui::TimePanel;
 
-  // Get the percent real time line
-  QLineEdit *percentEdit = timePanel->findChild<QLineEdit*>(
-      "timePanelPercentRealTime");
+    // Get the percent real time line
+    QLineEdit *percentEdit = timePanel->findChild<QLineEdit*>(
+        "timePanelPercentRealTime");
 
-  // Get the sim time line
-  QLineEdit *simTimeEdit = timePanel->findChild<QLineEdit*>(
-      "timePanelSimTime");
+    // Get the sim time line
+    QLineEdit *simTimeEdit = timePanel->findChild<QLineEdit*>(
+        "timePanelSimTime");
 
-  // Get the real time line
-  QLineEdit *realTimeEdit = timePanel->findChild<QLineEdit*>(
-      "timePanelRealTime");
+    // Get the real time line
+    QLineEdit *realTimeEdit = timePanel->findChild<QLineEdit*>(
+        "timePanelRealTime");
 
-  QVERIFY(percentEdit != NULL);
-  QVERIFY(simTimeEdit != NULL);
-  QVERIFY(realTimeEdit != NULL);
+    QVERIFY(percentEdit != NULL);
+    QVERIFY(simTimeEdit != NULL);
+    QVERIFY(realTimeEdit != NULL);
 
-  // Wait a little bit so that time increases.
-  for (unsigned int i = 0; i < 10; ++i)
-  {
-    gazebo::common::Time::MSleep(100);
-    QCoreApplication::processEvents();
+    // Wait a little bit so that time increases.
+    for (unsigned int i = 0; i < 10; ++i)
+    {
+      gazebo::common::Time::MSleep(100);
+      QCoreApplication::processEvents();
+    }
+
+    std::string txt;
+    double value;
+
+    // Make sure real time is greater than zero
+    txt = realTimeEdit->text().toStdString();
+    value = boost::lexical_cast<double>(txt.substr(txt.find(".")));
+    QVERIFY(value > 0.0);
+
+    // Make sure sim time is greater than zero
+    txt = simTimeEdit->text().toStdString();
+    value = boost::lexical_cast<double>(txt.substr(txt.find(".")));
+    QVERIFY(value > 0.0);
+
+    // Make sure the percent real time is greater than zero
+    txt = percentEdit->text().toStdString();
+    value = boost::lexical_cast<double>(txt.substr(0, txt.find(" ")));
+    QVERIFY(value > 0.0);
   }
-
-  std::string txt;
-  double value;
-
-  // Make sure real time is greater than zero
-  txt = realTimeEdit->text().toStdString();
-  value = boost::lexical_cast<double>(txt.substr(txt.find(".")));
-  QVERIFY(value > 0.0);
-
-  // Make sure sim time is greater than zero
-  txt = simTimeEdit->text().toStdString();
-  value = boost::lexical_cast<double>(txt.substr(txt.find(".")));
-  QVERIFY(value > 0.0);
-
-  // Make sure the percent real time is greater than zero
-  txt = percentEdit->text().toStdString();
-  value = boost::lexical_cast<double>(txt.substr(0, txt.find(" ")));
-  QVERIFY(value > 0.0);
 }
 
 // Generate a main function for the test

gazebo/gui/viewers/ImagesView_TEST.cc

 /////////////////////////////////////////////////
 void ImagesView_TEST::Construction()
 {
-  this->Load("worlds/empty.world");
+  QBENCHMARK
+  {
+    this->Load("worlds/empty.world");
 
-  // Create a new data logger widget
-  gazebo::gui::ImagesView *view = new gazebo::gui::ImagesView(NULL);
-  view->show();
+    // Create a new data logger widget
+    gazebo::gui::ImagesView *view = new gazebo::gui::ImagesView(NULL);
+    view->show();
 
-  QCoreApplication::processEvents();
+    QCoreApplication::processEvents();
 
-  // Get the frame that holds the images
-  QFrame *frame = view->findChild<QFrame*>("blackBorderFrame");
+    // Get the frame that holds the images
+    QFrame *frame = view->findChild<QFrame*>("blackBorderFrame");
 
-  // The layout should be the only child of the frame on construction.
-  QVERIFY(frame->children().size() == 1);
+    // The layout should be the only child of the frame on construction.
+    QVERIFY(frame->children().size() == 1);
 
-  view->hide();
-  delete view;
+    view->hide();
+    delete view;
+  }
 }
 
 /////////////////////////////////////////////////
 void ImagesView_TEST::Switch()
 {
-  this->Load("worlds/multicamera_test.world");
+  QBENCHMARK
+  {
+    this->Load("worlds/multicamera_test.world");
 
-  // Create a new data logger widget
-  gazebo::gui::ImagesView *view = new gazebo::gui::ImagesView(NULL);
-  view->show();
+    // Create a new data logger widget
+    gazebo::gui::ImagesView *view = new gazebo::gui::ImagesView(NULL);
+    view->show();
 
-  // Get the frame that holds the images
-  QFrame *frame = view->findChild<QFrame*>("blackBorderFrame");
+    // Get the frame that holds the images
+    QFrame *frame = view->findChild<QFrame*>("blackBorderFrame");
 
-  // The layout should be the only child of the frame on construction.
-  QVERIFY(frame->children().size() == 1);
+    // The layout should be the only child of the frame on construction.
+    QVERIFY(frame->children().size() == 1);
 
-  this->SetTopic(view, "~/multicamera_1/link/cam1/images", 2);
-  this->SetTopic(view, "~/multicamera_2/link/cam2/images", 3);
-  this->SetTopic(view, "~/multicamera_3/link/cam3/images", 4);
-  this->SetTopic(view, "~/multicamera_4/link/cam4/images", 5);
-  this->SetTopic(view, "~/multicamera_5/link/cam5/images", 6);
-  this->SetTopic(view, "~/multicamera_6/link/cam6/images", 7);
+    this->SetTopic(view, "~/multicamera_1/link/cam1/images", 2);
+    this->SetTopic(view, "~/multicamera_2/link/cam2/images", 3);
+    this->SetTopic(view, "~/multicamera_3/link/cam3/images", 4);
+    this->SetTopic(view, "~/multicamera_4/link/cam4/images", 5);
+    this->SetTopic(view, "~/multicamera_5/link/cam5/images", 6);
+    this->SetTopic(view, "~/multicamera_6/link/cam6/images", 7);
 
-  this->SetTopic(view, "~/multicamera_6/link/cam6/images", 7);
-  this->SetTopic(view, "~/multicamera_5/link/cam5/images", 6);
-  this->SetTopic(view, "~/multicamera_4/link/cam4/images", 5);
-  this->SetTopic(view, "~/multicamera_3/link/cam3/images", 4);
-  this->SetTopic(view, "~/multicamera_2/link/cam2/images", 3);
-  this->SetTopic(view, "~/multicamera_1/link/cam1/images", 2);
+    this->SetTopic(view, "~/multicamera_6/link/cam6/images", 7);
+    this->SetTopic(view, "~/multicamera_5/link/cam5/images", 6);
+    this->SetTopic(view, "~/multicamera_4/link/cam4/images", 5);
+    this->SetTopic(view, "~/multicamera_3/link/cam3/images", 4);
+    this->SetTopic(view, "~/multicamera_2/link/cam2/images", 3);
+    this->SetTopic(view, "~/multicamera_1/link/cam1/images", 2);
 
-  std::map<int, std::string> topicMap;
-  topicMap[2] = "~/multicamera_1/link/cam1/images";
-  topicMap[3] = "~/multicamera_2/link/cam2/images";
-  topicMap[4] = "~/multicamera_3/link/cam3/images";
-  topicMap[5] = "~/multicamera_4/link/cam4/images";
-  topicMap[6] = "~/multicamera_5/link/cam5/images";
-  topicMap[7] = "~/multicamera_6/link/cam6/images";
+    std::map<int, std::string> topicMap;
+    topicMap[2] = "~/multicamera_1/link/cam1/images";
+    topicMap[3] = "~/multicamera_2/link/cam2/images";
+    topicMap[4] = "~/multicamera_3/link/cam3/images";
+    topicMap[5] = "~/multicamera_4/link/cam4/images";
+    topicMap[6] = "~/multicamera_5/link/cam5/images";
+    topicMap[7] = "~/multicamera_6/link/cam6/images";
 
-  // Switch the topic 50 times
-  for (unsigned int i = 0; i < 50; ++i)
-  {
-    // Get a random topic index.
-    int index = gazebo::math::Rand::GetIntUniform(1, 7);
+    // Switch the topic 50 times
+    for (unsigned int i = 0; i < 50; ++i)
+    {
+      // Get a random topic index.
+      int index = gazebo::math::Rand::GetIntUniform(1, 7);
 
-    // Switch the topic
-    view->SetTopic(topicMap[index]);
+      // Switch the topic
+      view->SetTopic(topicMap[index]);
 
-    // Sping the QT update loop for a while to process events.
-    for (int j = 0; j < 50; ++j)
-    {
-      gazebo::common::Time::MSleep(gazebo::math::Rand::GetIntUniform(10, 50));
-      QCoreApplication::processEvents();
+      // Sping the QT update loop for a while to process events.
+      for (int j = 0; j < 50; ++j)
+      {
+        gazebo::common::Time::MSleep(gazebo::math::Rand::GetIntUniform(10, 50));
+        QCoreApplication::processEvents();
+      }
     }
+
+    view->hide();
+    delete view;
   }
-
-  view->hide();
-  delete view;
 }
 
 /////////////////////////////////////////////////
 void ImagesView_TEST::SetTopic(gazebo::gui::ImagesView *_view,
     const std::string &_topicName, int _count)
 {
-  QFrame *frame = _view->findChild<QFrame*>("blackBorderFrame");
+  QBENCHMARK
+  {
+    QFrame *frame = _view->findChild<QFrame*>("blackBorderFrame");
 
-  _view->SetTopic(_topicName);
+    _view->SetTopic(_topicName);
 
-  int i = 0;
+    int i = 0;
 
-  for (i = 0; frame->children().size() != 1 && i < 1000; ++i)
-  {
-    gazebo::common::Time::MSleep(10);
-    QCoreApplication::processEvents();
+    for (i = 0; frame->children().size() != 1 && i < 1000; ++i)
+    {
+      gazebo::common::Time::MSleep(10);
+      QCoreApplication::processEvents();
+    }
+
+    // Make sure the loop didn't exceed the maximum number of iterations
+    QVERIFY(i < 1000);
+
+    // Wait a bit for the images to appear
+    // This is done for visual confirmation that the test works.
+    for (i = 0; i < 100; ++i)
+    {
+      gazebo::common::Time::MSleep(10);
+      QCoreApplication::processEvents();
+    }
+
+    // Make sure the number of images is correct.
+    QVERIFY(frame->children().size() == _count);
   }
-
-  // Make sure the loop didn't exceed the maximum number of iterations
-  QVERIFY(i < 1000);
-
-  // Wait a bit for the images to appear
-  // This is done for visual confirmation that the test works.
-  for (i = 0; i < 100; ++i)
-  {
-    gazebo::common::Time::MSleep(10);
-    QCoreApplication::processEvents();
-  }
-
-  // Make sure the number of images is correct.
-  QVERIFY(frame->children().size() == _count);
 }
 
 // Generate a main function for the test