Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
- name: Test PcapPlusPlus
run: |
. .venv/bin/activate
python3 ci/run_tests/run_tests.py --interface eth0 ${{ matrix.additional-test-flags }}
python3 ci/run_tests/run_tests.py --interface eth0 ${{ matrix.additional-test-flags }} "$BUILD_DIR"

- name: Test Examples
run: |
Expand Down 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 "packet" "$BUILD_DIR"

- name: Check installation
run: |
Expand Down Expand Up @@ -444,7 +444,7 @@ jobs:
if: ${{ matrix.host-arch == matrix.arch }}
run: |
. .venv/bin/activate
python ci/run_tests/run_tests.py --interface en0
python ci/run_tests/run_tests.py --interface en0 "$BUILD_DIR"

- name: Test Examples
if: ${{ matrix.host-arch == matrix.arch }}
Expand Down Expand Up @@ -700,7 +700,7 @@ jobs:
echo "Testing PcapPlusPlus"
python3 -m ensurepip
python3 -m pip install -r ci/run_tests/requirements.txt
python3 ci/run_tests/run_tests.py --interface "$interface_name"
python3 ci/run_tests/run_tests.py --interface "$interface_name" "$BUILD_DIR"

echo "Testing PcapPlusPlus examples"
cd Tests/ExamplesTest
Expand Down Expand Up @@ -833,7 +833,7 @@ jobs:
- name: Test PcapPlusPlus
run: |
. .venv/bin/activate
python ci/run_tests/run_tests.py --interface eth0 --use-sudo --pcap-test-args="-t xdp"
python ci/run_tests/run_tests.py --interface eth0 --use-sudo --pcap-test-args="-t xdp" "$BUILD_DIR"

