author | Alberto Bertogli
<albertito@blitiri.com.ar> 2009-07-12 18:10:47 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2009-07-12 23:09:37 UTC |
parent | a6b69402e36857faca266e0dff329ea61e23d4ca |
tests/behaviour/t_corruption.py | +39 | -0 |
tests/behaviour/t_normal.py | +99 | -0 |
tests/behaviour/tf.py | +4 | -2 |
diff --git a/tests/behaviour/t_corruption.py b/tests/behaviour/t_corruption.py index ed1bedf..1524d36 100644 --- a/tests/behaviour/t_corruption.py +++ b/tests/behaviour/t_corruption.py @@ -105,4 +105,43 @@ def test_c05(): assert content(n) == '' cleanup(n) +def test_c06(): + "header version != 1" + c = gencontent() + + def f1(f, jf): + fiu.enable("jio/commit/tf_sync") + jf.write(c) + + n = run_with_tmp(f1) + assert content(n) == '' + + # there is no need to recalculate the checsum because it is verified + # after the version check + tf = TransFile(transpath(n, 1)) + tf.ver = 8 + tf.save() + fsck_verify(n, broken = 1) + assert content(n) == '' + cleanup(n) + +def test_c07(): + "trailer numops mismatch" + c = gencontent() + + def f1(f, jf): + fiu.enable("jio/commit/tf_sync") + jf.write(c) + + n = run_with_tmp(f1) + assert content(n) == '' + + # there is no need to recalculate the checsum because it is verified + # after the numops check + tf = TransFile(transpath(n, 1)) + tf.numops = 55 + tf.save() + fsck_verify(n, broken = 1) + assert content(n) == '' + cleanup(n) diff --git a/tests/behaviour/t_normal.py b/tests/behaviour/t_normal.py index 942bffc..cb8ab91 100644 --- a/tests/behaviour/t_normal.py +++ b/tests/behaviour/t_normal.py @@ -233,4 +233,103 @@ def test_n15(): fsck_verify(n) cleanup(n) +def test_n16(): + "jopen r/o + jtrans_add + jtrans_commit" + c = gencontent() + + # create the file before opening, read-only mode does not create it + n = tmppath() + open(n, 'w+') + f, jf = biopen(n, mode = 'r') + + t = jf.new_trans() + + try: + t.add(c, 80) + except IOError: + pass + else: + raise AssertionError + + try: + t.commit() + except IOError: + pass + else: + raise AssertionError + + cleanup(n) + +def test_n17(): + "move journal to an existing dir" + import os + + f, jf = bitmp() + n = f.name + p = tmppath() + os.mkdir(p) + open(p + '/x', 'w') + + jf.write('x') + jf.jmove_journal(p) + jf.write('y') + del jf + os.unlink(p + '/x') + + assert libjio.jfsck(n, p)['total'] == 0 + os.unlink(n) + +def test_n18(): + "jtrans_rollback with norollback" + c = gencontent() + f, jf = bitmp(jflags = libjio.J_NOROLLBACK) + n = f.name + + t = jf.new_trans() + t.add(c, 80) + t.commit() + try: + t.rollback() + except IOError: + pass + else: + raise AssertionError + + assert content(n) == '\0' * 80 + c + fsck_verify(n) + cleanup(n) + +def test_n19(): + "jwrite in files opened with O_APPEND" + c1 = gencontent() + c2 = gencontent() + f, jf = bitmp(mode = 'a') + n = f.name + + jf.write(c1) + jf.write(c2) + + assert content(n) == c1 + c2 + fsck_verify(n) + cleanup(n) + +def test_n20(): + "jtrans_add of 0 length" + f, jf = bitmp() + n = f.name + + t = jf.new_trans() + + try: + t.add('', 80) + except IOError: + pass + else: + raise AssertionError + + del t + del jf + fsck_verify(n) + cleanup(n) + diff --git a/tests/behaviour/tf.py b/tests/behaviour/tf.py index 20450ee..3591f94 100644 --- a/tests/behaviour/tf.py +++ b/tests/behaviour/tf.py @@ -81,6 +81,8 @@ def biopen(path, mode = 'w+', jflags = 0): flags = os.O_RDWR if '+' in mode: flags = flags | os.O_CREAT | os.O_TRUNC + elif 'a' in mode: + flags = os.O_RDWR | os.O_APPEND else: raise RuntimeError @@ -160,7 +162,7 @@ class attrdict (dict): class TransFile (object): def __init__(self, path = ''): - self.ver = 0 + self.ver = 1 self.id = -1 self.flags = 0 self.numops = -1 @@ -201,7 +203,7 @@ class TransFile (object): # intentional, so we can write broken transactions and see how # jfsck() copes with them fd = open(self.path, 'w') - fd.write(struct.pack("!HHI", 1, self.flags, self.id)) + fd.write(struct.pack("!HHI", self.ver, self.flags, self.id)) for o in self.ops: fd.write(struct.pack("!IQs", o.tlen, o.offset, o.payload))