• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3# Copyright 2025 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
18import logging
19import os
20import subprocess
21import unittest
22
23_DEFAULT_COMMAND_TIMEOUT = 300
24_LAUNCHER_PATH = "/system_ext/bin/avf_early_vm_test_launcher"
25_RIALTO_PATH = "/system_ext/etc/avf/rialto_test.bin"
26
27def _RunCommand(cmd, timeout=_DEFAULT_COMMAND_TIMEOUT):
28    with subprocess.Popen(args=cmd,
29                          stderr=subprocess.PIPE,
30                          stdout=subprocess.PIPE,
31                          universal_newlines=True) as proc:
32        try:
33            out, err = proc.communicate(timeout=timeout)
34            returncode = proc.returncode
35        except subprocess.TimeoutExpired:
36            proc.kill()
37            out, err = proc.communicate()
38            returncode = proc.returncode
39
40    return out, err, returncode
41
42class AvfEarlyVmTest(unittest.TestCase):
43    def setUp(self):
44        self._serial_number = os.environ.get("ANDROID_SERIAL")
45        self.assertTrue(self._serial_number, "$ANDROID_SERIAL is empty.")
46
47    def _TestAvfEarlyVm(self, protected):
48        adb_cmd = ["adb", "-s", self._serial_number, "shell", _LAUNCHER_PATH, "--kernel",
49                   _RIALTO_PATH]
50        if protected:
51            adb_cmd.append("--protected")
52
53        _, err, returncode = _RunCommand(adb_cmd)
54        self.assertEqual(returncode, 0, f"{adb_cmd} failed: {err}")
55
56    def testAvfEarlyVmNonProtected(self):
57        self._TestAvfEarlyVm(False)
58
59    def testAvfEarlyVmProtected(self):
60        self._TestAvfEarlyVm(True)
61
62if __name__ == "__main__":
63    # Setting verbosity is required to generate output that the TradeFed test
64    # runner can parse.
65    unittest.main(verbosity=3)
66