Example #1
0
 def test_4_write(self):
     # print('Test 4 - Write test - write a big block')
     data = b'B' * 6644
     hw3.write("/file.7", data, 0)  # offset=0
     v, result = hw3.read("/file.7", len(data), 0)
     self.assertEqual(v, (len(data)))
     self.assertEqual(result, data),
 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()
Example #3
0
    def test_5_write(self):
        # print('Test 5 - Write test - write multiple smaller blocks')
        data = 'M' * 10
        table = [100, 1000, 1024, 3000]
        b_count = 10
        for data_length in table:
            data += 'M' * data_length
            b_count += data_length
            hw3.write("/file.7", bytes(data, 'utf-8'), 0)
        v, result = hw3.read("/file.7", 10000, 0)
        self.assertEqual(v, 6644)

        num_4 = 6644 - len(data)
        expected = data + ("4" * num_4)
        self.assertEqual(result, bytes(expected, 'utf-8'))
Example #4
0
    def test_write_err(self):
        errs = [("/dir1", 0, hw3.EISDIR),
                ("/bogus", 0, hw3.ENOENT),
                ("/file.A", 1001, hw3.EINVAL)]

        for name, off, err in errs:
            v = hw3.write(name, "Hello", off)
            self.assertEqual(v, -err)
 def test_6_write(self):
     print "Test 6a - write:"
     data = 'K' * 289150
     v = hw3.write("/dir1/file.A", data, 0)  # offset=0
     self.assertTrue(v == len(data))
     v, result = hw3.read("/dir1/file.A", len(data) + 100, 0)  # offset=0
     self.assertTrue(v == len(data))
     self.assertTrue(result == data)
     print "Test 6b - write in small pieces:"
     data = "B" * 1000
     i = 0
     while i < 280:
         v = hw3.write("/dir1/file.A", data, i * 1000)
         i += 1
     v, result = hw3.read("/dir1/file.A", 280000, 0)
     self.assertTrue(result == "B" * 280000)
     self.fsck()
    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()
Example #7
0
    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)
Example #8
0
    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)
Example #9
0
    def test_2_mkdir_deep(self):
        num = 250  # Could go deeper, but it takes O(n^2) (if not more) time

        for i in range(1, num + 1):
            pathname = "/a" * i

            v = hw3.mkdir(pathname, 0)
            self.assertEqual(v, 0)

        v = hw3.create("/a" * num + "/deep.txt", 0)
        self.assertEqual(v, 0)

        v = hw3.write("/a" * num + "/deep.txt", b"This is deep stuff", 0)
        self.assertEqual(v, 18)

        v, b = hw3.read("/a" * num + "/deep.txt", 1000, 0)
        self.assertEqual(v, 18)
        self.assertEqual(b, b"This is deep stuff")
Example #10
0
    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)