vdso_linux_amd64_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright © 2021 Jeffrey H. Johnson <trnsz@pobox.com>
  2. // Copyright © 2021 Gridfinity, LLC.
  3. // Copyright © 2019 Neal.
  4. // Copyright © 2018 lrita@163.com.
  5. //
  6. // Use of this source code is governed by the MIT
  7. // license that can be found in the LICENSE file.
  8. package gonuma_test
  9. import (
  10. "testing"
  11. gonuma "github.com/johnsonjh/gonuma"
  12. )
  13. func TestELFHash(t *testing.T) {
  14. tt := []struct {
  15. s string
  16. h uint32
  17. g uint32
  18. }{
  19. {s: "__vdso_gettimeofday", h: 0x315ca59, g: 0xb01bca00},
  20. {s: "__vdso_clock_gettime", h: 0xd35ec75, g: 0x6e43a318},
  21. {s: "__vdso_getcpu", h: 0xb01045, g: 0x6562b026},
  22. }
  23. for _, v := range tt {
  24. h := gonuma.ELFHash(v.s)
  25. if h != v.h {
  26. t.Errorf("%s got 0x%x", v.s, h)
  27. }
  28. g := gonuma.ELFGNUHash(v.s)
  29. if g != v.g {
  30. t.Errorf("%s got 0x%x", v.s, g)
  31. }
  32. }
  33. }
  34. func TestVdsoSym(t *testing.T) {
  35. tt := []struct {
  36. s string
  37. v bool
  38. }{
  39. {"__vdso_gettimeofday", true},
  40. {"__vdso_clock_gettime", true},
  41. {"__vdso_time", true},
  42. {"__vdso_getcpu", true},
  43. {"__abc", false},
  44. }
  45. for _, v := range tt {
  46. p := gonuma.VdsoSym(v.s)
  47. if x := p != 0; x != v.v {
  48. t.Errorf("VdsoSym %v got 0x%x", v.s, p)
  49. }
  50. }
  51. }