test_msr_tools.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import os
  2. import infra.basetest
  3. class TestMsrTools(infra.basetest.BRTest):
  4. config = \
  5. """
  6. BR2_x86_64=y
  7. BR2_x86_corei7=y
  8. BR2_TOOLCHAIN_EXTERNAL=y
  9. BR2_LINUX_KERNEL=y
  10. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  11. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="5.15.55"
  12. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  13. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/x86_64/linux.config"
  14. BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{}"
  15. BR2_LINUX_KERNEL_NEEDS_HOST_LIBELF=y
  16. BR2_PACKAGE_MSR_TOOLS=y
  17. BR2_TARGET_ROOTFS_CPIO=y
  18. # BR2_TARGET_ROOTFS_TAR is not set
  19. """.format(
  20. infra.filepath("tests/package/test_msr_tools/linux.config"))
  21. def test_run(self):
  22. kernel = os.path.join(self.builddir, "images", "bzImage")
  23. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  24. self.emulator.boot(
  25. arch="x86_64",
  26. kernel=kernel, kernel_cmdline=["console=ttyS0"],
  27. options=["-cpu", "Nehalem", "-m", "320", "-initrd", cpio_file]
  28. )
  29. self.emulator.login()
  30. # CPU ID.
  31. cmd = "cpuid"
  32. self.assertRunOk(cmd)
  33. # Write MSR.
  34. # We write to TSC_AUX.
  35. cmd = "wrmsr 0xc0000103 0x1234567812345678"
  36. self.assertRunOk(cmd)
  37. # Read MSR.
  38. # We read back the TSC_AUX and we verify that we read back the correct
  39. # value.
  40. cmd = "rdmsr 0xc0000103"
  41. output, exit_code = self.emulator.run(cmd)
  42. self.assertEqual(exit_code, 0)
  43. self.assertEqual(output[0], "1234567812345678")