xref: /aosp_15_r20/tools/asuite/atest/integration_tests/atest_command_verification_tests.py (revision c2e18aaa1096c836b086f94603d04f4eb9cf37f5)
1#!/usr/bin/env python3
2#
3# Copyright 2023, The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""A collection of integration test cases for atest."""
18
19import os
20from typing import Any, Callable
21import atest_integration_test
22
23
24class CommandVerificationTests(atest_integration_test.AtestTestCase):
25  """Checks atest tradefed commands."""
26
27  @atest_integration_test.run_in_parallel
28  def test_animator_test(self):
29    """Verify that the test's command runs correctly."""
30    atest_cmd = 'AnimatorTest'
31    expected_cmd = (
32        'atest_tradefed.sh template/atest_device_test_base --template:map'
33        ' test=atest --template:map log_saver=template/log/atest_log_saver'
34        ' --no-enable-granular-attempts --module CtsAnimationTestCases'
35        ' --atest-include-filter'
36        ' CtsAnimationTestCases:android.animation.cts.AnimatorTest'
37        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
38        ' VERBOSE --no-early-device-release --test-arg'
39        ' com.android.tradefed.testtype.AndroidJUnitTest:exclude-annotation:android.platform.test.annotations.AppModeInstant'
40        ' --enable-parameterized-modules --exclude-module-parameters'
41        ' secondary_user --exclude-module-parameters instant_app'
42        ' --exclude-module-parameters multi_abi'
43    )
44    self._verify_atest_internal_runner_command(
45        atest_cmd,
46        self._assert_equivalent_cmds,
47        expected_cmd=expected_cmd,
48    )
49
50  # Disabled due to b/358615386
51  # @atest_integration_test.run_in_parallel
52  # def test_cts_animation_test_cases_animator_test(self):
53  #   """Verify that the test's command runs correctly."""
54  #   atest_cmd = 'CtsAnimationTestCases:AnimatorTest'
55  #   expected_cmd = (
56  #       'atest_tradefed.sh template/atest_device_test_base --template:map'
57  #       ' test=atest --template:map log_saver=template/log/atest_log_saver'
58  #       ' --no-enable-granular-attempts --module CtsAnimationTestCases'
59  #       ' --atest-include-filter'
60  #       ' CtsAnimationTestCases:android.animation.cts.AnimatorTest'
61  #       ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
62  #       ' VERBOSE --no-early-device-release --test-arg'
63  #       ' com.android.tradefed.testtype.AndroidJUnitTest:exclude-annotation:android.platform.test.annotations.AppModeInstant'
64  #       ' --enable-parameterized-modules --exclude-module-parameters multi_abi'
65  #       ' --exclude-module-parameters instant_app --exclude-module-parameters'
66  #       ' secondary_user'
67  #   )
68  #   self._verify_atest_internal_runner_command(
69  #       atest_cmd,
70  #       self._assert_equivalent_cmds,
71  #       expected_cmd=expected_cmd,
72  #   )
73
74  # Disabled due to b/358615386
75  # @atest_integration_test.run_in_parallel
76  # def test_cts_sample_device_cases_shared_prefs_test(self):
77  #   """Verify that the test's command runs correctly."""
78  #   atest_cmd = (
79  #       'CtsSampleDeviceTestCases:SampleDeviceTest#testSharedPreferences'
80  #   )
81  #   expected_cmd = (
82  #       'atest_tradefed.sh template/atest_device_test_base --template:map'
83  #       ' test=atest'
84  #       ' --template:map log_saver=template/log/atest_log_saver'
85  #       ' --no-enable-granular-attempts --include-filter'
86  #       ' CtsSampleDeviceTestCases --atest-include-filter'
87  #       ' CtsSampleDeviceTestCases:android.sample.cts.SampleDeviceTest#testSharedPreferences'
88  #       ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
89  #       ' VERBOSE --no-early-device-release --test-arg'
90  #       ' com.android.tradefed.testtype.AndroidJUnitTest:exclude-annotation:android.platform.test.annotations.AppModeInstant'
91  #   )
92  #   self._verify_atest_internal_runner_command(
93  #       atest_cmd,
94  #       self._assert_equivalent_cmds,
95  #       expected_cmd=expected_cmd,
96  #   )
97
98  # Disabled due to b/358615386
99  # @atest_integration_test.run_in_parallel
100  # def test_cts_sample_device_cases_android_sample_test(self):
101  #   """Verify that the test's command runs correctly."""
102  #   atest_cmd = 'CtsSampleDeviceTestCases:android.sample.cts'
103  #   expected_cmd = (
104  #       'atest_tradefed.sh template/atest_device_test_base --template:map'
105  #       ' test=atest'
106  #       ' --template:map log_saver=template/log/atest_log_saver'
107  #       ' --no-enable-granular-attempts --include-filter'
108  #       ' CtsSampleDeviceTestCases --atest-include-filter'
109  #       ' CtsSampleDeviceTestCases:android.sample.cts --skip-loading-config-jar'
110  #       ' --log-level-display VERBOSE --log-level VERBOSE'
111  #       ' --no-early-device-release --test-arg'
112  #       ' com.android.tradefed.testtype.AndroidJUnitTest:exclude-annotation:android.platform.test.annotations.AppModeInstant'
113  #   )
114  #   self._verify_atest_internal_runner_command(
115  #       atest_cmd,
116  #       self._assert_equivalent_cmds,
117  #       expected_cmd=expected_cmd,
118  #   )
119
120  # Disabled due to b/358615386
121  # @atest_integration_test.run_in_parallel
122  # def test_cts_sample_device_cases_device_report_log_test(self):
123  #   """Verify that the test's command runs correctly."""
124  #   atest_cmd = (
125  #       'CtsSampleDeviceTestCases:android.sample.cts.SampleDeviceReportLogTest'
126  #   )
127  #   expected_cmd = (
128  #       'atest_tradefed.sh template/atest_device_test_base --template:map'
129  #       ' test=atest'
130  #       ' --template:map log_saver=template/log/atest_log_saver'
131  #       ' --no-enable-granular-attempts --include-filter'
132  #       ' CtsSampleDeviceTestCases --atest-include-filter'
133  #       ' CtsSampleDeviceTestCases:android.sample.cts.SampleDeviceReportLogTest'
134  #       ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
135  #       ' VERBOSE --no-early-device-release --test-arg'
136  #       ' com.android.tradefed.testtype.AndroidJUnitTest:exclude-annotation:android.platform.test.annotations.AppModeInstant'
137  #   )
138  #   self._verify_atest_internal_runner_command(
139  #       atest_cmd,
140  #       self._assert_equivalent_cmds,
141  #       expected_cmd=expected_cmd,
142  #   )
143
144  # Disabled due to b/358615386
145  # @atest_integration_test.run_in_parallel
146  # def test_cts_animation_cases_sample_device_cases_test(self):
147  #   """Verify that the test's command runs correctly."""
148  #   atest_cmd = 'CtsAnimationTestCases CtsSampleDeviceTestCases'
149  #   expected_cmd = (
150  #       'atest_tradefed.sh template/atest_device_test_base --template:map'
151  #       ' test=atest'
152  #       ' --template:map log_saver=template/log/atest_log_saver'
153  #       ' --no-enable-granular-attempts --include-filter CtsAnimationTestCases'
154  #       ' --include-filter CtsSampleDeviceTestCases --skip-loading-config-jar'
155  #       ' --log-level-display VERBOSE --log-level VERBOSE'
156  #       ' --no-early-device-release --test-arg'
157  #       ' com.android.tradefed.testtype.AndroidJUnitTest:exclude-annotation:android.platform.test.annotations.AppModeInstant'
158  #   )
159  #   self._verify_atest_internal_runner_command(
160  #       atest_cmd,
161  #       self._assert_equivalent_cmds,
162  #       expected_cmd=expected_cmd,
163  #   )
164
165  @atest_integration_test.run_in_parallel
166  def test_hello_world_tests_test(self):
167    """Verify that the test's command runs correctly."""
168    atest_cmd = 'HelloWorldTests'
169    expected_cmd = (
170        'atest_tradefed.sh template/atest_device_test_base --template:map'
171        ' test=atest --template:map log_saver=template/log/atest_log_saver'
172        ' --no-enable-granular-attempts --include-filter HelloWorldTests'
173        ' --include-filter hallo-welt --skip-loading-config-jar'
174        ' --log-level-display VERBOSE --log-level VERBOSE'
175        ' --no-early-device-release'
176    )
177    self._verify_atest_internal_runner_command(
178        atest_cmd,
179        self._assert_equivalent_cmds,
180        expected_cmd=expected_cmd,
181    )
182
183  @atest_integration_test.run_in_parallel
184  def test_perinstance_camerahidl_config_injection_test(self):
185    """Verify that the test's command runs correctly."""
186    atest_cmd = (
187        'PerInstance/CameraHidlTest#'
188        'configureInjectionStreamsAvailableOutputs/0_internal_0'
189    )
190    expected_cmd = (
191        'atest_tradefed.sh template/atest_device_test_base --template:map'
192        ' test=atest --template:map log_saver=template/log/atest_log_saver'
193        ' --no-enable-granular-attempts --include-filter'
194        ' VtsHalCameraProviderV2_4TargetTest --atest-include-filter'
195        ' VtsHalCameraProviderV2_4TargetTest:PerInstance/CameraHidlTest.configureInjectionStreamsAvailableOutputs/0_internal_0'
196        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
197        ' VERBOSE --no-early-device-release'
198    )
199    self._verify_atest_internal_runner_command(
200        atest_cmd,
201        self._assert_equivalent_cmds,
202        expected_cmd=expected_cmd,
203    )
204
205  @atest_integration_test.run_in_parallel
206  def test_vts_hal_camera_provider_config_injection_test(self):
207    """Verify that the test's command runs correctly."""
208    atest_cmd = (
209        'VtsHalCameraProviderV2_4TargetTest:PerInstance/'
210        'CameraHidlTest#configureInjectionStreamsAvailableOutputs/'
211        '0_internal_0'
212    )
213    expected_cmd = (
214        'atest_tradefed.sh template/atest_device_test_base --template:map'
215        ' test=atest --template:map log_saver=template/log/atest_log_saver'
216        ' --no-enable-granular-attempts --include-filter'
217        ' VtsHalCameraProviderV2_4TargetTest --atest-include-filter'
218        ' VtsHalCameraProviderV2_4TargetTest:PerInstance/CameraHidlTest.configureInjectionStreamsAvailableOutputs/0_internal_0'
219        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
220        ' VERBOSE --no-early-device-release'
221    )
222    self._verify_atest_internal_runner_command(
223        atest_cmd,
224        self._assert_equivalent_cmds,
225        expected_cmd=expected_cmd,
226    )
227
228  @atest_integration_test.run_in_parallel
229  def test_android_animation_cts_test(self):
230    """Verify that the test's command runs correctly."""
231    atest_cmd = 'android.animation.cts'
232    expected_cmd = (
233        'atest_tradefed.sh template/atest_device_test_base --template:map'
234        ' test=atest --template:map log_saver=template/log/atest_log_saver'
235        ' --no-enable-granular-attempts --module CtsAnimationTestCases'
236        ' --atest-include-filter CtsAnimationTestCases:android.animation.cts'
237        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
238        ' VERBOSE --no-early-device-release --test-arg'
239        ' com.android.tradefed.testtype.AndroidJUnitTest:exclude-annotation:android.platform.test.annotations.AppModeInstant'
240        ' --enable-parameterized-modules --exclude-module-parameters multi_abi'
241        ' --exclude-module-parameters instant_app --exclude-module-parameters'
242        ' secondary_user'
243    )
244    self._verify_atest_internal_runner_command(
245        atest_cmd,
246        self._assert_equivalent_cmds,
247        expected_cmd=expected_cmd,
248    )
249
250  # Disabled due to b/358615386
251  # @atest_integration_test.run_in_parallel
252  # def test_android_sample_cts_device_report_log_test(self):
253  #   """Verify that the test's command runs correctly."""
254  #   atest_cmd = 'android.sample.cts.SampleDeviceReportLogTest'
255  #   expected_cmd = (
256  #       'atest_tradefed.sh template/atest_device_test_base --template:map'
257  #       ' test=atest'
258  #       ' --template:map log_saver=template/log/atest_log_saver'
259  #       ' --no-enable-granular-attempts --include-filter'
260  #       ' CtsSampleDeviceTestCases --atest-include-filter'
261  #       ' CtsSampleDeviceTestCases:android.sample.cts.SampleDeviceReportLogTest'
262  #       ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
263  #       ' VERBOSE --no-early-device-release --test-arg'
264  #       ' com.android.tradefed.testtype.AndroidJUnitTest:exclude-annotation:android.platform.test.annotations.AppModeInstant'
265  #   )
266  #   self._verify_atest_internal_runner_command(
267  #       atest_cmd,
268  #       self._assert_equivalent_cmds,
269  #       expected_cmd=expected_cmd,
270  #   )
271
272  # Disabled due to b/358615386
273  # @atest_integration_test.run_in_parallel
274  # def test_android_sample_cts_shared_prefs_test(self):
275  #   """Verify that the test's command runs correctly."""
276  #   atest_cmd = 'android.sample.cts.SampleDeviceTest#testSharedPreferences'
277  #   expected_cmd = (
278  #       'atest_tradefed.sh template/atest_device_test_base --template:map'
279  #       ' test=atest'
280  #       ' --template:map log_saver=template/log/atest_log_saver'
281  #       ' --no-enable-granular-attempts --include-filter'
282  #       ' CtsSampleDeviceTestCases --atest-include-filter'
283  #       ' CtsSampleDeviceTestCases:android.sample.cts.SampleDeviceTest#testSharedPreferences'
284  #       ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
285  #       ' VERBOSE --no-early-device-release --test-arg'
286  #       ' com.android.tradefed.testtype.AndroidJUnitTest:exclude-annotation:android.platform.test.annotations.AppModeInstant'
287  #   )
288  #   self._verify_atest_internal_runner_command(
289  #       atest_cmd,
290  #       self._assert_equivalent_cmds,
291  #       expected_cmd=expected_cmd,
292  #   )
293
294  @atest_integration_test.run_in_parallel
295  def test_hello_world_test(self):
296    """Verify that the test's command runs correctly."""
297    atest_cmd = 'hello_world_test'
298    expected_cmd = (
299        'atest_tradefed.sh template/atest_device_test_base --template:map'
300        ' test=atest --template:map log_saver=template/log/atest_log_saver'
301        ' --no-enable-granular-attempts --include-filter hello_world_test'
302        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
303        ' VERBOSE --no-early-device-release'
304    )
305    self._verify_atest_internal_runner_command(
306        atest_cmd,
307        self._assert_equivalent_cmds,
308        expected_cmd=expected_cmd,
309    )
310
311  @atest_integration_test.run_in_parallel
312  def test_native_benchmark_test(self):
313    """Verify that the test's command runs correctly."""
314    atest_cmd = 'native-benchmark'
315    expected_cmd = (
316        'atest_tradefed.sh template/atest_device_test_base --template:map'
317        ' test=atest --template:map log_saver=template/log/atest_log_saver'
318        ' --no-enable-granular-attempts --include-filter native-benchmark'
319        ' --log-level-display VERBOSE --log-level VERBOSE'
320        ' --no-early-device-release'
321    )
322    self._verify_atest_internal_runner_command(
323        atest_cmd,
324        self._assert_equivalent_cmds,
325        expected_cmd=expected_cmd,
326    )
327
328  @atest_integration_test.run_in_parallel
329  def test_platform_native_example_test(self):
330    """Verify that the test's command runs correctly."""
331    atest_cmd = 'platform_testing/tests/example/native'
332    expected_cmd = (
333        'atest_tradefed.sh template/atest_device_test_base --template:map'
334        ' test=atest --template:map log_saver=template/log/atest_log_saver'
335        ' --no-enable-granular-attempts --include-filter hello_world_test'
336        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
337        ' VERBOSE --no-early-device-release'
338    )
339    self._verify_atest_internal_runner_command(
340        atest_cmd,
341        self._assert_equivalent_cmds,
342        expected_cmd=expected_cmd,
343    )
344
345  @atest_integration_test.run_in_parallel
346  def test_platform_android_example_test(self):
347    """Verify that the test's command runs correctly."""
348    atest_cmd = 'platform_testing/tests/example/native/Android.bp'
349    expected_cmd = (
350        'atest_tradefed.sh template/atest_device_test_base --template:map'
351        ' test=atest --template:map log_saver=template/log/atest_log_saver'
352        ' --no-enable-granular-attempts --include-filter hello_world_test'
353        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
354        ' VERBOSE --no-early-device-release'
355    )
356    self._verify_atest_internal_runner_command(
357        atest_cmd,
358        self._assert_equivalent_cmds,
359        expected_cmd=expected_cmd,
360    )
361
362  @atest_integration_test.run_in_parallel
363  def test_tf_core_config_native_benchmark_test(self):
364    """Verify that the test's command runs correctly."""
365    atest_cmd = 'tools/tradefederation/core/res/config/native-benchmark.xml'
366    expected_cmd = (
367        'atest_tradefed.sh template/atest_device_test_base --template:map'
368        ' test=atest --template:map log_saver=template/log/atest_log_saver'
369        ' --no-enable-granular-attempts --include-filter native-benchmark'
370        ' --log-level-display VERBOSE --log-level VERBOSE'
371        ' --no-early-device-release'
372    )
373    self._verify_atest_internal_runner_command(
374        atest_cmd,
375        self._assert_equivalent_cmds,
376        expected_cmd=expected_cmd,
377    )
378
379  @atest_integration_test.run_in_parallel
380  def test_quick_access_wallet_robo_test(self):
381    """Verify that the test's command runs correctly."""
382    atest_cmd = 'QuickAccessWalletRoboTests'
383    expected_cmd = (
384        'atest_tradefed.sh template/atest_device_test_base --template:map'
385        ' test=atest --template:map log_saver=template/log/atest_log_saver'
386        ' --no-enable-granular-attempts --include-filter'
387        ' QuickAccessWalletRoboTests --skip-loading-config-jar'
388        ' --log-level-display VERBOSE --log-level VERBOSE'
389        ' --no-early-device-release'
390    )
391    self._verify_atest_internal_runner_command(
392        atest_cmd,
393        self._assert_equivalent_cmds,
394        expected_cmd=expected_cmd,
395    )
396
397  @atest_integration_test.run_in_parallel
398  def test_quick_access_wallet_robo_host_test(self):
399    """Verify that the test's command runs correctly."""
400    atest_cmd = 'QuickAccessWalletRoboTests --host'
401    expected_cmd = (
402        'atest_tradefed.sh template/atest_deviceless_test_base --template:map'
403        ' test=atest --template:map log_saver=template/log/atest_log_saver'
404        ' --no-enable-granular-attempts --include-filter'
405        ' QuickAccessWalletRoboTests --skip-loading-config-jar'
406        ' --log-level-display VERBOSE --log-level VERBOSE'
407        ' --no-early-device-release -n --prioritize-host-config'
408        ' --skip-host-arch-check'
409    )
410    self._verify_atest_internal_runner_command(
411        atest_cmd,
412        self._assert_equivalent_cmds,
413        expected_cmd=expected_cmd,
414    )
415
416  @atest_integration_test.run_in_parallel
417  def test_cts_wifi_aware_cases_test(self):
418    """Verify that the test's command runs correctly."""
419    atest_cmd = 'CtsWifiAwareTestCases'
420    expected_cmd = (
421        'atest_tradefed.sh template/atest_device_test_base --template:map'
422        ' test=atest --template:map log_saver=template/log/atest_log_saver'
423        ' --no-enable-granular-attempts --include-filter CtsWifiAwareTestCases'
424        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
425        ' VERBOSE --no-early-device-release --replicate-parent-setup'
426        ' --multi-device-count 2'
427    )
428    self._verify_atest_internal_runner_command(
429        atest_cmd,
430        self._assert_equivalent_cmds,
431        expected_cmd=expected_cmd,
432    )
433
434  @atest_integration_test.run_in_parallel
435  def test_pts_bot_test(self):
436    """Verify that the test's command runs correctly."""
437    atest_cmd = 'pts-bot:PAN/GN/MISC/UUID/BV-01-C'
438    expected_cmd = (
439        'atest_tradefed.sh template/atest_device_test_base --template:map'
440        ' test=atest --template:map log_saver=template/log/atest_log_saver'
441        ' --no-enable-granular-attempts --include-filter pts-bot'
442        ' --atest-include-filter pts-bot:PAN/GN/MISC/UUID/BV-01-C'
443        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
444        ' VERBOSE --no-early-device-release'
445    )
446    self._verify_atest_internal_runner_command(
447        atest_cmd,
448        self._assert_equivalent_cmds,
449        expected_cmd=expected_cmd,
450    )
451
452  @atest_integration_test.run_in_parallel
453  def test_tee_ui_utils_test(self):
454    """Verify that the test's command runs correctly."""
455    atest_cmd = 'TeeUIUtilsTest'
456    expected_cmd = (
457        'atest_tradefed.sh template/atest_device_test_base --template:map'
458        ' test=atest --template:map log_saver=template/log/atest_log_saver'
459        ' --no-enable-granular-attempts --include-filter teeui_unit_tests'
460        ' --atest-include-filter teeui_unit_tests:TeeUIUtilsTest.*'
461        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
462        ' VERBOSE --no-early-device-release'
463    )
464    self._verify_atest_internal_runner_command(
465        atest_cmd,
466        self._assert_equivalent_cmds,
467        expected_cmd=expected_cmd,
468    )
469
470  @atest_integration_test.run_in_parallel
471  def test_tee_ui_utils_intersect_convext_obj_test(self):
472    """Verify that the test's command runs correctly."""
473    atest_cmd = (
474        'TeeUIUtilsTest#intersectTest,ConvexObjectConstruction,'
475        'ConvexObjectLineIntersection'
476    )
477    expected_cmd = (
478        'atest_tradefed.sh template/atest_device_test_base --template:map'
479        ' test=atest --template:map log_saver=template/log/atest_log_saver'
480        ' --no-enable-granular-attempts --include-filter teeui_unit_tests'
481        ' --atest-include-filter'
482        ' teeui_unit_tests:TeeUIUtilsTest.ConvexObjectConstruction:TeeUIUtilsTest.ConvexObjectLineIntersection:TeeUIUtilsTest.intersectTest'
483        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
484        ' VERBOSE --no-early-device-release'
485    )
486    self._verify_atest_internal_runner_command(
487        atest_cmd,
488        self._assert_equivalent_cmds,
489        expected_cmd=expected_cmd,
490    )
491
492  @atest_integration_test.run_in_parallel
493  def test_cts_activity_mgr_register_ui_change_test(self):
494    """Verify that the test's command runs correctly."""
495    atest_cmd = (
496        'CtsSecurityTestCases:android.security.cts.'
497        'ActivityManagerTest#testActivityManager_'
498        'registerUidChangeObserver_allPermission'
499    )
500    expected_cmd = (
501        'atest_tradefed.sh template/atest_device_test_base --template:map'
502        ' test=atest --template:map log_saver=template/log/atest_log_saver'
503        ' --no-enable-granular-attempts --module CtsSecurityTestCases'
504        ' --atest-include-filter'
505        ' CtsSecurityTestCases:android.security.cts.ActivityManagerTest#testActivityManager_registerUidChangeObserver_allPermission'
506        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
507        ' VERBOSE --no-early-device-release --enable-parameterized-modules'
508        ' --exclude-module-parameters instant_app --exclude-module-parameters'
509        ' secondary_user --exclude-module-parameters multi_abi'
510    )
511    self._verify_atest_internal_runner_command(
512        atest_cmd,
513        self._assert_equivalent_cmds,
514        expected_cmd=expected_cmd,
515    )
516
517  @atest_integration_test.run_in_parallel
518  def test_cts_activity_mgr_register_ui_change_java_test(self):
519    """Verify that the test's command runs correctly."""
520    atest_cmd = (
521        'cts/tests/tests/security/src/android/security/cts/'
522        'ActivityManagerTest.java#testActivityManager_'
523        'registerUidChangeObserver_allPermission'
524    )
525    expected_cmd = (
526        'atest_tradefed.sh template/atest_device_test_base --template:map'
527        ' test=atest --template:map log_saver=template/log/atest_log_saver'
528        ' --no-enable-granular-attempts --module CtsSecurityTestCases'
529        ' --atest-include-filter'
530        ' CtsSecurityTestCases:android.security.cts.ActivityManagerTest#testActivityManager_registerUidChangeObserver_allPermission'
531        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
532        ' VERBOSE --no-early-device-release --enable-parameterized-modules'
533        ' --exclude-module-parameters instant_app --exclude-module-parameters'
534        ' secondary_user --exclude-module-parameters multi_abi'
535    )
536    self._verify_atest_internal_runner_command(
537        atest_cmd,
538        self._assert_equivalent_cmds,
539        expected_cmd=expected_cmd,
540    )
541
542  @atest_integration_test.run_in_parallel
543  def test_permission_memory_footprint_apps_size_kt_test(self):
544    """Verify that the test's command runs correctly."""
545    atest_cmd = (
546        'cts/tests/tests/security/src/android/security/cts/'
547        'PermissionMemoryFootprintTest.kt#'
548        'checkAppsCantIncreasePermissionSizeAfterCreating'
549    )
550    expected_cmd = (
551        'atest_tradefed.sh template/atest_device_test_base --template:map'
552        ' test=atest --template:map log_saver=template/log/atest_log_saver'
553        ' --no-enable-granular-attempts --module CtsSecurityTestCases'
554        ' --atest-include-filter'
555        ' CtsSecurityTestCases:android.security.cts.PermissionMemoryFootprintTest#checkAppsCantIncreasePermissionSizeAfterCreating'
556        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
557        ' VERBOSE --no-early-device-release --enable-parameterized-modules'
558        ' --exclude-module-parameters instant_app --exclude-module-parameters'
559        ' multi_abi --exclude-module-parameters secondary_user'
560    )
561    self._verify_atest_internal_runner_command(
562        atest_cmd,
563        self._assert_equivalent_cmds,
564        expected_cmd=expected_cmd,
565    )
566
567  @atest_integration_test.run_in_parallel
568  def test_permission_memory_footprint_test(self):
569    """Verify that the test's command runs correctly."""
570    atest_cmd = 'android.security.cts.PermissionMemoryFootprintTest'
571    expected_cmd = (
572        'atest_tradefed.sh template/atest_device_test_base --template:map'
573        ' test=atest --template:map log_saver=template/log/atest_log_saver'
574        ' --no-enable-granular-attempts --module CtsSecurityTestCases'
575        ' --atest-include-filter'
576        ' CtsSecurityTestCases:android.security.cts.PermissionMemoryFootprintTest'
577        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
578        ' VERBOSE --no-early-device-release --enable-parameterized-modules'
579        ' --exclude-module-parameters multi_abi --exclude-module-parameters'
580        ' instant_app --exclude-module-parameters secondary_user'
581    )
582    self._verify_atest_internal_runner_command(
583        atest_cmd,
584        self._assert_equivalent_cmds,
585        expected_cmd=expected_cmd,
586    )
587
588  @atest_integration_test.run_in_parallel
589  def test_permission_memory_footprint_apps_size_test(self):
590    """Verify that the test's command runs correctly."""
591    atest_cmd = (
592        'android.security.cts.PermissionMemoryFootprintTest#'
593        'checkAppsCantIncreasePermissionSizeAfterCreating'
594    )
595    expected_cmd = (
596        'atest_tradefed.sh template/atest_device_test_base --template:map'
597        ' test=atest --template:map log_saver=template/log/atest_log_saver'
598        ' --no-enable-granular-attempts --module CtsSecurityTestCases'
599        ' --atest-include-filter'
600        ' CtsSecurityTestCases:android.security.cts.PermissionMemoryFootprintTest#checkAppsCantIncreasePermissionSizeAfterCreating'
601        ' --skip-loading-config-jar --log-level-display VERBOSE --log-level'
602        ' VERBOSE --no-early-device-release --enable-parameterized-modules'
603        ' --exclude-module-parameters secondary_user'
604        ' --exclude-module-parameters multi_abi --exclude-module-parameters'
605        ' instant_app'
606    )
607    self._verify_atest_internal_runner_command(
608        atest_cmd,
609        self._assert_equivalent_cmds,
610        expected_cmd=expected_cmd,
611    )
612
613  @classmethod
614  @atest_integration_test.setup_parallel_in_build_env
615  def setUpClassForParallelInBuild(cls):
616    """Setup method for parallel run in build env.
617
618    This setup executes an initial run of atest on a simple method,
619    disregarding the results. This is needed so that atest will build any
620    dependencies required before the parallel run starts. Without this
621    setup, on certain build environment the parallel run may trigger
622    parallel soong build which will result in lock timeout.
623    """
624    cls.run_atest_command(
625        'hello_world_test --dry-run -cit',
626        atest_integration_test.StepInput(
627            os.environ, os.environ['ANDROID_BUILD_TOP'], cls.get_config(), {}
628        ),
629        include_device_serial=False,
630        print_output=False,
631    ).check_returncode()
632
633  def _assert_equivalent_cmds(
634      self,
635      atest_cmd: str,
636      actual_cmd: str,
637      expected_cmd: str,
638  ) -> None:
639    """Assert that the expected command is equivalent to the actual command.
640
641    Non-essential arguments such as log directory and serial will be ignored.
642
643    Args:
644        atest_cmd: The atest command string that is being tested.
645        actual_cmd: The actual atest internal runner command string.
646        expected_cmd: The expected atest internal runner command string.
647
648    Returns:
649    """
650    actual_cmd = atest_integration_test.sanitize_runner_command(actual_cmd)
651    expected_cmd = atest_integration_test.sanitize_runner_command(expected_cmd)
652
653    self.assertEqual(
654        set(actual_cmd.split()),
655        set(expected_cmd.split()),
656        'Unexpected atest internal runner command generated for the'
657        ' atest command `%s`.\nActual:\n`%s`\nExpected:\n`%s`'
658        % (atest_cmd, actual_cmd, expected_cmd),
659    )
660
661  def _verify_atest_internal_runner_command(
662      self,
663      atest_cmd: str,
664      assertion_func: Callable[str, None],
665      **assertion_func_params: dict[str, Any],
666  ) -> None:
667    """Verifies atest's runner command using the provided assertion function.
668
669    Args:
670        atest_cmd: The atest command to execute. Note: Do not add the atest
671          binary to the beginning of the command.
672        assertion_func: A function that takes a test command string and an atest
673          internal command string and runs assertions on it.
674        **assertion_func_params: Parameters for the assertion function.
675    """
676    script = self.create_atest_script()
677
678    def build_step(
679        step_in: atest_integration_test.StepInput,
680    ) -> atest_integration_test.StepOutput:
681      result = self.run_atest_command(
682          atest_cmd + ' --dry-run -cit', step_in, include_device_serial=False
683      )
684      result.check_returncode()
685      runner_cmd = result.get_atest_log_values_from_prefix(
686          atest_integration_test.DRY_RUN_COMMAND_LOG_PREFIX
687      )[0]
688
689      step_out = self.create_step_output()
690      step_out.set_snapshot_include_paths([])
691      step_out.add_snapshot_obj('runner_cmd', runner_cmd)
692      return step_out
693
694    def test_step(step_in: atest_integration_test.StepInput) -> None:
695      runner_cmd = step_in.get_obj('runner_cmd')
696      assertion_func(atest_cmd, runner_cmd, **assertion_func_params)
697
698    script.add_build_step(build_step)
699    script.add_test_step(test_step)
700    script.run()
701
702
703if __name__ == '__main__':
704  atest_integration_test.main()
705