test_clang.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import os
  2. import infra.basetest
  3. FUZZ_TIMEOUT = 120
  4. class TestClangCompilerRT(infra.basetest.BRTest):
  5. br2_external = [infra.filepath("tests/package/br2-external/clang-compiler-rt")]
  6. # Without this option the test fails due to insufficient address space for 64-bit allocator
  7. va48_fragment = infra.filepath("tests/package/test_clang/linux-arm64-va48.fragment")
  8. config = \
  9. f"""
  10. BR2_aarch64=y
  11. BR2_TOOLCHAIN_EXTERNAL=y
  12. BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
  13. BR2_LINUX_KERNEL=y
  14. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  15. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.283"
  16. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  17. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
  18. BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{va48_fragment}"
  19. BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
  20. BR2_PACKAGE_COMPILER_RT=y
  21. BR2_PACKAGE_LLVM=y
  22. BR2_TARGET_ROOTFS_CPIO=y
  23. BR2_TARGET_ROOTFS_CPIO_GZIP=y
  24. # BR2_TARGET_ROOTFS_TAR is not set
  25. BR2_PACKAGE_LIBFUZZER=y
  26. """
  27. def login(self):
  28. img = os.path.join(self.builddir, "images", "rootfs.cpio.gz")
  29. kern = os.path.join(self.builddir, "images", "Image")
  30. # Sanitizers overallocate memory and the minimum that seemed to work was 512MB
  31. self.emulator.boot(arch="aarch64",
  32. kernel=kern,
  33. kernel_cmdline=["console=ttyAMA0"],
  34. options=["-M", "virt", "-cpu", "cortex-a53", "-m", "512", "-initrd", img])
  35. self.emulator.login()
  36. def test_run(self):
  37. self.login()
  38. # The test case verifies the application executes and that
  39. # the symbolizer is working to decode the stack trace.
  40. cmd = "fuzz_me 2>&1 | grep heap-buffer-overflow"
  41. _, exit_code = self.emulator.run(cmd, FUZZ_TIMEOUT)
  42. self.assertEqual(exit_code, 0)