tests: memif interface tests using libmemif

Type: test

Change-Id: I711dfe65ad542a45acd484f0b4e3e6ade9576f66
Signed-off-by: Naveen Joy <najoy@cisco.com>
This commit is contained in:
Naveen Joy 2023-07-28 16:33:30 -07:00 committed by Dave Wallace
parent 00c59e4965
commit 70335e8e50
5 changed files with 305 additions and 139 deletions

View File

@ -582,6 +582,10 @@ class VppAsfTestCase(CPUInterface, unittest.TestCase):
def get_api_sock_path(cls):
return "%s/api.sock" % cls.tempdir
@classmethod
def get_memif_sock_path(cls):
return "%s/memif.sock" % cls.tempdir
@classmethod
def get_api_segment_prefix(cls):
return os.path.basename(cls.tempdir) # Only used for VAPI

File diff suppressed because it is too large Load Diff

View File

@ -318,5 +318,15 @@ test_config = {
"server_if_checksum_offload": 0,
"x_connect_mode": "L3",
},
{
"id": 27,
"client_if_type": "tap,memif",
"client_if_version": 2,
"client_if_checksum_offload": 0,
"server_if_type": "tap,memif",
"server_if_version": 2,
"server_if_checksum_offload": 0,
"x_connect_mode": "L2",
},
],
}

View File

@ -4,6 +4,8 @@
import subprocess
import sys
import os
import multiprocessing as mp
def can_create_namespaces(namespace="vpp_chk_4212"):
@ -243,3 +245,64 @@ def list_namespace(ns):
subprocess.run(["ip", "netns", "exec", ns, "ip", "addr"])
except subprocess.CalledProcessError as e:
raise Exception("Error listing namespace IP:", e.output)
def libmemif_test_app(memif_sock_path, logger):
"""Build & run the libmemif test_app for memif interface testing."""
test_dir = os.path.dirname(os.path.realpath(__file__))
ws_root = os.path.dirname(test_dir)
libmemif_app = os.path.join(
ws_root, "extras", "libmemif", "build", "examples", "test_app"
)
def build_libmemif_app():
if not os.path.exists(libmemif_app):
print(f"Building app:{libmemif_app} for memif interface testing")
libmemif_app_dir = os.path.join(ws_root, "extras", "libmemif", "build")
if not os.path.exists(libmemif_app_dir):
os.makedirs(libmemif_app_dir)
os.chdir(libmemif_app_dir)
try:
p = subprocess.run(["cmake", ".."], capture_output=True)
logger.debug(p.stdout)
if p.returncode != 0:
print(f"libmemif app:{libmemif_app} cmake error:{p.stderr}")
sys.exit(1)
p = subprocess.run(["make"], capture_output=True)
logger.debug(p.stdout)
if p.returncode != 0:
print(f"Error building libmemif app:{p.stderr}")
sys.exit(1)
except subprocess.CalledProcessError as e:
raise Exception("Error building libmemif_test_app:", e.output)
def start_libmemif_app():
"""Restart once if the initial run fails."""
max_tries = 2
run = 0
if not os.path.exists(libmemif_app):
raise Exception(
f"Error could not locate the libmemif test app:{libmemif_app}"
)
args = [libmemif_app, "-b", "9216", "-s", memif_sock_path]
while run < max_tries:
try:
process = subprocess.run(args, capture_output=True)
logger.debug(process.stdout)
if process.returncode != 0:
msg = f"Error starting libmemif app:{libmemif_app}"
logger.error(msg)
raise Exception(msg)
except Exception:
msg = f"re-starting libmemif app:{libmemif_app}"
logger.error(msg)
continue
else:
break
finally:
run += 1
build_libmemif_app()
process = mp.Process(target=start_libmemif_app)
process.start()
return process

View File

@ -26,6 +26,7 @@ def use_running(cls):
RunningVPP.get_set_vpp_sock_files()
cls.get_stats_sock_path = RunningVPP.get_stats_sock_path
cls.get_api_sock_path = RunningVPP.get_api_sock_path
cls.get_memif_sock_path = RunningVPP.get_memif_sock_path
cls.run_vpp = RunningVPP.run_vpp
cls.quit_vpp = RunningVPP.quit_vpp
cls.vpp = RunningVPP
@ -36,6 +37,7 @@ def use_running(cls):
class RunningVPP:
api_sock = "" # api_sock file path
stats_sock = "" # stats sock_file path
memif_sock = "" # memif sock path
socket_dir = "" # running VPP's socket directory
pid = None # running VPP's pid
returncode = None # indicates to the framework that VPP is running
@ -48,6 +50,10 @@ class RunningVPP:
def get_api_sock_path(cls):
return cls.api_sock
@classmethod
def get_memif_sock_path(cls):
return cls.memif_sock
@classmethod
def run_vpp(cls):
"""VPP is already running -- skip this action."""
@ -112,6 +118,8 @@ class RunningVPP:
cls.api_sock = os.path.abspath(sock_file)
elif "stats.sock" in sock_file:
cls.stats_sock = os.path.abspath(sock_file)
elif "memif.sock" in sock_file:
cls.memif_sock = os.path.abspath(sock_file)
if not cls.api_sock:
print(
f"Error: Could not find a valid api.sock file "