Пример #1
0
func BenchmarkIcmpProcessICMPv4(b *testing.B) {
	if testing.Verbose() {
		logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"icmp", "icmpdetailed"})
	}

	results := &publish.ChanTransactions{make(chan common.MapStr, 10)}
	icmp, err := New(true, results, ucfg.New())
	if err != nil {
		b.Error("Failed to create ICMP processor")
		return
	}

	icmpRequestData := createICMPv4Layer(b, "08"+"00"+"0000"+"ffff"+"0001")
	packetRequestData := new(protos.Packet)

	icmpResponseData := createICMPv4Layer(b, "00"+"00"+"0000"+"ffff"+"0001")
	packetResponseData := new(protos.Packet)

	b.ResetTimer()

	for n := 0; n < b.N; n++ {
		icmp.ProcessICMPv4(nil, icmpRequestData, packetRequestData)
		icmp.ProcessICMPv4(nil, icmpResponseData, packetResponseData)

		client := icmp.results.(*publish.ChanTransactions)
		<-client.Channel
	}
}
Пример #2
0
// Test OutputWorker by calling onStop() and onMessage() with various inputs.
func TestOutputWorker(t *testing.T) {
	outputer := &testOutputer{events: make(chan common.MapStr, 10)}
	ow := newOutputWorker(
		ucfg.New(),
		outputer,
		common.NewWorkerSignal(),
		1, 0)

	ow.onStop() // Noop

	var testCases = []message{
		testMessage(newTestSignaler(), nil),
		testMessage(newTestSignaler(), testEvent()),
		testBulkMessage(newTestSignaler(), []common.MapStr{testEvent()}),
	}

	for _, m := range testCases {
		sig := m.context.Signal.(*testSignaler)
		ow.onMessage(m)
		assert.True(t, sig.wait())

		if m.event != nil {
			assert.Equal(t, m.event, <-outputer.events)
		} else {
			for _, e := range m.events {
				assert.Equal(t, e, <-outputer.events)
			}
		}
	}
}
Пример #3
0
func httpModForTests() *HTTP {
	results := &publish.ChanTransactions{Channel: make(chan common.MapStr, 10)}
	http, err := New(false, results, ucfg.New())
	if err != nil {
		panic(err)
	}
	return http.(*HTTP)
}
Пример #4
0
func NewConfig() *Config {
	return fromConfig(ucfg.New())
}