+top_dir = os.getcwd()
+
+
+def ex(*cmd):
+ try:
+ cmd_str = ' '.join(cmd)
+ print >> sys.stderr, cmd_str
+ rc = subprocess.call(cmd)
+ if rc < 0:
+ print >> sys.stderr, 'terminated by signal', - rc
+ sys.exit(1)
+ elif rc > 0:
+ print >> sys.stderr, 'returned exit status', rc
+ sys.exit(1)
+ except OSError, e:
+ print >> sys.stderr, 'subprocess call failed:', e
+ sys.exit(1)
+
+
+def setup_testfs():
+ # Set up testfs with user_xattr, etc.
+ subprocess.call(['umount', 'testfs'])
+ ex('dd', 'if=/dev/zero', 'of=testfs.img', 'bs=1M', 'count=32')
+ ex('mke2fs', '-F', '-j', '-m', '0', 'testfs.img')
+ ex('rm', '-rf', 'testfs')
+ os.mkdir('testfs')
+ ex('mount', '-o', 'loop,acl,user_xattr', 'testfs.img', 'testfs')
+ # Hide, so that tests can't create risks.
+ ex('chown', 'root:root', 'testfs')
+ os.chmod('testfs', 0700)
+
+
+def cleanup_testfs():
+ subprocess.call(['umount', 'testfs'])
+ subprocess.call(['rm', '-f', 'testfs.img'])
+
+