Skip to content
Open
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
5f02028
Added Common++ unit test project based on Gtest.
Dimi1010 Jul 21, 2024
0687ddd
Fixed includes.
Dimi1010 Jul 21, 2024
a004e3c
Changed gtest version to 1.12 which is the last to support Cpp11.
Dimi1010 Jul 21, 2024
94a3b0e
Added Gmock in addition to Gtest.
Dimi1010 Jul 21, 2024
be20d78
Added IPv6 tests.
Dimi1010 Jul 21, 2024
3395ac7
Added IPAddress tests.
Dimi1010 Jul 21, 2024
55fdf10
Lint
Dimi1010 Jul 21, 2024
f447d9c
Fixed matcher error.
Dimi1010 Jul 21, 2024
5b37a1f
Added _ipv4 and _ipv6 string literals.
Dimi1010 Jul 21, 2024
12e4599
Added IPv4 Network unit tests.
Dimi1010 Jul 21, 2024
0f20bb9
Added IPv6 Network unit tests.
Dimi1010 Jul 21, 2024
a2718d8
Added IPNetwork unit tests.
Dimi1010 Jul 21, 2024
e29190a
Added more unit tests.
Dimi1010 Jul 22, 2024
0f3f927
Added IP(v4/v6)Address match network tests.
Dimi1010 Jul 22, 2024
c8d04de
Lint
Dimi1010 Jul 22, 2024
a67ebe7
Added MacAddress constructor from std::array.
Dimi1010 Jul 22, 2024
a93a202
Added MacAddress unit tests.
Dimi1010 Jul 22, 2024
66d1937
Added MacAddress tests for output to stream.
Dimi1010 Jul 22, 2024
aa92f72
Added unit tests for PointerVector and test fixture with built-in mem…
Dimi1010 Jul 22, 2024
d191cdb
Lint
Dimi1010 Jul 22, 2024
bd8ecd9
Included 'googletest' configuration for cppcheck.
Dimi1010 Jul 24, 2024
70708fd
Fixed include of MemoryLeakDetectorFixture... hopefully the correct way.
Dimi1010 Jul 24, 2024
d45b54d
Fixed wrong variable assert.
Dimi1010 Jul 24, 2024
a9cd1b8
Added unit test for functions in the general utilities header.
Dimi1010 Jul 24, 2024
4803471
Added unit tests for LRUList.
Dimi1010 Jul 24, 2024
9e77c18
Lint
Dimi1010 Jul 24, 2024
63a8fbe
Merge remote-tracking branch 'upstream/dev' into feature/gtest-framework
Dimi1010 Jul 30, 2024
d503bcd
Added cast to ptr type because direct nullptr is deleted function.
Dimi1010 Jul 30, 2024
bf9c3ca
Merge branch 'dev' into feature/gtest-framework
Dimi1010 Aug 15, 2024
f1baa83
Lint
Dimi1010 Aug 15, 2024
6b50130
Fixed issue with temporary.
Dimi1010 Aug 15, 2024
706fb4b
Merge branch 'dev' into feature/gtest-framework
Dimi1010 Sep 7, 2024
012df84
Lint - hopefully.
Dimi1010 Sep 7, 2024
e875c0b
Pulled operator << overloads into the 'pcpp' namespace to leverage AD…
Dimi1010 Sep 8, 2024
3a97325
Renamed MacAddress ToStream test to be consistent with IPAddress test…
Dimi1010 Sep 8, 2024
f07b0bf
Merge remote-tracking branch 'upstream/dev' into feature/gtest-framework
Dimi1010 Sep 8, 2024
01b5cc1
CMakeLists lint...
Dimi1010 Sep 8, 2024
ddf1d3a
Merge remote-tracking branch 'upstream/dev' into feature/gtest-framework
Dimi1010 Oct 24, 2024
c20e5d3
Merge remote-tracking branch 'upstream/dev' into feature/gtest-framework
Dimi1010 Nov 5, 2024
4b71919
Merge branch 'dev' into feature/gtest-framework
Dimi1010 Nov 14, 2024
2c461f0
Merge branch 'dev' into feature/gtest-framework
Dimi1010 Jan 22, 2025
db34edb
Split common unit tests into smaller tests.
Dimi1010 Jan 22, 2025
84d7d32
Added const qualifier to MacAddress::Zero.
Dimi1010 Jan 22, 2025
e9f7930
Lint
Dimi1010 Jan 22, 2025
1b02e45
Added basic single threaded logger unit tests.
Dimi1010 Jan 22, 2025
b09fc3c
Simplified logger fixture setup and teardown.
Dimi1010 Jan 23, 2025
977abb4
Added explicit main file.
Dimi1010 Jan 23, 2025
67c6a22
Added conditional skipping of memory leak checks for MSVC Release bui…
Dimi1010 Jan 23, 2025
e5cf5fb
Added build information to the test executable.
Dimi1010 Jan 23, 2025
5076d29
Added tests for CoreMask transformations.
Dimi1010 Jan 23, 2025
4d0c5d1
Merge remote-tracking branch 'upstream/dev' into feature/gtest-framework
Dimi1010 Jan 23, 2025
d7046d7
Merge remote-tracking branch 'upstream/dev' into feature/gtest-framework
Dimi1010 Apr 3, 2025
3fa3dfd
Removed make_unique usage.
Dimi1010 Apr 3, 2025
fc0ea18
Lint
Dimi1010 Apr 3, 2025
3c7285b
Added const to MacAddress::Broadcast static variable.
Dimi1010 Apr 3, 2025
e45d5a9
Added Broadcast unit test.
Dimi1010 Apr 3, 2025
6a88fd8
Merge remote-tracking branch 'upstream/dev' into feature/gtest-framework
Dimi1010 Jun 28, 2025
6fb03e8
Bump googletest to v1.16.0
Dimi1010 Jun 28, 2025
6722666
Added unit tests for DynamicObjectPool
Dimi1010 Jun 28, 2025
453943a
cmake formatting.
Dimi1010 Jun 28, 2025
21f16f5
Include cleanup
Dimi1010 Jun 28, 2025
4df5ddb
Added precompiled header
Dimi1010 Jun 28, 2025
2b9a148
Added unit tests for timespec to timeval conversions.
Dimi1010 Jun 28, 2025
3b4d4d3
Updated logger tests.
Dimi1010 Jun 28, 2025
782623d
Lint
Dimi1010 Jun 28, 2025
62d48da
Version print formatting.
Dimi1010 Jun 28, 2025
58aa8ec
Merge branch 'dev' into feature/gtest-framework
Dimi1010 Jul 12, 2025
bf81cbe
Added todo for googletest fetch content.
Dimi1010 Jul 12, 2025
5f8a763
Added common unit test to run_tests CI script.
Dimi1010 Jul 12, 2025
37cb883
Merge remote-tracking branch 'upstream/dev' into feature/gtest-framework
Dimi1010 Jul 12, 2025
dae7b6b
Lint
Dimi1010 Jul 12, 2025
40efcd5
Updated packet only to run common + packet suites.
Dimi1010 Jul 12, 2025
b76fa62
Fixed explicit ctor
Dimi1010 Jul 12, 2025
247da32
Updated run_tests_windows to have separate functions for calls to sub…
Dimi1010 Jul 12, 2025
463b632
Added common test to windows CI.
Dimi1010 Jul 12, 2025
bc03910
Lint
Dimi1010 Jul 12, 2025
44f6094
Delayed startup of tcpreplay until pcap++ tests.
Dimi1010 Jul 12, 2025
3d57ddd
Added tests for new functions.
Dimi1010 Jul 12, 2025
00e8f94
Merge branch 'dev' into feature/gtest-framework
Dimi1010 Jul 29, 2025
2b9a0ba
Fixed memory leak fixture not respecting mem leak checks.
Dimi1010 Jul 29, 2025
7a1d6d7
Changed MemoryLeak Fixture to default fixture under TEST macro.
Dimi1010 Jul 29, 2025
a3fddb8
Temporarely disabled memory leak fixture testing due to false positiv…
Dimi1010 Jul 29, 2025
68eaf83
Changed MemoryLeakFixture into a gtest listener.
Dimi1010 Jul 29, 2025
36bea65
Updated log tests to utilize functor object instead of static function.
Dimi1010 Jul 29, 2025
480f802
Reverted on test end back to free all memory.
Dimi1010 Jul 29, 2025
86a0e5b
Fixed visibility.
Dimi1010 Aug 1, 2025
a6cd38b
Lint
Dimi1010 Aug 1, 2025
5d8e0af
Merge remote-tracking branch 'upstream/dev' into feature/gtest-framework
Dimi1010 Aug 2, 2025
ac73ed8
Fix cppcheck warnings.
Dimi1010 Aug 2, 2025
1e0df40
Merge remote-tracking branch 'upstream/dev' into feature/gtest-framework
Dimi1010 Aug 2, 2025
532678a
Merge remote-tracking branch 'upstream/dev' into feature/gtest-framework
Dimi1010 Aug 3, 2025
fc2873d
Merge remote-tracking branch 'upstream/dev' into feature/gtest-framework
Dimi1010 Aug 4, 2025
a0f005a
Commented out memory leak warning as it is disabled in all modes.
Dimi1010 Aug 4, 2025
789a17e
Added googletest 1.16 to 3rdParty dependencies.
Dimi1010 Aug 4, 2025
9b4db8b
Added googletest to pre-commit exclusions.
Dimi1010 Aug 4, 2025
888a5a1
Fixup regex string.
Dimi1010 Aug 4, 2025
c98dff8
Disabled clang format for commented line.
Dimi1010 Aug 4, 2025
3f78f4d
Merge remote-tracking branch 'upstream/dev' into feature/gtest-framework
Dimi1010 Aug 8, 2025
5e477f1
Merge branch 'dev' into feature/gtest-framework
Dimi1010 Sep 11, 2025
29ff777
Merge remote-tracking branch 'upstream/dev' into feature/gtest-framework
Dimi1010 Sep 14, 2025
449c523
Revert "Added googletest 1.16 to 3rdParty dependencies."
Dimi1010 Sep 14, 2025
340e2af
Merge branch 'dev' into feature/gtest-framework
Dimi1010 Sep 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ jobs:
- name: Test PcapPlusPlus
run: |
. .venv/bin/activate
python3 ci/run_tests/run_tests.py --interface eth0 --test-suites "packet"
python3 ci/run_tests/run_tests.py --interface eth0 --test-suites "common" "packet"

