Home | History | Annotate | Download | only in platform_TempFS
      1 #!/usr/bin/python
      2 #
      3 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 
      7 __author__ = 'kdlucas (at] chromium.org (Kelly Lucas)'
      8 
      9 import logging, os
     10 
     11 from autotest_lib.client.bin import test, utils
     12 from autotest_lib.client.common_lib import error
     13 
     14 
     15 class platform_TempFS(test.test):
     16     """
     17     Test temp file systems.
     18     """
     19     version = 1
     20 
     21     def run_once(self):
     22         errors = 0
     23         # The minimum available space we expect on temp filesystems.
     24         # TempFS allows 1/2 of Total Memory for each temp fs. Our threshold
     25         # allows for 50% usage of space allocated before this test is run.
     26 
     27         threshold = utils.memtotal()/4
     28         tempdirs = ['/dev', '/tmp', '/dev/shm', '/var/tmp', '/var/run',
     29                     '/var/lock']
     30 
     31         for dir in tempdirs:
     32             if os.path.isdir(dir):
     33                 # utils.freespace is in bytes, so convert to kb.
     34                 avail = utils.freespace(dir)/1024
     35                 if avail < threshold:
     36                     logging.error('Not enough available space on %s', dir)
     37                     logging.error('%d bytes is minimum, found %d bytes',
     38                                   (threshold, avail))
     39                     errors += 1
     40             else:
     41                 logging.error('%s does not exist!' % dir)
     42                 errors += 1
     43 
     44         if errors:
     45             raise error.TestFail('There were %d temp directory errors' % errors)
     46