fix(streamhub-test): unblock make test by fixing BoundsCheckTest C++98 build and registering both orphaned GTest files

This commit is contained in:
Martino Ferrari
2026-07-01 18:34:16 +02:00
parent 462b05b71a
commit 1fcc4e4e6d
2 changed files with 27 additions and 27 deletions
+26 -26
View File
@@ -9,8 +9,7 @@
*/ */
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <cstdint> #include "GeneralDefinitions.h"
#include <cstring>
// HI-1: Verify that a 64-bit bounds check rejects a payload where // HI-1: Verify that a 64-bit bounds check rejects a payload where
// elemsToRead * wireElemBytes would overflow uint32. // elemsToRead * wireElemBytes would overflow uint32.
@@ -18,56 +17,57 @@ TEST(BoundsCheckTest, OverflowRejected) {
// Simulate: numSamples = 0x20000001, wireElemBytes = 8 // Simulate: numSamples = 0x20000001, wireElemBytes = 8
// 32-bit: 0x20000001 * 8 = 0x8 (overflow!) // 32-bit: 0x20000001 * 8 = 0x8 (overflow!)
// 64-bit: 0x100000008 (correctly large, > any reasonable payload size) // 64-bit: 0x100000008 (correctly large, > any reasonable payload size)
uint32_t elemsToRead = 0x20000001u; MARTe::uint32 elemsToRead = 0x20000001u;
uint32_t wireElemBytes = 8u; MARTe::uint32 wireElemBytes = 8u;
uint32_t off = 12u; // after HRT + numSamples MARTe::uint32 off = 12u; // after HRT + numSamples
uint32_t size = 1400u; // typical max payload MARTe::uint32 size = 1400u; // typical max payload
// This is the FIXED pattern (64-bit): // This is the FIXED pattern (64-bit):
uint64_t bytesNeeded = static_cast<uint64_t>(off) + MARTe::uint64 bytesNeeded = static_cast<MARTe::uint64>(off) +
static_cast<uint64_t>(elemsToRead) * static_cast<MARTe::uint64>(elemsToRead) *
static_cast<uint64_t>(wireElemBytes); static_cast<MARTe::uint64>(wireElemBytes);
// Should reject (bytesNeeded >> size) // Should reject (bytesNeeded >> size)
EXPECT_GT(bytesNeeded, static_cast<uint64_t>(size)) EXPECT_GT(bytesNeeded, static_cast<MARTe::uint64>(size))
<< "64-bit check should detect overflow that 32-bit would miss"; << "64-bit check should detect overflow that 32-bit would miss";
// Verify the OLD (buggy) 32-bit pattern would have passed: // Verify the OLD (buggy) 32-bit pattern would have passed:
uint32_t oldCheck = off + (elemsToRead * wireElemBytes); MARTe::uint32 oldCheck = off + (elemsToRead * wireElemBytes);
// On 32-bit: 0x20000001 * 8 = 0x100000008 truncated to 0x8 // On 32-bit: 0x20000001 * 8 = 0x100000008 truncated to 0x8
// off + 0x8 = 20, which is < 1400, so the old check would pass (bug!) // off + 0x8 = 20, which is < 1400, so the old check would pass (bug!)
// On 64-bit: the multiply doesn't overflow, so oldCheck is huge // On 64-bit: the multiply doesn't overflow, so oldCheck is huge
// This test documents that the 64-bit fix is necessary on 32-bit platforms // This test documents that the 64-bit fix is necessary on 32-bit platforms
// and correct on 64-bit. // and correct on 64-bit.
(void) oldCheck;
} }
// HI-1: Verify a normal (non-overflow) case passes the 64-bit check. // HI-1: Verify a normal (non-overflow) case passes the 64-bit check.
TEST(BoundsCheckTest, NormalCasePasses) { TEST(BoundsCheckTest, NormalCasePasses) {
uint32_t elemsToRead = 100u; MARTe::uint32 elemsToRead = 100u;
uint32_t wireElemBytes = 4u; MARTe::uint32 wireElemBytes = 4u;
uint32_t off = 12u; MARTe::uint32 off = 12u;
uint32_t size = 500u; MARTe::uint32 size = 500u;
uint64_t bytesNeeded = static_cast<uint64_t>(off) + MARTe::uint64 bytesNeeded = static_cast<MARTe::uint64>(off) +
static_cast<uint64_t>(elemsToRead) * static_cast<MARTe::uint64>(elemsToRead) *
static_cast<uint64_t>(wireElemBytes); static_cast<MARTe::uint64>(wireElemBytes);
EXPECT_LE(bytesNeeded, static_cast<uint64_t>(size)) EXPECT_LE(bytesNeeded, static_cast<MARTe::uint64>(size))
<< "normal case should pass the bounds check"; << "normal case should pass the bounds check";
} }
// HI-1: Verify numRows * numCols overflow is detected. // HI-1: Verify numRows * numCols overflow is detected.
TEST(BoundsCheckTest, NumRowsNumColsOverflow) { TEST(BoundsCheckTest, NumRowsNumColsOverflow) {
uint32_t numRows = 0x10000u; MARTe::uint32 numRows = 0x10000u;
uint32_t numCols = 0x10000u; MARTe::uint32 numCols = 0x10000u;
// 32-bit: 0x10000 * 0x10000 = 0 (overflow!) // 32-bit: 0x10000 * 0x10000 = 0 (overflow!)
uint32_t oldResult = numRows * numCols; MARTe::uint32 oldResult = numRows * numCols;
EXPECT_EQ(oldResult, 0u) << "32-bit multiply should overflow to 0"; EXPECT_EQ(oldResult, 0u) << "32-bit multiply should overflow to 0";
// 64-bit fix: // 64-bit fix:
uint64_t newResult = static_cast<uint64_t>(numRows) * MARTe::uint64 newResult = static_cast<MARTe::uint64>(numRows) *
static_cast<uint64_t>(numCols); static_cast<MARTe::uint64>(numCols);
EXPECT_EQ(newResult, static_cast<uint64_t>(0x100000000u)) EXPECT_EQ(newResult, static_cast<MARTe::uint64>(0x100000000ULL))
<< "64-bit multiply should give correct result"; << "64-bit multiply should give correct result";
EXPECT_GT(newResult, static_cast<uint64_t>(0x100000u)) EXPECT_GT(newResult, static_cast<MARTe::uint64>(0x100000u))
<< "should exceed the sanity cap, triggering rejection"; << "should exceed the sanity cap, triggering rejection";
} }
+1 -1
View File
@@ -22,7 +22,7 @@
# #
############################################################# #############################################################
OBJSX = TriggerEngineSrc.x BinaryRecorderSrc.x SignalRingBufferGTest.x TriggerEngineGTest.x LTTBGTest.x BinaryRecorderGTest.x OBJSX = TriggerEngineSrc.x BinaryRecorderSrc.x SignalRingBufferGTest.x TriggerEngineGTest.x LTTBGTest.x BinaryRecorderGTest.x BoundsCheckTest.x WSServerBufferTest.x
PACKAGE=Applications PACKAGE=Applications
ROOT_DIR=../../.. ROOT_DIR=../../..