def test_stress_write_unlink(self): v, res = hw3.statfs() self.assertEqual(v, 0) blocks_free = res.f_bavail sizes = [12, 577, 1011, 1024, 1025, 2001, 8099, 37000, 289150, 1024 * 1024] writes = [17, 100, 1000, 1024, 1970] cases = [(size, write, "/%s-%s" % (size, write)) for size in sizes for write in writes] bigdata = b'123456789' * 33333333 for size, write, name in cases: towrite = bigdata[0:size] v = hw3.create(name, 0) self.assertEqual(v, 0) idx = 0 while idx < size: maxwrite = min(size, idx + write) data = towrite[idx:maxwrite] v = hw3.write(name, data, idx) self.assertEqual(v, len(data)) idx += write v, data = hw3.read(name, size + 10000, 0) self.assertEqual(v, size) self.assertEqual(len(data), size) self.assertEqual(data, towrite, name) # Truncate before the unlink roughly half of the time if size % 2 == 0: v = hw3.truncate(name, 0) self.assertEqual(v, 0) v, attr = hw3.getattr(name) self.assertEqual(v, 0) self.assertEqual(attr.st_size, 0) v = hw3.unlink(name) self.assertEqual(v, 0) v, attr = hw3.getattr(name) self.assertEqual(v, -hw3.ENOENT) v, stat = hw3.statfs() self.assertEqual(v, 0) self.assertEqual(stat.f_bavail, blocks_free)
def test_7_truncate(self): print "Test 7 - truncate:" v, sfs = hw3.statfs() f_bfree = sfs.f_bfree hw3.create('/to_be_truncate', 0o100777) hw3.write('/to_be_truncate', 10000 * 'K', 0) v = hw3.truncate("/to_be_truncate", 0) self.assertTrue(v == 0) v, sb = hw3.getattr("/to_be_truncate") self.assertTrue(v == 0) self.assertTrue(sb.st_size == 0) v, sfs = hw3.statfs() self.assertTrue(sfs.f_bfree == f_bfree) self.fsck()
def test_1_statfs(self): v, sfs = hw3.statfs() self.assertTrue(v == 0) self.assertTrue(sfs.f_bsize == 4096) # defined in fs5600.h self.assertTrue( sfs.f_blocks == 398) # test.img - 400 blocks - super - bitmap self.assertTrue(sfs.f_bfree == 355) # test.img self.assertTrue(sfs.f_namemax == 27) # again from FS definition
def test_1_statfs(self): print "Test 1 - statfs:" v, sfs = hw3.statfs() self.assertTrue(v == 0) self.assertTrue(sfs.f_bsize == 1024) self.assertTrue(sfs.f_blocks == 1024) self.assertTrue(sfs.f_bfree == 731) self.assertTrue(sfs.f_namemax == 27)
def test_1_statfs(self): # print('Test 1 - statfs:') v, sfs = hw3.statfs() self.assertEqual(v, 0) self.assertEqual(sfs.f_bsize, 1024) # any fsx600 file system self.assertEqual(sfs.f_blocks, 1024) # only if image size = 1MB self.assertEqual(sfs.f_bfree, 720) # for un-modified mktest output (with -extra) self.assertEqual(sfs.f_namemax, 27) # any fsx600 file system
def test_complex_rmdir(self): v, stat = hw3.statfs() self.assertEqual(v, 0) free = stat.f_bfree self.assertTrue(free >= 900) actions = [ (hw3.mkdir("/test8", 0o777), 0), (hw3.mkdir("/test8/dir1", 0o777), 0), (hw3.mkdir("/test8/dir2", 0o777), 0), (hw3.mkdir("/test8/dir3", 0o777), 0), (hw3.mkdir("/test8/dir1/a", 0o777), 0), (hw3.mkdir("/test8/dir1/b", 0o777), 0), (hw3.create("/test8/dir2/c", 0o777), 0), (hw3.create("/test8/dir2/d", 0o777), 0), (hw3.rmdir("/test8/dir2/c"), -20), (hw3.rmdir("/test8/dir2"), -39), (hw3.rmdir("/test8/dir1"), -39), (hw3.unlink("/test8/dir3"), -21), (hw3.unlink("/test8/dir1/a"), -21), (hw3.rmdir("/test8/dir3"), 0), (hw3.rmdir("/test8/dir1/a"), 0), (hw3.rmdir("/test8/dir1/b"), 0), (hw3.unlink("/test8/dir2/c/foo"), -20), (hw3.unlink("/test8/dir1/q/foo"), -2), (hw3.rmdir("/test8/dir2/c/foo"), -20), (hw3.rmdir("/test8/dir1/q/foo"), -2), (hw3.unlink("/test8/dir1/q"), -2), (hw3.rmdir("/test8/dir1/q"), -2), (hw3.unlink("/test8/dir2/c"), 0), (hw3.unlink("/test8/dir2/d"), 0), (hw3.rmdir("/test8/dir2"), 0), (hw3.rmdir("/test8/dir1"), 0), (hw3.rmdir("/test8"), 0) ] actions = [(i, actions[i][0], actions[i][1]) for i in range(len(actions))] for i, result, expected in actions: self.assertEqual(result, expected, str(i) + ": " + hw3.strerr(result)) v, stat = hw3.statfs() self.assertEqual(v, 0) self.assertEqual(free, stat.f_bfree)
def test_stress_write_truncate(self): v, res = hw3.statfs() self.assertEqual(v, 0) blocks_free = res.f_bfree sizes = [12, 577, 1011, 1024, 1025, 2001, 8099, 37000, 289150, 1024 * 1024] cases = [(size, "/%s" % (size)) for size in sizes] bigdata = b'123456789' * 33333333 for size, name in cases: towrite = bigdata[0:size] v = hw3.create(name, 0) self.assertEqual(v, 0) v = hw3.write(name, towrite, 0) self.assertEqual(v, size) v, data = hw3.read(name, size + 10000, 0) self.assertEqual(v, size) self.assertEqual(len(data), size) self.assertEqual(data, towrite, name) # Truncate before the unlink roughly half of the time v = hw3.truncate(name, 0) self.assertEqual(v, 0) v, attr = hw3.getattr(name) self.assertEqual(v, 0) self.assertEqual(attr.st_size, 0) v = hw3.unlink(name) self.assertEqual(v, 0) v, attr = hw3.getattr(name) self.assertEqual(v, -hw3.ENOENT) v, stat = hw3.statfs() self.assertEqual(v, 0) self.assertEqual(stat.f_bfree, blocks_free)
def test_8_unlink(self): print "Test 8a - unlink:" v, sfs = hw3.statfs() f_bfree = sfs.f_bfree path = 'to_be_delete' hw3.create(path, 0o100777) hw3.write(path, 10000 * 'K', 0) v = hw3.unlink(path) self.assertTrue(v == 0) v, sb = hw3.getattr(path) self.assertTrue(v == -hw3.ENOENT) v, sfs = hw3.statfs() self.assertTrue(sfs.f_bfree == f_bfree) print "Test 8b - cannot unlink a directory:" v = hw3.unlink('dir1/dir2') self.assertTrue(v == -hw3.EISDIR) self.fsck()