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
2
3
4
5
6
7
wget https://www.cpan.org/src/5.0/perl-5.36.0.tar.gz
tar -xzf perl-5.36.0.tar.gz
cd perl-5.36.0
./Configure -des -Dprefix=$HOME/.local/perl
make && make install
echo 'export PATH="$HOME/.local/perl/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

cpanm

1
2
3
curl -L https://cpanmin.us | perl - App::cpanminus
echo 'export PATH="$HOME/perl5/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

验证

1
2
3
4
java -version
svn --version
perl -v
cpanm --version

Defect4J

  1. Clone Defects4J:
    • git clone https://github.com/rjust/defects4j
  2. 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
  3. 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”.)
  4. 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
2
3
4
5
6
fatal error: crypt.h: No such file or directory
124 | # include <crypt.h>
| ^~~~~~~~~
compilation terminated.
make: *** [Makefile:336: PadWalker.o] Error 1
-> FAIL Installing PadWalker failed

通过 Conda 安装 libxcrypt:conda install -c conda-forge libxcrypt

Safe-Hole
1
2
3
4
Building and testing Safe-Hole-0.14
Building Safe-Hole
Error: no compiler detected to compile 'lib/Safe/Hole.c'. Aborting
-> FAIL Installing Safe::Hole failed.

可以使用系统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
2
3
4
5
6
7
8
9
# 编译 C 文件
$CONDA_PREFIX/bin/gcc -shared -fPIC -o lib/Safe/Hole.so lib/Safe/Hole.c \
-I$CONDA_PREFIX/lib/5.34.0/x86_64-linux-thread-multi/CORE

# 手动安装模块
mkdir -p $CONDA_PREFIX/lib/site_perl/5.34.0/Safe/
mkdir -p $CONDA_PREFIX/lib/site_perl/5.34.0/x86_64-linux-thread-multi/auto/Safe/Hole/
cp lib/Safe/Hole.pm $CONDA_PREFIX/lib/site_perl/5.34.0/Safe/
cp lib/Safe/Hole.so $CONDA_PREFIX/lib/site_perl/5.34.0/x86_64-linux-thread-multi/auto/Safe/Hole/

使用(常用命令)

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文件名,没用过