• Defects4j数据集安装及使用


    0、常见问题

    1. 所有配置完成后运行defects4j info -p Lang测试出现错误
    这里一定要注意,perl系统自带(Ubuntu22.04.3)的版本就是5.34.0,在这个版本下出现这个错误才是下面的解决方法,千万不需要再使用conda进行下载perl,那样会出错的。

    Can't locate DBI.pm in @INC (you may need to install the DBI module) (@INC contains: /myproject/defects4j/framework/lib /myproject/defects4j/framework /myproject/defects4j/framework/core /myproject/defects4j/framework/core /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.34.0 /usr/local/share/perl/5.34.0 /usr/lib/x86_64-linux-gnu/perl5/5.34 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl-base /usr/lib/x86_64-linux-gnu/perl/5.34 /usr/share/perl/5.34 /usr/local/lib/site_perl) at /myproject/defects4j/framework/core/DB.pm line 43.
    BEGIN failed--compilation aborted at /myproject/defects4j/framework/core/DB.pm line 43.
    Compilation failed in require at /myproject/defects4j/framework/core/Mutation.pm line 41.
    BEGIN failed--compilation aborted at /myproject/defects4j/framework/core/Mutation.pm line 41.
    Compilation failed in require at /myproject/defects4j/framework/core/Project.pm line 103.
    BEGIN failed--compilation aborted at /myproject/defects4j/framework/core/Project.pm line 103.
    Compilation failed in require at /myproject/defects4j/framework/bin/d4j/d4j-info line 58.
    BEGIN failed--compilation aborted at /myproject/defects4j/framework/bin/d4j/d4j-info line 58.
    Compilation failed in require at /myproject/defects4j/framework/bin/defects4j line 155.
    # 一、Defects4j数据集安装
    **`在Ubuntu系统上进行操作`**,具体的在:[Defects4j数据集安装](https://blog.csdn.net/weixin_46439193/article/details/104721218)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    解决方法:

     sudo apt-get install libdbi-perl
    
    • 1

    二、Defects4j数据集的使用

    1. 常用命令

    Getting started
    ----------------
    #### Setting up Defects4J
    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`
        - `./init.sh`
    
    3. Add Defects4J's executables to your PATH:
        - `export PATH=$PATH:"path2defects4j"/framework/bin`
    
    #### Using Defects4J
    4. Check installation and get information for a specific project (commons lang):
        - `defects4j info -p Lang`
        - `defects4j info -p Math`
    
    5. Get information for a specific bug (commons lang, bug 1):
        - `defects4j info -p Lang -b 1`
    
    6. Checkout a buggy source code version (commons lang, bug 1, buggy version):
        - `defects4j checkout -p Lang -v 1b -w /tmp/lang_1_buggy`
    
    7. Change to the working directory, compile sources and tests, and run tests:
        - `cd /tmp/lang_1_buggy`
        - `defects4j compile`
        - `defects4j test`
    
    8. More examples of how to use the framework are available in `framework/test`
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    2. 框架

    defects4j
       |
       |--- project_repos:     The version control repositories of the provided projects.
       |
       |--- major:             The Major mutation framework.
       |
       |--- framework:         Libraries and executables of the database abstraction and
           |                   test execution framework.
           |
           |--- bin:           Command line interface to Defects4J.
           |
           |--- core:          The modules of the core framework.
           |
           |--- lib:           Libraries used in the core framework.
           |
           |--- util:          Util scripts used by Defects4J.
           |
           |--- projects:      Project-specific resource files.
           |
           |--- test:          Scripts to test the framework.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    首先看一下文件结构,首先是project_repos,指提供的含有故障的项目的版本控制库,之后是major,是主要的变异框架,再framework中存在我们比较需要的各种信息,重点关注projects,里面是各种真实故障的项目。

    以Lang为例,讲解一下里面的目录结构

    Lang
    在这里插入图片描述
    逻辑是这样的,对每个defects4j项目来有很多测试类,每个测试类里面有很多测试用例,如果全通过了就说明程序没有问题,但有些情况下测试可能不通过,可能只是某一两个测试方法不通过,难道要把所有的程序再重新加载,进行实验吗?西门子故障程序是那么做的,不同版本的故障程序之间只有一两行不一样,所有的测试用例也都是一样的,测试用例对在运行不同版本的故障程序时结果是不同的。这种情况在defects4j上行不通,因为西门子程序太小了,这里动辄上万行的代码。

    • trigger tests
      每个故障版本都对应个一个trigger test,这个trigger test里面包含了一些引发了程序bug的测试方法。

    在这里插入图片描述

    • modified classes
      既然有了trigger test ,那么就必然有bug,那么文件夹modified_classes里面装的就是将bug修复时,需要改动源程序中的哪些类。
      在这里插入图片描述
      如图,Lang项目的第一个故障版本需要改动NumberUtils类即可修复。

    • loaded classes/relevant classes
      虽然bug只和这一个类有关,但程序是一个整体,只有这一个类跑不起来呀,想要跑起来需要很多relevant classes,在项目里是loaded_classes文件夹下,只有将这些类都加载进JVM中,trigger test方法才能跑起来。

    • relevant tests
      既然trigger test的运行,说明了程序中存在bug,只是在trigger_test中引发了bug,其他的测试程序中可能也跑了故障代码(modified classes),但是没有引发故障,所以relevent tests里面记录的就是所有的相关测试类。所谓相关测试类就是指当执行测试方法时,JVM中加载了modified classes,这样就保证了所有相关的测试都包含在内。

    • patches
      最后就是patches,其中src.patch记录了故障应该怎么修复,比如说,按照github的教程上执行了

    defects4j checkout -p Lang -v 1b -w /tmp/lang_1_buggy
    
    • 1

    这行代码后,实际上就是在/tmp/lang_1_buggy文件夹下将这个Lang 1 版本编译,测试所需要所有类和测试类都写进去了,在src文件夹下,我们再执行

    cd /tmp/lang_1_buggy
    defects4j compile
    defects4j test
    
    • 1
    • 2
    • 3

    注意,这里可以直接在linux中使用命令进行编译和测试,如果想在IDEA中进行运行测试,我这里用的环境是jdk1.7和maven3.8.1,注意:亲测maven3.6不行

    这时候我们编译的是含有故障的代码,运行后
    在这里插入图片描述
    它就会显示trigger test中记录的故障代号。

    如果我们想要一个没有故障的版本怎么办呢,就对defects4j checkout后,/tmp/lang_1_buggy中的源码进行更改即可,按照src.patch更改源码,其中@@后是代码在NumberUtils.java中的行数,每行代码前面没有符号时,代表代码无需改动,- 代表是新加的正确代码,+ 代表是错误代码,注释掉即可。
    在这里插入图片描述
    更改完代码后,我们再执行defexts4j test 就没有错误了。
    这种方法可以帮助我们获取无故障的源码,以及为程序中插入故障提供思路。

    三、 Defects4j-FL

  • 相关阅读:
    Oracle死锁问题: enq: TX - row lock contention
    NVIDIA JETSON AGX XAVIER DEVELOPER KIT刷机教程(各种踩雷篇)
    周赛370(模拟、树形DP(正难则反)、树状数组优化DP)
    【C++ 程序设计】第 3 章:类和对象进阶
    WebRTC AIMD算法用处
    业务规则引擎:Code Effects 5.X Crack-New
    Mysql-库的操作
    C和指针 第14章 预处理器 14.2 #define
    我凭这个引流套路做到月入10万+,你也可以(瞎编的)
    (swjtu西南交大)数据库实验(数据库需求分析):音乐软件数据管理系统
  • 原文地址:https://blog.csdn.net/qq_43978754/article/details/133787238