我正在尝试使用llvm-lit运行一个简单的测试。我有一个专用目录:
llvm-lit-dir
+---lit.cfg
+---llvm_lit_example.ccfg文件来自llvm-3.8.0/utils/lit/lit/ExampleTests.ObjDir。这就是它:
$ cat lit.cfg
config.example_obj_root = os.path.dirname(__file__)
lit.load_config(config, os.path.join(config.test_source_root,'lit.cfg'))下面是我要检查的示例:
$ cat llvm_lit_example.c
// RUN: %clang -o %t0 %s
// RUN: %t0 | grep "YES"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int i=rand()%4;
char s1[5]={'0','1','2','3', 0 };
char s2[5]={'0','1','2','3', 0 };
s1[i]='6';
if (strcmp(s1,s2) == 0) printf("NO \n");
if (strcmp(s1,s2) != 0) printf("YES\n");
}我尝试了几种方法,但似乎都不起作用:
$ llvm-lit llvm-lit-dir/llvm_lit_example.c
llvm-lit: TestingConfig.py:114: fatal: unable to parse config file '/home//llvm-lit-dir/lit.site.cfg', traceback: Traceback (most recent call last):
File "/home/llvm-3.8.0/llvm/utils/lit/lit/TestingConfig.py", line 101, in load_from_path
exec(compile(data, path, 'exec'), cfg_globals, None)
File "/home/llvm-lit-dir/lit.site.cfg", line 14, in <module>
lit.load_config(config, os.path.join(config.test_source_root,'lit.cfg'))
NameError: name 'lit' is not defined我做错了什么?谢谢!
发布于 2019-07-09 04:42:52
下面是我正在使用的简约的"hello world“示例:
配置文件:lit.cfg
import lit.formats
config.name = "LIT hello world"
config.test_format = lit.formats.ShTest("0")测试文件:测试测试/
; RUN: echo "Foo" | FileCheck %s
; CHECK: Foo用来运行它
lit -v tests/test要使测试失败,请将其更改为echo "Bar"。
另外两条评论:
1)安装lit很简单:
pip3 install lit要安装FileCheck,我必须下载LLVM源代码(LLVM Download page)并使用CMake构建FileCheck目标。
2) config.test_format = lit.formats.ShTest("0")很重要,否则lit会失败,并显示以下错误:
AttributeError: 'NoneType' object has no attribute 'execute'看起来ShTest是默认格式,但用户仍然需要手动激活它。
发布于 2018-06-25 15:16:07
此配置是一个python源代码。lit显然是没有定义的。尝试导入与lit相关的内容,如from lit.llvm import llvm_config。看看LLVM源代码中的test/lit.cfg.py。
https://stackoverflow.com/questions/51008411
复制相似问题