- name: Create Cobertura Report
run: |
Expand Down
27 changes: 23 additions & 4 deletions Tests/Packet++Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,31 @@ add_executable(

target_link_libraries(Packet++Test PUBLIC memplumber Packet++ PcppTestFramework EndianPortable)

target_include_directories(Packet++Test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")

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

set_property(TARGET Packet++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
set_property(TARGET Packet++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
set_property(TARGET Packet++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
add_test(NAME Packet++Test COMMAND $<TARGET_FILE:Packet++Test> WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/)
add_custom_command(
TARGET Packet++Test
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/PacketExamples
$<TARGET_FILE_DIR:Packet++Test>/PacketExamples
)

add_custom_command(
TARGET Packet++Test
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/../../3rdParty/OUIDataset/PCPP_OUIDataset.json"
"$<TARGET_FILE_DIR:Packet++Test>/PCPP_OUIDataset.json"
)

# set_property(TARGET Packet++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
# set_property(TARGET Packet++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
# set_property(TARGET Packet++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
# add_test(NAME Packet++Test COMMAND $<TARGET_FILE:Packet++Test> WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/)
add_test(NAME Packet++Test COMMAND $<TARGET_FILE:Packet++Test> WORKING_DIRECTORY $<TARGET_FILE_DIR:Packet++Test>)
3 changes: 1 addition & 2 deletions Tests/Packet++Test/Tests/EthAndArpTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
PTF_TEST_CASE(OUILookup)
{
pcpp::OUILookup lookupEngineJson;
PTF_ASSERT_GREATER_THAN(lookupEngineJson.initOUIDatabaseFromJson("../../3rdParty/OUIDataset/PCPP_OUIDataset.json"),
0);
PTF_ASSERT_GREATER_THAN(lookupEngineJson.initOUIDatabaseFromJson("PCPP_OUIDataset.json"), 0);

PTF_ASSERT_EQUAL(lookupEngineJson.getVendorName("aa:aa:aa:aa:aa:aa"), "Unknown");
// CIDR 36
Expand Down
2 changes: 1 addition & 1 deletion Tests/Packet++Test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "PcppTestFrameworkRun.h"
#include "TestDefinition.h"
#include "Logger.h"
#include "../../Tests/Packet++Test/Utils/TestUtils.h"
#include "Utils/TestUtils.h"

static struct option PacketTestOptions[] = {
{ "include-tags", required_argument, nullptr, 't' },
Expand Down
16 changes: 12 additions & 4 deletions Tests/Pcap++Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ if(MSVC)
target_link_libraries(Pcap++Test PRIVATE Getopt-for-Visual-Studio)
endif()

set_property(TARGET Pcap++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
set_property(TARGET Pcap++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
set_property(TARGET Pcap++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
add_custom_command(
TARGET Pcap++Test
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/PcapExamples"
"$<TARGET_FILE_DIR:Pcap++Test>/PcapExamples"
)

add_test(NAME Pcap++Test COMMAND $<TARGET_FILE:Pcap++Test> -n WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/)
# set_property(TARGET Pcap++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
# set_property(TARGET Pcap++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
# set_property(TARGET Pcap++Test PROPERTY RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/Bin")
# add_test(NAME Pcap++Test COMMAND $<TARGET_FILE:Pcap++Test> -n WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/)
add_test(NAME Pcap++Test COMMAND $<TARGET_FILE:Pcap++Test> -n WORKING_DIRECTORY $<TARGET_FILE_DIR:Pcap++Test>)
64 changes: 43 additions & 21 deletions ci/run_tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import os
import subprocess
import argparse
from pathlib import Path
from dataclasses import dataclass
from contextlib import contextmanager
from scapy.all import get_if_addr

Expand All @@ -21,29 +23,42 @@ def tcp_replay_worker(interface: str, tcpreplay_dir: str):
tcpreplay_proc.kill()


def run_packet_tests(args: list[str], use_sudo: bool):
cmd_line = ["sudo"] if use_sudo else []
cmd_line += [os.path.join("Bin", "Packet++Test"), *args]
@dataclass
class Runner:
build_dir: Path
use_sudo: bool = False
packet_test_path = Path("Tests", "Packet++Test", "Packet++Test")
pcap_test_path = Path("Tests", "Pcap++Test", "Pcap++Test")

completed_process = subprocess.run(cmd_line, cwd="Tests/Packet++Test")
def run_packet_tests(self, args: list[str]):
exe_path = self.build_dir / self.packet_test_path
work_dir = exe_path.parent

if completed_process.returncode != 0:
raise RuntimeError(f"Error while executing Packet++ tests: {completed_process}")
cmd_line = ["sudo"] if self.use_sudo else []
cmd_line += [str(exe_path), *args]

completed_process = subprocess.run(cmd_line, cwd=str(work_dir))

def run_pcap_tests(interface: str, tcpreplay_dir: str, args: list[str], use_sudo: bool):
ip_address = get_if_addr(interface)
print(f"IP address is: {ip_address}")
if completed_process.returncode != 0:
raise RuntimeError(f"Error while executing Packet++ tests: {completed_process}")

with tcp_replay_worker(interface, tcpreplay_dir):
cmd_line = ["sudo"] if use_sudo else []
cmd_line += [os.path.join("Bin", "Pcap++Test"), "-i", ip_address, *args]

completed_process = subprocess.run(cmd_line, cwd="Tests/Pcap++Test")
if completed_process.returncode != 0:
raise RuntimeError(
f"Error while executing Pcap++ tests: {completed_process}"
)
def run_pcap_tests(self, interface: str, tcpreplay_dir: str, args: list[str]):
ip_address = get_if_addr(interface)
print(f"IP address is: {ip_address}")

exe_path = self.build_dir / self.pcap_test_path
work_dir = exe_path.parent

cmd_line = ["sudo"] if self.use_sudo else []
cmd_line += [str(exe_path), "-i", ip_address, *args]

with tcp_replay_worker(interface, tcpreplay_dir):
completed_process = subprocess.run(cmd_line, cwd=str(work_dir))
if completed_process.returncode != 0:
raise RuntimeError(
f"Error while executing Pcap++ tests: {completed_process}"
)


def main():
Expand Down Expand Up @@ -78,17 +93,24 @@ def main():
default=None,
help="tcpreplay directory",
)
parser.add_argument(
"build_dir",
type=str,
default=os.getcwd(),
help="path to the build directory"
)
args = parser.parse_args()

runner = Runner(build_dir=Path(args.build_dir), use_sudo=args.use_sudo)

if "packet" in args.test_suites:
run_packet_tests(args.packet_test_args.split(), args.use_sudo)
runner.run_packet_tests(args.packet_test_args.split())

if "pcap" in args.test_suites:
run_pcap_tests(
runner.run_pcap_tests(
args.interface,
args.tcpreplay_dir,
args.pcap_test_args.split(),
args.use_sudo,
args.pcap_test_args.split()
)


Expand Down
Loading