Commit d660688f authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime/race: add tests for method thunks

R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/10257043
parent f84cbd09
......@@ -1811,3 +1811,90 @@ And Brutus is an honourable man.`
}
_ = res
}
type Base int
func (b *Base) Foo() int {
return 42
}
func (b Base) Bar() int {
return int(b)
}
func TestNoRaceMethodThunk(t *testing.T) {
type Derived struct {
pad int
Base
}
var d Derived
done := make(chan bool)
go func() {
_ = d.Foo()
done <- true
}()
d = Derived{}
<-done
}
func TestRaceMethodThunk(t *testing.T) {
type Derived struct {
pad int
*Base
}
var d Derived
done := make(chan bool)
go func() {
_ = d.Foo()
done <- true
}()
d = Derived{}
<-done
}
func TestRaceMethodThunk2(t *testing.T) {
type Derived struct {
pad int
Base
}
var d Derived
done := make(chan bool)
go func() {
_ = d.Bar()
done <- true
}()
d = Derived{}
<-done
}
func TestRaceMethodThunk3(t *testing.T) {
type Derived struct {
pad int
*Base
}
var d Derived
d.Base = new(Base)
done := make(chan bool)
go func() {
_ = d.Bar()
done <- true
}()
d.Base = new(Base)
<-done
}
func TestRaceMethodThunk4(t *testing.T) {
type Derived struct {
pad int
*Base
}
var d Derived
d.Base = new(Base)
done := make(chan bool)
go func() {
_ = d.Bar()
done <- true
}()
*(*int)(d.Base) = 42
<-done
}
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