• 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
18from vts.runners.host import const
19from vts.testcases.kernel.api.proc import KernelProcFileTestBase
20from vts.testcases.kernel.api.proc.KernelProcFileTestBase import repeat_rule, literal_token
21
22
23class ProcMountsTest(KernelProcFileTestBase.KernelProcFileTestBase):
24    '''/proc/self/mounts lists the mounted filesystems.
25
26    /proc/mounts must symlink to this file.'''
27
28    def parse_contents(self, contents):
29        if len(contents) == 0 or contents[-1] != '\n':
30            raise SyntaxError('Missing final newline')
31        result = []
32        for line in contents.split('\n')[:-1]:
33            parsed = line.split(' ')
34            parsed[3] = parsed[3].split(',')
35            result.append(parsed)
36        return result
37
38    def result_correct(self, parse_results):
39        for line in parse_results:
40            if len(line[3]) < 1 or line[3][0] not in {'rw', 'ro'}:
41                logging.error("First attribute must be rw or ro")
42                return False
43            if line[4] != '0' or line[5] != '0':
44                logging.error("Last 2 columns must be 0")
45                return False
46        return True
47
48    def prepare_test(self, shell):
49        # Follow the symlink
50        results = shell.Execute('readlink /proc/mounts')
51        if results[const.EXIT_CODE][0] != 0:
52            return False
53        return results[const.STDOUT][0] == 'self/mounts\n'
54
55    def get_path(self):
56        return "/proc/self/mounts"
57