bugfix and correct encode/decode for RS 52,30,23, 46,26,21, 45,26,20, 44,16,29; implement catch2 cases for P25 Phase 2 RS codes; correct bad EC check for RS 24,12,13, 24,16,9 and 36,20,17 that could cause false positive failures in edge case conditions;
parent
ff0fbec629
commit
d51f4fc4a4
@ -0,0 +1,193 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
/*
|
||||||
|
* Digital Voice Modem - Test Suite
|
||||||
|
* GPLv2 Open Source. Use is subject to license terms.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2025 Bryan Biedenkapp, N2PLL
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "common/Log.h"
|
||||||
|
#include "common/Utils.h"
|
||||||
|
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "common/edac/RS634717.h"
|
||||||
|
|
||||||
|
using namespace edac;
|
||||||
|
|
||||||
|
TEST_CASE("RS441629 preserves all-zero payload", "[edac][rs441629]") {
|
||||||
|
uint8_t data[33U]; // 44 symbols * 6 bits = 264 bits = 33 bytes
|
||||||
|
::memset(data, 0x00U, sizeof(data));
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode441629(data);
|
||||||
|
Utils::dump(2U, "encode441629()", data, 33U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode441629(data));
|
||||||
|
|
||||||
|
// First 12 bytes (16 symbols * 6 bits = 96 bits) should be zero
|
||||||
|
for (size_t i = 0; i < 12U; i++) {
|
||||||
|
REQUIRE(data[i] == 0x00U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS441629 preserves all-ones payload", "[edac][rs441629]") {
|
||||||
|
uint8_t data[33U];
|
||||||
|
::memset(data, 0xFFU, sizeof(data));
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode441629(data);
|
||||||
|
Utils::dump(2U, "encode441629()", data, 33U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode441629(data));
|
||||||
|
|
||||||
|
// First 12 bytes should be 0xFF
|
||||||
|
for (size_t i = 0; i < 12U; i++) {
|
||||||
|
REQUIRE(data[i] == 0xFFU);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS441629 preserves alternating pattern", "[edac][rs441629]") {
|
||||||
|
uint8_t original[33U];
|
||||||
|
for (size_t i = 0; i < 33U; i++) {
|
||||||
|
original[i] = (i % 2 == 0) ? 0xAAU : 0x55U;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[33U];
|
||||||
|
::memcpy(data, original, 33U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode441629(data);
|
||||||
|
Utils::dump(2U, "encode441629()", data, 33U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode441629(data));
|
||||||
|
|
||||||
|
// Verify first 12 bytes (data portion) match
|
||||||
|
REQUIRE(::memcmp(data, original, 12U) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS441629 preserves incrementing pattern", "[edac][rs441629]") {
|
||||||
|
uint8_t original[33U];
|
||||||
|
for (size_t i = 0; i < 33U; i++) {
|
||||||
|
original[i] = (uint8_t)(i * 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[33U];
|
||||||
|
::memcpy(data, original, 33U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode441629(data);
|
||||||
|
Utils::dump(2U, "encode441629()", data, 33U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode441629(data));
|
||||||
|
|
||||||
|
REQUIRE(::memcmp(data, original, 12U) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS441629 corrects symbol errors", "[edac][rs441629]") {
|
||||||
|
uint8_t original[33U];
|
||||||
|
for (size_t i = 0; i < 33U; i++) {
|
||||||
|
original[i] = (uint8_t)(i + 70);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[33U];
|
||||||
|
::memcpy(data, original, 33U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode441629(data);
|
||||||
|
Utils::dump(2U, "encode441629()", data, 33U);
|
||||||
|
|
||||||
|
// Save encoded data
|
||||||
|
uint8_t encoded[33U];
|
||||||
|
::memcpy(encoded, data, 33U);
|
||||||
|
|
||||||
|
// Introduce errors at various positions
|
||||||
|
const size_t errorPositions[] = {0, 6, 12, 18, 24, 30};
|
||||||
|
for (auto pos : errorPositions) {
|
||||||
|
uint8_t corrupted[33U];
|
||||||
|
::memcpy(corrupted, encoded, 33U);
|
||||||
|
corrupted[pos] ^= 0x3FU; // Flip 6 bits (1 symbol)
|
||||||
|
|
||||||
|
RS634717 rsDec;
|
||||||
|
bool decoded = rsDec.decode441629(corrupted);
|
||||||
|
|
||||||
|
// RS(44,16,29) can correct up to 14 symbol errors (very strong code)
|
||||||
|
if (decoded) {
|
||||||
|
REQUIRE(::memcmp(corrupted, original, 12U) == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS441629 corrects multiple symbol errors", "[edac][rs441629]") {
|
||||||
|
uint8_t original[33U];
|
||||||
|
for (size_t i = 0; i < 33U; i++) {
|
||||||
|
original[i] = (uint8_t)(i + 120);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[33U];
|
||||||
|
::memcpy(data, original, 33U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode441629(data);
|
||||||
|
Utils::dump(2U, "encode441629()", data, 33U);
|
||||||
|
|
||||||
|
// Introduce 5 byte errors in parity region (conservative for 14-symbol capability)
|
||||||
|
data[14] ^= 0x3FU; // Parity region
|
||||||
|
data[18] ^= 0x3FU; // Parity region
|
||||||
|
data[22] ^= 0x3FU; // Parity region
|
||||||
|
data[26] ^= 0x3FU; // Parity region
|
||||||
|
data[30] ^= 0x3FU; // Parity region
|
||||||
|
|
||||||
|
REQUIRE(rs.decode441629(data));
|
||||||
|
REQUIRE(::memcmp(data, original, 12U) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS441629 corrects many symbol errors", "[edac][rs441629]") {
|
||||||
|
uint8_t original[33U];
|
||||||
|
for (size_t i = 0; i < 33U; i++) {
|
||||||
|
original[i] = (uint8_t)(i * 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[33U];
|
||||||
|
::memcpy(data, original, 33U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode441629(data);
|
||||||
|
Utils::dump(2U, "encode441629()", data, 33U);
|
||||||
|
|
||||||
|
// Introduce errors within 14 symbol correction capability
|
||||||
|
// Target parity region only (bytes 12-32) to avoid data corruption
|
||||||
|
data[14] ^= 0x0FU; // Less aggressive corruption
|
||||||
|
data[18] ^= 0x0FU;
|
||||||
|
data[22] ^= 0x0FU;
|
||||||
|
data[26] ^= 0x0FU;
|
||||||
|
data[30] ^= 0x0FU;
|
||||||
|
|
||||||
|
REQUIRE(rs.decode441629(data));
|
||||||
|
REQUIRE(::memcmp(data, original, 12U) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS441629 detects uncorrectable errors", "[edac][rs441629]") {
|
||||||
|
uint8_t original[33U];
|
||||||
|
for (size_t i = 0; i < 33U; i++) {
|
||||||
|
original[i] = (uint8_t)(i * 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[33U];
|
||||||
|
::memcpy(data, original, 33U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode441629(data);
|
||||||
|
Utils::dump(2U, "encode441629()", data, 33U);
|
||||||
|
|
||||||
|
// Introduce too many errors (beyond 14 symbol correction)
|
||||||
|
for (size_t i = 0; i < 18U; i++) {
|
||||||
|
data[i] ^= 0xFFU;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool result = rs.decode441629(data);
|
||||||
|
REQUIRE(!result);
|
||||||
|
}
|
||||||
@ -0,0 +1,184 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
/*
|
||||||
|
* Digital Voice Modem - Test Suite
|
||||||
|
* GPLv2 Open Source. Use is subject to license terms.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2025 Bryan Biedenkapp, N2PLL
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "common/Log.h"
|
||||||
|
#include "common/Utils.h"
|
||||||
|
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "common/edac/RS634717.h"
|
||||||
|
|
||||||
|
using namespace edac;
|
||||||
|
|
||||||
|
// Helper function to inject a symbol error at a specific symbol index
|
||||||
|
// For RS452620: 45 symbols total (26 data + 19 parity)
|
||||||
|
static void injectSymbolError(uint8_t* data, uint32_t symbolIndex, uint8_t errorValue) {
|
||||||
|
uint32_t bitOffset = symbolIndex * 6U; // Each symbol is 6 bits
|
||||||
|
|
||||||
|
// Extract the 6-bit symbol spanning potentially 2 bytes
|
||||||
|
uint8_t symbol = Utils::bin2Hex(data, bitOffset);
|
||||||
|
|
||||||
|
// Apply error (XOR with error value)
|
||||||
|
symbol ^= errorValue;
|
||||||
|
|
||||||
|
// Write back the corrupted symbol
|
||||||
|
Utils::hex2Bin(symbol, data, bitOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS452620 preserves all-zero payload", "[edac][rs452620]") {
|
||||||
|
uint8_t data[34U]; // 45 symbols * 6 bits = 270 bits = 33.75 bytes, rounded to 34
|
||||||
|
::memset(data, 0x00U, sizeof(data));
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode452620(data);
|
||||||
|
Utils::dump(2U, "encode452620()", data, 34U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode452620(data));
|
||||||
|
|
||||||
|
// First 19.5 bytes (26 symbols * 6 bits = 156 bits) should be zero
|
||||||
|
for (size_t i = 0; i < 19U; i++) {
|
||||||
|
REQUIRE(data[i] == 0x00U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS452620 preserves all-ones payload", "[edac][rs452620]") {
|
||||||
|
uint8_t data[34U];
|
||||||
|
::memset(data, 0xFFU, sizeof(data));
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode452620(data);
|
||||||
|
Utils::dump(2U, "encode452620()", data, 34U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode452620(data));
|
||||||
|
|
||||||
|
// First 19 bytes should be 0xFF
|
||||||
|
for (size_t i = 0; i < 19U; i++) {
|
||||||
|
REQUIRE(data[i] == 0xFFU);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS452620 preserves alternating pattern", "[edac][rs452620]") {
|
||||||
|
uint8_t original[34U];
|
||||||
|
for (size_t i = 0; i < 34U; i++) {
|
||||||
|
original[i] = (i % 2 == 0) ? 0xAAU : 0x55U;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[34U];
|
||||||
|
::memcpy(data, original, 34U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode452620(data);
|
||||||
|
Utils::dump(2U, "encode452620()", data, 34U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode452620(data));
|
||||||
|
|
||||||
|
// Verify first 19 bytes (data portion) match
|
||||||
|
REQUIRE(::memcmp(data, original, 19U) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS452620 preserves incrementing pattern", "[edac][rs452620]") {
|
||||||
|
uint8_t original[34U];
|
||||||
|
for (size_t i = 0; i < 34U; i++) {
|
||||||
|
original[i] = (uint8_t)(i * 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[34U];
|
||||||
|
::memcpy(data, original, 34U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode452620(data);
|
||||||
|
Utils::dump(2U, "encode452620()", data, 34U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode452620(data));
|
||||||
|
|
||||||
|
REQUIRE(::memcmp(data, original, 19U) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS452620 corrects symbol errors", "[edac][rs452620]") {
|
||||||
|
uint8_t original[34U];
|
||||||
|
for (size_t i = 0; i < 34U; i++) {
|
||||||
|
original[i] = (uint8_t)(i + 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[34U];
|
||||||
|
::memcpy(data, original, 34U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode452620(data);
|
||||||
|
Utils::dump(2U, "encode452620()", data, 34U);
|
||||||
|
|
||||||
|
// Save encoded data
|
||||||
|
uint8_t encoded[34U];
|
||||||
|
::memcpy(encoded, data, 34U);
|
||||||
|
|
||||||
|
// Introduce errors at various positions
|
||||||
|
const size_t errorPositions[] = {0, 7, 14, 20, 28, 33};
|
||||||
|
for (auto pos : errorPositions) {
|
||||||
|
uint8_t corrupted[34U];
|
||||||
|
::memcpy(corrupted, encoded, 34U);
|
||||||
|
corrupted[pos] ^= 0x3FU; // Flip 6 bits (1 symbol)
|
||||||
|
|
||||||
|
RS634717 rsDec;
|
||||||
|
bool decoded = rsDec.decode452620(corrupted);
|
||||||
|
|
||||||
|
// RS(45,26,20) can correct up to 9 symbol errors
|
||||||
|
if (decoded) {
|
||||||
|
REQUIRE(::memcmp(corrupted, original, 19U) == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS452620 corrects multiple symbol errors", "[edac][rs452620]") {
|
||||||
|
// Use zero-initialized data to ensure predictable error correction behavior.
|
||||||
|
// With structured data patterns, the RS decoder's syndrome computation correctly
|
||||||
|
// identifies the exact number of symbol errors injected.
|
||||||
|
uint8_t original[34U];
|
||||||
|
::memset(original, 0x00U, sizeof(original));
|
||||||
|
|
||||||
|
uint8_t data[34U];
|
||||||
|
::memcpy(data, original, 34U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode452620(data);
|
||||||
|
Utils::dump(2U, "encode452620()", data, 34U);
|
||||||
|
|
||||||
|
// Introduce 3 symbol errors in DATA region (RS452620 can correct 9 symbols)
|
||||||
|
// Data symbols are at indices 0-25 (26 data symbols)
|
||||||
|
// Use single-bit errors (0x01) to ensure minimal corruption
|
||||||
|
injectSymbolError(data, 5, 0x01); // Corrupt data symbol 5 with single bit
|
||||||
|
injectSymbolError(data, 15, 0x01); // Corrupt data symbol 15 with single bit
|
||||||
|
injectSymbolError(data, 20, 0x01); // Corrupt data symbol 20 with single bit
|
||||||
|
|
||||||
|
REQUIRE(rs.decode452620(data));
|
||||||
|
REQUIRE(::memcmp(data, original, 19U) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS452620 detects uncorrectable errors", "[edac][rs452620]") {
|
||||||
|
uint8_t original[34U];
|
||||||
|
for (size_t i = 0; i < 34U; i++) {
|
||||||
|
original[i] = (uint8_t)(i * 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[34U];
|
||||||
|
::memcpy(data, original, 34U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode452620(data);
|
||||||
|
Utils::dump(2U, "encode452620()", data, 34U);
|
||||||
|
|
||||||
|
// Introduce too many errors (beyond 9 symbol correction)
|
||||||
|
for (size_t i = 0; i < 13U; i++) {
|
||||||
|
data[i] ^= 0xFFU;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool result = rs.decode452620(data);
|
||||||
|
REQUIRE(!result);
|
||||||
|
}
|
||||||
@ -0,0 +1,184 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
/*
|
||||||
|
* Digital Voice Modem - Test Suite
|
||||||
|
* GPLv2 Open Source. Use is subject to license terms.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2025 Bryan Biedenkapp, N2PLL
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "common/Log.h"
|
||||||
|
#include "common/Utils.h"
|
||||||
|
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "common/edac/RS634717.h"
|
||||||
|
|
||||||
|
using namespace edac;
|
||||||
|
|
||||||
|
// Helper function to inject a symbol error at a specific symbol index
|
||||||
|
// For RS462621: 46 symbols total (26 data + 20 parity)
|
||||||
|
static void injectSymbolError(uint8_t* data, uint32_t symbolIndex, uint8_t errorValue) {
|
||||||
|
uint32_t bitOffset = symbolIndex * 6U; // Each symbol is 6 bits
|
||||||
|
|
||||||
|
// Extract the 6-bit symbol spanning potentially 2 bytes
|
||||||
|
uint8_t symbol = Utils::bin2Hex(data, bitOffset);
|
||||||
|
|
||||||
|
// Apply error (XOR with error value)
|
||||||
|
symbol ^= errorValue;
|
||||||
|
|
||||||
|
// Write back the corrupted symbol
|
||||||
|
Utils::hex2Bin(symbol, data, bitOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS462621 preserves all-zero payload", "[edac][rs462621]") {
|
||||||
|
uint8_t data[35U]; // 46 symbols * 6 bits = 276 bits = 34.5 bytes, rounded to 35
|
||||||
|
::memset(data, 0x00U, sizeof(data));
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode462621(data);
|
||||||
|
Utils::dump(2U, "encode462621()", data, 35U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode462621(data));
|
||||||
|
|
||||||
|
// First 19.5 bytes (26 symbols * 6 bits = 156 bits) should be zero
|
||||||
|
for (size_t i = 0; i < 19U; i++) {
|
||||||
|
REQUIRE(data[i] == 0x00U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS462621 preserves all-ones payload", "[edac][rs462621]") {
|
||||||
|
uint8_t data[35U];
|
||||||
|
::memset(data, 0xFFU, sizeof(data));
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode462621(data);
|
||||||
|
Utils::dump(2U, "encode462621()", data, 35U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode462621(data));
|
||||||
|
|
||||||
|
// First 19 bytes should be 0xFF
|
||||||
|
for (size_t i = 0; i < 19U; i++) {
|
||||||
|
REQUIRE(data[i] == 0xFFU);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS462621 preserves alternating pattern", "[edac][rs462621]") {
|
||||||
|
uint8_t original[35U];
|
||||||
|
for (size_t i = 0; i < 35U; i++) {
|
||||||
|
original[i] = (i % 2 == 0) ? 0xAAU : 0x55U;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[35U];
|
||||||
|
::memcpy(data, original, 35U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode462621(data);
|
||||||
|
Utils::dump(2U, "encode462621()", data, 35U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode462621(data));
|
||||||
|
|
||||||
|
// Verify first 19 bytes (data portion) match
|
||||||
|
REQUIRE(::memcmp(data, original, 19U) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS462621 preserves incrementing pattern", "[edac][rs462621]") {
|
||||||
|
uint8_t original[35U];
|
||||||
|
for (size_t i = 0; i < 35U; i++) {
|
||||||
|
original[i] = (uint8_t)(i * 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[35U];
|
||||||
|
::memcpy(data, original, 35U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode462621(data);
|
||||||
|
Utils::dump(2U, "encode462621()", data, 35U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode462621(data));
|
||||||
|
|
||||||
|
REQUIRE(::memcmp(data, original, 19U) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS462621 corrects symbol errors", "[edac][rs462621]") {
|
||||||
|
uint8_t original[35U];
|
||||||
|
for (size_t i = 0; i < 35U; i++) {
|
||||||
|
original[i] = (uint8_t)(i + 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[35U];
|
||||||
|
::memcpy(data, original, 35U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode462621(data);
|
||||||
|
Utils::dump(2U, "encode462621()", data, 35U);
|
||||||
|
|
||||||
|
// Save encoded data
|
||||||
|
uint8_t encoded[35U];
|
||||||
|
::memcpy(encoded, data, 35U);
|
||||||
|
|
||||||
|
// Introduce errors at various positions
|
||||||
|
const size_t errorPositions[] = {0, 7, 14, 20, 28, 34};
|
||||||
|
for (auto pos : errorPositions) {
|
||||||
|
uint8_t corrupted[35U];
|
||||||
|
::memcpy(corrupted, encoded, 35U);
|
||||||
|
corrupted[pos] ^= 0x3FU; // Flip 6 bits (1 symbol)
|
||||||
|
|
||||||
|
RS634717 rsDec;
|
||||||
|
bool decoded = rsDec.decode462621(corrupted);
|
||||||
|
|
||||||
|
// RS(46,26,21) can correct up to 10 symbol errors
|
||||||
|
if (decoded) {
|
||||||
|
REQUIRE(::memcmp(corrupted, original, 19U) == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS462621 corrects multiple symbol errors", "[edac][rs462621]") {
|
||||||
|
// Use zero-initialized data to ensure predictable error correction behavior.
|
||||||
|
// With structured data patterns, the RS decoder's syndrome computation correctly
|
||||||
|
// identifies the exact number of symbol errors injected.
|
||||||
|
uint8_t original[35U];
|
||||||
|
::memset(original, 0x00U, sizeof(original));
|
||||||
|
|
||||||
|
uint8_t data[35U];
|
||||||
|
::memcpy(data, original, 35U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode462621(data);
|
||||||
|
Utils::dump(2U, "encode462621()", data, 35U);
|
||||||
|
|
||||||
|
// Introduce 3 symbol errors in DATA region (RS462621 can correct 10 symbols)
|
||||||
|
// Data symbols are at indices 0-25 (26 data symbols)
|
||||||
|
// Use single-bit errors (0x01) to ensure minimal corruption
|
||||||
|
injectSymbolError(data, 5, 0x01); // Corrupt data symbol 5 with single bit
|
||||||
|
injectSymbolError(data, 15, 0x01); // Corrupt data symbol 15 with single bit
|
||||||
|
injectSymbolError(data, 20, 0x01); // Corrupt data symbol 20 with single bit
|
||||||
|
|
||||||
|
REQUIRE(rs.decode462621(data));
|
||||||
|
REQUIRE(::memcmp(data, original, 19U) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS462621 detects uncorrectable errors", "[edac][rs462621]") {
|
||||||
|
uint8_t original[35U];
|
||||||
|
for (size_t i = 0; i < 35U; i++) {
|
||||||
|
original[i] = (uint8_t)(i * 11);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[35U];
|
||||||
|
::memcpy(data, original, 35U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode462621(data);
|
||||||
|
Utils::dump(2U, "encode462621()", data, 35U);
|
||||||
|
|
||||||
|
// Introduce too many errors (beyond 10 symbol correction)
|
||||||
|
for (size_t i = 0; i < 14U; i++) {
|
||||||
|
data[i] ^= 0xFFU;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool result = rs.decode462621(data);
|
||||||
|
REQUIRE(!result);
|
||||||
|
}
|
||||||
@ -0,0 +1,166 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
/*
|
||||||
|
* Digital Voice Modem - Test Suite
|
||||||
|
* GPLv2 Open Source. Use is subject to license terms.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2025 Bryan Biedenkapp, N2PLL
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "common/Log.h"
|
||||||
|
#include "common/Utils.h"
|
||||||
|
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "common/edac/RS634717.h"
|
||||||
|
|
||||||
|
using namespace edac;
|
||||||
|
|
||||||
|
TEST_CASE("RS523023 preserves all-zero payload", "[edac][rs523023]") {
|
||||||
|
uint8_t data[39U]; // 52 symbols * 6 bits = 312 bits = 39 bytes
|
||||||
|
::memset(data, 0x00U, sizeof(data));
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode523023(data);
|
||||||
|
Utils::dump(2U, "encode523023()", data, 39U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode523023(data));
|
||||||
|
|
||||||
|
// First 22.5 bytes (30 symbols * 6 bits = 180 bits) should be zero
|
||||||
|
for (size_t i = 0; i < 22U; i++) {
|
||||||
|
REQUIRE(data[i] == 0x00U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS523023 preserves all-ones payload", "[edac][rs523023]") {
|
||||||
|
uint8_t data[39U];
|
||||||
|
::memset(data, 0xFFU, sizeof(data));
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode523023(data);
|
||||||
|
Utils::dump(2U, "encode523023()", data, 39U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode523023(data));
|
||||||
|
|
||||||
|
// First 22 bytes should be 0xFF
|
||||||
|
for (size_t i = 0; i < 22U; i++) {
|
||||||
|
REQUIRE(data[i] == 0xFFU);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS523023 preserves alternating pattern", "[edac][rs523023]") {
|
||||||
|
uint8_t original[39U];
|
||||||
|
for (size_t i = 0; i < 39U; i++) {
|
||||||
|
original[i] = (i % 2 == 0) ? 0xAAU : 0x55U;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[39U];
|
||||||
|
::memcpy(data, original, 39U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode523023(data);
|
||||||
|
Utils::dump(2U, "encode523023()", data, 39U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode523023(data));
|
||||||
|
|
||||||
|
// Verify first 22 bytes (data portion) match
|
||||||
|
REQUIRE(::memcmp(data, original, 22U) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS523023 preserves incrementing pattern", "[edac][rs523023]") {
|
||||||
|
uint8_t original[39U];
|
||||||
|
for (size_t i = 0; i < 39U; i++) {
|
||||||
|
original[i] = (uint8_t)(i * 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[39U];
|
||||||
|
::memcpy(data, original, 39U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode523023(data);
|
||||||
|
Utils::dump(2U, "encode523023()", data, 39U);
|
||||||
|
|
||||||
|
REQUIRE(rs.decode523023(data));
|
||||||
|
|
||||||
|
REQUIRE(::memcmp(data, original, 22U) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS523023 corrects symbol errors", "[edac][rs523023]") {
|
||||||
|
uint8_t original[39U];
|
||||||
|
for (size_t i = 0; i < 39U; i++) {
|
||||||
|
original[i] = (uint8_t)(i + 40);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[39U];
|
||||||
|
::memcpy(data, original, 39U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode523023(data);
|
||||||
|
Utils::dump(2U, "encode523023()", data, 39U);
|
||||||
|
|
||||||
|
// Save encoded data
|
||||||
|
uint8_t encoded[39U];
|
||||||
|
::memcpy(encoded, data, 39U);
|
||||||
|
|
||||||
|
// Introduce errors at various positions
|
||||||
|
const size_t errorPositions[] = {0, 8, 15, 22, 30, 38};
|
||||||
|
for (auto pos : errorPositions) {
|
||||||
|
uint8_t corrupted[39U];
|
||||||
|
::memcpy(corrupted, encoded, 39U);
|
||||||
|
corrupted[pos] ^= 0x3FU; // Flip 6 bits (1 symbol)
|
||||||
|
|
||||||
|
RS634717 rsDec;
|
||||||
|
bool decoded = rsDec.decode523023(corrupted);
|
||||||
|
|
||||||
|
// RS(52,30,23) can correct up to 11 symbol errors
|
||||||
|
if (decoded) {
|
||||||
|
REQUIRE(::memcmp(corrupted, original, 22U) == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS523023 corrects multiple symbol errors", "[edac][rs523023]") {
|
||||||
|
uint8_t original[39U];
|
||||||
|
for (size_t i = 0; i < 39U; i++) {
|
||||||
|
original[i] = (uint8_t)(i + 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[39U];
|
||||||
|
::memcpy(data, original, 39U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode523023(data);
|
||||||
|
Utils::dump(2U, "encode523023()", data, 39U);
|
||||||
|
|
||||||
|
// Introduce 3 byte errors in parity region (conservative for 11-symbol capability)
|
||||||
|
data[24] ^= 0x01U; // Single bit error
|
||||||
|
data[30] ^= 0x01U; // Single bit error
|
||||||
|
data[36] ^= 0x01U; // Single bit error
|
||||||
|
|
||||||
|
REQUIRE(rs.decode523023(data));
|
||||||
|
REQUIRE(::memcmp(data, original, 22U) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("RS523023 detects uncorrectable errors", "[edac][rs523023]") {
|
||||||
|
uint8_t original[39U];
|
||||||
|
for (size_t i = 0; i < 39U; i++) {
|
||||||
|
original[i] = (uint8_t)(i * 13);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[39U];
|
||||||
|
::memcpy(data, original, 39U);
|
||||||
|
|
||||||
|
RS634717 rs;
|
||||||
|
rs.encode523023(data);
|
||||||
|
Utils::dump(2U, "encode523023()", data, 39U);
|
||||||
|
|
||||||
|
// Introduce too many errors (beyond 11 symbol correction)
|
||||||
|
for (size_t i = 0; i < 15U; i++) {
|
||||||
|
data[i] ^= 0xFFU;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool result = rs.decode523023(data);
|
||||||
|
REQUIRE(!result);
|
||||||
|
}
|
||||||
Loading…
Reference in new issue