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.