diff --git a/CMakeLists.txt b/CMakeLists.txt index d78ee0a2..802e15bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,6 +131,8 @@ file(GLOB dvmcmd_SRC file(GLOB dvmtests_SRC "tests/nulltest.cpp" + "tests/edac/*.cpp" + "tests/p25/*.cpp" ) diff --git a/tests/edac/CRC_32_Test.cpp b/tests/edac/CRC_32_Test.cpp new file mode 100644 index 00000000..1364b5e7 --- /dev/null +++ b/tests/edac/CRC_32_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", "[32_Test]") { + SECTION("32_Test") { + bool failed = false; + + INFO("CRC 32-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 - 4U; i++) { + random[i] = rand(); + } + + CRC::addCRC32(random, len); + + Utils::dump(2U, "32_Test CRC", random, len); + + bool ret = CRC::checkCRC32(random, len); + if (!ret) { + ::LogDebug("T", "32_Test, failed CRC32 check"); + failed = true; + goto cleanup; + } + + random[10U] >>= 8; + random[11U] >>= 8; + + ret = CRC::checkCRC32(random, len); + if (ret) { + ::LogDebug("T", "32_Test, failed CRC32 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 new file mode 100644 index 00000000..ddedafbf --- /dev/null +++ b/tests/edac/CRC_CCITT_161_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", "[CCITT-161_Test]") { + SECTION("CCITT-161_Test") { + bool failed = false; + + INFO("CRC CCITT-161 16-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 - 2U; i++) { + random[i] = rand(); + } + + CRC::addCCITT161(random, len); + + Utils::dump(2U, "CCITT-161_Test CRC", random, len); + + bool ret = CRC::checkCCITT161(random, len); + if (!ret) { + ::LogDebug("T", "CCITT-161_Test, failed CRC CCITT-162 check"); + failed = true; + goto cleanup; + } + + random[10U] >>= 8; + random[11U] >>= 8; + + ret = CRC::checkCCITT161(random, len); + if (ret) { + ::LogDebug("T", "CCITT-161_Test, failed CRC CCITT-162 check"); + failed = true; + goto cleanup; + } + +cleanup: + delete random; + REQUIRE(failed==false); + } +} diff --git a/tests/edac/CRC_CCITT_162_Test.cpp b/tests/edac/CRC_CCITT_162_Test.cpp new file mode 100644 index 00000000..38421088 --- /dev/null +++ b/tests/edac/CRC_CCITT_162_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", "[CCITT-162_Test]") { + SECTION("CCITT-162_Test") { + bool failed = false; + + INFO("CRC CCITT-162 16-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 - 2U; i++) { + random[i] = rand(); + } + + CRC::addCCITT162(random, len); + + Utils::dump(2U, "CCITT-162_Test CRC", random, len); + + bool ret = CRC::checkCCITT162(random, len); + if (!ret) { + ::LogDebug("T", "CCITT-162_Test, failed CRC CCITT-162 check"); + failed = true; + goto cleanup; + } + + random[10U] >>= 8; + random[11U] >>= 8; + + ret = CRC::checkCCITT162(random, len); + if (ret) { + ::LogDebug("T", "CCITT-162_Test, failed CRC CCITT-162 check"); + failed = true; + goto cleanup; + } + +cleanup: + delete random; + REQUIRE(failed==false); + } +}