Skip to content

Commit

Permalink
renaming test files; env vars cleaned
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoooao committed Jul 19, 2023
1 parent fb3b3e8 commit 89c4220
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/ci-ptf-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ jobs:
- name: Build p4c with only the DPDK backend
working-directory: p4c
env:
OUTPUT_DIR: ${{ github.workspace }}/p4c/tools/ci-dpdk-ptf-test/ptf-simple-test/add_on_miss0
run: |
sudo -E tools/ci-dpdk-ptf-test/ci-build.sh
sudo -E tools/dpdk-ci-build.sh
- name: 'Compile ipdk recipe'
run: |
Expand All @@ -87,4 +85,4 @@ jobs:
source $IPDK_RECIPE/scripts/dpdk/setup_env.sh $IPDK_RECIPE $SDE_INSTALL $DEPEND_INSTALL
sudo $IPDK_RECIPE/scripts/dpdk/copy_config_files.sh $IPDK_RECIPE $SDE_INSTALL
sudo $IPDK_RECIPE/scripts/dpdk/set_hugepages.sh
sudo env PATH="$PATH" HOME="$HOME" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" SDE_INSTALL="$SDE_INSTALL" IPDK_RECIPE="$IPDK_RECIPE" DEPEND_INSTALL="$DEPEND_INSTALL" python3 $P4C_DIR/backends/dpdk/run-dpdk-ptf-test.py $P4C_DIR/testdata/p4_16_samples/add_on_miss0.p4 -p4c $P4C_DIR --ipdk-recipe $IPDK_RECIPE --testfile $P4C_DIR/testdata/p4_16_samples/add_on_miss0.py -ll DEBUG
sudo python3 $P4C_DIR/backends/dpdk/run-dpdk-ptf-test.py $P4C_DIR/testdata/p4_16_samples/pna-dpdk-add_on_miss0.p4 -p4c $P4C_DIR --ipdk-recipe $IPDK_RECIPE --sde-install $SDE_INSTALL --ld-library-path $LD_LIBRARY_PATH --testfile $P4C_DIR/testdata/p4_16_samples/pna-dpdk-add_on_miss0.py -ll DEBUG
47 changes: 37 additions & 10 deletions backends/dpdk/run-dpdk-ptf-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import random
import sys
import tempfile
import subprocess
import uuid
import time
import json
Expand Down Expand Up @@ -45,8 +46,20 @@
PARSER.add_argument(
"--ipdk-recipe",
dest="ipdk_recipe",
help="The location of the IPDK_RECIPE folder.",
help="The location of the IPDK_RECIPE folder for infrap4d-related executables.",
)
PARSER.add_argument(
"--sde-install",
dest="sde_install",
help="The location of the SDE_INSTALL folder, which is used for locating the dpdk libs.",
)

PARSER.add_argument(
"--ld-library-path",
dest="ld_library_path",
help="The location of the shared libs for ipdk and dpdk",
)

