Make run-jdwp-tests.sh warn about deprecation

Since the internal jdwp implementation is deprecated when running the
JDWP test suite one should generally use ./tools/run-libjdwp-tests.sh
instead of ./tools/run-jdwp-tests.sh. This makes run-jdwp-tests.sh
require a special flag to run if not invoked through
run-libjdwp-tests.sh or by LUCI. This should help ensure people run
the appropriate tests.

Test: ./art/tools/run-jdwp-tests.sh --mode=host
Test: ./art/tools/run-jdwp-tests.sh --mode=host --force-run-test
Test: ./art/tools/run-libjdwp-tests.sh --mode=host
Change-Id: Id31fddafe6112656945e544c0dba7a9629deb247
diff --git a/tools/run-jdwp-tests.sh b/tools/run-jdwp-tests.sh
index e686d7d..da89403 100755
--- a/tools/run-jdwp-tests.sh
+++ b/tools/run-jdwp-tests.sh
@@ -80,6 +80,12 @@
 instant_jit=false
 variant_cmdline_parameter="--variant=X32"
 dump_command="/bin/true"
+called_from_libjdwp=${RUN_JDWP_TESTS_CALLED_FROM_LIBJDWP:-false}
+run_internal_jdwp_test=false
+# Let LUCI bots do what they want.
+if test -v LUCI_CONTEXT; then
+  run_internal_jdwp_test=true
+fi
 # Timeout of JDWP test in ms.
 #
 # Note: some tests expect a timeout to check that *no* reply/event is received for a specific case.
@@ -123,6 +129,7 @@
   elif [[ "$1" == "--mode=jvm" ]]; then
     mode="ri"
     make_target_name="apache-harmony-jdwp-tests"
+    run_internal_jdwp_test=true
     art="$(which java)"
     art_debugee="$(which java)"
     # No need for extra args.
@@ -138,6 +145,11 @@
     # We don't care about jit with the RI
     use_jit=false
     shift
+  elif [[ $1 == --force-run-test ]]; then
+    run_internal_jdwp_test=true
+    # remove the --force-run-test
+    args=${args/$1}
+    shift
   elif [[ $1 == --test-timeout-ms ]]; then
     # Remove the --test-timeout-ms from the arguments.
     args=${args/$1}
@@ -237,6 +249,16 @@
   fi
 fi
 
+if [[ $called_from_libjdwp != "true" ]]; then
+  if [[ $run_internal_jdwp_test = "false" ]]; then
+    echo "Calling run_jdwp_tests.sh directly is probably not what you want. You probably want to"
+    echo "run ./art/tools/run-libjdwp-tests.sh instead in order to test the JDWP implementation"
+    echo "used by apps. If you really wish to run these tests using the deprecated internal JDWP"
+    echo "implementation pass the '--force-run-test' flag."
+    exit 1
+  fi
+fi
+
 if [[ $has_gdb = "yes" ]]; then
   if [[ $explicit_debug = "no" ]]; then
     debug="yes"
diff --git a/tools/run-libjdwp-tests.sh b/tools/run-libjdwp-tests.sh
index 0bea6a5..d514c0c 100755
--- a/tools/run-libjdwp-tests.sh
+++ b/tools/run-libjdwp-tests.sh
@@ -118,6 +118,9 @@
   env "$@"
 }
 
+# Tell run-jdwp-tests.sh it was called from run-libjdwp-tests.sh
+export RUN_JDWP_TESTS_CALLED_FROM_LIBJDWP=true
+
 verbose_run ./art/tools/run-jdwp-tests.sh \
             "${args[@]}"                  \
             --jdwp-path "libjdwp.so"      \