diff options
author | Joshua MacDonald <josh.macdonald@gmail.com> | 2015-11-29 23:14:04 -0800 |
---|---|---|
committer | Joshua MacDonald <josh.macdonald@gmail.com> | 2015-11-29 23:14:04 -0800 |
commit | bdcbbc839ca7fd3e8edd1617bbf9bfdba4bf543d (patch) | |
tree | d2ed2ff8a4972c3e88db485f1d7c40d173eedd46 /xdelta3/go/src/xdelta/rstream.go | |
parent | 4b74451f9e9b976a2a0984130662f58bd39e1478 (diff) |
Test this on Linux
Diffstat (limited to 'xdelta3/go/src/xdelta/rstream.go')
-rw-r--r-- | xdelta3/go/src/xdelta/rstream.go | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/xdelta3/go/src/xdelta/rstream.go b/xdelta3/go/src/xdelta/rstream.go index eafcfeb..7d205c6 100644 --- a/xdelta3/go/src/xdelta/rstream.go +++ b/xdelta3/go/src/xdelta/rstream.go | |||
@@ -3,19 +3,20 @@ package xdelta | |||
3 | 3 | ||
4 | import ( | 4 | import ( |
5 | "io" | 5 | "io" |
6 | "fmt" | ||
6 | "math/rand" | 7 | "math/rand" |
7 | ) | 8 | ) |
8 | 9 | ||
9 | const ( | 10 | const ( |
10 | blocksize = 1<<20 | 11 | blocksize = 1<<17 |
11 | ) | 12 | ) |
12 | 13 | ||
13 | func WriteRstreams(t *TestGroup, seed, offset, len int64, | 14 | func (t *TestGroup) WriteRstreams(desc string, seed, offset, len int64, |
14 | src, tgt io.WriteCloser) { | 15 | src, tgt io.WriteCloser) { |
15 | t.Go("src-write", func (g Goroutine) { | 16 | t.Go("src-write:"+desc, func (g Goroutine) { |
16 | writeOne(g, seed, 0, len, src, false) | 17 | writeOne(g, seed, 0, len, src, false) |
17 | }) | 18 | }) |
18 | t.Go("tgt-write", func (g Goroutine) { | 19 | t.Go("tgt-write:"+desc, func (g Goroutine) { |
19 | writeOne(g, seed, offset, len, tgt, true) | 20 | writeOne(g, seed, offset, len, tgt, true) |
20 | }) | 21 | }) |
21 | } | 22 | } |
@@ -29,31 +30,37 @@ func writeOne(g Goroutine, seed, offset, len int64, stream io.WriteCloser, reada | |||
29 | } | 30 | } |
30 | if offset != 0 { | 31 | if offset != 0 { |
31 | // Fill with other random data until the offset | 32 | // Fill with other random data until the offset |
32 | if err := writeRand(rand.New(rand.NewSource(^seed)), offset, stream); err != nil { | 33 | fmt.Println(g, "pre-offset case", offset) |
34 | if err := writeRand(g, rand.New(rand.NewSource(^seed)), offset, stream); err != nil { | ||
33 | g.Panic(err) | 35 | g.Panic(err) |
34 | } | 36 | } |
35 | } | 37 | } |
36 | if err := writeRand(rand.New(rand.NewSource(seed)), | 38 | fmt.Println(g, "offset case", len - offset) |
39 | if err := writeRand(g, rand.New(rand.NewSource(seed)), | ||
37 | len - offset, stream); err != nil { | 40 | len - offset, stream); err != nil { |
38 | g.Panic(err) | 41 | g.Panic(err) |
39 | } | 42 | } |
43 | fmt.Println(g, "closing", len) | ||
40 | if err := stream.Close(); err != nil { | 44 | if err := stream.Close(); err != nil { |
41 | g.Panic(err) | 45 | g.Panic(err) |
42 | } | 46 | } |
43 | g.OK() | 47 | g.OK() |
44 | } | 48 | } |
45 | 49 | ||
46 | func writeRand(r *rand.Rand, len int64, s io.Writer) error { | 50 | func writeRand(g Goroutine, r *rand.Rand, len int64, s io.Writer) error { |
47 | blk := make([]byte, blocksize) | 51 | blk := make([]byte, blocksize) |
52 | fmt.Println(g, "rstream", len) | ||
48 | for len > 0 { | 53 | for len > 0 { |
49 | fillRand(r, blk) | 54 | fillRand(r, blk) |
50 | c := blocksize | 55 | c := blocksize |
51 | if len < blocksize { | 56 | if len < blocksize { |
52 | c = int(len) | 57 | c = int(len) |
53 | } | 58 | } |
59 | fmt.Println(g, "writing...", c, s) | ||
54 | if _, err := s.Write(blk[0:c]); err != nil { | 60 | if _, err := s.Write(blk[0:c]); err != nil { |
55 | return err | 61 | return err |
56 | } | 62 | } |
63 | fmt.Println(g, "...written", c) | ||
57 | len -= int64(c) | 64 | len -= int64(c) |
58 | } | 65 | } |
59 | return nil | 66 | return nil |