1import os 2 3import infra.basetest 4 5BASIC_CONFIG = \ 6 """ 7 BR2_x86_pentium4=y 8 BR2_TOOLCHAIN_EXTERNAL=y 9 BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y 10 BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y 11 BR2_TOOLCHAIN_EXTERNAL_URL="http://autobuild.buildroot.org/toolchains/tarballs/br-i386-pentium4-full-2017.05-1078-g95b1dae.tar.bz2" 12 BR2_TOOLCHAIN_EXTERNAL_GCC_6=y 13 BR2_TOOLCHAIN_EXTERNAL_HEADERS_3_2=y 14 BR2_TOOLCHAIN_EXTERNAL_LOCALE=y 15 # BR2_TOOLCHAIN_EXTERNAL_HAS_THREADS_DEBUG is not set 16 BR2_TOOLCHAIN_EXTERNAL_CXX=y 17 BR2_TARGET_GENERIC_GETTY_PORT="ttyS0" 18 BR2_TARGET_GENERIC_GETTY_BAUDRATE_115200=y 19 BR2_LINUX_KERNEL=y 20 BR2_LINUX_KERNEL_CUSTOM_VERSION=y 21 BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.204" 22 BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y 23 BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="{}" 24 # BR2_TARGET_ROOTFS_TAR is not set 25 """.format(infra.filepath("conf/minimal-x86-qemu-kernel.config")) 26 27 28def test_mount_internal_external(emulator, builddir, internal=True, efi=False): 29 img = os.path.join(builddir, "images", "rootfs.iso9660") 30 if efi: 31 efi_img = os.path.join(builddir, "images", "OVMF.fd") 32 emulator.boot(arch="i386", options=["-cdrom", img, "-bios", efi_img]) 33 else: 34 emulator.boot(arch="i386", options=["-cdrom", img]) 35 emulator.login() 36 37 if internal: 38 cmd = "mount | grep 'rootfs on / type rootfs'" 39 else: 40 cmd = "mount | grep '/dev/root on / type iso9660'" 41 42 _, exit_code = emulator.run(cmd) 43 return exit_code 44 45 46def test_touch_file(emulator): 47 _, exit_code = emulator.run("touch test") 48 return exit_code 49 50# 51# Grub 2 52 53 54class TestIso9660Grub2External(infra.basetest.BRTest): 55 config = BASIC_CONFIG + \ 56 """ 57 BR2_TARGET_ROOTFS_ISO9660=y 58 # BR2_TARGET_ROOTFS_ISO9660_INITRD is not set 59 BR2_TARGET_GRUB2=y 60 BR2_TARGET_GRUB2_BOOT_PARTITION="cd" 61 BR2_TARGET_GRUB2_BUILTIN_MODULES_PC="boot linux ext2 fat part_msdos part_gpt normal biosdisk iso9660" 62 BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}" 63 """.format(infra.filepath("conf/grub2.cfg")) 64 65 def test_run(self): 66 exit_code = test_mount_internal_external(self.emulator, 67 self.builddir, internal=False) 68 self.assertEqual(exit_code, 0) 69 70 exit_code = test_touch_file(self.emulator) 71 self.assertEqual(exit_code, 1) 72 73 74class TestIso9660Grub2ExternalCompress(infra.basetest.BRTest): 75 config = BASIC_CONFIG + \ 76 """ 77 BR2_TARGET_ROOTFS_ISO9660=y 78 # BR2_TARGET_ROOTFS_ISO9660_INITRD is not set 79 BR2_TARGET_ROOTFS_ISO9660_TRANSPARENT_COMPRESSION=y 80 BR2_TARGET_GRUB2=y 81 BR2_TARGET_GRUB2_BOOT_PARTITION="cd" 82 BR2_TARGET_GRUB2_BUILTIN_MODULES_PC="boot linux ext2 fat part_msdos part_gpt normal biosdisk iso9660" 83 BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}" 84 """.format(infra.filepath("conf/grub2.cfg")) 85 86 def test_run(self): 87 exit_code = test_mount_internal_external(self.emulator, 88 self.builddir, internal=False) 89 self.assertEqual(exit_code, 0) 90 91 exit_code = test_touch_file(self.emulator) 92 self.assertEqual(exit_code, 1) 93 94 95class TestIso9660Grub2Internal(infra.basetest.BRTest): 96 config = BASIC_CONFIG + \ 97 """ 98 BR2_TARGET_ROOTFS_ISO9660=y 99 BR2_TARGET_ROOTFS_ISO9660_INITRD=y 100 BR2_TARGET_GRUB2=y 101 BR2_TARGET_GRUB2_BOOT_PARTITION="cd" 102 BR2_TARGET_GRUB2_BUILTIN_MODULES_PC="boot linux ext2 fat part_msdos part_gpt normal biosdisk iso9660" 103 BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}" 104 """.format(infra.filepath("conf/grub2.cfg")) 105 106 def test_run(self): 107 exit_code = test_mount_internal_external(self.emulator, 108 self.builddir, internal=True) 109 self.assertEqual(exit_code, 0) 110 111 exit_code = test_touch_file(self.emulator) 112 self.assertEqual(exit_code, 0) 113 114 115class TestIso9660Grub2EFI(infra.basetest.BRTest): 116 config = BASIC_CONFIG + \ 117 """ 118 BR2_TARGET_ROOTFS_ISO9660=y 119 BR2_TARGET_ROOTFS_ISO9660_INITRD=y 120 BR2_TARGET_GRUB2=y 121 BR2_TARGET_GRUB2_I386_EFI=y 122 BR2_TARGET_GRUB2_BUILTIN_MODULES_EFI="boot linux ext2 fat part_msdos part_gpt normal iso9660" 123 BR2_TARGET_GRUB2_BUILTIN_CONFIG_EFI="{}" 124 BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}" 125 BR2_TARGET_EDK2=y 126 """.format(infra.filepath("conf/grub2-efi.cfg"), 127 infra.filepath("conf/grub2.cfg")) 128 129 def test_run(self): 130 exit_code = test_mount_internal_external(self.emulator, 131 self.builddir, internal=True, 132 efi=True) 133 self.assertEqual(exit_code, 0) 134 135 exit_code = test_touch_file(self.emulator) 136 self.assertEqual(exit_code, 0) 137 138 139class TestIso9660Grub2Hybrid(infra.basetest.BRTest): 140 config = BASIC_CONFIG + \ 141 """ 142 BR2_TARGET_ROOTFS_ISO9660=y 143 BR2_TARGET_ROOTFS_ISO9660_INITRD=y 144 BR2_TARGET_GRUB2=y 145 BR2_TARGET_GRUB2_I386_PC=y 146 BR2_TARGET_GRUB2_I386_EFI=y 147 BR2_TARGET_GRUB2_BOOT_PARTITION="cd" 148 BR2_TARGET_GRUB2_BUILTIN_MODULES_PC="boot linux ext2 fat squash4 part_msdos part_gpt normal iso9660 biosdisk" 149 BR2_TARGET_GRUB2_BUILTIN_CONFIG_PC="" 150 BR2_TARGET_GRUB2_BUILTIN_MODULES_EFI="boot linux ext2 fat squash4 part_msdos part_gpt normal iso9660 efi_gop" 151 BR2_TARGET_GRUB2_BUILTIN_CONFIG_EFI="{}" 152 BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}" 153 BR2_TARGET_EDK2=y 154 """.format(infra.filepath("conf/grub2-efi.cfg"), 155 infra.filepath("conf/grub2.cfg")) 156 157 def test_run(self): 158 exit_code = test_mount_internal_external(self.emulator, 159 self.builddir, internal=True, 160 efi=False) 161 self.assertEqual(exit_code, 0) 162 163 exit_code = test_touch_file(self.emulator) 164 self.assertEqual(exit_code, 0) 165 166 self.emulator.stop() 167 168 exit_code = test_mount_internal_external(self.emulator, 169 self.builddir, internal=True, 170 efi=True) 171 self.assertEqual(exit_code, 0) 172 173 exit_code = test_touch_file(self.emulator) 174 self.assertEqual(exit_code, 0) 175 176 177# 178# Syslinux 179 180 181class TestIso9660SyslinuxExternal(infra.basetest.BRTest): 182 config = BASIC_CONFIG + \ 183 """ 184 BR2_TARGET_ROOTFS_ISO9660=y 185 # BR2_TARGET_ROOTFS_ISO9660_INITRD is not set 186 BR2_TARGET_ROOTFS_ISO9660_HYBRID=y 187 BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}" 188 BR2_TARGET_SYSLINUX=y 189 """.format(infra.filepath("conf/isolinux.cfg")) 190 191 def test_run(self): 192 exit_code = test_mount_internal_external(self.emulator, 193 self.builddir, internal=False) 194 self.assertEqual(exit_code, 0) 195 196 exit_code = test_touch_file(self.emulator) 197 self.assertEqual(exit_code, 1) 198 199 200class TestIso9660SyslinuxExternalCompress(infra.basetest.BRTest): 201 config = BASIC_CONFIG + \ 202 """ 203 BR2_TARGET_ROOTFS_ISO9660=y 204 # BR2_TARGET_ROOTFS_ISO9660_INITRD is not set 205 BR2_TARGET_ROOTFS_ISO9660_TRANSPARENT_COMPRESSION=y 206 BR2_TARGET_ROOTFS_ISO9660_HYBRID=y 207 BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}" 208 BR2_TARGET_SYSLINUX=y 209 """.format(infra.filepath("conf/isolinux.cfg")) 210 211 def test_run(self): 212 exit_code = test_mount_internal_external(self.emulator, 213 self.builddir, internal=False) 214 self.assertEqual(exit_code, 0) 215 216 exit_code = test_touch_file(self.emulator) 217 self.assertEqual(exit_code, 1) 218 219 220class TestIso9660SyslinuxInternal(infra.basetest.BRTest): 221 config = BASIC_CONFIG + \ 222 """ 223 BR2_TARGET_ROOTFS_ISO9660=y 224 BR2_TARGET_ROOTFS_ISO9660_INITRD=y 225 BR2_TARGET_ROOTFS_ISO9660_HYBRID=y 226 BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="{}" 227 BR2_TARGET_SYSLINUX=y 228 """.format(infra.filepath("conf/isolinux.cfg")) 229 230 def test_run(self): 231 exit_code = test_mount_internal_external(self.emulator, 232 self.builddir, internal=True) 233 self.assertEqual(exit_code, 0) 234 235 exit_code = test_touch_file(self.emulator) 236 self.assertEqual(exit_code, 0) 237