前言

创作开始时间:2021年3月25日08:47:45

如题。一气呵成冲冲冲。

1.1 创建Ubuntu虚拟机

1.1.1下载VMWare

首先下载VMWare安装包(版本:VMware® Workstation 16 Pro 16.1.0 build-17198959),官方下载地址为:
https://my.vmware.com/cn/web/vmware/downloads/info/slug/desktop_end_user_computing/vmware_workstation_pro/16_0

1.1.2 下载Ubuntu系统镜像

随后下载Ubuntu 18.04安装镜像,下载网址为:

  • Ubuntu官方网站http://releases.ubuntu.com/18.04/ubuntu-18.04.5-desktop-amd64.iso
  • 阿里云镜像网站 http://mirrors.aliyun.com/ubuntu-releases/18.04/ubuntu-18.04.5-desktop-amd64.iso

1.1.3 新建虚拟机

在VMWare界面开始新建即可,基本上是默认安装,下列图中提供部分描述:
在这里插入图片描述
图:新建虚拟机(1)

在这里插入图片描述
图:新建虚拟机(2):选定镜像

在这里插入图片描述

图:新建虚拟机(3):设定用户名(密码:123456)
在这里插入图片描述
图:新建虚拟机(4):自动安装VM-tools

1.1.4 更换apt源

此时,我们已经得到一台名为apr-demo的虚拟机。启动这台虚拟机,在安装新软件之前,我们需要先更换一下apt源,以免下载太慢。
此处换源可参考:

换源之后运行一下sudo apt-get update即可(此处不需要运行sudo apt-get upgrade)。

1.1.5 【可选】使用xshell连接

通过xshell以ssh的方式连接本地虚拟机。这是为了在终端输入命令的时候更加方便,免去了在Windows本机和Ubuntu虚拟机之间的切换。

此处参考:

备注: 如果无法连接,则需要在虚拟机中输入:

sudo apt-get install openssh-server  #下载
sudo service ssh --full-restart            #重新启动ssh服务
ssh localhost              #仍旧在Ubuntu上运行这个指令,此时发现已经可以连接

此处参考:

然后再重新用xshell试试。此时发现已经可以顺利连接了。(如下图)
在这里插入图片描述

图:xshell成功连接Ubuntu虚拟机

1.1.6 安装JDK8

在虚拟机终端运行:

sudo apt update
sudo apt install openjdk-8-jdk openjdk-8-jre
java -version

随后往/etc/environment文件中添加:

JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
JRE_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre

此处参考:How to Install JAVA 8 on Ubuntu 18.04/16.04, Linux Mint 19/18 https://tecadmin.net/install-oracle-java-8-ubuntu-via-ppa/

1.2 配置Defects4J缺陷数据集

1.2.1 安装基础工具

安装git等基础工具:

sudo apt install git -y
sudo apt install subversion -y
sudo apt install curl -y (defects4j下载文件需要)
sudo apt install htop -y
sudo apt install make -y (cpan需要)
sudo apt install gcc -y (cpan需要,否则DBI模块无法下载)

1.2.2 下载Defects4J

Defects4J的仓库地址在:https://github.com/rjust/defects4j
有两种方式下载该repo:

  1. 直接运行git clone https://github.com/rjust/defects4j.git
  2. 如果觉得github克隆网速太慢,可以先克隆到自己的gitee账户,然后再从gitee中克隆到虚拟机(如git clone https://gitee.com/xxx/defects4j.git)

1.2.3 自动配置Defects4J

cd ~/env/defects4j
sudo apt install cpanminus
sudo cpanm --installdeps . (一定要sudo的,不然无法写入,等于没装)
./init.sh

而后修改/etc/profile/文件,加入如下内容:

export PATH=$PATH:/home/apr-demo/env/defects4j/framework/bin

然而,由于./init.sh运行时会从对应网站下载一系列压缩文件,这个过程中网速通常比较慢。如下图(预计三小时才能下载好一个压缩包):
在这里插入图片描述

图:./init.sh运行时的网速

因此,下面给出手动配置方案。

1.2.4 【可选】手动配置Defects4J

手动下载如下压缩包:
4. https://defects4j.org/downloads/defects4j-repos.zip
5. https://mutation-testing.org/downloads/major-1.3.4_jre7.zip
6. https://github.com/EvoSuite/evosuite/releases/download/v1.1.0/evosuite-1.1.0.jar
7. https://github.com/EvoSuite/evosuite/releases/download/v1.1.0/evosuite-standalone-runtime-1.1.0.jar
8. https://github.com/randoop/randoop/releases/download/v4.2.5/randoop-4.2.5.zip
9. https://defects4j.org/downloads/defects4j-gradle-dists.zip
10. https://defects4j.org/downloads/defects4j-gradle-deps.zip
11. https://github.com/jose/build-analyzer/releases/download/v0.0.1/build-analyzer-0.0.1.jar

然后在Defects4J目录下新建一个文件夹“manual_download”,把刚刚下载的文件都拷贝进去,随后在此文件夹下写一个cp.sh脚本:

BASE=/home/apr-demo/env/defects4j/
DIR_REPOS="$BASE/project_repos"
DIR_LIB_GEN="$BASE/framework/lib/test_generation/generation"
DIR_LIB_RT="$BASE/framework/lib/test_generation/runtime"
DIR_LIB_GRADLE="$BASE/framework/lib/build_systems/gradle"

cp defects4j-repos.zip $DIR_REPOS

cp major-1.3.4_jre7.zip $BASE

cp evosuite-1.1.0.jar $DIR_LIB_GEN
cp evosuite-standalone-runtime-1.1.0.jar $DIR_LIB_RT

cp randoop-4.2.5.zip $DIR_LIB_GEN

cp defects4j-gradle-deps.zip $DIR_LIB_GRADLE
cp defects4j-gradle-dists.zip $DIR_LIB_GRADLE

cp build-analyzer-0.0.1.jar $BASE/framework/lib

运行一下这个脚本,然后再回到defects4j的主目录,注意:要相应改动init.sh文件中的内容,即禁止download_url函数。具体此处不赘述(因为init.sh行数较多),可参考我已配置好的虚拟机。

而后运行./init.sh即可。

在这里插入图片描述

图:右侧终端表明Defects4J配置成功
另外,gradle要额外配置一下,在defects4j目录下新建init_gradle.sh(内容较长,此处不贴),然后运行,才算配置好了gradle。
最后,需要修改/etc/profile,添加:

# defects4j
export PATH=$PATH:/home/apr-demo/env/defects4j/framework/bin

#Time Zone for d4j
TZ="America/Los_Angeles"
export TZ

1.2.5 Defect4J实例展示

在终端运行:

defects4j checkout -p Lang -v 1b -w /tmp/lang_1_buggy
cd /tmp/lang_1_buggy
defects4j compile
defects4j test

此外,还可以参考虚拟机中文件:/home/apr-demo/apr_tools/d4j/single_download.sh

小结

以上。

创作结束时间:2021年3月25日08:54:10

参考文献

见正文。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