From 21e85558cedd11c8a3a7077cd284d1b1f310b843 Mon Sep 17 00:00:00 2001 From: Danila Date: Mon, 18 May 2026 16:42:15 +0300 Subject: [PATCH] 1. Repeated test name approved. 2. Overal timeout for UART receiving data done. All works --- .../test_start_March_FTE_by_blocks.json | 2 +- configs/test_plan.json | 4 +- src/core/uart.cpp | 15 +++++- src/tests/test_runner.cpp | 51 ++++++++++++++----- src/tests/uart_fixture.cpp | 28 +++++----- src/tests/uart_fixture.h | 16 +++++- 6 files changed, 83 insertions(+), 33 deletions(-) diff --git a/configs/test_cases/test_start_March_FTE_by_blocks.json b/configs/test_cases/test_start_March_FTE_by_blocks.json index b21a361..587d2d6 100644 --- a/configs/test_cases/test_start_March_FTE_by_blocks.json +++ b/configs/test_cases/test_start_March_FTE_by_blocks.json @@ -50,5 +50,5 @@ } }, - "timeout_msec": 27000 + "timeout_msec": 35000 } diff --git a/configs/test_plan.json b/configs/test_plan.json index 66a005b..3ced3e1 100644 --- a/configs/test_plan.json +++ b/configs/test_plan.json @@ -14,8 +14,8 @@ "test_randomDataTest_100_110.json", "test_endurance_50_60_marchFTE_5.json", "test_abort.json", - "#test_start_March_FTE_all_targ0_repeat2.json", - "#test_abort.json" + "test_start_March_FTE_all_targ0_repeat2.json", + "test_abort.json" ], "abort": [ diff --git a/src/core/uart.cpp b/src/core/uart.cpp index 1505435..3eb9b24 100644 --- a/src/core/uart.cpp +++ b/src/core/uart.cpp @@ -43,11 +43,22 @@ bool UART::send(const QByteArray& data, QString &err) QByteArray UART::receive(int timeoutMs) { + // overall timeout for all received chunks from UART QByteArray result; + QElapsedTimer timer; + timer.start(); - while (serial.waitForReadyRead(timeoutMs)) + while(timer.elapsed() < timeoutMs) { - result += serial.readAll(); + int remain = timeoutMs - timer.elapsed(); + + if (remain <= 0) break; + + if (serial.waitForReadyRead(remain)) + { + result += serial.readAll(); + } + else { break; } } return result; diff --git a/src/tests/test_runner.cpp b/src/tests/test_runner.cpp index 144ffa7..8d53545 100644 --- a/src/tests/test_runner.cpp +++ b/src/tests/test_runner.cpp @@ -3,10 +3,25 @@ extern TestOptions g_options; -std::vector getJsonTests() +QString prepareTestName(QString name) +{ + // replace invalid symbols into "_" + name.replace(QRegularExpression("[^a-zA-Z0-9_]"), "_"); + + // prepend T is digit first + if (!name.isEmpty() && name[0].isDigit()) { name.prepend("T_"); } + + // protection from empty name: + if (name.isEmpty()) { name = "unnamed"; } + + return name; +} + +std::vector getJsonTests() { QStringList list; - std::vector result; + std::vector result; + QMap counters; try { @@ -26,10 +41,25 @@ std::vector getJsonTests() return result; } - - for (const auto& s : list) + for (const QString &path : list) { - result.push_back(s); + QFile f(path); + + QString testName = "unknown"; + + if (f.open(QIODevice::ReadOnly)) + { + QJsonObject obj = QJsonDocument::fromJson(f.readAll()).object(); + testName = obj["meta"].toObject()["name"].toString(); + } + + int index = counters[testName]++; + + TestCaseParam p; + p.path = path; + p.name = prepareTestName(QString("%1_%2").arg(testName).arg(index)); + + result.push_back(p); } return result; @@ -39,15 +69,10 @@ std::vector getJsonTests() INSTANTIATE_TEST_SUITE_P( JsonTestSuite, UARTFixture, - ::testing::ValuesIn( - getJsonTests() - ), - [](const testing::TestParamInfo& info) + ::testing::ValuesIn(getJsonTests()), + [](const testing::TestParamInfo& info) { - QFileInfo fi(info.param); - - return fi.baseName() - .toStdString(); + return info.param.name.toStdString(); } ); diff --git a/src/tests/uart_fixture.cpp b/src/tests/uart_fixture.cpp index e26a740..15713cd 100644 --- a/src/tests/uart_fixture.cpp +++ b/src/tests/uart_fixture.cpp @@ -2,6 +2,7 @@ UART UARTFixture::uart; comSettings_t UARTFixture::comPortSettings; +Stats_t UARTFixture::stats; path_t UARTFixture::path; QString UARTFixture::logFile; @@ -12,12 +13,9 @@ int UARTFixture::extract_struct_from_elf(QString structTypeName) QStringList arguments; arguments << path.elf_parser - << "-f" - << path.MK_elf_file - << "-t" - << structTypeName - << "-o" - << path.iar_json_out; + << "-f" << path.MK_elf_file + << "-t" << structTypeName + << "-o" << path.iar_json_out; process.start(program, arguments); @@ -52,12 +50,9 @@ int UARTFixture::convert_map_file() QStringList arguments; arguments << path.map_parser - << "-f" - << path.MK_map_file - << "-s" - << "ENTRY LIST" - << "-o" - << path.iar_json_out; + << "-f" << path.MK_map_file + << "-s" << "ENTRY LIST" + << "-o" << path.iar_json_out; process.start(program, arguments); @@ -153,6 +148,7 @@ int UARTFixture::readConfig() void UARTFixture::SetUpTestSuite() { Logger::setupLog(); + memset(&stats, 0, sizeof(stats)); int fail = UARTFixture::readConfig(); if (fail == true) { return; } @@ -184,6 +180,7 @@ void UARTFixture::TearDownTestSuite() QString curTime1 = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss"); QString htmlFile = path.stand_report_html_path; + Logger::appendSummary(logFile, stats.total, stats.passed, stats.failed); HtmlReport::generate(logFile, htmlFile, curTime1); } @@ -195,7 +192,8 @@ extern TestOptions g_options; TEST_P(UARTFixture, JsonCase) { - QString caseFile = GetParam(); + TestCaseParam param = GetParam(); + QString caseFile = param.path; runCase(caseFile); } @@ -207,7 +205,6 @@ void UARTFixture::runCase( QString err; QString error; - QFile caseFileJson(caseFile); // ASSERT_TRUE(caseFileJson.open(QIODevice::ReadOnly)); if (!caseFileJson.open(QIODevice::ReadOnly)) @@ -260,6 +257,9 @@ void UARTFixture::runCase( Logger::saveTestLog(logFile, handler, cfg, passed, error); + stats.total++; + if (passed) stats.passed++; + else stats.failed++; EXPECT_TRUE(passed); if (g_options.delayMs > 0) diff --git a/src/tests/uart_fixture.h b/src/tests/uart_fixture.h index 8c22426..91fd154 100644 --- a/src/tests/uart_fixture.h +++ b/src/tests/uart_fixture.h @@ -7,11 +7,25 @@ #include "../core/test_stats.h" #include +struct TestCaseParam +{ + QString path; + QString name; +}; + +struct Stats_t +{ + uint16_t total; + uint16_t passed; + uint16_t failed; +}; + class UARTFixture : - public ::testing::TestWithParam + public ::testing::TestWithParam { protected: static UART uart; + static Stats_t stats; static comSettings_t comPortSettings; static path_t path; static QString logFile;