lib9p

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

file_test.go (967B)


      1 package diskfs
      2 
      3 import (
      4 	"context"
      5 	"io"
      6 	"testing"
      7 
      8 	"git.mtkn.jp/lib9p"
      9 	"git.mtkn.jp/lib9p/client"
     10 )
     11 
     12 func BenchmarkRead(b *testing.B) {
     13 	testdir := "../testdir"
     14 	cr, sw := io.Pipe()
     15 	defer cr.Close()
     16 	defer sw.Close()
     17 	sr, cw := io.Pipe()
     18 	defer sr.Close()
     19 	defer cw.Close()
     20 	ctx, cancel := context.WithCancel(context.Background())
     21 	defer cancel()
     22 	disk, err := Open(testdir)
     23 	if err != nil {
     24 		b.Fatalf("open dir: %v", err)
     25 	}
     26 	s := lib9p.NewServer(disk)
     27 	go s.Serve(ctx, sr, sw)
     28 	c := client.NewClient(ctx, 8*1024, "kenji", cr, cw)
     29 	_, err = c.Attach(^uint16(0), 0, lib9p.NOFID, "kenji", "")
     30 	if err != nil {
     31 		b.Fatalf("attach: %v", err)
     32 	}
     33 	wqid, err := c.Walk(0, 0, 1, []string{"a"})
     34 	if err != nil || len(wqid) != 1 {
     35 		b.Fatalf("walk: %v", err)
     36 	}
     37 	_, _, err = c.Open(0, 1, lib9p.OREAD)
     38 	if err != nil {
     39 		b.Fatalf("open: %v", err)
     40 	}
     41 	for i := 0; i < b.N; i++ {
     42 		_, err := c.Read(0, 1, 0, 8*1024)
     43 		if err != nil {
     44 			b.Fatalf("read: %v", err)
     45 		}
     46 	}
     47 }