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