From 94c40d701a9a258a31d679b09d0e89c3a03e4d9d Mon Sep 17 00:00:00 2001 From: Aiden Grossman Date: Fri, 2 Feb 2024 21:59:34 -0800 Subject: [PATCH] Add test target for llvm-cm (#42) This patch sets up a ninja target for testing llvm-cm, akin to the tool specific test targets in the monorepo. This allows for actually running the tests. Documentation has been added to the README. --- README.md | 6 ++++++ llvm_cm/CMakeLists.txt | 10 ++++++++++ llvm_cm/test/X86/bb-frequency.s | 2 +- llvm_cm/test/X86/lit.local.cfg | 2 -- llvm_cm/test/lit.cfg | 19 +++++++++++++++++++ llvm_cm/test/lit.site.cfg.in | 12 ++++++++++++ 6 files changed, 48 insertions(+), 3 deletions(-) delete mode 100644 llvm_cm/test/X86/lit.local.cfg create mode 100644 llvm_cm/test/lit.cfg create mode 100644 llvm_cm/test/lit.site.cfg.in diff --git a/README.md b/README.md index 0262ceced110e5..3c38c1c7889aec 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,12 @@ ninja llvm-granite llvm-cm Where `LLVM_PROJECT_SRC` is the absolute path to your local llvm repo, and `GEMATRIA_SRC` the path to this (the gematria) repo. +To run the `llvm-cm` tests, you can run the following target: + +```shell +ninja check-llvm-tools-llvm-cm +``` + ### Platform Support We develop and test our code on Linux and x86-64, and we test it on Mac OS X and diff --git a/llvm_cm/CMakeLists.txt b/llvm_cm/CMakeLists.txt index f7c6b56eb7ad42..6e1df1ab6d976d 100644 --- a/llvm_cm/CMakeLists.txt +++ b/llvm_cm/CMakeLists.txt @@ -1 +1,11 @@ add_subdirectory(tools) + +configure_lit_site_cfg( + "${CMAKE_CURRENT_SOURCE_DIR}/test/lit.site.cfg.in" + "${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg" +) + +add_lit_testsuite(check-llvm-tools-llvm-cm "Running llvm-cm tests" + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS "llvm-cm" "yaml2obj" "not" "FileCheck" "count" "split-file" "llvm-mc" +) diff --git a/llvm_cm/test/X86/bb-frequency.s b/llvm_cm/test/X86/bb-frequency.s index 18970e36b553a7..301a0d4533d3be 100644 --- a/llvm_cm/test/X86/bb-frequency.s +++ b/llvm_cm/test/X86/bb-frequency.s @@ -1,5 +1,5 @@ ## LLVM-CM frequency weighting test. -# REQUIRES: x86 +# REQUIRES: target-x86_64, native # RUN: split-file %s %t # RUN: llvm-mc -o %t.o --filetype=obj -triple=x86_64-unknown-linux-gnu %t/bb-frequency-test.s # RUN: llvm-cm %t.o --csv=%t/bb-frequency.csv -granite_model=%S/Inputs/gb-token-mit-2022_12_02.tflite -evaluator=granite| FileCheck %t/bb-frequency-test.s diff --git a/llvm_cm/test/X86/lit.local.cfg b/llvm_cm/test/X86/lit.local.cfg deleted file mode 100644 index 42bf50dcc13c35..00000000000000 --- a/llvm_cm/test/X86/lit.local.cfg +++ /dev/null @@ -1,2 +0,0 @@ -if not "X86" in config.root.targets: - config.unsupported = True diff --git a/llvm_cm/test/lit.cfg b/llvm_cm/test/lit.cfg new file mode 100644 index 00000000000000..51b2d5d30ac8b7 --- /dev/null +++ b/llvm_cm/test/lit.cfg @@ -0,0 +1,19 @@ +import os + +import lit.formats + +from lit.llvm import llvm_config + +config.name = "llvm-cm" +config.test_format = lit.formats.ShTest(execute_external=False) + +config.suffixes = [".s", ".test"] + +config.test_source_root = os.path.dirname(__file__) +config.test_exec_root = config.obj_root + +llvm_config.use_default_substitutions() +config.substitutions.append(("yaml2obj", llvm_config.use_llvm_tool("yaml2obj"))) +config.substitutions.append(("llvm-cm", llvm_config.use_llvm_tool("llvm-cm"))) +config.substitutions.append(("split-file", llvm_config.use_llvm_tool("split-file"))) +config.substitutions.append(("llvm-mc", llvm_config.use_llvm_tool("llvm-mc"))) diff --git a/llvm_cm/test/lit.site.cfg.in b/llvm_cm/test/lit.site.cfg.in new file mode 100644 index 00000000000000..4b95c903cc5641 --- /dev/null +++ b/llvm_cm/test/lit.site.cfg.in @@ -0,0 +1,12 @@ +@LIT_SITE_CFG_IN_HEADER@ + +config.host_triple = "@LLVM_HOST_TRIPLE@" +config.target_triple = "@LLVM_TARGET_TRIPLE@" +config.src_root = "@LLVM_SOURCE_DIR@" +config.obj_root = "@LLVM_BINARY_DIR@" +config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@") + +import lit.llvm +lit.llvm.initialize(lit_config, config) + +lit_config.load_config(config, "@LLVM_EXTERNAL_GEMATRIA_SOURCE_DIR@/llvm_cm/test/lit.cfg")