Skip to content

Commit

Permalink
Merge pull request avocado-framework-tests#1504 from harish-24/fsx_thp
Browse files Browse the repository at this point in the history
Add option to run fsx test with THP mount
  • Loading branch information
PraveenPenguin authored Jan 6, 2020
2 parents a0be5ea + b93a68c commit 216261b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 51 additions & 1 deletion fs/fsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
import os
from avocado import Test
from avocado import main
from avocado.utils import process
from avocado.utils import process, genio
from avocado.utils.software_manager import SoftwareManager
from avocado.utils.partition import Partition


class Fsx(Test):
Expand All @@ -27,6 +28,39 @@ class Fsx(Test):
:avocado: tags=fs
'''

@staticmethod
def mount_point(mount_dir):
lines = genio.read_file('/proc/mounts').rstrip('\t\r\0').splitlines()
for substr in lines:
mop = substr.split(" ")[1]
if mop == mount_dir:
return True
return False

def check_thp(self):
if 'thp_file_alloc' in genio.read_file('/proc/vm'
'stat').rstrip('\t\r\n\0'):
self.thp = True
return self.thp

def setup_tmpfs_dir(self):
# check for THP page cache
self.check_thp()

if not os.path.isdir(self.mount_dir):
os.makedirs(self.mount_dir)

self.device = None
if not self.mount_point(self.mount_dir):
if self.thp:
self.device = Partition(
device="none", mountpoint=self.mount_dir,
mount_options="huge=always")
else:
self.device = Partition(
device="none", mountpoint=self.mount_dir)
self.device.mount(mountpoint=self.mount_dir, fstype="tmpfs")

def setUp(self):
'''
Setup fsx
Expand All @@ -41,6 +75,7 @@ def setUp(self):
'master/testcases/kernel/fs/fsx-linux/fsx-linux.c', expire='7d')
os.chdir(self.workdir)
process.system('gcc -o fsx %s' % fsx, shell=True, ignore_status=True)
self.thp = False

def test(self):
'''
Expand All @@ -50,6 +85,17 @@ def test(self):
op_ub = self.params.get('op_ub', default='1000000')
output = self.params.get('output_file', default='/tmp/result')
num_times = self.params.get('num_times', default='10000')
self.mount_dir = self.params.get('tmpfs_mount_dir', default=None)
thp_page_cache = self.params.get('thp_page_cache', default=None)

if thp_page_cache:
if self.mount_dir:
self.setup_tmpfs_dir()
output = os.path.join(self.mount_dir, 'result')
else:
self.cancel("tmpfs_mount_dir not specified")
else:
output = self.params.get('output_file', default='/tmp/result')

results = process.system_output(
'./fsx -l %s -o %s -n -s 1 -N %s -d %s'
Expand All @@ -58,6 +104,10 @@ def test(self):
if b'All operations completed' not in results.splitlines()[-1]:
self.fail('Fsx test failed')

def tearDown(self):
if self.mount_dir:
self.device.unmount()


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions fs/fsx.py.data/fsx-mm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
thp_page_cache: True
tmpfs_mount_dir: '/mnt/tmpfs/'

0 comments on commit 216261b

Please sign in to comment.