erasure: Coding blocks during encoding were garbage, fixes #21

This commit is contained in:
Harshavardhana 2014-11-13 21:48:04 -08:00
parent c39c51328e
commit 6a6dac8365
5 changed files with 35 additions and 37 deletions

View file

@ -4,13 +4,13 @@ all: build test
test: cauchy vandermonde
cauchy:
@go test -test.run="TestCauchy*"
@godep go test -test.run="TestCauchy*"
vandermonde:
@go test -test.run="TestVanderMonde*"
@godep go test -test.run="TestVanderMonde*"
isal/isal-l.so:
@$(MAKE) --quiet -C isal
build: isal/isal-l.so
@go build
@godep go build

View file

@ -18,33 +18,33 @@ package erasure
import (
"bytes"
. "gopkg.in/check.v1"
"testing"
)
func TestCachyEncode(t *testing.T) {
type MySuite struct{}
var _ = Suite(&MySuite{})
func Test(t *testing.T) { TestingT(t) }
func (s *MySuite) TestCachyEncode(c *C) {
ep, _ := ValidateParams(10, 5, 8, CAUCHY)
p := NewEncoder(ep)
data := make([]byte, 1000)
chunks, length := p.Encode(data)
t.Logf("chunks length: %d;\nlength: %d\n", len(chunks), length)
if length != len(data) {
t.Fatal()
}
_, length := p.Encode(data)
c.Assert(length, Equals, len(data))
}
func TestCauchyDecode(t *testing.T) {
func (s *MySuite) TestCauchyDecode(c *C) {
ep, _ := ValidateParams(10, 5, 8, CAUCHY)
data := []byte("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")
p := NewEncoder(ep)
chunks, length := p.Encode(data)
t.Logf("chunks length: %d;\nlength: %d\n", len(chunks), length)
if length != len(data) {
t.Fatal()
}
c.Assert(length, Equals, len(data))
chunks[0] = nil
chunks[3] = nil
@ -53,11 +53,9 @@ func TestCauchyDecode(t *testing.T) {
chunks[13] = nil
recovered_data, err := p.Decode(chunks, length)
if err != nil {
t.Fatalf("Error: %s", err)
}
c.Assert(err, Not(IsNil))
if i := bytes.Compare(recovered_data, data); i < 0 {
t.Fatalf("Error: recovered data is less than original data")
c.Fatalf("Error: recovered data is less than original data")
}
}

View file

@ -94,6 +94,7 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
for i := range chunks {
pointers[i] = &chunks[i][0]
}
data := (**C.uchar)(unsafe.Pointer(&pointers[:k][0]))
coding := (**C.uchar)(unsafe.Pointer(&pointers[k:][0]))

View file

@ -181,18 +181,22 @@ func (e *Encoder) Encode(block []byte) ([][]byte, int) {
pointers := make([]*byte, e.p.n)
var i int
// Add data and code blocks to chunks
for i = 0; i < e.p.n; i++ {
// Add data blocks to chunks
for i = 0; i < e.p.k; i++ {
chunks[i] = block[i*chunk_size : (i+1)*chunk_size]
pointers[i] = &chunks[i][0]
}
for i = e.p.k; i < e.p.n; i++ {
chunks[i] = make([]byte, chunk_size)
pointers[i] = &chunks[i][0]
}
data := (**C.uchar)(unsafe.Pointer(&pointers[:e.p.k][0]))
coding := (**C.uchar)(unsafe.Pointer(&pointers[e.p.k:][0]))
C.ec_encode_data(C.int(chunk_size), e.k, e.m, e.encode_tbls, data,
coding)
return chunks, block_len
}

View file

@ -18,33 +18,30 @@ package erasure
import (
"bytes"
"testing"
. "gopkg.in/check.v1"
)
func TestVanderMondeEncode(t *testing.T) {
func (s *MySuite) TestVanderMondeEncode(c *C) {
ep, _ := ValidateParams(10, 5, 8, VANDERMONDE)
p := NewEncoder(ep)
data := make([]byte, 1000)
chunks, length := p.Encode(data)
t.Logf("chunks length: %d;\nlength: %d\n", len(chunks), length)
if length != len(data) {
t.Fatal()
}
c.Logf("chunks length: %d;\nlength: %d\n", len(chunks), length)
c.Assert(length, Equals, len(data))
}
func TestVanderMondeDecode(t *testing.T) {
func (s *MySuite) TestVanderMondeDecode(c *C) {
ep, _ := ValidateParams(10, 5, 8, VANDERMONDE)
p := NewEncoder(ep)
data := []byte("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")
chunks, length := p.Encode(data)
t.Logf("chunks length: %d;\nlength: %d\n", len(chunks), length)
if length != len(data) {
t.Fatal()
}
c.Logf("chunks length: %d", len(chunks))
c.Logf("length: %d", length)
c.Assert(length, Equals, len(data))
chunks[0] = nil
chunks[3] = nil
@ -53,11 +50,9 @@ func TestVanderMondeDecode(t *testing.T) {
chunks[13] = nil
recovered_data, err := p.Decode(chunks, length)
if err != nil {
t.Fatalf("Error: %s", err)
}
c.Assert(err, Not(IsNil))
if i := bytes.Compare(recovered_data, data); i < 0 {
t.Fatalf("Error: recovered data is less than original data")
c.Fatalf("Error: recovered data is less than original data")
}
}