Commit c532b502 authored by Kirill Smelkov's avatar Kirill Smelkov

X Settled on tracepoints for testing; XXX something is not ok with go:linkname...

X Settled on tracepoints for testing; XXX something is not ok with go:linkname and relative imports?

For the reference how go:linkname works:

	https://lab.nexedi.com/snippets/224
parent 6ac7ebf8
...@@ -760,12 +760,15 @@ func (c *Conn) Recv() (Msg, error) { ...@@ -760,12 +760,15 @@ func (c *Conn) Recv() (Msg, error) {
return nil, &ConnError{Conn: c, Op: "decode", Err: err} return nil, &ConnError{Conn: c, Op: "decode", Err: err}
} }
traceConnRecv(c, msg)
return msg, nil return msg, nil
} }
// Send sends message // Send sends message
// it encodes message into packet and sends it // it encodes message into packet and sends it
func (c *Conn) Send(msg Msg) error { func (c *Conn) Send(msg Msg) error {
traceConnSend(c, msg)
l := msg.NEOMsgEncodedLen() l := msg.NEOMsgEncodedLen()
buf := PktBuf{make([]byte, PktHeadLen + l)} // TODO -> freelist buf := PktBuf{make([]byte, PktHeadLen + l)} // TODO -> freelist
......
...@@ -25,6 +25,7 @@ import ( ...@@ -25,6 +25,7 @@ import (
//"reflect" //"reflect"
"testing" "testing"
"../../neo"
//"../../neo/client" //"../../neo/client"
//"../../zodb" //"../../zodb"
...@@ -63,7 +64,14 @@ type MyTracer struct { ...@@ -63,7 +64,14 @@ type MyTracer struct {
func (t *MyTracer) TraceNetConnect(ev *xnet.TraceConnect) { t.Trace1(ev) } func (t *MyTracer) TraceNetConnect(ev *xnet.TraceConnect) { t.Trace1(ev) }
func (t *MyTracer) TraceNetListen(ev *xnet.TraceListen) { t.Trace1(ev) } func (t *MyTracer) TraceNetListen(ev *xnet.TraceListen) { t.Trace1(ev) }
func (t *MyTracer) TraceNetTx(ev *xnet.TraceTx) { t.Trace1(ev) } func (t *MyTracer) TraceNetTx(ev *xnet.TraceTx) {} // { t.Trace1(ev) }
type traceNeoRecv struct {conn *neo.Conn; msg neo.Msg}
func (t *MyTracer) traceNeoConnRecv(c *neo.Conn, msg neo.Msg) { t.Trace1(&traceNeoRecv{c, msg}) }
type traceNeoSend struct {conn *neo.Conn; msg neo.Msg}
func (t *MyTracer) traceNeoConnSend(c *neo.Conn, msg neo.Msg) { t.Trace1(&traceNeoSend{c, msg}) }
/* /*
...@@ -115,11 +123,17 @@ func (tc *TraceChecker) ExpectNetTx(src, dst string, pkt string) { ...@@ -115,11 +123,17 @@ func (tc *TraceChecker) ExpectNetTx(src, dst string, pkt string) {
// M drives cluster with 1 S through recovery -> verification -> service -> shutdown // M drives cluster with 1 S through recovery -> verification -> service -> shutdown
func TestMasterStorage(t *testing.T) { func TestMasterStorage(t *testing.T) {
println("server: &_neo_traceConnSend:", &_neo_traceConnSend)
tracer := &MyTracer{xtesting.NewSyncTracer()} tracer := &MyTracer{xtesting.NewSyncTracer()}
tc := xtesting.NewTraceChecker(t, tracer.SyncTracer) tc := xtesting.NewTraceChecker(t, tracer.SyncTracer)
net := pipenet.New("testnet") // test network net := pipenet.New("testnet") // test network
// XXX change back after test
_neo_traceConnRecv = tracer.traceNeoConnRecv
_neo_traceConnSend = tracer.traceNeoConnSend
// shortcut for addresses // shortcut for addresses
xaddr := func(addr string) *pipenet.Addr { xaddr := func(addr string) *pipenet.Addr {
a, err := net.ParseAddr(addr) a, err := net.ParseAddr(addr)
...@@ -176,17 +190,23 @@ func TestMasterStorage(t *testing.T) { ...@@ -176,17 +190,23 @@ func TestMasterStorage(t *testing.T) {
tc.Expect(netlisten("s:0")) tc.Expect(netlisten("s:0"))
tc.Expect(netconnect("s:1", "m:1", "m:0")) tc.Expect(netconnect("s:1", "m:1", "m:0"))
tc.ExpectPar( //tc.ExpectPar(
nettx("s:1", "m:1", "\x00\x00\x00\x01"), // handshake // nettx("s:1", "m:1", "\x00\x00\x00\x01"), // handshake
nettx("m:1", "s:1", "\x00\x00\x00\x01"), // nettx("m:1", "s:1", "\x00\x00\x00\x01"),
) //)
_ = nettx
// XXX temp // XXX temp
return //return
// M <- S .? RequestIdentification{...} + TODO test ID rejects // M <- S .? RequestIdentification{...} + TODO test ID rejects
println("111")
tc.Expect(netlisten("s:0")) // XXX no -> temp only to get complate
println("222")
return
// M.nodeTab <- Node(S) XXX order can be racy? // M.nodeTab <- Node(S) XXX order can be racy?
// M -> S .? AcceptIdentification{...} // M -> S .? AcceptIdentification{...}
// S.nodeTab <- Node(M) XXX order can be racy? // S.nodeTab <- Node(M) XXX order can be racy?
......
// Copyright (C) 2016-2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
package server
// tracepoints
import (
"../../neo"
_ "unsafe"
)
// TODO autogenerate vvv from "//trace:import path/to/neo"
// + check consistency (e.g. by hash in neo.trace and here must be the same)
//go:linkname neo_traceConnRecv aaaneo._traceConnRecv
var _neo_traceConnRecv func(*neo.Conn, neo.Msg)
//go:linkname neo_traceConnSend neo._traceConnSend
var _neo_traceConnSend func(*neo.Conn, neo.Msg)
// Copyright (C) 2016-2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
package neo
// tracepoints
// XXX put under 'build +tracedef'
// func traceConnRecv(c *Conn, msg Msg)
// func traceConnSend(c *Conn, msg Msg) // XXX -> traceConnSendPre ?
// TODO autogenerate vvv from ^^^
// XXX after https://github.com/golang/go/issues/19348 won't cost a function
// call when tracepoint is disabled
// XXX do we need *_Enabled() ?
var _traceConnRecv func(*Conn, Msg)
func traceConnRecv(c *Conn, msg Msg) {
println("A traceConnRecv", &_traceConnRecv)
if _traceConnRecv != nil {
println(" _traceConnRecv")
_traceConnRecv(c, msg)
}
}
var _traceConnSend func(*Conn, Msg)
func traceConnSend(c *Conn, msg Msg) {
println("A traceConnSend", &_traceConnSend)
if _traceConnSend != nil {
println(" _traceConnSend")
_traceConnSend(c, msg)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment