MRPT  2.0.4
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: it fails to run in build servers for some unknown reason (!)
18 // (JLBC May 2020, after debian package release 2:2.0.3-3)
19 #if MRPT_HAS_FFMPEG && MRPT_HAS_OPENCV && 0
20 TEST(RawlogGrabberApp, CGenericCamera_AVI)
21 #else
22 TEST(RawlogGrabberApp, DISABLED_CGenericCamera_AVI)
23 #endif
24 {
25  using namespace std::string_literals;
26 
27  const std::string ini_fil =
28  mrpt::UNITTEST_BASEDIR +
29  "/share/mrpt/config_files/rawlog-grabber/camera_ffmpeg_video_file.ini"s;
31 
32  const std::string video_fil =
33  mrpt::UNITTEST_BASEDIR + "/share/mrpt/datasets/dummy_video.avi"s;
35 
36  try
37  {
40 
41  const char* argv[] = {"rawlog-grabber", ini_fil.c_str()};
42  const int argc = sizeof(argv) / sizeof(argv[0]);
43 
44  app.initialize(argc, argv);
45 
46  // Create output dir:
47  const auto out_dir = mrpt::system::getTempFileName() + "_dir"s;
49  THROW_EXCEPTION_FMT("Could not mkdir: `%s`", out_dir.c_str());
50 
51  app.params.write("global", "rawlog_prefix", out_dir + "/dataset"s);
52  app.params.write("Camera1", "ffmpeg_url", video_fil);
53 
54  // Run slowly, so we have time to capture a few frames from the
55  // (otherwise really short) test video file:
56  app.params.write("Camera1", "process_rate", "10.0");
57 
58  // Max. run time.
59  // Should end much sooner when the video file is entirely processed.
60  app.run_for_seconds = 45.0;
61 
62  // Less verbose output in tests:
64 
65  const std::size_t REQUIRED_GRAB_OBS = 1U;
66 
67  auto tWatchDog = std::thread([&]() {
68  for (;;)
69  {
70  if (!app.isRunning()) break;
71  if (app.rawlog_saved_objects >= REQUIRED_GRAB_OBS)
72  {
73  app.run_for_seconds = 1.0; // make it exit
74  break;
75  }
76  std::this_thread::sleep_for(std::chrono::milliseconds(500));
77  }
78  });
79 
80  // Run:
81  app.run();
82 
83  // Check expected results:
84  std::cout << "Rawlog grabbed objects: " << app.rawlog_saved_objects
85  << std::endl;
86  if (tWatchDog.joinable()) tWatchDog.join();
87 
88  EXPECT_GE(app.rawlog_saved_objects, REQUIRED_GRAB_OBS);
89  }
90  catch (const std::exception& e)
91  {
92  std::cerr << mrpt::exception_to_str(e);
93  GTEST_FAIL();
94  }
95 }
bool createDirectory(const std::string &dirName)
Creates a directory.
Definition: filesystem.cpp:161
const auto out_dir
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:128
void setMinLoggingLevel(const VerbosityLevel level)
Set the minimum logging level for which the incoming logs are going to be taken into account...
const std::string video_fil
bool show_sensor_thread_exceptions
If enabled (default), exceptions in sensor threads will be reported to std::cerr. ...
TEST(ICP_SLAM_App, MapFromRawlog_PointMap)
std::string getTempFileName()
Returns the name of a proposed temporary file name.
Definition: filesystem.cpp:283
void initialize(int argc, const char **argv)
Initializes the application from CLI parameters.
void run()
Runs with the current parameter set.
const std::string ini_fil
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())
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
double run_for_seconds
If >0, run() will return after this period (in seconds)
const char * argv[]
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
const int argc
std::atomic_size_t rawlog_saved_objects
Counter of saved objects.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:69
mrpt::config::CConfigFileMemory params
Populated in initialize().
RawlogGrabber application wrapper class.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 7b5ddf9de Fri May 29 14:02:56 2020 +0200 at vie may 29 14:15:09 CEST 2020