test_clang.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. config = \
  7. """
  8. BR2_aarch64=y
  9. BR2_TOOLCHAIN_EXTERNAL=y
  10. BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
  11. BR2_LINUX_KERNEL=y
  12. BR2_LINUX_KERNEL_CUSTOM_VERSION=y
  13. BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.16.7"
  14. BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
  15. BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config"
  16. BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y
  17. BR2_PACKAGE_COMPILER_RT=y
  18. BR2_PACKAGE_LLVM=y
  19. BR2_TARGET_ROOTFS_CPIO=y
  20. BR2_TARGET_ROOTFS_CPIO_GZIP=y
  21. # BR2_TARGET_ROOTFS_TAR is not set
  22. BR2_PACKAGE_LIBFUZZER=y
  23. """
  24. def login(self):
  25. img = os.path.join(self.builddir, "images", "rootfs.cpio.gz")
  26. kern = os.path.join(self.builddir, "images", "Image")
  27. # Sanitizers overallocate memory and the minimum that seemed to work was 512MB
  28. self.emulator.boot(arch="aarch64",
  29. kernel=kern,
  30. kernel_cmdline=["console=ttyAMA0"],
  31. options=["-M", "virt", "-cpu", "cortex-a53", "-m", "512", "-initrd", img])
  32. self.emulator.login()
  33. def test_run(self):
  34. self.login()
  35. # The test case verifies the application executes and that
  36. # the symbolizer is working to decode the stack trace.
  37. cmd = "fuzz_me 2>&1 | grep heap-buffer-overflow"
  38. _, exit_code = self.emulator.run(cmd, FUZZ_TIMEOUT)
  39. self.assertEqual(exit_code, 0)