2019-01-05 18:18:49 -08:00
|
|
|
package attr
|
2018-12-30 19:57:01 -08:00
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
|
|
func TestAttributeAsm(t *testing.T) {
|
|
|
|
|
cases := []struct {
|
|
|
|
|
Attribute Attribute
|
|
|
|
|
Expect string
|
|
|
|
|
}{
|
|
|
|
|
{0, "0"},
|
|
|
|
|
{32768, "32768"},
|
|
|
|
|
{1, "NOPROF"},
|
|
|
|
|
{DUPOK, "DUPOK"},
|
|
|
|
|
{RODATA | NOSPLIT, "NOSPLIT|RODATA"},
|
|
|
|
|
{WRAPPER | 16384 | NOPTR, "NOPTR|WRAPPER|16384"},
|
2018-12-31 17:30:03 -08:00
|
|
|
{NEEDCTXT + NOFRAME + TLSBSS, "NEEDCTXT|TLSBSS|NOFRAME"},
|
2019-09-27 13:11:50 +09:00
|
|
|
{REFLECTMETHOD, "REFLECTMETHOD"},
|
|
|
|
|
{TOPFRAME, "TOPFRAME"},
|
2018-12-30 19:57:01 -08:00
|
|
|
}
|
|
|
|
|
for _, c := range cases {
|
|
|
|
|
got := c.Attribute.Asm()
|
|
|
|
|
if got != c.Expect {
|
|
|
|
|
t.Errorf("Attribute(%d).Asm() = %#v; expect %#v", c.Attribute, got, c.Expect)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAttributeContainsTextFlags(t *testing.T) {
|
|
|
|
|
cases := []struct {
|
|
|
|
|
Attribute Attribute
|
|
|
|
|
Expect bool
|
|
|
|
|
}{
|
|
|
|
|
{0, false},
|
|
|
|
|
{32768, false},
|
|
|
|
|
{1, true},
|
|
|
|
|
{DUPOK, true},
|
|
|
|
|
{WRAPPER | 16384 | NOPTR, true},
|
|
|
|
|
}
|
|
|
|
|
for _, c := range cases {
|
|
|
|
|
if c.Attribute.ContainsTextFlags() != c.Expect {
|
|
|
|
|
t.Errorf("%s: ContainsTextFlags() expected %#v", c.Attribute.Asm(), c.Expect)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-11 13:25:13 -07:00
|
|
|
|
|
|
|
|
func TestAttributeTestMethods(t *testing.T) {
|
|
|
|
|
cases := []struct {
|
|
|
|
|
Attribute Attribute
|
|
|
|
|
Predicate func(Attribute) bool
|
|
|
|
|
Expect bool
|
|
|
|
|
}{
|
|
|
|
|
// Confirm logic works as expected.
|
|
|
|
|
{DUPOK | NOSPLIT, Attribute.DUPOK, true},
|
|
|
|
|
{DUPOK | NOSPLIT, Attribute.NOSPLIT, true},
|
|
|
|
|
{DUPOK | NOSPLIT, Attribute.NOFRAME, false},
|
|
|
|
|
|
|
|
|
|
// Basic test for every method.
|
|
|
|
|
{NOPROF, Attribute.NOPROF, true},
|
|
|
|
|
{DUPOK, Attribute.DUPOK, true},
|
|
|
|
|
{NOSPLIT, Attribute.NOSPLIT, true},
|
|
|
|
|
{RODATA, Attribute.RODATA, true},
|
|
|
|
|
{NOPTR, Attribute.NOPTR, true},
|
|
|
|
|
{WRAPPER, Attribute.WRAPPER, true},
|
|
|
|
|
{NEEDCTXT, Attribute.NEEDCTXT, true},
|
|
|
|
|
{TLSBSS, Attribute.TLSBSS, true},
|
|
|
|
|
{NOFRAME, Attribute.NOFRAME, true},
|
|
|
|
|
{REFLECTMETHOD, Attribute.REFLECTMETHOD, true},
|
|
|
|
|
{TOPFRAME, Attribute.TOPFRAME, true},
|
|
|
|
|
}
|
|
|
|
|
for _, c := range cases {
|
|
|
|
|
if c.Predicate(c.Attribute) != c.Expect {
|
|
|
|
|
t.Errorf("%s: expected %#v", c.Attribute.Asm(), c.Expect)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|