PARSER.add_argument(
"-b",
"--nocleanup",
Expand Down Expand Up @@ -88,6 +101,10 @@ class Options:
p4c_dir: Path = Path(".")
# IPDK Recipe folder
ipdk_recipe: Path = Path(".")
# SDE_INSTALL folder
sde_install: Path = Path(".")
# LD_LIBRARY_PATH
ld_library_path: Path = Path(".")
# Number of TAPs to create
num_taps: int = 2

Expand All @@ -96,6 +113,7 @@ class Options:
class PTFTestEnv:
options: Options = Options()
switch_proc: testutils.subprocess.Popen = None
proc_env_vars: dict = None

def __init__(self, options):
self.options = options
Expand All @@ -106,7 +124,7 @@ def __del__(self):
testutils.kill_proc_group(self.switch_proc)


def create_TAPs(self, insecure_mode: bool = True) -> int:
def create_TAPs(self, proc_env_vars:dict, insecure_mode: bool = True) -> int:
""" Create TAPs with gNMI """
testutils.log.info(
"---------------------- Creating TAPs ----------------------",
Expand All @@ -116,7 +134,8 @@ def create_TAPs(self, insecure_mode: bool = True) -> int:
cmd = (f"{self.options.ipdk_recipe}/install/bin/gnmi-ctl set "
f"device:virtual-device,name:{tap_name},pipeline-name:pipe,mempool-name:MEMPOOL0,mtu:1500,port-type:TAP "
f"-grpc_use_insecure_mode={insecure_mode}")
_, returncode = testutils.exec_process(cmd, timeout=5)
_, returncode = testutils.exec_process(cmd, env=proc_env_vars)
#returncode=subprocess.Popen(cmd, shell=True)
if returncode != testutils.SUCCESS:
testutils.log.error("Failed to create TAP")
return returncode
Expand Down Expand Up @@ -152,7 +171,7 @@ def compile_program(self,info_name:Path, bf_rt_schema:Path,context:Path, dpdk_sp
testutils.log.error("Failed to compile the P4 program %s.", self.options.p4_file)
return returncode

def run_infrap4d(self,insecure_mode: bool = True) -> testutils.subprocess.Popen:
def run_infrap4d(self, proc_env_vars:dict, insecure_mode: bool = True) -> testutils.subprocess.Popen:
"""Start infrap4d and return the process handle."""
testutils.log.info(
"---------------------- Start infrap4d ----------------------",
Expand All @@ -161,19 +180,19 @@ def run_infrap4d(self,insecure_mode: bool = True) -> testutils.subprocess.Popen:
f"{self.options.ipdk_recipe}/install/sbin/infrap4d "
f"-grpc_open_insecure_mode={insecure_mode}"
)
self.switch_proc = testutils.open_process(run_infrap4d_cmd)
self.switch_proc = testutils.open_process(run_infrap4d_cmd,env=proc_env_vars)
time.sleep(2)
return self.switch_proc


def build_and_load_pipeline(self, p4c_conf: Path, conf_bin: Path, info_name: Path) -> int:
def build_and_load_pipeline(self, p4c_conf: Path, conf_bin: Path, info_name: Path,proc_env_vars: dict) -> int:
testutils.log.info("---------------------- Build and Load Pipleline ----------------------")
command = (
f"{self.options.ipdk_recipe}/install/bin/tdi_pipeline_builder "
f"--p4c_conf_file={p4c_conf} "
f"--bf_pipeline_config_binary_file={conf_bin}")

_, returncode = testutils.exec_process(command, timeout=30)
_, returncode = testutils.exec_process(command, timeout=30,env=proc_env_vars)
if returncode != testutils.SUCCESS:
testutils.log.error("Failed to build pipeline")
return returncode
Expand Down Expand Up @@ -213,6 +232,11 @@ def run_ptf(self, grpc_port: int) -> int:
return returncode

def run_test(options: Options) -> int:
""" Add necessary environment variables for libs and executables """
proc_env_vars:dict = os.environ.copy()
proc_env_vars["LD_LIBRARY_PATH"] = f"{options.ld_library_path}"
proc_env_vars["SDE_INSTALL"] = f"{options.sde_install}"

"""Define the test environment and compile the P4 target"""
test_name = Path(options.p4_file.name)
info_name = options.testdir.joinpath("p4Info.txt")
Expand All @@ -235,17 +259,17 @@ def run_test(options: Options) -> int:
return returncode

# Run the switch.
switch_proc = testenv.run_infrap4d()
switch_proc = testenv.run_infrap4d(proc_env_vars)
if switch_proc is None:
return testutils.FAILURE

# Create the TAP interfaces.
returncode = testenv.create_TAPs()
returncode = testenv.create_TAPs(proc_env_vars)
if returncode != testutils.SUCCESS:
return returncode

# Build and load the pipeline
returncode = testenv.build_and_load_pipeline(p4c_conf, conf_bin, info_name)
returncode = testenv.build_and_load_pipeline(p4c_conf, conf_bin, info_name,proc_env_vars)
if returncode != testutils.SUCCESS:
return returncode

Expand Down Expand Up @@ -289,6 +313,8 @@ def create_options(test_args) -> testutils.Optional[Options]:
options.testdir = Path(testdir)
options.p4c_dir = Path(test_args.p4c_dir)
options.ipdk_recipe = Path(test_args.ipdk_recipe)
options.sde_install = Path(test_args.sde_install)
options.ld_library_path = Path(test_args.ld_library_path)
options.num_taps = test_args.num_taps

# Configure logging.
Expand All @@ -304,6 +330,7 @@ def create_options(test_args) -> testutils.Optional[Options]:
return options



if __name__ == "__main__":
# Parse options and process argv
args, argv = PARSER.parse_known_args()
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ CMAKE_FLAGS+="
mkdir build
cd build
cmake .. ${CMAKE_FLAGS}
make -j1
make install
make clean
ldconfig
make "-j$(nproc)"



0 comments on commit 89c4220

Please sign in to comment.