MRPT  2.0.3
RawlogGrabberApp_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <gtest/gtest.h>
12 #include <mrpt/config.h>
13 #include <mrpt/system/filesystem.h>
14 #include <test_mrpt_common.h>
15 #include <thread>
16 
17 // test disabled since it seems to fail in build farms for some reason.
18 #if MRPT_HAS_FFMPEG && MRPT_HAS_OPENCV && 0
19 TEST(RawlogGrabberApp, CGenericCamera_AVI)
20 #else
21 TEST(RawlogGrabberApp, DISABLED_CGenericCamera_AVI)
22 #endif
23 {
24  using namespace std::string_literals;
25 
26  const std::string ini_fil =
27  mrpt::UNITTEST_BASEDIR +
28  "/share/mrpt/config_files/rawlog-grabber/camera_ffmpeg_video_file.ini"s;
30 
31  const std::string video_fil =
32  mrpt::UNITTEST_BASEDIR + "/share/mrpt/datasets/dummy_video.avi"s;
34 
35  try
36  {
39 
40  const char* argv[] = {"rawlog-grabber", ini_fil.c_str()};
41  const int argc = sizeof(argv) / sizeof(argv[0]);
42 
43  app.initialize(argc, argv);
44 
45  // Create output dir:
46  const auto out_dir = mrpt::system::getTempFileName() + "_dir"s;
48  THROW_EXCEPTION_FMT("Could not mkdir: `%s`", out_dir.c_str());
49 
50  app.params.write("global", "rawlog_prefix", out_dir + "/dataset"s);
51  app.params.write("Camera1", "ffmpeg_url", video_fil);
52 
53  // Run slowly, so we have time to capture a few frames from the
54  // (otherwise really short) test video file:
55  app.params.write("Camera1", "process_rate", "10.0");
56 
57  // Max. run time.
58  // Should end much sooner when the video file is entirely processed.
59  app.run_for_seconds = 45.0;
60 
61  // Less verbose output in tests:
63 
64  const std::size_t REQUIRED_GRAB_OBS = 1U;
65 
66  auto tWatchDog = std::thread([&]() {
67  for (;;)
68  {
69  if (!app.isRunning()) break;
70  if (app.rawlog_saved_objects >= REQUIRED_GRAB_OBS)
71  {
72  app.run_for_seconds = 1.0; // make it exit
73  break;
74  }
75  std::this_thread::sleep_for(std::chrono::milliseconds(500));
76  }
77  });
78 
79  // Run:
80  app.run();
81 
82  // Check expected results:
83  std::cout << "Rawlog grabbed objects: " << app.rawlog_saved_objects
84  << std::endl;
85  if (tWatchDog.joinable()) tWatchDog.join();
86 
87  EXPECT_GE(app.rawlog_saved_objects, REQUIRED_GRAB_OBS);
88  }
89  catch (const std::exception& e)
90  {
91  std::cerr << mrpt::exception_to_str(e);
92  GTEST_FAIL();
93  }
94 }
filesystem.h
mrpt::apps::RawlogGrabberApp::params
mrpt::config::CConfigFileMemory params
Populated in initialize().
Definition: RawlogGrabberApp.h:66
mrpt::config::CConfigFileBase::write
void write(const std::string &section, const std::string &name, enum_t value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
Definition: config/CConfigFileBase.h:107
mrpt::apps::RawlogGrabberApp::isRunning
bool isRunning() const
Definition: RawlogGrabberApp.h:49
mrpt::apps::RawlogGrabberApp::show_sensor_thread_exceptions
bool show_sensor_thread_exceptions
If enabled (default), exceptions in sensor threads will be reported to std::cerr.
Definition: RawlogGrabberApp.h:61
TEST
TEST(ICP_SLAM_App, MapFromRawlog_PointMap)
Definition: ICP_SLAM_App_unittest.cpp:80
video_fil
const std::string video_fil
Definition: RawlogGrabberApp_unittest.cpp:31
THROW_EXCEPTION_FMT
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:69
out_dir
const auto out_dir
Definition: RawlogGrabberApp_unittest.cpp:46
ini_fil
const std::string ini_fil
Definition: RawlogGrabberApp_unittest.cpp:26
mrpt::system::getTempFileName
std::string getTempFileName()
Returns the name of a proposed temporary file name.
Definition: filesystem.cpp:283
mrpt::system::fileExists
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:128
mrpt::apps::RawlogGrabberApp
RawlogGrabber application wrapper class.
Definition: RawlogGrabberApp.h:28
mrpt::apps::RawlogGrabberApp::initialize
void initialize(int argc, const char **argv)
Initializes the application from CLI parameters.
Definition: RawlogGrabberApp.cpp:39
mrpt::apps::RawlogGrabberApp::run_for_seconds
double run_for_seconds
If >0, run() will return after this period (in seconds)
Definition: RawlogGrabberApp.h:57
mrpt::system::COutputLogger::setMinLoggingLevel
void setMinLoggingLevel(const VerbosityLevel level)
Set the minimum logging level for which the incoming logs are going to be taken into account.
Definition: COutputLogger.cpp:144
argv
const char * argv[]
Definition: RawlogGrabberApp_unittest.cpp:40
mrpt::apps::RawlogGrabberApp::run
void run()
Runs with the current parameter set.
Definition: RawlogGrabberApp.cpp:219
EXPECT_TRUE
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
RawlogGrabberApp.h
argc
const int argc
Definition: RawlogGrabberApp_unittest.cpp:41
mrpt::system::LVL_ERROR
@ LVL_ERROR
Definition: system/COutputLogger.h:33
mrpt::exception_to_str
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Definition: exceptions.cpp:59
mrpt::apps::RawlogGrabberApp::rawlog_saved_objects
std::atomic_size_t rawlog_saved_objects
Counter of saved objects.
Definition: RawlogGrabberApp.h:74
mrpt::system::createDirectory
bool createDirectory(const std::string &dirName)
Creates a directory.
Definition: filesystem.cpp:161



Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 15 15:49:54 UTC 2020