1# Copyright 2016 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import common 6from autotest_lib.client.common_lib import error 7from autotest_lib.server import test 8 9 10class android_Invariants(test.test): 11 """Verify basic characteristics common to all Android devices.""" 12 version = 1 13 14 15 def assert_path_test(self, path, test, negative=False): 16 """Performs a test against a path. 17 18 See the man page for test(1) for valid tests (e.g. -e, -b, -d). 19 20 @param path: the path to check. 21 @param test: the test to perform, without leading dash. 22 @param negative: if True, test for the negative. 23 """ 24 self.host.run('test %s -%s %s' % ('!' if negative else '', test, path)) 25 26 27 def assert_selinux_context(self, path, ctx): 28 """Checks the selinux context of a path. 29 30 @param path: the path to check. 31 @param ctx: the selinux context to check for. 32 33 @raises error.TestFail 34 """ 35 # Example output of 'ls -LZ /dev/block/by-name/misc' is: 36 # u:object_r:misc_block_device:s0 /dev/block/by-name/misc 37 tokens = self.host.run_output('ls -LZ %s' % path).split() 38 path_ctx = tokens[0] 39 if not ctx in path_ctx: 40 raise error.TestFail('Context "%s" for path "%s" does not ' 41 'contain "%s"' % (path_ctx, path, ctx)) 42 43 44 def check_fstab_name(self): 45 """Checks that the fstab file has the name /fstab.<ro.hardware>. 46 """ 47 hardware = self.host.run_output('getprop ro.hardware') 48 self.assert_path_test('/fstab.%s' % hardware, 'e') 49 50 51 def run_once(self, host=None): 52 """Verify basic characteristics common to all Android devices. 53 54 @param host: host object representing the device under test. 55 """ 56 self.host = host 57 self.check_fstab_name() 58