base.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import os
  2. import subprocess
  3. import infra.basetest
  4. class InitSystemBase(infra.basetest.BRTest):
  5. def start_emulator(self, fs_type, kernel=None, dtb=None, init=None):
  6. img = os.path.join(self.builddir, "images", "rootfs.{}".format(fs_type))
  7. subprocess.call(["truncate", "-s", "%1M", img])
  8. options = ["-drive",
  9. "file={},if=sd,format=raw".format(img),
  10. "-M", "vexpress-a9"]
  11. if kernel is None:
  12. kernel = "builtin"
  13. else:
  14. kernel = os.path.join(self.builddir, "images", kernel)
  15. options.extend(["-dtb", os.path.join(self.builddir, "images",
  16. "{}.dtb".format(dtb))])
  17. kernel_cmdline = ["root=/dev/mmcblk0",
  18. "rootfstype={}".format(fs_type),
  19. "rootwait",
  20. "ro",
  21. "console=ttyAMA0"]
  22. if init is not None:
  23. kernel_cmdline.extend(["init={}".format(init)])
  24. self.emulator.boot(arch="armv7",
  25. kernel=kernel,
  26. kernel_cmdline=kernel_cmdline,
  27. options=options)
  28. if init is None:
  29. self.emulator.login()
  30. def check_init(self, path):
  31. cmd = "cmp /proc/1/exe {}".format(path)
  32. _, exit_code = self.emulator.run(cmd)
  33. self.assertEqual(exit_code, 0)
  34. def check_network(self, interface, exitCode=0):
  35. cmd = "ip addr show {} |grep inet".format(interface)
  36. _, exit_code = self.emulator.run(cmd)
  37. self.assertEqual(exit_code, exitCode)