def test_3_read(self):
     print "Test 3a - read:"
     data = 'K' * 276177  # see description above
     v, result = hw3.read("/dir1/file.270", len(data) + 100, 0)  # offset=0
     self.assertTrue(v == len(data))
     self.assertTrue(result == data)
     print "Test 3b - read in small pieces:"
     result = ""
     i = 0
     while i < 276177:
         v, temp = hw3.read("/dir1/file.270", 1024, i)
         i += 1024
         result += temp
     self.assertTrue(result == data)
Esempio n. 2
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_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()
Esempio n. 4
0
 def test_43_read(self):
     data = 'K' * 276177  # see description above
     v1, data1 = hw3.read("/dir2/file.4k+", 1000, 0)  # offset = 0
     self.assertEqual(v1, 1000)
     self.assertEqual(len(data1), 1000)
     v2, data2 = hw3.read("/dir2/file.4k+", 17, 1000)  # offset = 0
     self.assertEqual(v2, 17)
     self.assertEqual(len(data2), 17)
     v3, data3 = hw3.read("/dir2/file.4k+", 100, 1017)  # offset = 0
     self.assertEqual(v3, 100)
     self.assertEqual(len(data3), 100)
     v4, data4 = hw3.read("/dir2/file.4k+", 1000, 1117)  # offset = 0
     self.assertEqual(v4, 1000)
     self.assertEqual(len(data4), 1000)
     v5, data5 = hw3.read("/dir2/file.4k+", 1024, 2117)  # offset = 0
     self.assertEqual(v5, 1024)
     self.assertEqual(len(data5), 1024)
     v6, data6 = hw3.read("/dir2/file.4k+", 1970, 3141)  # offset = 0
     self.assertEqual(v6, 957)
     self.assertEqual(len(data6), 957)
     v7, data7 = hw3.read("/dir2/file.4k+", 3000, 5111)  # offset = 0
     self.assertEqual(v7, 0)
     self.assertEqual(len(data7), 0)
     total_data = data1 + data2 + data3 + data4 + data5 + data6 + data7
     v_total = v1 + v2 + v3 + v4 + v5 + v6 + v7
     self.assertEqual(v_total, 4098)
     self.assertEqual(len(total_data), 4098)
     self.assertEqual(cksum(total_data), 799580753)
Esempio n. 5
0
 def test_8_read(self):
     # print('Test 8 - Multiple smaller reads')
     data = 'K' * 10
     table = [17, 100, 1000, 1024, 1970, 3000]
     for data_length in table:
         data += 'K' * data_length
         v, result = hw3.read("/dir1/file.270", len(data), data_length)
         self.assertEqual(v, (len(data)))
         self.assertEqual(result, bytes(data, 'utf-8'))
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
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'))
Esempio n. 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")
Esempio n. 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)
Esempio n. 11
0
 def test_42_read(self):
     data = 'K' * 276177  # see description above
     v, data = hw3.read("/file.1k", 1000, 1000)  # offset = 0
     self.assertEqual(v, 0)
Esempio n. 12
0
 def test_41_read(self):
     data = 'K' * 276177  # see description above
     v, data = hw3.read("/dir3/file.10", 15000, 0)  # offset = 0
     self.assertEqual(v, -hw3.ENOENT)
Esempio n. 13
0
 def test_40_read(self):
     data = 'K' * 276177  # see description above
     v, data = hw3.read("/dir3", 15000, 0)  # offset = 0
     self.assertEqual(v, -hw3.EISDIR)
Esempio n. 14
0
 def test_39_read(self):
     data = 'K' * 276177  # see description above
     v, data = hw3.read("/dir3/file.12k-", 15000, 0)  # offset = 0
     self.assertEqual(v, 12287)
     self.assertEqual(len(data), 12287)
     self.assertEqual(cksum(data), 2954788945)
Esempio n. 15
0
 def test_38_read(self):
     data = 'K' * 276177  # see description above
     v, data = hw3.read("/file.1k", 10000, 0)  # offset = 0
     self.assertEqual(v, 1000)
     self.assertEqual(len(data), 1000)
     self.assertEqual(cksum(data), 1786485602)
Esempio n. 16
0
 def test_7_read(self):
     # print('Test 7 - big data read')
     data = bytes('K' * 276177, 'utf-8')
     v, result = hw3.read("/dir1/file.270", len(data) + 100, 0)  # offset=0
     self.assertEqual(v, len(data))
     self.assertEqual(result, data)
Esempio n. 17
0
 def test_dir_read(self):
     v, data = hw3.read("/dir1", 0, 0)
     self.assertEqual(v, -hw3.EISDIR)
Esempio n. 18
0
 def test_unlink_big(self):
     v = hw3.unlink('/dir1/file.270')
     self.assertEqual(v, 0)
     v, data = hw3.read("/dir1/file.270", 1000, 0)
     self.assertEqual(v, -hw3.ENOENT)