mirror of https://bitbucket.org/ausocean/av.git
Merged in pipeline-test (pull request #448)
revid: renamed revid_test.go to pipeline_test.go
This commit is contained in:
commit
60187c797d
|
@ -32,7 +32,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"bitbucket.org/ausocean/av/revid/config"
|
||||
|
@ -51,7 +50,7 @@ func TestRaspivid(t *testing.T) {
|
|||
t.Skip("Skipping TestRaspivid since no raspivid found.")
|
||||
}
|
||||
|
||||
var logger simpleLogger
|
||||
var logger testLogger
|
||||
ns, err := netsender.New(&logger, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Errorf("netsender.New failed with error %v", err)
|
||||
|
@ -72,27 +71,6 @@ func TestRaspivid(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// simpleLogger implements a netsender.Logger.
|
||||
type simpleLogger struct{}
|
||||
|
||||
func (tl *simpleLogger) SetLevel(level int8) {}
|
||||
|
||||
func (tl *simpleLogger) Log(level int8, msg string, params ...interface{}) {
|
||||
logLevels := [...]string{"Debug", "Info", "Warn", "Error", "", "", "Fatal"}
|
||||
if level < -1 || level > 5 {
|
||||
panic("Invalid log level")
|
||||
}
|
||||
if !silent {
|
||||
fmt.Printf("%s: %s\n", logLevels[level+1], msg)
|
||||
}
|
||||
if level == 5 {
|
||||
buf := make([]byte, 1<<16)
|
||||
size := runtime.Stack(buf, true)
|
||||
fmt.Printf("%s\n", string(buf[:size]))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// tstMtsEncoder emulates the mts.Encoder to the extent of the dst field.
|
||||
// This will allow access to the dst to check that it has been set corrctly.
|
||||
type tstMtsEncoder struct {
|
||||
|
@ -216,7 +194,7 @@ func TestResetEncoderSenderSetup(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
rv, err := New(config.Config{Logger: &simpleLogger{}}, nil)
|
||||
rv, err := New(config.Config{Logger: &testLogger{}}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
|
@ -225,7 +203,7 @@ func TestResetEncoderSenderSetup(t *testing.T) {
|
|||
for testNum, test := range tests {
|
||||
// Create a new config and reset revid with it.
|
||||
const dummyURL = "rtmp://dummy"
|
||||
c := config.Config{Logger: &simpleLogger{}, Outputs: test.outputs, RTMPURL: dummyURL}
|
||||
c := config.Config{Logger: &testLogger{}, Outputs: test.outputs, RTMPURL: dummyURL}
|
||||
err := rv.setConfig(c)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v for test %v", err, testNum)
|
|
@ -38,7 +38,6 @@ import (
|
|||
|
||||
"bitbucket.org/ausocean/av/container/mts"
|
||||
"bitbucket.org/ausocean/av/container/mts/meta"
|
||||
"bitbucket.org/ausocean/utils/logger"
|
||||
"bitbucket.org/ausocean/utils/ring"
|
||||
)
|
||||
|
||||
|
@ -98,40 +97,6 @@ func (ts *destination) Write(d []byte) (int, error) {
|
|||
|
||||
func (ts *destination) Close() error { return nil }
|
||||
|
||||
// testLogger will allow logging to be done by the testing pkg.
|
||||
type testLogger testing.T
|
||||
|
||||
func (tl *testLogger) Debug(msg string, args ...interface{}) { tl.log(logger.Debug, msg, args...) }
|
||||
func (tl *testLogger) Info(msg string, args ...interface{}) { tl.log(logger.Info, msg, args...) }
|
||||
func (tl *testLogger) Warning(msg string, args ...interface{}) { tl.log(logger.Warning, msg, args...) }
|
||||
func (tl *testLogger) Error(msg string, args ...interface{}) { tl.log(logger.Error, msg, args...) }
|
||||
func (tl *testLogger) Fatal(msg string, args ...interface{}) { tl.log(logger.Fatal, msg, args...) }
|
||||
|
||||
func (dl *testLogger) log(lvl int8, msg string, args ...interface{}) {
|
||||
var l string
|
||||
switch lvl {
|
||||
case logger.Warning:
|
||||
l = "warning"
|
||||
case logger.Debug:
|
||||
l = "debug"
|
||||
case logger.Info:
|
||||
l = "info"
|
||||
case logger.Error:
|
||||
l = "error"
|
||||
case logger.Fatal:
|
||||
l = "fatal"
|
||||
}
|
||||
msg = l + ": " + msg
|
||||
for i := 0; i < len(args); i++ {
|
||||
msg += " %v"
|
||||
}
|
||||
if len(args) == 0 {
|
||||
dl.Log(msg + "\n")
|
||||
return
|
||||
}
|
||||
dl.Logf(msg+"\n", args)
|
||||
}
|
||||
|
||||
// TestSegment ensures that the mtsSender correctly segments data into clips
|
||||
// based on positioning of PSI in the mtsEncoder's output stream.
|
||||
func TestMTSSenderSegment(t *testing.T) {
|
||||
|
@ -142,7 +107,7 @@ func TestMTSSenderSegment(t *testing.T) {
|
|||
dst := &destination{t: t, done: make(chan struct{}), doneAt: numberOfClips}
|
||||
const testRBCapacity = 50000000
|
||||
nElements := testRBCapacity / rbStartingElementSize
|
||||
sender := newMTSSender(dst, (*testLogger)(t).log, ring.NewBuffer(nElements, rbStartingElementSize, 0), 0)
|
||||
sender := newMTSSender(dst, (*testLogger)(t).Log, ring.NewBuffer(nElements, rbStartingElementSize, 0), 0)
|
||||
|
||||
const psiSendCount = 10
|
||||
encoder, err := mts.NewEncoder(sender, (*testLogger)(t), mts.PacketBasedPSI(psiSendCount), mts.Rate(25), mts.MediaType(mts.EncodeH264))
|
||||
|
@ -223,7 +188,7 @@ func TestMtsSenderFailedSend(t *testing.T) {
|
|||
dst := &destination{t: t, testFails: true, failAt: clipToFailAt, done: make(chan struct{})}
|
||||
const testRBCapacity = 50000000 // 50MB
|
||||
nElements := testRBCapacity / rbStartingElementSize
|
||||
sender := newMTSSender(dst, (*testLogger)(t).log, ring.NewBuffer(nElements, rbStartingElementSize, 0), 0)
|
||||
sender := newMTSSender(dst, (*testLogger)(t).Log, ring.NewBuffer(nElements, rbStartingElementSize, 0), 0)
|
||||
|
||||
const psiSendCount = 10
|
||||
encoder, err := mts.NewEncoder(sender, (*testLogger)(t), mts.PacketBasedPSI(psiSendCount), mts.Rate(25), mts.MediaType(mts.EncodeH264))
|
||||
|
@ -304,7 +269,7 @@ func TestMtsSenderDiscontinuity(t *testing.T) {
|
|||
// Create destination, the mtsSender and the mtsEncoder.
|
||||
const clipToDelay = 3
|
||||
dst := &destination{t: t, sendDelay: 10 * time.Millisecond, delayAt: clipToDelay, done: make(chan struct{})}
|
||||
sender := newMTSSender(dst, (*testLogger)(t).log, ring.NewBuffer(1, rbStartingElementSize, 0), 0)
|
||||
sender := newMTSSender(dst, (*testLogger)(t).Log, ring.NewBuffer(1, rbStartingElementSize, 0), 0)
|
||||
|
||||
const psiSendCount = 10
|
||||
encoder, err := mts.NewEncoder(sender, (*testLogger)(t), mts.PacketBasedPSI(psiSendCount), mts.Rate(25), mts.MediaType(mts.EncodeH264))
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package revid
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"bitbucket.org/ausocean/utils/logger"
|
||||
)
|
||||
|
||||
// testLogger will allow logging to be done by the testing pkg.
|
||||
type testLogger testing.T
|
||||
|
||||
func (tl *testLogger) Debug(msg string, args ...interface{}) { tl.Log(logger.Debug, msg, args...) }
|
||||
func (tl *testLogger) Info(msg string, args ...interface{}) { tl.Log(logger.Info, msg, args...) }
|
||||
func (tl *testLogger) Warning(msg string, args ...interface{}) { tl.Log(logger.Warning, msg, args...) }
|
||||
func (tl *testLogger) Error(msg string, args ...interface{}) { tl.Log(logger.Error, msg, args...) }
|
||||
func (tl *testLogger) Fatal(msg string, args ...interface{}) { tl.Log(logger.Fatal, msg, args...) }
|
||||
func (tl *testLogger) SetLevel(lvl int8) {}
|
||||
func (dl *testLogger) Log(lvl int8, msg string, args ...interface{}) {
|
||||
var l string
|
||||
switch lvl {
|
||||
case logger.Warning:
|
||||
l = "warning"
|
||||
case logger.Debug:
|
||||
l = "debug"
|
||||
case logger.Info:
|
||||
l = "info"
|
||||
case logger.Error:
|
||||
l = "error"
|
||||
case logger.Fatal:
|
||||
l = "fatal"
|
||||
}
|
||||
msg = l + ": " + msg
|
||||
|
||||
// Just use test.T.Log if no formatting required.
|
||||
if len(args) == 0 {
|
||||
((*testing.T)(dl)).Log(msg)
|
||||
return
|
||||
}
|
||||
|
||||
// Add braces with args inside to message.
|
||||
msg += " ("
|
||||
for i := 0; i < len(args); i += 2 {
|
||||
msg += " %v:\"%v\""
|
||||
}
|
||||
msg += " )"
|
||||
|
||||
if lvl == logger.Fatal {
|
||||
dl.Fatalf(msg+"\n", args...)
|
||||
}
|
||||
|
||||
dl.Logf(msg+"\n", args...)
|
||||
}
|
Loading…
Reference in New Issue