lib9p

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

stat_unix_test.go (784B)


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