• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3.4
2#
3# Copyright (C) 2017 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
19
20from vts.runners.host import asserts
21from vts.runners.host import base_test
22from vts.runners.host import const
23from vts.runners.host import test_runner
24from vts.utils.python.android import api
25
26
27class VtsTreblePlatformVersionTest(base_test.BaseTestClass):
28    """VTS should run on devices launched with O or later."""
29
30    def setUpClass(self):
31        self.dut = self.android_devices[0]
32        self.dut.shell.InvokeTerminal("VtsTreblePlatformVersionTest")
33
34    def getProp(self, prop, required=True):
35        """Helper to retrieve a property from device."""
36
37        results = self.dut.shell.Execute("getprop " + prop)
38        if required:
39            asserts.assertEqual(results[const.EXIT_CODE][0], 0,
40                "getprop must succeed")
41            asserts.assertTrue(len(results[const.STDOUT][0].strip()) > 0,
42                "getprop must return a value")
43        else:
44            if (results[const.EXIT_CODE][0] != 0 or
45                len(results[const.STDOUT][0].strip()) == 0):
46                logging.info("sysprop %s undefined", prop)
47                return None
48
49        result = results[const.STDOUT][0].strip()
50
51        logging.info("getprop {}={}".format(prop, result))
52
53        return result
54
55    def getEnv(self, env):
56        """Helper to retrieve an environment varable from device."""
57
58        results = self.dut.shell.Execute("printenv " + env)
59        if (results[const.EXIT_CODE][0] != 0 or
60            len(results[const.STDOUT][0].strip()) == 0):
61            logging.info("environment variable %s undefined", env)
62            return None
63
64        result = results[const.STDOUT][0].strip()
65
66        logging.info("printenv {}:{}".format(env, result))
67
68        return result
69
70    def testFirstApiLevel(self):
71        """Test that device launched with O or later."""
72        firstApiLevel = self.dut.getLaunchApiLevel()
73        asserts.assertTrue(firstApiLevel >= api.PLATFORM_API_LEVEL_O,
74            "VTS can only be run for new launches in O or above")
75
76    def testTrebleEnabled(self):
77        """Test that device has Treble enabled."""
78        trebleIsEnabledStr = self.getProp("ro.treble.enabled")
79        asserts.assertEqual(trebleIsEnabledStr, "true",
80            "VTS can only be run for Treble enabled devices")
81
82    def testSdkVersion(self):
83        """Test that SDK version >= O (26)."""
84        try:
85            sdkVersion = int(self.getProp("ro.build.version.sdk"))
86            asserts.assertTrue(sdkVersion >= api.PLATFORM_API_LEVEL_O,
87                "VTS is for devices launching in O or above")
88        except ValueError as e:
89            asserts.fail("Unexpected value returned from getprop: %s" % e)
90
91    def testVndkVersion(self):
92        """Test that VNDK version is specified.
93
94        If ro.vndk.version is not defined on boot, GSI sets LD_CONFIG_FILE to
95        temporary configuration file and ro.vndk.version to default value.
96        """
97
98        vndkVersion = self.getProp("ro.vndk.version")
99        if vndkVersion is None:
100            asserts.fail("VNDK version is not defined")
101
102        firstApiLevel = self.dut.getLaunchApiLevel()
103        if firstApiLevel > api.PLATFORM_API_LEVEL_O_MR1:
104            vndkLite = self.getProp("ro.vndk.lite", False)
105            if vndkLite is not None:
106                asserts.fail("ro.vndk.lite is defined as %s" % vndkLite)
107            envLdConfigFile = self.getEnv("LD_CONFIG_FILE")
108            if envLdConfigFile is not None:
109                asserts.fail("LD_CONFIG_FILE is defined as %s" % envLdConfigFile)
110
111if __name__ == "__main__":
112    test_runner.main()
113