• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright (C) 2017 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17import logging
18import os
19import subprocess
20
21from vts.runners.host import asserts
22from vts.runners.host import base_test
23from vts.runners.host import keys
24from vts.runners.host import test_runner
25from vts.utils.python.common import cmd_utils
26
27
28class HostBinaryTest(base_test.BaseTestClass):
29    """Base class to run a host-side, native binary test.
30
31    Note that a host-side binary test is not highly recommended because
32    such can be written in Python. Currently, this is used only for legacy
33    host-side native tests. And all new host-side native tests should be
34    written in Python or Java.
35    """
36
37    def setUpClass(self):
38        """Retrieves the required param."""
39        required_params = [keys.ConfigKeys.IKEY_BINARY_TEST_SOURCE]
40        self.getUserParams(req_param_names=required_params)
41
42    def testHostBinary(self):
43        """Tests host-side binaries."""
44        android_build_top = os.getenv("ANDROID_BUILD_TOP", "")
45        asserts.assertTrue(
46            android_build_top,
47            "$ANDROID_BUILD_TOP is not set. Please run lunch <build target>")
48
49        for binary_test_source in self.binary_test_source:
50            binary_test_source = str(binary_test_source)
51            binary_path = os.path.join(android_build_top, binary_test_source)
52
53            cmd_result = cmd_utils.ExecuteShellCommand(binary_path)
54            asserts.assertFalse(
55                any(cmd_result[cmd_utils.EXIT_CODE]),
56                "Test failed with the following results:\n "
57                "command result: %s" % cmd_result)
58
59
60if __name__ == "__main__":
61    test_runner.main()
62