github.com/leslie-fei/fastcache@v0.0.0-20240520092641-b7a9eb05711f/shm/shm_test.go (about)

     1  package shm
     2  
     3  import "testing"
     4  
     5  func TestNewMemory(t *testing.T) {
     6  
     7  	mem := NewMemory("/shm/test", 1024, true)
     8  
     9  	if err := mem.Attach(); nil != err {
    10  		t.Fatal(err)
    11  	}
    12  
    13  	p1 := (*uint32)(mem.Ptr())
    14  	*p1 = 1234567
    15  
    16  	p2 := (*uint32)(mem.PtrOffset(0))
    17  
    18  	if *p1 != *p2 {
    19  		t.Fatal("not equal:", *p1, "!=", *p2)
    20  	}
    21  
    22  	if err := mem.Detach(); nil != err {
    23  		t.Fatal(err)
    24  	}
    25  }