1# Copyright (c) 2010 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 5""" 6This testcase exercises the file system by ensuring we can create a sufficient 7number of files into one directory. In this case we will create 150,000 files on 8the stateful partition and 2,000 files on the /tmp partition. 9""" 10 11__author__ = ['kdlucas@chromium.org (Kelly Lucas)', 12 'dalecurtis@chromium.org (Dale Curtis)'] 13 14import os 15import shutil 16 17from autotest_lib.client.bin import test 18from autotest_lib.client.common_lib import error 19 20 21class platform_FileNum(test.test): 22 """Test file number limitations per directory.""" 23 version = 1 24 25 _TEST_PLAN = [ 26 {'dir': '/mnt/stateful_partition', 'count': 150000}, 27 {'dir': '/tmp', 'count': 2000}] 28 29 _TEST_TEXT = 'ChromeOS rocks with fast response and low maintenance costs!' 30 31 def create_files(self, target_dir, count): 32 """Create the number of files specified by count in target_dir. 33 34 Args: 35 target_dir: Directory to create files in. 36 count: Number of files to create. 37 Returns: 38 Number of files created. 39 """ 40 create_dir = os.path.join(target_dir, 'createdir') 41 try: 42 if os.path.exists(create_dir): 43 shutil.rmtree(create_dir) 44 45 os.makedirs(create_dir) 46 47 for i in range(count): 48 f = open(os.path.join(create_dir, '%d.txt' % i), 'w') 49 f.write(self._TEST_TEXT) 50 f.close() 51 52 total_created = len(os.listdir(create_dir)) 53 finally: 54 shutil.rmtree(create_dir) 55 56 return total_created 57 58 def run_once(self): 59 for item in self._TEST_PLAN: 60 actual_count = self.create_files(item['dir'], item['count']) 61 if actual_count != item['count']: 62 raise error.TestFail( 63 'File creation count in %s is incorrect! Found %d files ' 64 'when there should have been %d!' 65 % (item['dir'], actual_count, item['count'])) 66