filesystem: expand some msdos ptable tests to vtoc

This commit is contained in:
Dan Bungert 2022-07-14 18:15:50 -06:00
parent 832caeda55
commit 481400ce02
1 changed files with 51 additions and 34 deletions

View File

@ -692,53 +692,69 @@ class TestPartitionNumbering(unittest.TestCase):
for _ in range(8): for _ in range(8):
self.assert_next(make_partition(m, d1)) self.assert_next(make_partition(m, d1))
def test_msdos_all_primary(self): @parameterized.expand([
m, d1 = make_model_and_disk(ptable='msdos') ['msdos', 4],
for _ in range(4): ['vtoc', 3],
])
def test_all_primary(self, ptable, primaries):
m = make_model(storage_version=2)
d1 = make_disk(m, ptable=ptable)
for _ in range(primaries):
self.assert_next(make_partition(m, d1)) self.assert_next(make_partition(m, d1))
def test_msdos_one_primary(self): @parameterized.expand([
m, d1 = make_model_and_disk(ptable='msdos') ['msdos', 4],
self.assert_next(make_partition(m, d1)) ['vtoc', 3],
self.assert_next(make_partition(m, d1, flag='extended')) ])
self.cur_idx = 5 def test_primary_and_extended(self, ptable, primaries):
m = make_model(storage_version=2)
d1 = make_disk(m, ptable=ptable, size=100 << 20)
for _ in range(primaries - 1):
self.assert_next(make_partition(m, d1, size=5 << 20))
self.assert_next(make_partition(m, d1, flag='extended', size=80 << 20))
for _ in range(3): for _ in range(3):
self.assert_next(make_partition(m, d1, flag='logical')) self.assert_next(
make_partition(m, d1, flag='logical', size=10 << 20))
def test_msdos_three_primary(self): @parameterized.expand(
m, d1 = make_model_and_disk(ptable='msdos') [[pt, primaries, i]
for _ in range(3): for pt, primaries in (('msdos', 4), ('vtoc', 3))
self.assert_next(make_partition(m, d1)) for i in range(3)]
self.assert_next( )
make_partition(m, d1, flag='extended')) def test_delete_logical(self, ptable, primaries, idx_to_remove):
for _ in range(3): m = make_model(storage_version=2)
self.assert_next(make_partition(m, d1, flag='logical')) d1 = make_disk(m, ptable=ptable, size=100 << 20)
self.assert_next(make_partition(m, d1, size=10 << 20))
@parameterized.expand([[0], [1], [2]]) self.assert_next(make_partition(m, d1, size=80 << 20, flag='extended'))
def test_msdos_delete_logical(self, idx_to_remove): self.cur_idx = primaries + 1
m, d1 = make_model_and_disk(ptable='msdos') parts = [make_partition(m, d1, size=10 << 20, flag='logical')
self.assert_next(make_partition(m, d1)) for _ in range(3)]
self.assert_next(make_partition(m, d1, flag='extended'))
self.cur_idx = 5
parts = [make_partition(m, d1, flag='logical') for _ in range(3)]
for p in parts: for p in parts:
self.assert_next(p) self.assert_next(p)
to_remove = parts.pop(idx_to_remove) to_remove = parts.pop(idx_to_remove)
m.remove_partition(to_remove) m.remove_partition(to_remove)
self.cur_idx = 5 self.cur_idx = primaries + 1
for p in parts: for p in parts:
self.assert_next(p) self.assert_next(p)
def test_msdos_no_fifth_primary(self): @parameterized.expand([
m, d1 = make_model_and_disk(ptable='msdos') [1, 'msdos', 4],
for _ in range(4): [1, 'vtoc', 3],
self.assert_next(make_partition(m, d1)) [2, 'msdos', 4],
[2, 'vtoc', 3],
])
def test_no_extra_primary(self, sv, ptable, primaries):
m = make_model(storage_version=sv)
d1 = make_disk(m, ptable=ptable, size=100 << 30)
for _ in range(primaries):
self.assert_next(make_partition(m, d1, size=1 << 30))
with self.assertRaises(Exception): with self.assertRaises(Exception):
make_partition(m, d1) make_partition(m, d1)
def test_p1_preserved(self): @parameterized.expand([['gpt'], ['msdos'], ['vtoc']])
def test_p1_preserved(self, ptable):
m = make_model(storage_version=2) m = make_model(storage_version=2)
d1 = make_disk(m, ptable='gpt') d1 = make_disk(m, ptable=ptable)
p1 = make_partition(m, d1, preserve=True, number=1) p1 = make_partition(m, d1, preserve=True, number=1)
p2 = make_partition(m, d1) p2 = make_partition(m, d1)
p3 = make_partition(m, d1) p3 = make_partition(m, d1)
@ -749,9 +765,10 @@ class TestPartitionNumbering(unittest.TestCase):
self.assertEqual(3, p3.number) self.assertEqual(3, p3.number)
self.assertEqual(False, p3.preserve) self.assertEqual(False, p3.preserve)
def test_p2_preserved(self): @parameterized.expand([['gpt'], ['msdos'], ['vtoc']])
def test_p2_preserved(self, ptable):
m = make_model(storage_version=2) m = make_model(storage_version=2)
d1 = make_disk(m, ptable='gpt') d1 = make_disk(m, ptable=ptable)
p2 = make_partition(m, d1, preserve=True, number=2) p2 = make_partition(m, d1, preserve=True, number=2)
p1 = make_partition(m, d1) p1 = make_partition(m, d1)
p3 = make_partition(m, d1) p3 = make_partition(m, d1)