test(tecs): write a log file per parameterized closed-loop test

Parameterized test names contain '/', so TECS_TEST_LOG_DIR pointed fopen
at a missing subdirectory and the TECSControlClosedLoopWeightTest cases
wrote nothing. Flatten the name, create the log directory if needed and
report a file that cannot be opened.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: RomanBapst <bapstroman@gmail.com>
This commit is contained in:
RomanBapst authored and GitHub committed 2026-11-27 10:16:17 +03:00
1 parent 88a5b53b4b
commit 6daedeb36d
1 file changed
+13 -1
+13 -1
View File
@@ -57,6 +57,8 @@
#include "TECS.hpp"
#include <lib/geo/geo.h>
#include <px4_platform_common/param.h>
#include <algorithm>
#include <sys/stat.h>
#include <cmath>
#include <cstdio>
@@ -311,9 +313,19 @@ protected:
if (log_dir) {
const auto *test_info = ::testing::UnitTest::GetInstance()->current_test_info();
std::string path = std::string(log_dir) + "/" + test_info->name() + ".csv";
// Parameterized tests are named "Test/Param": flatten to one file name
std::string name = test_info->name();
std::replace(name.begin(), name.end(), '/', '_');
mkdir(log_dir, 0755); // fails harmlessly if it exists
std::string path = std::string(log_dir) + "/" + name + ".csv";
_output_csv_file = std::fopen(path.c_str(), "w");
if (!_output_csv_file) {
std::fprintf(stderr, "TECS_TEST_LOG_DIR: cannot write %s\n", path.c_str());
}
if (_output_csv_file) {
std::fprintf(_output_csv_file,
"t,V,h,V_sp,alt_sp,pitch_cmd,throttle,"