diff --git a/tests/edac/CRC_12_Test.cpp b/tests/edac/CRC_12_Test.cpp new file mode 100644 index 00000000..24c1cffe --- /dev/null +++ b/tests/edac/CRC_12_Test.cpp @@ -0,0 +1,81 @@ +/** +* Digital Voice Modem - Host Software (Test Suite) +* GPLv2 Open Source. Use is subject to license terms. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* @package DVM / Host Software / Test Suite +* +*/ +/* +* Copyright (C) 2023 Bryan Biedenkapp N2PLL +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include "Defines.h" +#include "edac/CRC.h" +#include "Log.h" +#include "Utils.h" + +using namespace edac; + +#include +#include +#include + +TEST_CASE("CRC", "[12-bit Test]") { + SECTION("12_Sanity_Test") { + bool failed = false; + + INFO("CRC 12-bit CRC Test"); + + srand((unsigned int)time(NULL)); + + const uint32_t len = 32U; + const uint32_t lenBits = len * 8U; + uint8_t* random = (uint8_t*)malloc(len); + + for (size_t i = 0; i < len - 2U; i++) { + random[i] = rand(); + } + + CRC::addCRC12(random, lenBits); + + uint16_t inCrc = (random[len - 2U] << 8) | (random[len - 1U] << 0); + ::LogDebug("T", "CRC::checkCRC12(), crc = $%04X", inCrc); + + Utils::dump(2U, "12_Sanity_Test CRC", random, len); + + bool ret = CRC::checkCRC12(random, lenBits); + if (!ret) { + ::LogDebug("T", "12_Sanity_Test, failed CRC12 check"); + failed = true; + goto cleanup; + } + + random[10U] >>= 8; + random[11U] >>= 8; + + ret = CRC::checkCRC12(random, lenBits); + if (ret) { + ::LogDebug("T", "12_Sanity_Test, failed CRC12 error check"); + failed = true; + goto cleanup; + } + +cleanup: + delete random; + REQUIRE(failed==false); + } +} diff --git a/tests/edac/CRC_15_Test.cpp b/tests/edac/CRC_15_Test.cpp new file mode 100644 index 00000000..7b21b316 --- /dev/null +++ b/tests/edac/CRC_15_Test.cpp @@ -0,0 +1,81 @@ +/** +* Digital Voice Modem - Host Software (Test Suite) +* GPLv2 Open Source. Use is subject to license terms. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* @package DVM / Host Software / Test Suite +* +*/ +/* +* Copyright (C) 2023 Bryan Biedenkapp N2PLL +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include "Defines.h" +#include "edac/CRC.h" +#include "Log.h" +#include "Utils.h" + +using namespace edac; + +#include +#include +#include + +TEST_CASE("CRC", "[15-bit Test]") { + SECTION("15_Sanity_Test") { + bool failed = false; + + INFO("CRC 15-bit CRC Test"); + + srand((unsigned int)time(NULL)); + + const uint32_t len = 32U; + const uint32_t lenBits = len * 8U; + uint8_t* random = (uint8_t*)malloc(len); + + for (size_t i = 0; i < len - 2U; i++) { + random[i] = rand(); + } + + CRC::addCRC15(random, lenBits); + + uint16_t inCrc = (random[len - 2U] << 8) | (random[len - 1U] << 0); + ::LogDebug("T", "CRC::checkCRC15(), crc = $%04X", inCrc); + + Utils::dump(2U, "15_Sanity_Test CRC", random, len); + + bool ret = CRC::checkCRC15(random, lenBits); + if (!ret) { + ::LogDebug("T", "15_Sanity_Test, failed CRC15 check"); + failed = true; + goto cleanup; + } + + random[10U] >>= 8; + random[11U] >>= 8; + + ret = CRC::checkCRC15(random, lenBits); + if (ret) { + ::LogDebug("T", "15_Sanity_Test, failed CRC15 error check"); + failed = true; + goto cleanup; + } + +cleanup: + delete random; + REQUIRE(failed==false); + } +} diff --git a/tests/edac/CRC_16_Test.cpp b/tests/edac/CRC_16_Test.cpp new file mode 100644 index 00000000..59efd188 --- /dev/null +++ b/tests/edac/CRC_16_Test.cpp @@ -0,0 +1,81 @@ +/** +* Digital Voice Modem - Host Software (Test Suite) +* GPLv2 Open Source. Use is subject to license terms. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* @package DVM / Host Software / Test Suite +* +*/ +/* +* Copyright (C) 2023 Bryan Biedenkapp N2PLL +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include "Defines.h" +#include "edac/CRC.h" +#include "Log.h" +#include "Utils.h" + +using namespace edac; + +#include +#include +#include + +TEST_CASE("CRC", "[16-bit Test]") { + SECTION("16_Sanity_Test") { + bool failed = false; + + INFO("CRC 16-bit CRC Test"); + + srand((unsigned int)time(NULL)); + + const uint32_t len = 32U; + const uint32_t lenBits = len * 8U; + uint8_t* random = (uint8_t*)malloc(len); + + for (size_t i = 0; i < len - 2U; i++) { + random[i] = rand(); + } + + CRC::addCRC16(random, lenBits); + + uint16_t inCrc = (random[len - 2U] << 8) | (random[len - 1U] << 0); + ::LogDebug("T", "CRC::checkCRC16(), crc = $%04X", inCrc); + + Utils::dump(2U, "16_Sanity_Test CRC", random, len); + + bool ret = CRC::checkCRC16(random, lenBits); + if (!ret) { + ::LogDebug("T", "16_Sanity_Test, failed CRC16 check"); + failed = true; + goto cleanup; + } + + random[10U] >>= 8; + random[11U] >>= 8; + + ret = CRC::checkCRC16(random, lenBits); + if (ret) { + ::LogDebug("T", "16_Sanity_Test, failed CRC16 error check"); + failed = true; + goto cleanup; + } + +cleanup: + delete random; + REQUIRE(failed==false); + } +} diff --git a/tests/edac/CRC_32_Test.cpp b/tests/edac/CRC_32_Test.cpp index 1364b5e7..1d78f553 100644 --- a/tests/edac/CRC_32_Test.cpp +++ b/tests/edac/CRC_32_Test.cpp @@ -34,8 +34,8 @@ using namespace edac; #include #include -TEST_CASE("CRC", "[32_Test]") { - SECTION("32_Test") { +TEST_CASE("CRC", "[32-bit Test]") { + SECTION("32_Sanity_Test") { bool failed = false; INFO("CRC 32-bit CRC Test"); @@ -51,11 +51,14 @@ TEST_CASE("CRC", "[32_Test]") { CRC::addCRC32(random, len); - Utils::dump(2U, "32_Test CRC", random, len); + uint32_t inCrc = (random[len - 4U] << 24) | (random[len - 3U] << 16) | (random[len - 2U] << 8) | (random[len - 1U] << 0); + ::LogDebug("T", "CRC::checkCRC32(), crc = $%08X", inCrc); + + Utils::dump(2U, "32_Sanity_Test CRC", random, len); bool ret = CRC::checkCRC32(random, len); if (!ret) { - ::LogDebug("T", "32_Test, failed CRC32 check"); + ::LogDebug("T", "32_Sanity_Test, failed CRC32 check"); failed = true; goto cleanup; } @@ -65,7 +68,7 @@ TEST_CASE("CRC", "[32_Test]") { ret = CRC::checkCRC32(random, len); if (ret) { - ::LogDebug("T", "32_Test, failed CRC32 check"); + ::LogDebug("T", "32_Sanity_Test, failed CRC32 error check"); failed = true; goto cleanup; } diff --git a/tests/edac/CRC_6_Test.cpp b/tests/edac/CRC_6_Test.cpp new file mode 100644 index 00000000..8c8487f7 --- /dev/null +++ b/tests/edac/CRC_6_Test.cpp @@ -0,0 +1,81 @@ +/** +* Digital Voice Modem - Host Software (Test Suite) +* GPLv2 Open Source. Use is subject to license terms. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* @package DVM / Host Software / Test Suite +* +*/ +/* +* Copyright (C) 2023 Bryan Biedenkapp N2PLL +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include "Defines.h" +#include "edac/CRC.h" +#include "Log.h" +#include "Utils.h" + +using namespace edac; + +#include +#include +#include + +TEST_CASE("CRC", "[6-bit Test]") { + SECTION("6_Sanity_Test") { + bool failed = false; + + INFO("CRC 6-bit CRC Test"); + + srand((unsigned int)time(NULL)); + + const uint32_t len = 32U; + const uint32_t lenBits = len * 8U; + uint8_t* random = (uint8_t*)malloc(len); + + for (size_t i = 0; i < len - 1U; i++) { + random[i] = rand(); + } + + CRC::addCRC6(random, lenBits); + + uint32_t inCrc = (random[len - 1U] << 0); + ::LogDebug("T", "CRC::checkCRC6(), crc = $%02X", inCrc); + + Utils::dump(2U, "6_Sanity_Test CRC", random, len); + + bool ret = CRC::checkCRC6(random, lenBits); + if (!ret) { + ::LogDebug("T", "6_Sanity_Test, failed CRC6 check"); + failed = true; + goto cleanup; + } + + random[10U] >>= 8; + random[11U] >>= 8; + + ret = CRC::checkCRC6(random, lenBits); + if (ret) { + ::LogDebug("T", "6_Sanity_Test, failed CRC6 error check"); + failed = true; + goto cleanup; + } + +cleanup: + delete random; + REQUIRE(failed==false); + } +} diff --git a/tests/edac/CRC_8_Test.cpp b/tests/edac/CRC_8_Test.cpp new file mode 100644 index 00000000..07bd0d2f --- /dev/null +++ b/tests/edac/CRC_8_Test.cpp @@ -0,0 +1,72 @@ +/** +* Digital Voice Modem - Host Software (Test Suite) +* GPLv2 Open Source. Use is subject to license terms. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* @package DVM / Host Software / Test Suite +* +*/ +/* +* Copyright (C) 2023 Bryan Biedenkapp N2PLL +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include "Defines.h" +#include "edac/CRC.h" +#include "Log.h" +#include "Utils.h" + +using namespace edac; + +#include +#include +#include + +TEST_CASE("CRC", "[8-bit Test]") { + SECTION("8_Sanity_Test") { + bool failed = false; + + INFO("CRC 8-bit CRC Test"); + + srand((unsigned int)time(NULL)); + + const uint32_t len = 32U; + uint8_t* random = (uint8_t*)malloc(len); + + for (size_t i = 0; i < len; i++) { + random[i] = rand(); + } + + uint8_t crc = CRC::crc8(random, len); + ::LogDebug("T", "crc = %02X", crc); + + Utils::dump(2U, "8_Sanity_Test CRC", random, len); + + random[10U] >>= 8; + random[11U] >>= 8; + + uint8_t calc = CRC::crc8(random, len); + ::LogDebug("T", "calc = %02X", calc); + if (crc == calc) { + ::LogDebug("T", "8_Sanity_Test, failed CRC8 error check"); + failed = true; + goto cleanup; + } + +cleanup: + delete random; + REQUIRE(failed==false); + } +} diff --git a/tests/edac/CRC_9_Test.cpp b/tests/edac/CRC_9_Test.cpp new file mode 100644 index 00000000..715e341e --- /dev/null +++ b/tests/edac/CRC_9_Test.cpp @@ -0,0 +1,77 @@ +/** +* Digital Voice Modem - Host Software (Test Suite) +* GPLv2 Open Source. Use is subject to license terms. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* @package DVM / Host Software / Test Suite +* +*/ +/* +* Copyright (C) 2023 Bryan Biedenkapp N2PLL +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include "Defines.h" +#include "edac/CRC.h" +#include "Log.h" +#include "Utils.h" + +using namespace edac; + +#include +#include +#include + +TEST_CASE("CRC", "[9-bit Test]") { + SECTION("9_Sanity_Test") { + bool failed = false; + + INFO("CRC 9-bit CRC Test"); + + srand((unsigned int)time(NULL)); + + const uint32_t len = 18U; + uint8_t* random = (uint8_t*)malloc(len); + + for (size_t i = 0; i < len; i++) { + random[i] = rand(); + } + + random[0U] = 0; + random[1U] = 0; + + uint16_t crc = edac::CRC::crc9(random, 144U); + ::LogDebug("T", "crc = %04X", crc); + + random[0U] = random[0U] + ((crc >> 8) & 0x01U); + random[1U] = (crc & 0xFFU); + + Utils::dump(2U, "9_Sanity_Test CRC", random, len); + + random[10U] >>= 8; + random[11U] >>= 8; + + uint16_t calculated = edac::CRC::crc9(random, 144U); + if (((crc ^ calculated) == 0) || ((crc ^ calculated) == 0x1FFU)) { + ::LogDebug("T", "9_Sanity_Test, failed CRC9 error check"); + failed = true; + goto cleanup; + } + +cleanup: + delete random; + REQUIRE(failed==false); + } +} diff --git a/tests/edac/CRC_CCITT_161_Test.cpp b/tests/edac/CRC_CCITT_161_Test.cpp index ddedafbf..8c58fa63 100644 --- a/tests/edac/CRC_CCITT_161_Test.cpp +++ b/tests/edac/CRC_CCITT_161_Test.cpp @@ -34,8 +34,8 @@ using namespace edac; #include #include -TEST_CASE("CRC", "[CCITT-161_Test]") { - SECTION("CCITT-161_Test") { +TEST_CASE("CRC", "[16-bit CCITT-161 Test]") { + SECTION("CCITT-161_Sanity_Test") { bool failed = false; INFO("CRC CCITT-161 16-bit CRC Test"); @@ -51,11 +51,14 @@ TEST_CASE("CRC", "[CCITT-161_Test]") { CRC::addCCITT161(random, len); - Utils::dump(2U, "CCITT-161_Test CRC", random, len); + uint16_t inCrc = (random[len - 2U] << 8) | (random[len - 1U] << 0); + ::LogDebug("T", "CRC::checkCCITT161(), crc = $%04X", inCrc); + + Utils::dump(2U, "CCITT-161_Sanity_Test CRC", random, len); bool ret = CRC::checkCCITT161(random, len); if (!ret) { - ::LogDebug("T", "CCITT-161_Test, failed CRC CCITT-162 check"); + ::LogDebug("T", "CCITT-161_Sanity_Test, failed CRC CCITT-162 check"); failed = true; goto cleanup; } @@ -65,7 +68,7 @@ TEST_CASE("CRC", "[CCITT-161_Test]") { ret = CRC::checkCCITT161(random, len); if (ret) { - ::LogDebug("T", "CCITT-161_Test, failed CRC CCITT-162 check"); + ::LogDebug("T", "CCITT-161_Sanity_Test, failed CRC CCITT-162 error check"); failed = true; goto cleanup; } diff --git a/tests/edac/CRC_CCITT_162_Test.cpp b/tests/edac/CRC_CCITT_162_Test.cpp index 38421088..0c1a65e6 100644 --- a/tests/edac/CRC_CCITT_162_Test.cpp +++ b/tests/edac/CRC_CCITT_162_Test.cpp @@ -34,8 +34,8 @@ using namespace edac; #include #include -TEST_CASE("CRC", "[CCITT-162_Test]") { - SECTION("CCITT-162_Test") { +TEST_CASE("CRC", "[16-bit CCITT-162 Test]") { + SECTION("CCITT-162_Sanity_Test") { bool failed = false; INFO("CRC CCITT-162 16-bit CRC Test"); @@ -51,11 +51,14 @@ TEST_CASE("CRC", "[CCITT-162_Test]") { CRC::addCCITT162(random, len); - Utils::dump(2U, "CCITT-162_Test CRC", random, len); + uint16_t inCrc = (random[len - 2U] << 8) | (random[len - 1U] << 0); + ::LogDebug("T", "CRC::checkCCITT162(), crc = $%04X", inCrc); + + Utils::dump(2U, "CCITT-162_Sanity_Test CRC", random, len); bool ret = CRC::checkCCITT162(random, len); if (!ret) { - ::LogDebug("T", "CCITT-162_Test, failed CRC CCITT-162 check"); + ::LogDebug("T", "CCITT-162_Sanity_Test, failed CRC CCITT-162 check"); failed = true; goto cleanup; } @@ -65,7 +68,7 @@ TEST_CASE("CRC", "[CCITT-162_Test]") { ret = CRC::checkCCITT162(random, len); if (ret) { - ::LogDebug("T", "CCITT-162_Test, failed CRC CCITT-162 check"); + ::LogDebug("T", "CCITT-162_Sanity_Test, failed CRC CCITT-162 error check"); failed = true; goto cleanup; } diff --git a/tests/p25/HDU_RS_Test.cpp b/tests/p25/HDU_RS_Test.cpp index e548b1cd..5ca37daa 100644 --- a/tests/p25/HDU_RS_Test.cpp +++ b/tests/p25/HDU_RS_Test.cpp @@ -36,7 +36,7 @@ using namespace p25; #include #include -TEST_CASE("HDU", "[RS_362017_Test]") { +TEST_CASE("HDU", "[Reed-Soloman 36,20,17 Test]") { SECTION("RS_362017_Test") { bool failed = false; diff --git a/tests/p25/LDU1_RS_Test.cpp b/tests/p25/LDU1_RS_Test.cpp index 769168fa..6fb48345 100644 --- a/tests/p25/LDU1_RS_Test.cpp +++ b/tests/p25/LDU1_RS_Test.cpp @@ -36,7 +36,7 @@ using namespace p25; #include #include -TEST_CASE("LDU1", "[RS_241213_Test]") { +TEST_CASE("LDU1", "[Reed-Soloman 24,12,13 Test]") { SECTION("RS_241213_Test") { bool failed = false; diff --git a/tests/p25/LDU2_RS_Test.cpp b/tests/p25/LDU2_RS_Test.cpp index a25df19b..4ec861c5 100644 --- a/tests/p25/LDU2_RS_Test.cpp +++ b/tests/p25/LDU2_RS_Test.cpp @@ -36,7 +36,7 @@ using namespace p25; #include #include -TEST_CASE("LDU2", "[RS_24169_Test]") { +TEST_CASE("LDU2", "[Reed-Soloman 24,16,9 Test]") { SECTION("RS_24169_Test") { bool failed = false;