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.controllers import android_device 25 26ANDROID_O_API_VERSION = 26 27 28class VtsTreblePlatformVersionTest(base_test.BaseTestClass): 29 """VTS should run on devices launched with O or later.""" 30 31 def setUpClass(self): 32 self.dut = self.registerController(android_device)[0] 33 self.dut.shell.InvokeTerminal("VtsTreblePlatformVersionTest") 34 35 def getProp(self, prop, required=True): 36 """Helper to retrieve a property from device.""" 37 38 results = self.dut.shell.VtsTreblePlatformVersionTest.Execute( 39 "getprop " + prop) 40 if required: 41 asserts.assertEqual(results[const.EXIT_CODE][0], 0, 42 "getprop must succeed") 43 else: 44 if results[const.EXIT_CODE][0] != 0: 45 logging.info("sysprop %s undefined", prop) 46 return None 47 48 result = results[const.STDOUT][0].strip() 49 50 logging.info("getprop {}={}".format(prop, result)) 51 52 return result 53 54 def testFirstApiLevel(self): 55 """Test that device launched with O or later.""" 56 try: 57 firstApiLevel = self.getProp("ro.product.first_api_level", 58 required=False) 59 if firstApiLevel is None: 60 asserts.skip("ro.product.first_api_level undefined") 61 firstApiLevel = int(firstApiLevel) 62 asserts.assertTrue(firstApiLevel >= ANDROID_O_API_VERSION, 63 "VTS can only be run for new launches in O or above") 64 except ValueError: 65 asserts.fail("Unexpected value returned from getprop") 66 67 def testTrebleEnabled(self): 68 """Test that device has Treble enabled.""" 69 trebleIsEnabledStr = self.getProp("ro.treble.enabled") 70 asserts.assertEqual(trebleIsEnabledStr, "true", 71 "VTS can only be run for Treble enabled devices") 72 73 def testSdkVersion(self): 74 """Test that SDK version >= O (26).""" 75 try: 76 sdkVersion = int(self.getProp("ro.build.version.sdk")) 77 asserts.assertTrue(sdkVersion >= ANDROID_O_API_VERSION, 78 "VTS is for devices launching in O or above") 79 except ValueError: 80 asserts.fail("Unexpected value returned from getprop") 81 82 def testVndkVersion(self): 83 """Test that VNDK version is specified.""" 84 vndkVersion = self.getProp("ro.vendor.vndk.version") 85 asserts.assertLess(0, len(vndkVersion), 86 "VNDK version is not defined") 87 88if __name__ == "__main__": 89 test_runner.main() 90