From c4d4800a463fb6c037c3a02ed609c452dd04c2c0 Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Wed, 13 Nov 2019 16:20:09 -0700 Subject: [PATCH] test/nvmf: add a test for bad discovery ctrlr. Make sure we don't crash or do any other bad memory accesses when we fail to connect to a discovery controller. Change-Id: I7c3e25899bc78f4beff9ad017612bacf286d52c7 Signed-off-by: Seth Howell Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/474153 Community-CI: Broadcom SPDK FC-NVMe CI Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- examples/nvme/reconnect/reconnect.c | 15 +++++++++++---- test/nvmf/host/target_disconnect.sh | 13 +++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/examples/nvme/reconnect/reconnect.c b/examples/nvme/reconnect/reconnect.c index b44c78029..6babd303a 100644 --- a/examples/nvme/reconnect/reconnect.c +++ b/examples/nvme/reconnect/reconnect.c @@ -1088,19 +1088,19 @@ int main(int argc, char **argv) } if (spdk_env_init(&opts) < 0) { fprintf(stderr, "Unable to initialize SPDK env\n"); - rc = -1; + rc = 1; goto cleanup; } g_tsc_rate = spdk_get_ticks_hz(); if (register_workers() != 0) { - rc = -1; + rc = 1; goto cleanup; } if (register_controllers() != 0) { - rc = -1; + rc = 1; goto cleanup; } @@ -1120,7 +1120,7 @@ int main(int argc, char **argv) } if (associate_workers_with_ns() != 0) { - rc = -1; + rc = 1; goto cleanup; } @@ -1156,6 +1156,13 @@ cleanup: if (rc != 0) { fprintf(stderr, "%s: errors occured\n", argv[0]); + /* + * return a generic error to the caller. This allows us to + * distinguish between a failure in the script and something + * like a segfault or an invalid access which causes the program + * to crash. + */ + rc = 1; } return rc; diff --git a/test/nvmf/host/target_disconnect.sh b/test/nvmf/host/target_disconnect.sh index 33a38a9b9..2122fc460 100755 --- a/test/nvmf/host/target_disconnect.sh +++ b/test/nvmf/host/target_disconnect.sh @@ -36,6 +36,19 @@ timing_enter target_disconnect nvmftestinit +# Test to make sure we don't segfault or access null pointers when we try to connect to +# a discovery controller that doesn't exist yet. +set +e +$rootdir/examples/nvme/reconnect/reconnect -q 32 -o 4096 -w randrw -M 50 -t 10 -c 0xF \ +-r "trtype:$TEST_TRANSPORT adrfam:IPv4 traddr:$NVMF_FIRST_TARGET_IP trsvcid:$NVMF_PORT" +# If the program crashes, the high bit of $? will be set so we will get a value in the hundreds. +# But if the reconnect code detects errors and exits normally it will return 1. +if [ $? != 1 ]; then + set -e + exit 1 +fi +set -e + disconnect_init $NVMF_FIRST_TARGET_IP # If perf doesn't shut down, this test will time out.