Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
103f97e
Update to Android Gradle plugin version 8.4.2
mhsmith Jul 10, 2024
fb1b54a
Separate Python test runner from MainActivity so it can be run from a…
mhsmith Jul 10, 2024
b99b769
Add `android.py test` command
mhsmith Jul 10, 2024
6f07a39
--connected mode working
mhsmith Jul 23, 2024
c71f3cf
--managed mode working, and add instructions to README
mhsmith Jul 23, 2024
cd27b0f
Clarifications
mhsmith Jul 23, 2024
6bbdfda
Restore build command logging, and only require adb when running tests
mhsmith Jul 23, 2024
e738689
Make testbed include only those ABIs which have been built
mhsmith Jul 30, 2024
4561930
Merge branch 'android-2024-07' into android-test-script
mhsmith Jul 30, 2024
b519874
Fix Windows issues
mhsmith Jul 31, 2024
b3ed4c7
Merge branch 'main' into android-test-script
mhsmith Aug 5, 2024
32f79d7
Clarify documentation; remove default `python -m test` arguments
mhsmith Aug 8, 2024
6471512
Link to page about test options; add newlines at end of files
mhsmith Aug 8, 2024
5c3967e
Add `android.py build-testbed` command
mhsmith Aug 8, 2024
cb60cc4
If test script fails before logcat starts, show the Gradle output eve…
mhsmith Aug 11, 2024
b075842
Fix logcat error messages being hidden
mhsmith Aug 11, 2024
2266e82
Improve logging, add timeouts
mhsmith Aug 11, 2024
397d20b
Make the app use the same NDK version as the Python build
mhsmith Aug 11, 2024
8e80dd2
Install platform-tools automatically
mhsmith Aug 11, 2024
709061e
In --connected mode, uninstall app before running Gradle
mhsmith Aug 12, 2024
756bc13
Handle adb logcat returning failure when device disconnects
mhsmith Aug 12, 2024
6b2ed6c
Filter logs by PID rather than UID
mhsmith Aug 12, 2024
05a26cc
Try to terminate subprocesses with SIGTERM before sending SIGKILL
mhsmith Aug 12, 2024
a0dd03b
Handle SIGTERM the same way as SIGINT
mhsmith Aug 12, 2024
2d53549
Fix race condition with pre-run uninstall
mhsmith Aug 12, 2024
c9d5bf5
Fix race condition in a more efficient way
mhsmith Aug 12, 2024
706a1da
Make testbed pick up edits to pure-Python files in the Lib directory
mhsmith Aug 12, 2024
ae3a460
Merge branch 'main' into android-test-script
mhsmith Aug 12, 2024
cf15b99
Remove `boot_completed`, which is unnecessary since we're no longer r…
mhsmith Aug 13, 2024
c56373a
Automatically accept SDK licenses, and log Gradle package installatio…
mhsmith Aug 13, 2024
1e89e58
Stop Gradle test tasks being skipped as up to date
mhsmith Aug 13, 2024
91f356b
Fix CalledProcessError formatting
mhsmith Aug 13, 2024
bdaad24
Add note about testing on Windows
mhsmith Aug 13, 2024
ca2bae2
Implement `fileno` method on stdout and stderr
mhsmith Aug 13, 2024
7a3d674
Correct comment
mhsmith Aug 13, 2024
f4b06f5
Merge branch 'main' into android-test-script
freakboy3742 Aug 13, 2024
47c02a5
Merge branch 'main' into android-test-script
mhsmith Aug 15, 2024
602fbdd
Add note about RAM requirements
mhsmith Aug 15, 2024
305d786
Handle transient failure of pidof
mhsmith Aug 15, 2024
2ad8e4b
Merge branch 'main' into android-test-script
freakboy3742 Aug 16, 2024
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
Prev Previous commit
Next Next commit
Filter logs by PID rather than UID
  • Loading branch information
