From 10e06145736de981d8c8f0701d3be15c661d4182 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 7 Nov 2023 23:46:23 -0600 Subject: [PATCH] TODO Fixup serial test --- tests/serialTest.cpp | 21 +++++++++++++++++++-- tests/test.h | 8 ++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tests/serialTest.cpp b/tests/serialTest.cpp index 88642ae..b4074c6 100644 --- a/tests/serialTest.cpp +++ b/tests/serialTest.cpp @@ -9,8 +9,25 @@ class SerialTest : public Test { SerialTest(): Test("serial_basic") {}; private: bool runTest() { - // Simply pass, as signalStart() and signalEnd() will indicate success or failure - return true; + char buff[25]; + // Print multiple messages to the BTF and have the BTF repeat a specific one + // Tests readAll() in BTF + printf("Testing serial communication\n"); + printf("Repeat this message\n"); + printf("Don't repeat this message\n"); + // Wait for BTF timeout to expire + ThisThread::sleep_for(1000ms); + // Read and verify response from BTF test runner + size_t nread = pc.readLine(buff, sizeof(buff)); + bool result = strcmp(buff, "Repeat this message") == 0; + + // Print a message with a delimiter (STOP) + // Tests readUntil() in BTF + printf("Should only read thisSTOPNot this\n"); + // Read and verify response from BTF test runner + nread = pc.readLine(buff, sizeof(buff)); + + return result && strcmp(buff, "Should only read this") == 0; } }; diff --git a/tests/test.h b/tests/test.h index d3bc431..f5bb6f2 100644 --- a/tests/test.h +++ b/tests/test.h @@ -69,7 +69,9 @@ class Test { printf("START TEST %s\n", testName.c_str()); // Read response from BTF test runner - size_t nread = pc.readLine(buff, sizeof(buff)); + // Give it a generouss 30 seconds to ensure timeout + // is not an issue during normal operation + size_t nread = pc.readLine(buff, sizeof(buff), 30000); // Set result code if(nread <= 0) { @@ -95,7 +97,9 @@ class Test { printf("%s\n", r->pass ? "PASS" : "FAIL"); // Read response from BTF test runner - size_t nread = pc.readLine(buff, sizeof(buff)); + // Give it a generouss 30 seconds to ensure timeout + // is not an issue during normal operation + size_t nread = pc.readLine(buff, sizeof(buff), 30000); // Set result code if(nread <= 0) {