Files
dynamorio/tools/run_on_android_device.sh.in
Jack Gallagher 64f768e9a5 i#2154 Android64: Fix adb argument quoting (#7206)
When building for Android with -DDR_COPY_TO_DEVICE=ON we can use CTest
to run the DynamoRIO tests on an attached Android device.

Previously this was done by adding `adb shell` to the beginning of the
test command. This works fine for many test commands but doesn't
properly preserve argument quoting so test commands which have spaces
inside an argument would get parsed incorrectly leading to test
failures.

For example if we run:
    adb shell "foo" "bar baz"
the quotes are interpreted by the host shell so the command that the
remote Android shell sees is:
    foo bar baz

The "bar baz" argument has been effectively split into two.

An easy way to solve this is to surround the test command in single
quotes:
    adb shell '"foo" "bar baz"'
so the full test command is passed to the Android shell with the
argument quotes intact:
    "foo" "bar baz"

I have changed the CMake scripts to use a wrapper script instead of
invoking adb directly (run_on_android_device.sh) which just applies this
extra layer of quoting and allows us to run tests on Android more
reliably.

Issues: #2154, #1874
2025-01-22 22:16:33 +00:00

7 lines
181 B
Bash
Executable File

#!/usr/bin/sh
# Used to run a command on an Android device when building for Android
# while preserving the argument quoting used on the host.
@ADB@ shell $(printf "'%s' " "$@")