Defects4J使用
Defects4J使用
安装
依赖
没写Git,一般Linux下都会有吧(
Java 11
1 | conda install -c conda-forge openjdk=11 |
Subversion (svn ≥ 1.8)
1 | conda install -c conda-forge subversion |
Perl ≥ 5.0.12
大多数 Linux 系统自带 Perl ≥ 5.0.12,检查版本:
1 | perl -v |
如果版本太低,可以手动编译或使用 perlbrew
。
1 | wget https://www.cpan.org/src/5.0/perl-5.36.0.tar.gz |
cpanm
1 | curl -L https://cpanmin.us | perl - App::cpanminus |
验证
1 | java -version |
Defect4J
- Clone Defects4J:
git clone https://github.com/rjust/defects4j
- Initialize Defects4J (download the project repositories and external libraries, which are not included in the git repository for size purposes and to avoid redundancies):
cd defects4j
cpanm --installdeps .
(这里有可能失败,可以尝试使用cpan App::cpanminus
命令)./init.sh
- Add Defects4J’s executables to your PATH:
export PATH=$PATH:"path2defects4j"/framework/bin
(“path2defects4j” points to the directory to which you cloned Defects4J; it looks like “/user/yourComputerUserName/desktop/defects4j”.)
- Check installation:
defects4j info -p Lang
On some platforms such as Windows, you might need to use perl "fullpath"\defects4j
where these instructions say to use defects4j
.
如果执行defects4j info -p Lang
报错:
1 | Can't locate DBI.pm in @INC (you may need to install the DBI module) |
说明cpanm --installdeps .
没有安装该依赖,比如这个DBI,可以手动cpanm -v --force DBI.pm
或者使用系统 Perl安装
一些依赖安装问题及解决方案
PadWalker
1 | fatal error: crypt.h: No such file or directory |
通过 Conda 安装 libxcrypt:conda install -c conda-forge libxcrypt
Safe-Hole
1 | Building and testing Safe-Hole-0.14 |
可以使用系统perl:perl -MSafe::Hole -e 'print "Safe::Hole OK\n"'
或者:首先确保安装了gccgcc --version
,安装:conda install -c conda-forge gcc_linux-64 gxx_linux-64
直接调用 Conda 的编译器编译 C 源码:
1 | # 编译 C 文件 |
使用(常用命令)
https://defects4j.org/html_doc/defects4j.html
打印所有可用项目 ID 的列表
1 | defects4j pids |
输出为可用项目 ID(名称)
打印项目所有可用Bug ID
1 | defects4j query -p project_id [-q query] [-o output_file] [-H] [-D|-A] |
https://defects4j.org/html_doc/d4j/d4j-query.html
或
1 | defects4j bids -p pid [-D|-A] |
https://defects4j.org/html_doc/d4j/d4j-bids.html
query相当于增强版的bids,提供更多自定义输出的支持
checkout
1 | defects4j checkout -p project_id -v version_id -w work_dir |
这里注意version_id
的格式是\d+[bf]
即数字加字母b或f,b即为bug,f即为fix。工作目录必须是空的,或者是以前使用过的工作目录,在checkout请求的项目版本之前,需要删除先前使用的工作目录中的所有文件。
compile
1 | defects4j compile [-w work_dir] |
编译已checkout项目版本的源代码和测试,work_dir
默认当前目录
test
1 | defects4j test [-w work_dir] [-r | [-t single_test] [-s test_suite]] |
-r:只执行相关的开发人员编写的测试。默认情况下,已checkout项目版本的所有开发人员编写的测试都会被执行。
-t:只运行该单个测试用例。默认情况下会执行所有测试。格式: <test_class>::<test_method>
.
-s:外部test_suite文件名,没用过