Cleanup: 'am instrument' readability and consistency

Reconcile android_helper and restricted_trace_perf formatting of
'am instrument' command. The only real difference is that
restricted_trace_perf uses 'shell=True' in subprocess which requires
escaping spaces inside ""

Bug: b/292249127
Change-Id: I002e49ae5b2913db46b92a7b643bc12d21abce1e
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4794430
Reviewed-by: Cody Northrop <cnorthrop@google.com>
Commit-Queue: Roman Lavrov <romanl@google.com>
This commit is contained in:
Roman Lavrov
2023-08-18 11:25:05 -04:00
parent 84576a5bf7
commit d41ac4dac3
2 changed files with 39 additions and 23 deletions

View File

@@ -413,17 +413,19 @@ def _TempLocalFile():
def _RunInstrumentation(flags):
assert TEST_PACKAGE_NAME == 'com.android.angle.test' # inlined below for readability
with _TempDeviceFile() as temp_device_file:
cmd = ' '.join([
'p=%s;' % TEST_PACKAGE_NAME,
'ntr=org.chromium.native_test.NativeTestInstrumentationTestRunner;',
'am instrument -w',
'-e $ntr.NativeTestActivity "$p".AngleUnitTestActivity',
'-e $ntr.ShardNanoTimeout 2400000000000',
'-e org.chromium.native_test.NativeTest.CommandLineFlags "%s"' % ' '.join(flags),
'-e $ntr.StdoutFile ' + temp_device_file,
'"$p"/org.chromium.build.gtest_apk.NativeTestInstrumentationTestRunner',
])
cmd = r'''
am instrument -w \
-e org.chromium.native_test.NativeTestInstrumentationTestRunner.StdoutFile {out} \
-e org.chromium.native_test.NativeTest.CommandLineFlags "{flags}" \
-e org.chromium.native_test.NativeTestInstrumentationTestRunner.ShardNanoTimeout "1000000000000000000" \
-e org.chromium.native_test.NativeTestInstrumentationTestRunner.NativeTestActivity \
com.android.angle.test.AngleUnitTestActivity \
com.android.angle.test/org.chromium.build.gtest_apk.NativeTestInstrumentationTestRunner
'''.format(
out=temp_device_file, flags=r' '.join(flags)).strip()
_AdbShell(cmd)
return _ReadDeviceFile(temp_device_file)

View File

@@ -195,23 +195,37 @@ def run_trace(trace, args):
memory_command = 'shell sh /data/local/tmp/gpumem.sh 0.25'
memory_process = run_async_adb_command(memory_command)
adb_command = 'shell am instrument -w '
adb_command += '-e org.chromium.native_test.NativeTestInstrumentationTestRunner.StdoutFile /sdcard/Download/out.txt '
adb_command += '-e org.chromium.native_test.NativeTest.CommandLineFlags "--gtest_filter=TraceTest.' + trace + '\ '
adb_command += '--use-gl=native\ '
flags = [
'--gtest_filter=TraceTest.' + trace, '--use-gl=native', '--verbose', '--verbose-logging'
]
if mode != '':
adb_command += '--{}\ '.format(mode)
flags.append('--' + mode)
if args.maxsteps != '':
adb_command += '--max-steps-performed\ ' + args.maxsteps + '\ '
flags += ['--max-steps-performed', args.maxsteps]
if args.fixedtime != '':
adb_command += '--fixed-test-time-with-warmup\ ' + args.fixedtime + '\ '
flags += ['--fixed-test-time-with-warmup', args.fixedtime]
if args.minimizegpuwork:
adb_command += '--minimize-gpu-work\ '
adb_command += '--verbose\ '
adb_command += '--verbose-logging\"\ '
adb_command += '-e org.chromium.native_test.NativeTestInstrumentationTestRunner.ShardNanoTimeout "1000000000000000000" '
adb_command += '-e org.chromium.native_test.NativeTestInstrumentationTestRunner.NativeTestActivity com.android.angle.test.AngleUnitTestActivity '
adb_command += 'com.android.angle.test/org.chromium.build.gtest_apk.NativeTestInstrumentationTestRunner'
flags.append('--minimize-gpu-work')
# Build a command that can be run directly over ADB, for example:
r'''
adb shell am instrument -w \
-e org.chromium.native_test.NativeTestInstrumentationTestRunner.StdoutFile /sdcard/Download/out.txt \
-e org.chromium.native_test.NativeTest.CommandLineFlags \
"--gtest_filter=TraceTest.empires_and_puzzles\ --use-angle=vulkan\ --screenshot-dir\ /sdcard\ --screenshot-frame\ 2\ --max-steps-performed\ 2\ --no-warmup" \
-e org.chromium.native_test.NativeTestInstrumentationTestRunner.ShardNanoTimeout "1000000000000000000" \
-e org.chromium.native_test.NativeTestInstrumentationTestRunner.NativeTestActivity com.android.angle.test.AngleUnitTestActivity \
com.android.angle.test/org.chromium.build.gtest_apk.NativeTestInstrumentationTestRunner
'''
adb_command = r'''
shell am instrument -w \
-e org.chromium.native_test.NativeTestInstrumentationTestRunner.StdoutFile /sdcard/Download/out.txt \
-e org.chromium.native_test.NativeTest.CommandLineFlags "{flags}" \
-e org.chromium.native_test.NativeTestInstrumentationTestRunner.ShardNanoTimeout "1000000000000000000" \
-e org.chromium.native_test.NativeTestInstrumentationTestRunner.NativeTestActivity \
com.android.angle.test.AngleUnitTestActivity \
com.android.angle.test/org.chromium.build.gtest_apk.NativeTestInstrumentationTestRunner
'''.format(flags=r'\ '.join(flags)).strip() # Note: space escaped due to subprocess shell=True
result = run_adb_command(adb_command)