controller_linux_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package controller
  2. import "testing"
  3. import "os"
  4. import "syscall"
  5. // import "fmt"
  6. import "gitlab.com/beoran/galago/os/linux"
  7. const IN = "/dev/input/by-id/usb-0583_USB_2-axis_8-button_gamepad-event-joystick"
  8. func TestGetDriverVersion(t * testing.T) {
  9. file , err := os.OpenFile(IN, syscall.O_RDWR, 0666)
  10. if err != nil {
  11. t.Errorf("Error OpenFile: %s\n", err)
  12. return
  13. }
  14. defer file.Close()
  15. version, err := GetDriverVersion(file)
  16. if err != nil {
  17. t.Errorf("Error GetDriverVersion: %s (%s %x)\n", err,
  18. "EVIOCGVERSION", linux.EVIOCGVERSION)
  19. return
  20. }
  21. if version != linux.EV_VERSION {
  22. t.Errorf("Version %x should be %x", version, linux.EV_VERSION)
  23. }
  24. t.Logf("GetDriverVersion: %d", version)
  25. }
  26. func TestGetName(t * testing.T) {
  27. file , err := os.OpenFile(IN, syscall.O_RDWR, 0666)
  28. if err != nil {
  29. t.Errorf("Error OpenFile: %s\n", err)
  30. return
  31. }
  32. defer file.Close()
  33. name, err := GetName(file)
  34. if err != nil {
  35. t.Errorf("Error GetName: %s\n", err)
  36. return
  37. }
  38. t.Logf("GetName: %s", name)
  39. }
  40. func TestGetId(t * testing.T) {
  41. file , err := os.OpenFile(IN, syscall.O_RDWR, 0666)
  42. if err != nil {
  43. t.Errorf("Error OpenFile: %s\n", err)
  44. return
  45. }
  46. defer file.Close()
  47. id, err := GetId(file)
  48. if err != nil {
  49. t.Errorf("Error GetId: %s\n", err)
  50. return
  51. }
  52. t.Logf("GetId: bustype 0x%x, vendor 0x%x, product 0x%x, version 0x%x",
  53. id.Bustype, id.Vendor, id.Product, id.Version)
  54. }