diff --git a/Test/Applications/StreamHub/BoundsCheckTest.cpp b/Test/Applications/StreamHub/BoundsCheckTest.cpp index 33c7793..f65d42d 100644 --- a/Test/Applications/StreamHub/BoundsCheckTest.cpp +++ b/Test/Applications/StreamHub/BoundsCheckTest.cpp @@ -9,8 +9,7 @@ */ #include -#include -#include +#include "GeneralDefinitions.h" // HI-1: Verify that a 64-bit bounds check rejects a payload where // elemsToRead * wireElemBytes would overflow uint32. @@ -18,56 +17,57 @@ TEST(BoundsCheckTest, OverflowRejected) { // Simulate: numSamples = 0x20000001, wireElemBytes = 8 // 32-bit: 0x20000001 * 8 = 0x8 (overflow!) // 64-bit: 0x100000008 (correctly large, > any reasonable payload size) - uint32_t elemsToRead = 0x20000001u; - uint32_t wireElemBytes = 8u; - uint32_t off = 12u; // after HRT + numSamples - uint32_t size = 1400u; // typical max payload + MARTe::uint32 elemsToRead = 0x20000001u; + MARTe::uint32 wireElemBytes = 8u; + MARTe::uint32 off = 12u; // after HRT + numSamples + MARTe::uint32 size = 1400u; // typical max payload // This is the FIXED pattern (64-bit): - uint64_t bytesNeeded = static_cast(off) + - static_cast(elemsToRead) * - static_cast(wireElemBytes); + MARTe::uint64 bytesNeeded = static_cast(off) + + static_cast(elemsToRead) * + static_cast(wireElemBytes); // Should reject (bytesNeeded >> size) - EXPECT_GT(bytesNeeded, static_cast(size)) + EXPECT_GT(bytesNeeded, static_cast(size)) << "64-bit check should detect overflow that 32-bit would miss"; // 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 // 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 // This test documents that the 64-bit fix is necessary on 32-bit platforms // and correct on 64-bit. + (void) oldCheck; } // HI-1: Verify a normal (non-overflow) case passes the 64-bit check. TEST(BoundsCheckTest, NormalCasePasses) { - uint32_t elemsToRead = 100u; - uint32_t wireElemBytes = 4u; - uint32_t off = 12u; - uint32_t size = 500u; + MARTe::uint32 elemsToRead = 100u; + MARTe::uint32 wireElemBytes = 4u; + MARTe::uint32 off = 12u; + MARTe::uint32 size = 500u; - uint64_t bytesNeeded = static_cast(off) + - static_cast(elemsToRead) * - static_cast(wireElemBytes); - EXPECT_LE(bytesNeeded, static_cast(size)) + MARTe::uint64 bytesNeeded = static_cast(off) + + static_cast(elemsToRead) * + static_cast(wireElemBytes); + EXPECT_LE(bytesNeeded, static_cast(size)) << "normal case should pass the bounds check"; } // HI-1: Verify numRows * numCols overflow is detected. TEST(BoundsCheckTest, NumRowsNumColsOverflow) { - uint32_t numRows = 0x10000u; - uint32_t numCols = 0x10000u; + MARTe::uint32 numRows = 0x10000u; + MARTe::uint32 numCols = 0x10000u; // 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"; // 64-bit fix: - uint64_t newResult = static_cast(numRows) * - static_cast(numCols); - EXPECT_EQ(newResult, static_cast(0x100000000u)) + MARTe::uint64 newResult = static_cast(numRows) * + static_cast(numCols); + EXPECT_EQ(newResult, static_cast(0x100000000ULL)) << "64-bit multiply should give correct result"; - EXPECT_GT(newResult, static_cast(0x100000u)) + EXPECT_GT(newResult, static_cast(0x100000u)) << "should exceed the sanity cap, triggering rejection"; } diff --git a/Test/Applications/StreamHub/Makefile.inc b/Test/Applications/StreamHub/Makefile.inc index 79eea1e..4afea34 100644 --- a/Test/Applications/StreamHub/Makefile.inc +++ b/Test/Applications/StreamHub/Makefile.inc @@ -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 ROOT_DIR=../../..