88
99import pytest
1010
11- from . import Envelope
11+ from . import adb , Envelope
1212from .assertions import assert_inproc_crash
1313from .build_config import get_test_executable_cmake_args , get_test_executable_env
14- from .conditions import is_tsan
14+ from .conditions import is_android , is_tsan
1515
1616fixture_path = pathlib .Path ("tests/fixtures/inproc_stress" )
1717
1818ANDROID_TMP = "/data/local/tmp"
1919
2020
21- def is_android ():
22- return bool (os .environ .get ("ANDROID_API" ))
23-
24-
25- def adb (* args ):
26- """Run an adb command."""
27- return subprocess .run (
28- ["{}/platform-tools/adb" .format (os .environ ["ANDROID_HOME" ]), * args ],
29- check = True ,
30- capture_output = True ,
31- )
32-
33-
3421def compile_test_program (tmp_path ):
3522 build_dir = tmp_path / "inproc_stress_build"
3623 build_dir .mkdir (exist_ok = True )
@@ -63,14 +50,14 @@ def compile_test_program(tmp_path):
6350 exe_path = build_dir / exe_name
6451
6552 # Push executable to Android device
66- if is_android () :
67- adb ("push" , str (exe_path ), ANDROID_TMP )
53+ if is_android :
54+ adb ("push" , str (exe_path ), ANDROID_TMP , check = True , capture_output = True )
6855
6956 return exe_path
7057
7158
7259def run_stress_test (tmp_path , test_executable , test_name , database_path = None ):
73- if is_android () :
60+ if is_android :
7461 return run_stress_test_android (test_executable , test_name , database_path )
7562
7663 if database_path is None :
@@ -100,20 +87,14 @@ def run_stress_test_android(test_executable, test_name, database_path):
10087 remote_db_path = f"{ ANDROID_TMP } /{ database_path .name } "
10188
10289 # Clear logcat before running so we limit the capture as close to this run as possible
103- subprocess .run (
104- ["{}/platform-tools/adb" .format (os .environ ["ANDROID_HOME" ]), "logcat" , "-c" ],
105- check = False ,
106- )
90+ adb ("logcat" , "-c" , check = False )
10791
10892 # Run on device - we need to capture both stdout and stderr, and the return code
10993 # Android shell doesn't separate stdout/stderr well, so we redirect stderr to stdout
11094 # and parse the return code from the output (same approach as tests/__init__.py)
111- result = subprocess .run (
112- [
113- "{}/platform-tools/adb" .format (os .environ ["ANDROID_HOME" ]),
114- "shell" ,
115- f"cd { ANDROID_TMP } && LD_LIBRARY_PATH=. ./{ exe_name } { test_name } { remote_db_path } 2>&1; echo ret:$?" ,
116- ],
95+ result = adb (
96+ "shell" ,
97+ f"cd { ANDROID_TMP } && LD_LIBRARY_PATH=. ./{ exe_name } { test_name } { remote_db_path } 2>&1; echo ret:$?" ,
11798 capture_output = True ,
11899 text = True ,
119100 )
@@ -130,14 +111,11 @@ def run_stress_test_android(test_executable, test_name, database_path):
130111 time .sleep (0.5 )
131112
132113 # Capture logcat to get our logs
133- logcat_result = subprocess .run (
134- [
135- "{}/platform-tools/adb" .format (os .environ ["ANDROID_HOME" ]),
136- "logcat" ,
137- "-d" ,
138- "-s" ,
139- "sentry-native:*" ,
140- ],
114+ logcat_result = adb (
115+ "logcat" ,
116+ "-d" ,
117+ "-s" ,
118+ "sentry-native:*" ,
141119 capture_output = True ,
142120 text = True ,
143121 )
@@ -150,20 +128,19 @@ def run_stress_test_android(test_executable, test_name, database_path):
150128
151129 # Pull the remote database to local path (pulls to parent, creates database_path)
152130 try :
153- adb ("pull" , f"{ remote_db_path } /" , str (database_path .parent ))
131+ adb (
132+ "pull" ,
133+ f"{ remote_db_path } /" ,
134+ str (database_path .parent ),
135+ check = True ,
136+ capture_output = True ,
137+ )
154138 except subprocess .CalledProcessError :
155139 # Database might not exist if crash wasn't captured
156140 pass
157141
158142 # Clean up remote database for next run
159- subprocess .run (
160- [
161- "{}/platform-tools/adb" .format (os .environ ["ANDROID_HOME" ]),
162- "shell" ,
163- f"rm -rf { remote_db_path } " ,
164- ],
165- check = False ,
166- )
143+ adb ("shell" , f"rm -rf { remote_db_path } " , check = False )
167144
168145 # Combine shell output with logcat output for assertion checks
169146 combined_output = output + "\n " + logcat_output
@@ -374,7 +351,7 @@ def test_inproc_handler_abort_crash(cmake):
374351
375352
376353@pytest .mark .skipif (
377- sys .platform != "darwin" or is_android ( ),
354+ sys .platform != "darwin" or bool ( is_android ),
378355 reason = "Stack trace tests are macOS-only" ,
379356)
380357@pytest .mark .parametrize (
0 commit comments