optimal & fix file cmake
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -19,10 +20,12 @@
|
||||
#include <nav_test_harness/scenario_runner.h>
|
||||
|
||||
#include "move_base2_scenario_driver.h"
|
||||
#include "recovery_scenario_driver.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
using move_base2::testing::MoveBase2ScenarioDriver;
|
||||
using move_base2::testing::RecoveryScenarioDriver;
|
||||
using nav_test_harness::Scenario;
|
||||
using nav_test_harness::ScenarioReport;
|
||||
using nav_test_harness::ScenarioRunner;
|
||||
@@ -47,13 +50,34 @@ void runScenarioFile(const std::string& path)
|
||||
Scenario scenario;
|
||||
std::string error;
|
||||
ASSERT_TRUE(nav_test_harness::loadScenarioFile(path, scenario, error))
|
||||
<< "không nạp được " << path << ": " << error;
|
||||
|
||||
MoveBase2ScenarioDriver driver;
|
||||
ASSERT_TRUE(driver.setup(scenario, error)) << scenario.name << ": setup thất bại: " << error;
|
||||
<< "could not load " << path << ": " << error;
|
||||
|
||||
// Chọn driver theo DỮ LIỆU của kịch bản, không theo một khoá cấu hình riêng: kịch bản khai vật
|
||||
// cản nghĩa là nó nói về va chạm thật, và chỉ driver nạp recovery_core thật mới trả lời được. Đây
|
||||
// cũng là lý do MoveBase2ScenarioDriver báo lỗi setup khi thấy `obstacles` thay vì chạy lặng lẽ.
|
||||
ScenarioRunner runner;
|
||||
const ScenarioReport report = runner.run(scenario, driver);
|
||||
ScenarioReport report;
|
||||
|
||||
// KHÔNG gọi setup() ở đây: `ScenarioRunner::run` đã tự gọi. Gọi hai lần từng làm driver nạp
|
||||
// plugin THẬT dựng registry hai lượt, và lượt cũ giữ con trỏ tới cầu nối vừa bị huỷ — use after
|
||||
// free, biểu hiện ra ngoài chỉ là một dòng "không lấy được pose" trông như lỗi TF.
|
||||
(void)error;
|
||||
|
||||
if (scenario.obstacles.empty())
|
||||
{
|
||||
MoveBase2ScenarioDriver driver;
|
||||
report = runner.run(scenario, driver);
|
||||
}
|
||||
else
|
||||
{
|
||||
RecoveryScenarioDriver driver;
|
||||
report = runner.run(scenario, driver);
|
||||
|
||||
EXPECT_GT(driver.startRejections(), 0u)
|
||||
<< scenario.name
|
||||
<< ": no behavior REFUSED to start — a test case with obstacles that never reaches a "
|
||||
"safety branch is checking something other than what it describes";
|
||||
}
|
||||
|
||||
EXPECT_TRUE(report.passed) << nav_test_harness::formatReport(report);
|
||||
}
|
||||
@@ -102,14 +126,22 @@ INSTANTIATE_TEST_SUITE_P(Scenarios, ScenarioFixture, ::testing::ValuesIn(scenari
|
||||
TEST(ScenarioSuite, ScenarioDirectoryIsNotEmpty)
|
||||
{
|
||||
const std::vector<std::string> files = scenarioFiles();
|
||||
EXPECT_FALSE(files.empty()) << "không tìm thấy kịch bản nào trong " << scenarioDir()
|
||||
<< " — suite sẽ xanh mà không kiểm gì cả";
|
||||
EXPECT_FALSE(files.empty()) << "no scenario found in " << scenarioDir()
|
||||
<< " — the suite would go green without checking anything";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// Kịch bản có vật cản nạp plugin recovery THẬT qua Boost.DLL; ctest không mang theo biến môi
|
||||
// trường của shell nên binary phải tự trỏ, giống recovery_runner_test.
|
||||
#ifdef MOVE_BASE2_TEST_CONFIG_DIR
|
||||
setenv("PNKX_NAV_CORE_CONFIG_DIR", MOVE_BASE2_TEST_CONFIG_DIR, 0);
|
||||
#endif
|
||||
#ifdef MOVE_BASE2_TEST_LIBRARY_DIR
|
||||
setenv("PNKX_NAV_CORE_LIBRARY_PATH", MOVE_BASE2_TEST_LIBRARY_DIR, 0);
|
||||
#endif
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user