From: zooko Date: Fri, 18 Jan 2008 14:48:44 +0000 (+0530) Subject: tests: add test suggested by agl's bug report X-Git-Url: https://git.rkrishnan.org/vdrive/README.win32?a=commitdiff_plain;h=d4008add302ceb0e7a67a0ac91e5d88f069d7819;p=tahoe-lafs%2Fzfec.git tests: add test suggested by agl's bug report darcs-hash:d0f2e6069fe17e2c115c76511d9f8de0989c3685 --- diff --git a/zfec/zfec/_fecmodule.c b/zfec/zfec/_fecmodule.c index 63b07cb..f0d8d6d 100644 --- a/zfec/zfec/_fecmodule.c +++ b/zfec/zfec/_fecmodule.c @@ -547,7 +547,45 @@ static PyTypeObject Decoder_type = { Decoder_new, /* tp_new */ }; -static PyMethodDef fec_methods[] = { +PyObject* +test_from_agl() { + unsigned char b1c[8], b2c[8]; + unsigned char b1[8], b2[8], b3[8], b4[8], b5[8]; + memset(b1, 1, 8); + memset(b2, 2, 8); + memset(b3, 3, 8); + const unsigned char *blocks[3] = {b1, b2, b3}; + unsigned char *outblocks[2] = {b4, b5}; + unsigned block_nums[] = {3, 4}; + + fec_t *const fec = fec_new(3, 5); + fec_encode(fec, blocks, outblocks, block_nums, 2, 8); + + write(1, b1, 8); + write(1, b2, 8); + write(1, b3, 8); + write(1, b4, 8); + write(1, b5, 8); + + memcpy(b1c, b1, 8); memcpy(b2c, b2, 8); + + const unsigned char *inpkts[] = {b3, b4, b5}; + unsigned char *outpkts[] = {b1, b2}; + unsigned indexes[] = {2, 3, 4}; + + fec_decode(fec, inpkts, outpkts, indexes, 8); + + write(1, b1, 8); + write(1, b2, 8); + + if ((memcmp(b1, b1c,8) == 0) && (memcmp(b2, b2c,8) == 0)) + Py_RETURN_TRUE; + else + Py_RETURN_FALSE; +} + +static PyMethodDef fec_functions[] = { + {"test_from_agl", test_from_agl, METH_NOARGS, NULL}, {NULL} }; @@ -564,7 +602,7 @@ init_fec(void) { if (PyType_Ready(&Decoder_type) < 0) return; - module = Py_InitModule3("_fec", fec_methods, fec__doc__); + module = Py_InitModule3("_fec", fec_functions, fec__doc__); if (module == NULL) return; diff --git a/zfec/zfec/test/test_zfec.py b/zfec/zfec/test/test_zfec.py index 130ef6f..1143cfc 100755 --- a/zfec/zfec/test/test_zfec.py +++ b/zfec/zfec/test/test_zfec.py @@ -79,6 +79,18 @@ def _help_test_random_with_l_easy(l): _h_easy(k, m, s) class ZFecTest(unittest.TestCase): + def test_from_agl_c(self): + self.failUnless(zfec._fec.test_from_agl()) + + def test_from_agl_py(self): + e = zfec.Encoder(3, 5) + b1 = '\x01'*8 ; b2 = '\x02'*8 ; b3 = '\x03'*8 + b4, b5 = e.encode([b1, b2, b3], (3, 4)) + d = zfec.Decoder(3, 5) + resblocks = d.decode((b3, b4, b5), (2, 3, 4)) + + print "b1: %r, b2: %r, b3: %r, b4: %r, b5: %r, resblocks: %r" % (b1, b2, b3, b4, b5, resblocks) + def test_small(self): for i in range(16): _help_test_random_with_l(i)