Skip to content

Commit

Permalink
Revert "Sanitize file path input in cmake, add travis check to skip t…
Browse files Browse the repository at this point in the history
…ests (#1476)"

This reverts commit 7fd89e9.
  • Loading branch information
liujed committed Sep 20, 2018
1 parent 5096e1c commit ca2217a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 37 deletions.
7 changes: 3 additions & 4 deletions backends/ebpf/targets/ebpfenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def ns_init(self):
""" Initialize the namespace. """
cmd = "ip netns add %s" % self.ns_name
errmsg = "Failed to create namespace %s :" % self.ns_name
result = run_timeout(self.verbose, cmd, TIMEOUT,
result = run_timeout(True, cmd, TIMEOUT,
self.outputs, errmsg)
self.ns_exec("ip link set dev lo up")
return result
Expand All @@ -48,7 +48,7 @@ def ns_del(self):
""" Delete the namespace. """
cmd = "ip netns del %s" % self.ns_name
errmsg = "Failed to delete namespace %s :" % self.ns_name
return run_timeout(self.verbose, cmd, TIMEOUT,
return run_timeout(True, cmd, TIMEOUT,
self.outputs, errmsg)

def get_ns_prefix(self):
Expand All @@ -61,8 +61,7 @@ def ns_exec(self, cmd_string):
prefix = self.get_ns_prefix()
# bash -c allows us to run multiple commands at once
cmd = "%s bash -c \"%s\"" % (prefix, cmd_string)
errmsg = "Failed to run command %s in namespace %s:" % (
cmd, self.ns_name)
errmsg = "Failed to run command in namespace %s:" % self.ns_name
return run_timeout(self.verbose, cmd, TIMEOUT,
self.outputs, errmsg)

Expand Down
9 changes: 2 additions & 7 deletions backends/ebpf/targets/kernel_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,11 @@ def _run_in_namespace(self, bridge):

def run(self):
# Root is necessary to load ebpf into the kernel
if not check_root():
if check_root():
errmsg = "This test requires root privileges; skipping execution."
report_err(self.outputs["stderr"], errmsg)
return SKIPPED
# Sadly the Travis environment does not work with ip netns yet
if check_travis():
errmsg = ("The travis build currently does not support virtual"
" namespaces; skipping execution.")
report_err(self.outputs["stderr"], errmsg)
return SKIPPED

result = self._create_runtime()
if result != SUCCESS:
return result
Expand Down
23 changes: 4 additions & 19 deletions cmake/P4CUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,18 @@ endmacro(p4c_add_test_label)
# The macro generates the test files in a directory prefixed by tag.
#
macro(p4c_add_test_list tag driver tests xfail)
# Sanitize the input lists to account for mixed path input
p4c_set_abs_path("${xfail}" __xfail_list)
p4c_set_abs_path("${tests}" __test_list)
set (__xfail_list "${xfail}")
set (__test_list "${tests}")
set (__testCounter 0)
set (__xfailCounter 0)
list (LENGTH __test_list __nTests)
foreach(t ${__test_list})
list (FIND __xfail_list ${t} __xfail_test)
# Convert back to relative path for all files
file(RELATIVE_PATH rel_t ${P4C_SOURCE_DIR} ${t})
if(__xfail_test GREATER -1)
p4c_add_test_with_args (${tag} ${driver} TRUE ${rel_t} ${rel_t} "${ARGN}" "")
p4c_add_test_with_args (${tag} ${driver} TRUE ${t} ${t} "${ARGN}" "")
math (EXPR __xfailCounter "${__xfailCounter} + 1")
else()
p4c_add_test_with_args (${tag} ${driver} FALSE ${rel_t} ${rel_t} "${ARGN}" "")
p4c_add_test_with_args (${tag} ${driver} FALSE ${t} ${t} "${ARGN}" "")
endif() # __xfail_test
endforeach() # tests
math (EXPR __testCounter "${__testCounter} + ${__nTests}")
Expand All @@ -151,18 +148,6 @@ function(p4c_find_test_names testsuites tests)
set(${tests} "${__tests}" PARENT_SCOPE)
endfunction()

# convert the paths from a list of input files to their absolute value
# - files is a list of explicit (relative) file paths
# - abs_files is the return set of absolute file paths
function(p4c_set_abs_path files abs_files)
foreach(file ${files})
get_filename_component(__file "${file}"
REALPATH BASE_DIR "${P4C_SOURCE_DIR}")
list (APPEND __abs_files ${__file})
endforeach()
set(${abs_files} "${__abs_files}" PARENT_SCOPE)
endfunction()

# generate all the tests specified in the testsuites: builds a list of tests
# from the testsuite patterns by calling p4c_find_test_names then pass the list
# to p4c_add_test_list
Expand Down
7 changes: 0 additions & 7 deletions tools/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
FAILURE = 1
SKIPPED = 2 # used occasionally to indicate that a test was not executed


def is_err(p4filename):
""" True if the filename represents a p4 program that should fail. """
return "_errors" in p4filename
Expand Down Expand Up @@ -146,9 +145,3 @@ def check_root():
""" This function returns False if the user does not have root privileges.
Caution: Only works on Unix systems """
return (os.getuid() == 0)


def check_travis():
""" This function returns True if the tests are being run in a
travis environment."""
return (os.environ.get('TRAVIS') == 'true')

0 comments on commit ca2217a

Please sign in to comment.