def test_rmdir_inval(self): v = hw3.rmdir("/dir1") self.assertEqual(v, -hw3.ENOTEMPTY) v = hw3.rmdir("/dir2") self.assertEqual(v, -hw3.ENOENT) hw3.unlink("/dir1/file.2") hw3.unlink("/dir1/file.0") hw3.unlink("/dir1/file.270") v = hw3.unlink("/dir1") self.assertEqual(v, -hw3.EISDIR) v = hw3.rmdir("/dir1") self.assertEqual(v, 0)
def test_9_rmdir(self): print "Test 9a - rmdir:" v = hw3.rmdir('dir1/dir2') v, sb = hw3.getattr('dir1/dir2') self.assertTrue(v == -hw3.ENOENT) print "Test 9b - cannot rmdir a file:" v = hw3.rmdir('dir1/file.A') self.assertTrue(v == -hw3.ENOTDIR) print "Test 9c - cannot rmdir a non-empty directory:" v = hw3.rmdir('dir1') self.assertTrue(v == -hw3.ENOTEMPTY) v = hw3.unlink('dir1/file.A') v = hw3.rmdir('dir1') self.assertTrue(v == 0) self.fsck()
def test_rmdir_valid(self): hw3.mkdir("/hello", 0) v, attr = hw3.getattr("/hello") self.assertEqual(v, 0) v = hw3.rmdir("/hello") self.assertEqual(v, 0) v, attr = hw3.getattr("/hello") self.assertEqual(v, -hw3.ENOENT) v, dirs = hw3.readdir("/hello") self.assertEqual(v, -hw3.ENOENT)
def test_create_write_concurrent(self): self.assertEqual(hw3.create("/", 0), -hw3.EEXIST) big_file = 512 * 1024 self.assertEqual(hw3.mkdir("/dir2", 0), 0) self.assertEqual(hw3.create("/dir2/.file", 0), 0) self.assertEqual(hw3.write("/dir2/.file", bytes("Hello, world", 'utf-8'), 0), 12) self.assertEqual(hw3.create("/dir2/file.2", 0), 0) self.assertEqual(hw3.write("/dir2/file.2", b'M' * big_file, 0), big_file) self.assertEqual(hw3.create("/dir2/.file", 0), -hw3.EEXIST) self.run_fsck() v, data = hw3.read("/dir2/.file", 1000, 7) self.assertEqual(v, 5) self.assertEqual(data.decode('utf-8'), "world") self.run_fsck() v, data = hw3.read("/dir2/file.2", big_file, 0) self.assertEqual(v, big_file) self.assertEqual(data, b'M' * big_file) self.run_fsck() self.assertEqual(hw3.unlink("/dir2/file.2"), 0) self.run_fsck() self.assertEqual(hw3.unlink("/dir2/.file"), 0) self.run_fsck() v, data = hw3.readdir("/dir2") self.assertEqual(v, 0) self.assertEqual(data, []) self.run_fsck() self.assertEqual(hw3.rmdir("/dir2"), 0)
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)