Skip to content

Commit

Permalink
#Centipede Fix OSS build error due to using Google-only code
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 654334593
  • Loading branch information
ussuri authored and copybara-github committed Jul 20, 2024
1 parent 031ae3f commit c6d4b96
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
16 changes: 16 additions & 0 deletions centipede/test_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,19 @@ function centipede::assert_fuzzing_success() {
centipede::assert_regex_in_file "centipede.*end-fuzz:" "${log}"
done
}

# Returns a random free port on the local machine.
function centipede::get_random_free_port() {
# Create an array with all ports in the range [1..65535] + all ports
# currently in use. This results in used ports appearing twice in the array.
declare -a ports=(
{1..65535}
$(netstat -tan | perl -ne '/.+?:(\d{1,5}).+/; print "$1\n";')
)
# Dedupe and shuffle the array. This leaves free ports only.
ports=(
$(echo "${ports[@]}" | tr ' ' '\n' | sort | uniq -u | shuf)
)
# Return a random free port.
echo "${ports[0]}"
}
1 change: 0 additions & 1 deletion centipede/testing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -408,5 +408,4 @@ sh_test(
"@com_google_fuzztest//centipede",
"@com_google_fuzztest//centipede:test_util_sh",
],
deps = ["//testing/shbase"],
)
9 changes: 3 additions & 6 deletions centipede/testing/external_target_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,27 @@

set -euo pipefail

source googletest.sh
source "$(dirname "$0")/../test_util.sh"

CENTIPEDE_TEST_SRCDIR="$(centipede::get_centipede_test_srcdir)"

centipede::maybe_set_var_to_executable_path \
CENTIPEDE_BINARY "${CENTIPEDE_TEST_SRCDIR}/centipede"

centipede::maybe_set_var_to_executable_path \
LLVM_SYMBOLIZER "$(centipede::get_llvm_symbolizer_path)"

centipede::maybe_set_var_to_executable_path \
SERVER_BINARY "${CENTIPEDE_TEST_SRCDIR}/testing/external_target_server"

centipede::maybe_set_var_to_executable_path \
TARGET_BINARY "${CENTIPEDE_TEST_SRCDIR}/testing/external_target"

readonly WD="${TEST_TMPDIR}/WD"
readonly LOG="${TEST_TMPDIR}/log"
centipede::ensure_empty_dir "${WD}"

readonly TARGET_PORT="$(get_port_from_portserver)"
TARGET_PORT=$(centipede::get_random_free_port)
readonly TARGET_PORT

echo "Starting the server binary ..."
echo "Starting the server binary using port ${TARGET_PORT}..."
env CENTIPEDE_RUNNER_FLAGS=":use_auto_dictionary:use_cmp_features:use_pc_features:" \
TARGET_PORT="${TARGET_PORT}" \
"${SERVER_BINARY}" &
Expand Down

0 comments on commit c6d4b96

Please sign in to comment.