test_gpsd.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import os
  2. import time
  3. import infra.basetest
  4. class TestGpsd(infra.basetest.BRTest):
  5. rootfs_overlay = \
  6. infra.filepath("tests/package/test_gpsd/rootfs-overlay")
  7. # This test is using the gpsfake Python script.
  8. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  9. f"""
  10. BR2_PACKAGE_GPSD=y
  11. BR2_PACKAGE_GPSD_PYTHON=y
  12. BR2_ROOTFS_OVERLAY="{rootfs_overlay}"
  13. BR2_TARGET_ROOTFS_CPIO=y
  14. # BR2_TARGET_ROOTFS_TAR is not set
  15. """
  16. def test_run(self):
  17. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  18. self.emulator.boot(arch="armv5",
  19. kernel="builtin",
  20. options=["-initrd", cpio_file])
  21. self.emulator.login()
  22. # We check the program can execute.
  23. self.assertRunOk("gpsd --version")
  24. # Since gpsd needs a real GPS device, we stop the service.
  25. self.assertRunOk("/etc/init.d/S50gpsd stop")
  26. # We start the "gpsfake" GPS emulator instead.
  27. cmd = "gpsfake"
  28. cmd += " --slow --cycle 0.1 --quiet"
  29. cmd += " /root/udp-nmea.log &> /dev/null &"
  30. self.assertRunOk(cmd)
  31. # Wait a bit, to let the gpsfake and gpsd to settle...
  32. time.sleep(3 * self.timeout_multiplier)
  33. # List the GPS devices. We should see our local UDP test GPS.
  34. out, ret = self.emulator.run("gpsctl")
  35. self.assertEqual(ret, 0)
  36. self.assertTrue(out[0].startswith("udp://127.0.0.1"))
  37. self.assertIn("NMEA0183", out[0])
  38. # Collect some of our fake GPS data, and check we got the
  39. # coordinates from our test data file.
  40. # Our expected coordinates are:
  41. # https://www.openstreetmap.org/#map=19/43.60439/1.44336
  42. out, ret = self.emulator.run("gpscsv --header 0 --count 3")
  43. self.assertEqual(ret, 0)
  44. _, gps_lat, gps_long, _ = out[0].split(",")
  45. self.assertAlmostEqual(float(gps_lat), 43.60439)
  46. self.assertAlmostEqual(float(gps_long), 1.44336)