test_timezone.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import os
  2. import infra.basetest
  3. def boot_armv5_cpio(emulator, builddir):
  4. img = os.path.join(builddir, "images", "rootfs.cpio")
  5. emulator.boot(arch="armv5", kernel="builtin",
  6. options=["-initrd", img])
  7. emulator.login()
  8. class TestNoTimezone(infra.basetest.BRTest):
  9. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  10. """
  11. # BR2_TARGET_TZ_INFO is not set
  12. BR2_TARGET_ROOTFS_CPIO=y
  13. # BR2_TARGET_ROOTFS_TAR is not set
  14. """
  15. def test_run(self):
  16. boot_armv5_cpio(self.emulator, self.builddir)
  17. tz, _ = self.emulator.run("TZ=UTC date +%Z")
  18. self.assertEqual(tz[0].strip(), "UTC")
  19. # This test is Glibc specific since there is no Time Zone Database installed
  20. # and other C libraries use their own rule for returning time zone name or
  21. # abbreviation when TZ is empty or set with a not installed time zone data file.
  22. tz, _ = self.emulator.run("TZ= date +%Z")
  23. self.assertEqual(tz[0].strip(), "Universal")
  24. class TestAllTimezone(infra.basetest.BRTest):
  25. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  26. """
  27. BR2_TARGET_TZ_INFO=y
  28. BR2_TARGET_ROOTFS_CPIO=y
  29. # BR2_TARGET_ROOTFS_TAR is not set
  30. """
  31. def test_run(self):
  32. boot_armv5_cpio(self.emulator, self.builddir)
  33. tz, _ = self.emulator.run("date +%Z")
  34. self.assertEqual(tz[0].strip(), "UTC")
  35. tz, _ = self.emulator.run("TZ=UTC date +%Z")
  36. self.assertEqual(tz[0].strip(), "UTC")
  37. tz, _ = self.emulator.run("TZ=America/Los_Angeles date +%Z")
  38. self.assertEqual(tz[0].strip(), "PST")
  39. tz, _ = self.emulator.run("TZ=Europe/Paris date +%Z")
  40. self.assertEqual(tz[0].strip(), "CET")
  41. class TestNonDefaultLimitedTimezone(infra.basetest.BRTest):
  42. config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
  43. """
  44. BR2_TARGET_TZ_INFO=y
  45. BR2_TARGET_TZ_ZONELIST="northamerica"
  46. BR2_TARGET_LOCALTIME="America/New_York"
  47. BR2_TARGET_ROOTFS_CPIO=y
  48. # BR2_TARGET_ROOTFS_TAR is not set
  49. """
  50. def test_run(self):
  51. boot_armv5_cpio(self.emulator, self.builddir)
  52. tz, _ = self.emulator.run("date +%Z")
  53. self.assertEqual(tz[0].strip(), "EST")
  54. tz, _ = self.emulator.run("TZ=UTC date +%Z")
  55. self.assertEqual(tz[0].strip(), "UTC")
  56. tz, _ = self.emulator.run("TZ=America/Los_Angeles date +%Z")
  57. self.assertEqual(tz[0].strip(), "PST")
  58. tz, _ = self.emulator.run("TZ=Europe/Paris date +%Z")
  59. self.assertEqual(tz[0].strip(), "Europe")