Merge pull request #22 from harshavardhana/pr_out_erasure_coding_blocks_during_encoding_were_garbage_fixes_21

erasure: Coding blocks during encoding were garbage, fixes #21
master
Harshavardhana 10 years ago
commit fa13804db0
  1. 6
      erasure/Makefile
  2. 30
      erasure/cauchy_test.go
  3. 1
      erasure/decode.go
  4. 10
      erasure/encode.go
  5. 25
      erasure/vandermonde_test.go

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

@ -18,33 +18,33 @@ package erasure
import ( import (
"bytes" "bytes"
. "gopkg.in/check.v1"
"testing" "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) ep, _ := ValidateParams(10, 5, 8, CAUCHY)
p := NewEncoder(ep) p := NewEncoder(ep)
data := make([]byte, 1000) data := make([]byte, 1000)
chunks, length := p.Encode(data) _, length := p.Encode(data)
c.Assert(length, Equals, len(data))
t.Logf("chunks length: %d;\nlength: %d\n", len(chunks), length)
if length != len(data) {
t.Fatal()
}
} }
func TestCauchyDecode(t *testing.T) { func (s *MySuite) TestCauchyDecode(c *C) {
ep, _ := ValidateParams(10, 5, 8, CAUCHY) 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.") 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) p := NewEncoder(ep)
chunks, length := p.Encode(data) chunks, length := p.Encode(data)
t.Logf("chunks length: %d;\nlength: %d\n", len(chunks), length) c.Assert(length, Equals, len(data))
if length != len(data) {
t.Fatal()
}
chunks[0] = nil chunks[0] = nil
chunks[3] = nil chunks[3] = nil
@ -53,11 +53,9 @@ func TestCauchyDecode(t *testing.T) {
chunks[13] = nil chunks[13] = nil
recovered_data, err := p.Decode(chunks, length) recovered_data, err := p.Decode(chunks, length)
if err != nil { c.Assert(err, Not(IsNil))
t.Fatalf("Error: %s", err)
}
if i := bytes.Compare(recovered_data, data); i < 0 { 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")
} }
} }

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

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

@ -18,33 +18,30 @@ package erasure
import ( import (
"bytes" "bytes"
"testing" . "gopkg.in/check.v1"
) )
func TestVanderMondeEncode(t *testing.T) { func (s *MySuite) TestVanderMondeEncode(c *C) {
ep, _ := ValidateParams(10, 5, 8, VANDERMONDE) ep, _ := ValidateParams(10, 5, 8, VANDERMONDE)
p := NewEncoder(ep) p := NewEncoder(ep)
data := make([]byte, 1000) data := make([]byte, 1000)
chunks, length := p.Encode(data) chunks, length := p.Encode(data)
t.Logf("chunks length: %d;\nlength: %d\n", len(chunks), length) c.Logf("chunks length: %d;\nlength: %d\n", len(chunks), length)
if length != len(data) { c.Assert(length, Equals, len(data))
t.Fatal()
}
} }
func TestVanderMondeDecode(t *testing.T) { func (s *MySuite) TestVanderMondeDecode(c *C) {
ep, _ := ValidateParams(10, 5, 8, VANDERMONDE) ep, _ := ValidateParams(10, 5, 8, VANDERMONDE)
p := NewEncoder(ep) 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.") 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) chunks, length := p.Encode(data)
t.Logf("chunks length: %d;\nlength: %d\n", len(chunks), length) c.Logf("chunks length: %d", len(chunks))
if length != len(data) { c.Logf("length: %d", length)
t.Fatal() c.Assert(length, Equals, len(data))
}
chunks[0] = nil chunks[0] = nil
chunks[3] = nil chunks[3] = nil
@ -53,11 +50,9 @@ func TestVanderMondeDecode(t *testing.T) {
chunks[13] = nil chunks[13] = nil
recovered_data, err := p.Decode(chunks, length) recovered_data, err := p.Decode(chunks, length)
if err != nil { c.Assert(err, Not(IsNil))
t.Fatalf("Error: %s", err)
}
if i := bytes.Compare(recovered_data, data); i < 0 { 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")
} }
} }

Loading…
Cancel
Save