lib9p

Go 9P library.
Log | Files | Refs | LICENSE

file_test.go (586B)


      1 package lib9p
      2 
      3 import (
      4 	"context"
      5 	"testing"
      6 )
      7 
      8 func BenchmarkRead(b *testing.B) {
      9 	c, rc := setupConn(testfs)
     10 	tc := make(chan *request)
     11 	ctx, cancel := context.WithCancel(context.Background())
     12 	defer cancel()
     13 	go sRead(ctx, c, tc)
     14 	fid, err := c.fPool.add(0)
     15 	if err != nil {
     16 		b.Fatal(err)
     17 	}
     18 	fid.omode = OREAD
     19 	fid.file, err = testfs.OpenFile("dir/file", O_RDONLY)
     20 	if err != nil {
     21 		b.Fatal(err)
     22 	}
     23 	fid.path = "dir/file"
     24 	for i := 0; i < b.N; i++ {
     25 		tc <- &request{ifcall: &TRead{Count: 8 * 1024}}
     26 		if rerr, ok := (<-rc).ofcall.(*RError); ok {
     27 			b.Fatal(rerr.Ename)
     28 		}
     29 	}
     30 }