LLVM LIT测试框架

不依赖LLVM任何库的LIT

LLVM LIT测试

  • LIT是一个测试基础设施,最初是为LLVM的回归测试而开发的

  • 现在可以用在LLVM之外

  • Python实现

pip3 install lit

  • FileCheck工具(配合lit,基于正则表达式工具)
pip3 install filecheck

最简单的使用

文件布局

test git:(main)X tree
lit.cfg.py
x.c

lit.cfg.py

import lit.formats
config.name ="My lit Example"
config.test_format =lit.formats.ShTest(True)
config.suffixes =['.c]

x.C

//RUN:CC%s-O%t
//RUN:%t|grep -e "hello lit"

在这里插入图片描述
执行测试
在这里插入图片描述

在CMakeLists中使用

文件布局
在这里插入图片描述
lit.site.cfg.py.in

  • lit的工作目录
  • lit.cfg.py:需要执行哪些源文件
  • llvm-lit
  • CMakeLists.txt
  • lit.local.cfg可以配置执行的是脚本还是源码里面的注释

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

  • %CC表示clang
  • %FILECHECK2表示"/home/ubuntu/.local/bin/filecheck"

在这里插入图片描述
FILECHECK2做的事情比较代码实际输出与**//check后面的字符串**是否匹配,匹配方式是前缀匹配

执行
在这里插入图片描述

测试情况1
在这里插入图片描述
测试情况2
在这里插入图片描述

LLVM测试框架

单元测试

gtest的应用以及实例

在这里插入图片描述

运行所有单元测试的指令:

 make check-llvm-unit
操作描述命令
Run all unit tests% make check-llvm-unit
Run all regression tests% make check-llvm
Run regression individual test% llvm-lit ~/llvm/test/Integer/BitPacked.ll
Run regression subsets% llvm-lit ~/llvm/test/CodeGen/ARM
Run LLVM and Clang% make check-all

在这里插入图片描述

在这里插入图片描述

回归测试

在这里插入图片描述

运行所有回归测试的指令:(需在build目录下运行)
% make check-llvm

运行单个测试用例:
% 1lvm-lit ~/llvm/test/CodeGen/ARM

运行LLVM和Clang:
make check-all

Sub-directories:
Analysis:检查Analysis是否都通过
Archive:检查Archive库
Assembler:检查汇编读取器/写入器的功能
Bitcode:检查位码读取/写入功能
CodeGen:检查代码生成和每个目标
Features:检查LLVM语言的各种特性
Linker:测试bitcode链接
Transforms:测试每个标量转换、IPO和实用程序转换,以确保它们转换无误
Verifier:测试IRverifier.

Lit的功能以及应用

用于执行LLVM和Clang测试套件的可移植工具
轻量级的测试工具,具有尽可能简洁的用户界面
可配置性

基本选项:
-h, --help
-j N, --workers=N
--config-prefix=NAME
-D NAME[=VALUE],--param NAME[=VALUE
输出选项:
-q,--quiet
-S,-succinct
(execution options,selection options,...)

选项用法:llvm-lit [options]path/to/test/or/directory/with/tests

在这里插入图片描述

测试结果:

  • PASS:测试通过。
  • FLAKYPASS:在重复运行多次之后,测试通过。这只适用于包含ALLOW_RETRIES:annotation的测试
  • XFAIL:测试失败,但是符合预期。它用于测试格式,允许指定测试当前不工作,但希望将其留在测试套件中。
  • XPASS:测试通过,但预期会失败。这用于预期失败但现在成功的测试(通常是因为它们测试的特性被破坏并被修复)。
  • FAIL:测试失败。
  • UNRESOLVED:无法确定测试结果。例如,当测试无法运行、测试本身无效或测试被中断时,就会发生这种情况。
  • UNSUPPORTED:该测试在此环境中不受支持。这是由可以报告不支持测试的测试格式使用的。
  • TIMEOUT:测试已经运行,但在能够完成之前超时了。这被认为是失败的。
MacroSubstitution
%ssource path (path to the file currently being run)
%Ssource dir (directory of the file currently being run)
%psame as %S
%[pathsep]path separator
%ttemporary file name unique to the test
%basename_tThe last path component of %t but without the .tmp extension
%Tparent directory of %t (not unique, deprecated, do not use)
%%%
MacroSubstitution
%ssource path (path to the file currently being run)
%Ssource dir (directory of the file currently being run)
%psame as %S
%{pathsep}path separator
%{pathsep}Expands to the path separator, i.e. : (or ; on Windows).
%{fs-src-root}root component of file system paths pointing to the LLVM checkout
%{fs-tmp-root}root component of file system paths pointing to the test’s temporary directory
%{fs-sep}file system path separator
%ttemporary file name unique to the test
%basename_tThe last path component of %t but without the .tmp extension
%%%
%(line)The number of the line where this substitution is used, with an optional integer offset. These expand only if they appear immediately in RUN:, DEFINE:, and REDEFINE: directives. Occurrences in substitutions defined elsewhere are never expanded.
%clangInvokes the Clang driver.
%clang_cppInvokes the Clang driver for C++.

如何写一个新的回归测试

必须有一个Lit.local.cfg文件<--------llvm-lit决定如何运行

if not'AMDGPU'in config.root.targets:
config.unsupported=True

RUN指令行:“RUN:”+Ii运行测试要执行的脚本

  • 其语法类似于shellpipeline语法

每一行RUN指令行都单独执行,除非最后是“\”字符。

注意引用规则,保持RUN指令行尽量简单

在这里插入图片描述

FillCheck的功能以及应用

基本格式:FileCheck match-filename [-check-prefix=Xxx][-strict-whitespace]

介绍:fleCheck读入两个文件,并使用其中一个文件验证另一个文件。“match-filename"指定了包含匹配模式的文件。除非使用了一input-file选项,否则要验证的文件从标准输入读取。

在这里插入图片描述

"--check-prefix"指定匹配模式前缀。FileCheck在match-filename指定的文件中查找匹配模式。

在这里插入图片描述

测试套件

在这里插入图片描述

结构介绍

Test-suite被分以下6类:
SingleSource/
包含只有一个源文件大小的测试程序。一个子目录可以包含几个程序。

MultiSource/
含带有多个源文件的整个程序的子目录。大型基准测试和整个应用程序都在这里。

MicroBenchmarks/
使用google基准库的程序。这些程序定义的函数要运行多次,直到测量结果具有统计意义为止。

External/
包含不能与测试套件一起直接分发的代码的描述和测试数据。

Bitcode/
这些测试大部分是用LLVMbitcode编写的。

CTMark/
包含指向其他基准的符号链接,这些基准构成编译性能度量的代表性示例。

运行步骤

1.首先需要lit工具来运行这些测试
%  <path to 1lvm build>/bin/1llvm-lit --version
1it 0.8.0dev

2.用以下指令检查测试套件模块:
% git clone https://github.com/llvm/llvm-test-suite.git test-suite

3.创建一个构建目录并使用CMake来配置套件。
% mkdir test-suite-build
% cd test-suite-build
% cmake -DCMAKE_C_COMPILER=<path to 1lvm build>/bin/clang -C../test-suite/cmake/caches/o3.cmake ../test-suite

4.构建benchmark
make
Scanning dependencies of target timeit-target
[0%]Building C object tools/CMakeFiles/timeit-target.dir/timeit.c.o
0%]Linking C executable timeit-target

5.使用lit运行测试
% llvm-lit -v -j 1 -o results.json.
-- Testing: 474 tests, 1 threads
PASS: test-suite ::MultiSource/Applications/ALAC/decode/alacconvert-decode.test (1 of 474)
********** TEST 'test-suite :: MultiSource/Applications/ALAC/decode/alacconvert-
decode.test' RESULTS**********
compile_time:0.2192
exec_time: 0.0462
hash:"59620e187c6ac38b36382685ccd2b63b"
size: 83348
**********
PASS: test-suite :: MultiSource/Applications/ALAC/encode/alacconvert-encode.test (2 of
474)

6.展示并比较结果(可选)
# Make sure pandas and scipy are installed. Prependsudo'if necessary
% pip install pandas scipy
# Show a single result file:
% test-suite/utils/compare.py results.json
# Compare two result files:
% test-suite/utils/compare.py results_a.json results_b.json

benchmark

Benchmarks
每个程序都可以作为正确性测试。但有些程序不适合进行性能评估,将TEST_SUITE_BENCHMARKING_ONLY CMaKe 选项设置为ON 可以禁用它们

Configuration
测试套件具有自定义构建和运行基准的配置选项。CMake可以print它们的列表

% cd test-suite-build

# Print basic options:
% cmake -LH

#Print all options:
% cmake -LAH

调试信息测试

调试信息测试:通过检查调试器输出来评估调试信息质量。

  • 位置:debuginfo-tests Subversion

要运行调试信息测试,只需签出clang/test目录中的测试即可

% cd clang/test
% svn co http://llvm.org/svn/llvm-project/debuginfo-tests/trunk debuginfo-tests

这些测试已经设置为作为clang回归测试的一部分运行。

总结

在这里插入图片描述

参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喜欢打篮球的普通人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值