- name: Check installation
run: |
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ repos:
args: ["--style=file", "-i"] # Use the .clang-format file for configuration and apply all fixes
files: ^(Common\+\+|Packet\+\+|Pcap\+\+|Tests|Examples)/.*\.(cpp|h)$
- id: cppcheck
args: ["--std=c++11", "--language=c++", "--suppressions-list=cppcheckSuppressions.txt", "--inline-suppr", "--force"]
args: ["--std=c++11", "--language=c++", "--suppressions-list=cppcheckSuppressions.txt", "--inline-suppr", "--force", "--library=googletest"]
- repo: https://github.com/BlankSpruce/gersemi
rev: 0.19.3
hooks:
Expand Down
13 changes: 13 additions & 0 deletions Common++/header/IpAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,19 @@ namespace pcpp
std::unique_ptr<IPv6Network> m_IPv6Network;
};

namespace literals
{
inline IPv4Address operator""_ipv4(const char* addrString, std::size_t size)
{
return IPv4Address(std::string(addrString, size));
}

inline IPv6Address operator""_ipv6(const char* addrString, std::size_t size)
{
return IPv6Address(std::string(addrString, size));
}
} // namespace literals

inline std::ostream& operator<<(std::ostream& oss, const pcpp::IPv4Address& ipv4Address)
{
oss << ipv4Address.toString();
Expand Down
5 changes: 3 additions & 2 deletions Common++/header/MacAddress.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <array>
#include <algorithm>
#include <initializer_list>
#include <iterator>
Expand Down Expand Up @@ -177,9 +178,9 @@ namespace pcpp
bool copyToNewBuffer(uint8_t** buffer, size_t& size) const;

/// A static value representing a zero value of MAC address, meaning address of value "00:00:00:00:00:00"
static MacAddress Zero;
static const MacAddress Zero;
/// A static value representing a broadcast MAC address, meaning address of value "ff:ff:ff:ff:ff:ff"
static MacAddress Broadcast;
static const MacAddress Broadcast;

private:
std::array<uint8_t, 6> m_Address{};
Expand Down
4 changes: 2 additions & 2 deletions Common++/src/MacAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace pcpp
{

MacAddress MacAddress::Zero(0, 0, 0, 0, 0, 0);
const MacAddress MacAddress::Zero(0, 0, 0, 0, 0, 0);

MacAddress MacAddress::Broadcast(0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
const MacAddress MacAddress::Broadcast(0xff, 0xff, 0xff, 0xff, 0xff, 0xff);

std::string MacAddress::toString() const
{
Expand Down
1 change: 1 addition & 0 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
if(PCAPPP_BUILD_TESTS)
add_subdirectory(PcppTestFramework)
add_subdirectory(Common++Test)
add_subdirectory(Packet++Test)

if(PCAPPP_BUILD_PCAPPP)
Expand Down
46 changes: 46 additions & 0 deletions Tests/Common++Test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.14)

include(FetchContent)

# TODO: This may have issues with brew as it doesn't allow the use of FetchContent.
FetchContent_Declare(googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.16.0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the TODO comment mentions, package managers don't approve packages that use FetchContent_Declare, we already had this experience before...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Tbh, we could possibly have a copy of the lib in 3rdParty to build the tests with.

I am unsure if we could use the brew version since we need to use up to 1.16 as 1.17 (current newest) requires cpp17.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, putting it in 3rdParty is the only option to keep PcapPlusPlus in package managers.

Though I'm still not sure that we want to merge this PR. Having 2 test frameworks doesn't look like a good idea, and converting all of our tests to Gtest will be an extremely hard task

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did start another branch [1] off of this one, for the Packet++ tests, to see how it would go. You can take a look, if you want. The new project is Tests/Packet++Test-google.

It actually mostly involves trivial changes, like macro replacements.

  • PTF_TEST_CASE -> TEST(Fixture, TestName)
  • PTF_ASSERT_EQUAL -> ASSERT_EQ / EXPECT_EQ
  • PTF_ASSERT_NULL -> ASSERT_EQ(statement, nullptr)
  • PTF_ASSERT_NOT_NULL -> ASSERT_NE(statement, nullptr)

The only non-trivial assertion so far has been PTF_ASSERT_BUF_COMPARE which was replaced by EXPECT_TRUE(test::BuffersMatch(actualBuf, actualBufSize, expectedBuf, expectedBufSize)) which ended up being a more comprehensive check IMO. [2].

The loading utilities needed a revamp, as I didn't want to use macros everywhere and the current ones had a limitation of always using the current working directory (has issues with out of source builds).

For the majority of the cases the code:

timeval time;
gettimeofday(&time, nullptr);

READ_FILE_AND_CREATE_PACKET(1, "PacketExamples/TcpPacketNoOptions.dat");
// rest of test case

ended up being a one liner:

// std::unique_ptr<RawPacket>
auto rawPacket1 = test::createPacketFromHexResource("PacketExamples/TcpPacketWithOptions3.dat", /* optional packet factory */, /* optional data loader */);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how we'll be able to review these huge PRs...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, that makes sense. I just wanted to confirm that we're not missing anything.

So I guess we decided to go with Gtest?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seladb I guess so.

IMO, the first thing to do would be to disable building the tests in vcpkg and homebrew install scenarios, via a revision to the portfile / bottle, so we know it can work fine as is, before adding fetch content to the test infrastructure.

Unless anyone has any objections? @egecetin @clementperon @tigercosmos

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think that's a good idea 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened a PR to disable the tests in vcpkg here microsoft/vcpkg#46941.

Also found a bug when examining the build. It placed the test executables inside the vcpkg_installed/vcpkg/blds/pcapplusplus/src/***.clean which is a bug, IMO.

Our test projects don't really support out of source builds currently, so I plan on fixing this in the Gtest rework.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Homebrew has also been updated Homebrew/homebrew-core#233719

Conan needs no update as we already don't build tests there on install.


if(WIN32)
# Prevent overriding the parent project's compiler/linker settings.
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()

FetchContent_MakeAvailable(googletest)

add_executable(
Common++Test
"main.cpp"
"Tests/GeneralUtilsTests.cpp"
"Tests/IPAddressTests.cpp"
"Tests/LoggerTests.cpp"
"Tests/LRUListTests.cpp"
"Tests/MacAddressTests.cpp"
"Tests/ObjectPoolTests.cpp"
"Tests/PointerVectorTests.cpp"
"Tests/SystemUtilsTests.cpp"
"Tests/TimespecTimevalTests.cpp"
"Utils/MemoryLeakListener.cpp"
)

target_link_libraries(Common++Test PRIVATE Common++ memplumber gtest gmock)

target_include_directories(Common++Test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_precompile_headers(Common++Test PRIVATE "pch.h")

if(MSVC)
# This executable requires getopt.h not available on VStudio
target_link_libraries(Common++Test PRIVATE Getopt-for-Visual-Studio)
endif()

set_property(TARGET Common++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
set_property(TARGET Common++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
set_property(TARGET Common++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/Bin")

enable_testing()

add_test(NAME Common++Test COMMAND $<TARGET_FILE:Common++Test> WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/)
37 changes: 37 additions & 0 deletions Tests/Common++Test/Tests/GeneralUtilsTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "pch.h"

#include <cstring>

#include "GeneralUtils.h"

namespace pcpp
{
TEST(GeneralUtilsTests, byteArrayToHexString)
{
std::array<uint8_t, 3> byteArr = { 0xaa, 0x2b, 0x10 };
EXPECT_EQ(byteArrayToHexString(byteArr.data(), byteArr.size()), "aa2b10");
};

TEST(GeneralUtilsTests, hexStringToByteArray)
{
std::array<uint8_t, 3> resultByteArr = { 0 };
EXPECT_EQ(hexStringToByteArray("aa2b10", resultByteArr.data(), resultByteArr.size()), 3);
EXPECT_EQ(resultByteArr, (std::array<uint8_t, 3>{ 0xaa, 0x2b, 0x10 }));
};

TEST(GeneralUtilsTests, cross_platform_memmem)
{
const char haystack[] = "Hello, World!";
const char needle[] = "World";
EXPECT_EQ(cross_platform_memmem(haystack, sizeof(haystack), needle,
sizeof(needle) - 1 /* ignore the null terminator */),
haystack + 7);
};

TEST(GeneralUtilsTests, align)
{
EXPECT_EQ(align<4>(3), 4);
EXPECT_EQ(align<4>(4), 4);
EXPECT_EQ(align<4>(5), 8);
};
} // namespace pcpp
Loading
Loading