mhsmith committed Aug 12, 2024
commit 6b2ed6c28716be286f57413fc93ef9d667b4c0e5
41 changes: 20 additions & 21 deletions Android/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,40 +368,39 @@ async def boot_completed(serial):
await asyncio.sleep(1)


async def find_uid(serial):
# An older version of this script in #121595 filtered the logs by UID instead,
# which is more reliable since the PID is shorter-lived. But logcat can't filter
# by UID until API level 31.
async def find_pid(serial):
print("Waiting for app to start - this may take several minutes")
while True:
Comment thread
freakboy3742 marked this conversation as resolved.
lines = (await async_check_output(
adb, "-s", serial, "shell", "pm", "list", "packages", "-U", APP_ID
)).splitlines()
try:
pid = (await async_check_output(
adb, "-s", serial, "shell", "pidof", "-s", APP_ID
)).strip()
except MySystemExit:
pid = None

# The unit test package {APP_ID}.test will also be returned.
for line in lines:
match = re.fullmatch(r"package:(\S+) uid:(\d+)", lines[0])
if not match:
raise ValueError(f"failed to parse {lines[0]!r}")
package, uid = match.groups()
if package == APP_ID:
print(f"UID: {uid}")
return uid
# Exit status is unreliable: some devices (e.g. Nexus 4) return 0 even
# when no process was found.
if pid:
print(f"PID: {pid}")
return pid

await asyncio.sleep(1)
# Loop fairly rapidly to avoid missing a short-lived process.
await asyncio.sleep(0.2)


async def logcat_task(context, initial_devices):
# Gradle may need to do some large downloads of libraries and emulator
# images. This will happen during find_device in --managed mode, or find_uid
# images. This will happen during find_device in --managed mode, or find_pid
# in --connected mode.
startup_timeout = 600
serial = await wait_for(find_device(context, initial_devices), startup_timeout)
await wait_for(boot_completed(serial), startup_timeout)
pid = await wait_for(find_pid(serial), startup_timeout)

# Because Gradle uninstalls the app after running the tests, its UID should
# be different every time. There's therefore no need to filter the logs by
# timestamp or PID.
uid = await wait_for(find_uid(serial), startup_timeout)

args = [adb, "-s", serial, "logcat", "--uid", uid, "--format", "tag"]
args = [adb, "-s", serial, "logcat", "--pid", pid, "--format", "tag"]
hidden_output = []
async with async_process(
*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
Expand Down
7 changes: 5 additions & 2 deletions Android/testbed/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,19 @@ android {
localDevices {
create("minVersion") {
device = "Small Phone"
systemImageSource = "aosp-atd"

// Managed devices have a minimum API level of 27.
apiLevel = max(27, defaultConfig.minSdk!!)

// ATD devices are smaller and faster, but have a minimum
// API level of 30.
systemImageSource = if (apiLevel >= 30) "aosp-atd" else "aosp"
}

create("maxVersion") {
device = "Small Phone"
systemImageSource = "aosp-atd"
apiLevel = defaultConfig.targetSdk!!
systemImageSource = "aosp-atd"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,21 @@ class PythonSuite {
@Test
@UiThreadTest
fun testPython() {
val context = InstrumentationRegistry.getInstrumentation().targetContext
val args = InstrumentationRegistry.getArguments().getString("pythonArgs", "")
val status = PythonTestRunner(context).run(args)
assertEquals(0, status)
val start = System.currentTimeMillis()
try {
val context =
InstrumentationRegistry.getInstrumentation().targetContext
val args =
InstrumentationRegistry.getArguments().getString("pythonArgs", "")
val status = PythonTestRunner(context).run(args)
assertEquals(0, status)
} finally {
// Make sure the process lives long enough for the test script to
// detect it.
val delay = 2000 - (System.currentTimeMillis() - start)
if (delay > 0) {
Thread.sleep(delay)
}
}
}
}