mirror of https://github.com/cbeuw/Cloak
Add and edit some tests
This commit is contained in:
parent
82fe177c24
commit
ea5bb44b0a
|
|
@ -17,6 +17,7 @@ func TestPipeRW(t *testing.T) {
|
||||||
"expecting", len(b),
|
"expecting", len(b),
|
||||||
"got", n,
|
"got", n,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(
|
t.Error(
|
||||||
|
|
@ -24,6 +25,7 @@ func TestPipeRW(t *testing.T) {
|
||||||
"expecting", "nil error",
|
"expecting", "nil error",
|
||||||
"got", err,
|
"got", err,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
b2 := make([]byte, len(b))
|
b2 := make([]byte, len(b))
|
||||||
|
|
@ -34,6 +36,7 @@ func TestPipeRW(t *testing.T) {
|
||||||
"expecting", len(b),
|
"expecting", len(b),
|
||||||
"got", n,
|
"got", n,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(
|
t.Error(
|
||||||
|
|
@ -41,6 +44,7 @@ func TestPipeRW(t *testing.T) {
|
||||||
"expecting", "nil error",
|
"expecting", "nil error",
|
||||||
"got", err,
|
"got", err,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !bytes.Equal(b, b2) {
|
if !bytes.Equal(b, b2) {
|
||||||
t.Error(
|
t.Error(
|
||||||
|
|
@ -67,6 +71,7 @@ func TestReadBlock(t *testing.T) {
|
||||||
"expecting", len(b),
|
"expecting", len(b),
|
||||||
"got", n,
|
"got", n,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(
|
t.Error(
|
||||||
|
|
@ -74,6 +79,7 @@ func TestReadBlock(t *testing.T) {
|
||||||
"expecting", "nil error",
|
"expecting", "nil error",
|
||||||
"got", err,
|
"got", err,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !bytes.Equal(b, b2) {
|
if !bytes.Equal(b, b2) {
|
||||||
t.Error(
|
t.Error(
|
||||||
|
|
@ -81,6 +87,7 @@ func TestReadBlock(t *testing.T) {
|
||||||
"expecting", b,
|
"expecting", b,
|
||||||
"got", b2,
|
"got", b2,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,6 +103,7 @@ func TestPartialRead(t *testing.T) {
|
||||||
"expecting", len(b1),
|
"expecting", len(b1),
|
||||||
"got", n,
|
"got", n,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(
|
t.Error(
|
||||||
|
|
@ -103,6 +111,7 @@ func TestPartialRead(t *testing.T) {
|
||||||
"expecting", "nil error",
|
"expecting", "nil error",
|
||||||
"got", err,
|
"got", err,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if b1[0] != b[0] {
|
if b1[0] != b[0] {
|
||||||
t.Error(
|
t.Error(
|
||||||
|
|
@ -126,6 +135,7 @@ func TestPartialRead(t *testing.T) {
|
||||||
"expecting", "nil error",
|
"expecting", "nil error",
|
||||||
"got", err,
|
"got", err,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !bytes.Equal(b[1:], b2) {
|
if !bytes.Equal(b[1:], b2) {
|
||||||
t.Error(
|
t.Error(
|
||||||
|
|
@ -133,6 +143,7 @@ func TestPartialRead(t *testing.T) {
|
||||||
"expecting", b[1:],
|
"expecting", b[1:],
|
||||||
"got", b2,
|
"got", b2,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,6 +167,7 @@ func TestReadAfterClose(t *testing.T) {
|
||||||
"expecting", "nil error",
|
"expecting", "nil error",
|
||||||
"got", err,
|
"got", err,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !bytes.Equal(b, b2) {
|
if !bytes.Equal(b, b2) {
|
||||||
t.Error(
|
t.Error(
|
||||||
|
|
@ -163,11 +175,12 @@ func TestReadAfterClose(t *testing.T) {
|
||||||
"expecting", b,
|
"expecting", b,
|
||||||
"got", b2,
|
"got", b2,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkBufferedPipe_RW(b *testing.B) {
|
func BenchmarkBufferedPipe_RW(b *testing.B) {
|
||||||
const PAYLOAD_LEN = 1300
|
const PAYLOAD_LEN = 1000
|
||||||
testData := make([]byte, PAYLOAD_LEN)
|
testData := make([]byte, PAYLOAD_LEN)
|
||||||
rand.Read(testData)
|
rand.Read(testData)
|
||||||
|
|
||||||
|
|
@ -187,6 +200,7 @@ func BenchmarkBufferedPipe_RW(b *testing.B) {
|
||||||
"For", "pipe write",
|
"For", "pipe write",
|
||||||
"got", err,
|
"got", err,
|
||||||
)
|
)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
b.SetBytes(PAYLOAD_LEN)
|
b.SetBytes(PAYLOAD_LEN)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ func TestRecvNewFrame(t *testing.T) {
|
||||||
fs.writeNewFrame(frame)
|
fs.writeNewFrame(frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(100 * time.Microsecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
||||||
var sortedResult []uint64
|
var sortedResult []uint64
|
||||||
for x := 0; x < len(set); x++ {
|
for x := 0; x < len(set); x++ {
|
||||||
|
|
@ -45,6 +45,7 @@ func TestRecvNewFrame(t *testing.T) {
|
||||||
n, err := sortedBuf.Read(oct)
|
n, err := sortedBuf.Read(oct)
|
||||||
if n != 8 || err != nil {
|
if n != 8 || err != nil {
|
||||||
ct.Error("failed to read from sorted Buf", n, err)
|
ct.Error("failed to read from sorted Buf", n, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
//log.Print(p)
|
//log.Print(p)
|
||||||
sortedResult = append(sortedResult, binary.BigEndian.Uint64(oct))
|
sortedResult = append(sortedResult, binary.BigEndian.Uint64(oct))
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,18 @@ func TestGenerateObfs(t *testing.T) {
|
||||||
i, err := obfuscator.Obfs(testFrame, obfsBuf)
|
i, err := obfuscator.Obfs(testFrame, obfsBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ct.Error("failed to obfs ", err)
|
ct.Error("failed to obfs ", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resultFrame, err := obfuscator.Deobfs(obfsBuf[:i])
|
resultFrame, err := obfuscator.Deobfs(obfsBuf[:i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ct.Error("failed to deobfs ", err)
|
ct.Error("failed to deobfs ", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !bytes.Equal(testFrame.Payload, resultFrame.Payload) || testFrame.StreamID != resultFrame.StreamID {
|
if !bytes.Equal(testFrame.Payload, resultFrame.Payload) || testFrame.StreamID != resultFrame.StreamID {
|
||||||
ct.Error("expecting", testFrame,
|
ct.Error("expecting", testFrame,
|
||||||
"got", resultFrame)
|
"got", resultFrame)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,6 +100,7 @@ func BenchmarkObfs(b *testing.B) {
|
||||||
n, err := obfs(testFrame, obfsBuf)
|
n, err := obfs(testFrame, obfsBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Error(err)
|
b.Error(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
b.SetBytes(int64(n))
|
b.SetBytes(int64(n))
|
||||||
}
|
}
|
||||||
|
|
@ -111,6 +115,7 @@ func BenchmarkObfs(b *testing.B) {
|
||||||
n, err := obfs(testFrame, obfsBuf)
|
n, err := obfs(testFrame, obfsBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Error(err)
|
b.Error(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
b.SetBytes(int64(n))
|
b.SetBytes(int64(n))
|
||||||
}
|
}
|
||||||
|
|
@ -122,6 +127,7 @@ func BenchmarkObfs(b *testing.B) {
|
||||||
n, err := obfs(testFrame, obfsBuf)
|
n, err := obfs(testFrame, obfsBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Error(err)
|
b.Error(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
b.SetBytes(int64(n))
|
b.SetBytes(int64(n))
|
||||||
}
|
}
|
||||||
|
|
@ -135,6 +141,7 @@ func BenchmarkObfs(b *testing.B) {
|
||||||
n, err := obfs(testFrame, obfsBuf)
|
n, err := obfs(testFrame, obfsBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Error(err)
|
b.Error(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
b.SetBytes(int64(n))
|
b.SetBytes(int64(n))
|
||||||
}
|
}
|
||||||
|
|
@ -168,6 +175,7 @@ func BenchmarkDeobfs(b *testing.B) {
|
||||||
_, err := deobfs(obfsBuf[:n])
|
_, err := deobfs(obfsBuf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Error(err)
|
b.Error(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
b.SetBytes(int64(n))
|
b.SetBytes(int64(n))
|
||||||
}
|
}
|
||||||
|
|
@ -185,6 +193,7 @@ func BenchmarkDeobfs(b *testing.B) {
|
||||||
_, err := deobfs(obfsBuf[:n])
|
_, err := deobfs(obfsBuf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Error(err)
|
b.Error(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
b.SetBytes(int64(n))
|
b.SetBytes(int64(n))
|
||||||
}
|
}
|
||||||
|
|
@ -199,6 +208,7 @@ func BenchmarkDeobfs(b *testing.B) {
|
||||||
_, err := deobfs(obfsBuf[:n])
|
_, err := deobfs(obfsBuf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Error(err)
|
b.Error(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
b.SetBytes(int64(n))
|
b.SetBytes(int64(n))
|
||||||
}
|
}
|
||||||
|
|
@ -215,6 +225,7 @@ func BenchmarkDeobfs(b *testing.B) {
|
||||||
_, err := deobfs(obfsBuf[:n])
|
_, err := deobfs(obfsBuf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Error(err)
|
b.Error(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
b.SetBytes(int64(n))
|
b.SetBytes(int64(n))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ func TestStream_Read(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ch := make(chan []byte)
|
ch := make(chan []byte)
|
||||||
l, _ := net.Listen("tcp", ":0")
|
l, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||||
go func() {
|
go func() {
|
||||||
conn, _ := net.Dial("tcp", l.Addr().String())
|
conn, _ := net.Dial("tcp", l.Addr().String())
|
||||||
for {
|
for {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package multiplex
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/cbeuw/Cloak/internal/util"
|
||||||
|
"math/rand"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkSwitchboard_Send(b *testing.B) {
|
||||||
|
sesh := MakeSession(0, UNLIMITED_VALVE, nil, util.ReadTLS)
|
||||||
|
sb := makeSwitchboard(sesh, UNLIMITED_VALVE)
|
||||||
|
hole := newBlackHole()
|
||||||
|
sb.addConn(hole)
|
||||||
|
connId, err := sb.assignRandomConn()
|
||||||
|
if err != nil {
|
||||||
|
b.Error("failed to get a random conn", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data := make([]byte, 1000)
|
||||||
|
rand.Read(data)
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
n, err := sb.send(data, &connId)
|
||||||
|
if err != nil {
|
||||||
|
b.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b.SetBytes(int64(n))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkPipe(b *testing.B) {
|
||||||
|
reader := rand.New(rand.NewSource(42))
|
||||||
|
buf := make([]byte, 16380)
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
n, err := io.ReadAtLeast(reader, buf, 1)
|
||||||
|
if err != nil {
|
||||||
|
b.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
n, err = ioutil.Discard.Write(buf[:n])
|
||||||
|
if err != nil {
|
||||||
|
b.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b.SetBytes(int64(n))
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue