Skip to content
Open
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
9 changes: 6 additions & 3 deletions src/control/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ def get_build_flags(benv):
"""Return string of build flags"""
if is_release_build(benv):
return '-buildmode=pie'
# Disable optimizations and inlining for debugger support
flags = '-gcflags "all=-N -l"'
# enable AddressSanitizer to detect memory safety issues at runtime
if 'SANITIZERS' in benv and benv['SANITIZERS'] != "":
return '-asan'
# enable race detector for non-release builds
return '-race'
return f'-asan {flags}'
# enable race detector to detect concurrent memory access issues
return f'-race {flags}'


def gen_build_id():
Expand Down
77 changes: 75 additions & 2 deletions src/control/run_go_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@
## Run linters across control plane code and execute Go tests
set -eu

function usage()
{
cat <<EOF
Usage: $(basename "$0") [OPTIONS] [EXTRA_ARGS]

Run Go linters and tests for the DAOS control plane.

Options:
--dlv <package> Launch an interactive Delve (dlv) debug session for the
given package instead of running the full test suite.
<package> must be a single fully-qualified Go package path.
Example: github.com/daos-stack/daos/src/control/fault
--run <TestName> Filter the test to run (only valid with --dlv).
Passed as -test.run to the binary.
-h, --help Show this help message and exit.

Without --dlv, all remaining arguments are forwarded to the test runner
(go test or gotestsum).

Examples:
# Run all tests
$(basename "$0")

# Debug a specific test with dlv
$(basename "$0") --dlv --run TestFaultComparison \\
github.com/daos-stack/daos/src/control/fault
EOF
}

function get_cpu_perf()
{
test_file=$(mktemp primebenchXXX.go)
Expand Down Expand Up @@ -175,6 +204,24 @@ function get_test_runner()
echo "$test_runner $test_args"
}

# Parse script-level flags; remaining args are passed through to the test runner
DLV_MODE=false
DLV_TEST_NAME=""
DLV_PACKAGE=""
PASSTHROUGH_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
--dlv) DLV_MODE=true; shift ;;
--run) DLV_TEST_NAME="$2"; shift 2 ;;
-h|--help) usage; exit 0 ;;
*) PASSTHROUGH_ARGS+=("$1"); shift ;;
esac
done
# In dlv mode the first non-flag argument is the package to debug
if $DLV_MODE && [[ ${#PASSTHROUGH_ARGS[@]} -gt 0 ]]; then
DLV_PACKAGE="${PASSTHROUGH_ARGS[0]}"
fi

setup_environment

DAOS_BASE=${DAOS_BASE:-${SL_SRC_DIR}}
Expand All @@ -187,11 +234,37 @@ export GOPROXY=${GOPROXY:-"https://proxy.golang.org,direct"}

export PATH=$SL_PREFIX/bin:$PATH
GO_TEST_XML="$DAOS_BASE/test_results/run_go_tests.xml"
GO_TEST_RUNNER=$(get_test_runner)
GO_TEST_EXTRA_ARGS=${*:-""}
GO_TEST_EXTRA_ARGS="${PASSTHROUGH_ARGS[*]:-}"

controldir="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")"

if $DLV_MODE; then
if [[ -z "$DLV_PACKAGE" ]]; then
echo "Usage: $0 --dlv [--run <TestName>] <package>" >&2
exit 1
fi
DLV_BUILD_FLAGS="-mod vendor -tags firmware,fault_injection,test_stubs,spdk"
DLV_ARGS=()
[[ -n "$DLV_TEST_NAME" ]] && DLV_ARGS=(-- -test.run "$DLV_TEST_NAME")
echo "Environment:"
echo " GO VERSION: $(go version | awk '{print $3" "$4}')"
echo " LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
echo " CGO_LDFLAGS: $CGO_LDFLAGS"
echo " CGO_CFLAGS: $CGO_CFLAGS"
echo
echo "Starting dlv session for $DLV_PACKAGE..."
pushd "$controldir" >/dev/null
LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
CGO_LDFLAGS="$CGO_LDFLAGS" \
CGO_CFLAGS="$CGO_CFLAGS" \
dlv test --build-flags "$DLV_BUILD_FLAGS" "$DLV_PACKAGE" "${DLV_ARGS[@]}"
testrc=$?
popd >/dev/null
exit $testrc
fi

GO_TEST_RUNNER=$(get_test_runner)

check_formatting "$controldir"

echo "Environment:"
Expand Down
1 change: 1 addition & 0 deletions utils/cq/words.dict
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ iface
indata
infiniband
init
inlining
inode
inodes
interoperability
Expand Down
Loading