1. 程式人生 > >在docker中配置defects4j基準測試集

在docker中配置defects4j基準測試集

前言

本文旨在記錄——如何在docker的Ubuntu映象下配置defects4j 1.2.0 (最新版本,此時時間:2018-09-16)。

一、配置過程

1)先要在docker下安裝Ubuntu(我的系統是win10家庭版)

docker pull ubuntu:14.04

docker run --name testByDale -it ubuntu:14.04

docker exec -u deheng -w /home/deheng/ -it testByDale bash docker exec -u deheng -it testByDale bash

docker exec -it --user root /bin/bash

在ubuntu中新增一個新的使用者賬戶: adduser deheng 密碼:deheng

刪除賬戶:deluser 或者 sudo deluser 重建sudo賬戶:sudo adduser deheng

先進入root,用su - 然而我不知道root的密碼。只能用docker exec 命令重新進入root了。

chmod u+w /etc/sudoers
新增deheng ALL=(ALL) ALL
chmod u-w /etc/sudoers

exit

docker exec -u deheng -it testByDale bash

Requirements Java 1.7 Perl >= 5.0.10 Perl modules: run cpan Bundle::CSV DBD::CSV DBI or sudo cpan Bundle::CSV DBD::CSV DBI Git >= 1.9 SVN >= 1.8

安裝git:

sudo apt-get update
sudo apt-get install git
git --version

安裝svn:

sudo apt-get subversion
svn --version

安裝perl 模組:

cpan Bundle::CSV DBD::CSV DBI

安裝jdk 1.7: 必須先拷貝jdk.tar.jar到docker container中,然後 zip -r archive_name.zip directory_to_compress 這個是用來壓縮目錄的 unzip archive_name.zip 解壓zip檔案

tar -cvf archive_name.tar directory_to_compress 壓縮資料夾成一個tar包 tar -xvf archive_name.tar.gz 解壓tar包。 tar -xvf archive_name.tar -C /tmp/extract_here/ 解壓到指定目錄 tar -zxvf archive_name.tar.gz 解壓縮tar包。 tar -zcvf archive_name.tar.gz directory_to_compress 壓縮tar包。

修改/etc/profile,新增java的環境變數,需要掌握vim指令: vim /erc/profile 按insert進入插入模式,按esc退出插入模式。 : q! (輸入q!, 不存檔強制退出vi) : wq (輸入「wq」,存檔並退出vi)

~/.bashrc裡面加一句 source /etc/profile

linux關於bashrc與profile的區別: https://www.cnblogs.com/hongzg1982/articles/2101792.html /etc/profile,/etc/bashrc 是系統全域性環境變數設定 /.profile,/.bashrc使用者家目錄下的私有環境變數設定

我知道為什麼我的deheng賬戶下的ubuntu沒有~./bashrc了,因為我之前就建了一個deheng的資料夾,所以現在需要自己新建一個bashrc, 我建立了之後,就搞定了,在~./bashrc裡面加上一行:source /etc/profile 就可以正確設定java 環境變量了。nice。

不信可以驗證一下,我重新建一個賬戶,絕對會自動生成一個資料夾出來:

exit docker exec -it testByDale bash sudo adduser justfortest exit docker exec -u justfortest -it testByDale bash ls ls -a

果然有結果:

deheng justfortest . … .bash_logout .bashrc .profile

3)把defects4j拷貝到ubuntu中

perl模組檢視: perldoc -l DBD::mysql perldoc perllocal perldoc -l Bundle::CSV

我先執行 cpan Bundle::CSV DBD::CSV DBI,結果不行 所以我分開: sudo cpan DBI 看來必須先安裝YAML,否則會提示:‘YAML’ not installed, will not store persistent state

檢視安裝的所有軟體 dpkg -l

二、步驟一已經失敗,現在進入另外的嘗試——configure defects4j in my ubuntu image from the scratch

更換阿里源: deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #備份
sudo vim /etc/apt/sources.list #修改
sudo apt-get update #更新列表

Linux下獲取當前的目錄,需執行以下命令:$(cd dirname $0;pwd)

其中,dirname $0,取得當前執行的指令碼檔案的父目錄 cd dirname $0,進入這個目錄(切換當前工作目錄) pwd,顯示當前工作目錄(cd執行後的)

關於wget: -N, –timestamping 不要重新下載檔案除非比本地檔案新 -nv, –non-verbose 關掉冗長模式,但不是安靜模式

關於unzip命令: -o 以 壓縮檔案內擁有最新更改時間的檔案為準,將壓縮檔案的更改時間設成和該檔案相同。 -o 不 必先詢問使用者,unzip執行後覆蓋原有檔案。 -q 執 行時不顯示任何資訊。 -q 不顯 示指令執行過程。 -u 更 換較新的檔案到壓縮檔案內。

關於stat命令: stat指令:檔案/檔案系統的詳細資訊顯示。 stat命令主要用於顯示檔案或檔案系統的詳細資訊,該命令的語法格式如下: -f  不顯示檔案本身的資訊,顯示檔案所在檔案系統的資訊 -c 自定義輸出格式,結尾有換行

執行: $ docker cp ./ubuntu/defects4j/project_repos/defects4j-repos.zip testByDale:/home/deheng/defects4j/project_repos

$ docker cp ./ubuntu/defects4j/framework/lib/test_generation/generation/evosuite-0.2.0.jar testByDale:/home/deheng/defe cts4j/framework/lib/test_generation/generation/

$ docker cp ./ubuntu/defects4j/framework/lib/test_generation/runtime/evosuite-standalone-runtime-0.2.0.jar testByDale:/ home/deheng/defects4j/framework/lib/test_generation/runtime

拷貝檔案到ubuntu中。

雕蟲小技。。。 我覺得只要習慣了看init.sh,還是不難把defects4j配置出來的。

docker cp ./ubuntu/defects4j/framework/lib/test_generation/generation/replacecall-4.0.4.jar testByDale:/home/deheng/d efects4j/framework/lib/test_generation/generation/

發現一個神奇海螺般的問題: 在wget的時候,如果進度條不動了,我只要按一下ctrl + c,進度條就又動起來了,神奇。

問題: 2018-09-16 14:58:33 (14.9 KB/s) - ‘major-1.3.2_jre7.zip’ saved [4490962/4490962]

cp: cannot stat ‘major/bin/.ant’: No such file or directory

Setting up EvoSuite …

Setting up Randoop … ./init.sh: line 83: jar: command not found

3)然而,還需要: cpan Bundle::CSV DBD::CSV DBI

這個命令不可行。

$ docker cp ./ubuntu/sources.list testByDale:/home/deheng/

幸好之前還記錄了一些DBI perl模組的安裝,,,

不過我先裝make。我這個ubuntu好像沒有make,也沒有gcc??有點奇怪。

不過163網易源已經不行了啊,全部是miss,bad,所以只能用清華源了

sudo apt-get install gcc (裝gcc)

sudo apt-get install cmake (裝cmake,不知道有用沒)

原來確實是我沒有裝gcc和cmake,裝了之後,現在執行的可好了 cpan Bundle::CSV DBD::CSV DBI

##三、儲存對docker 容器的修改

儲存對容器的修改

當你對某一個容器做了修改之後(通過在容器中執行某一個命令),可以把對容器的修改儲存下來,這樣下次可以從儲存後的最新狀態執行該容器。docker中儲存狀態的過程稱之為committing,它儲存的新舊狀態之間的區別,從而產生一個新的版本。

執行docker commit,可以檢視該命令的引數列表。 你需要指定要提交儲存容器的ID。(譯者按:通過docker ps -l 命令獲得) 無需拷貝完整的id,通常來講最開始的三至四個字母即可區分。(譯者按:非常類似git裡面的版本號)

$docker commit 698 learn/ping docker commit -a “runoob.com” -m “my apache” a404c6c174a2 mymysql:v1

$ docker save busybox > busybox.tar $ ls -sh busybox.tar 2.7M busybox.tar $ docker save --output busybox.tar busybox $ ls -sh busybox.tar 2.7M busybox.tar $ docker save -o fedora-all.tar fedora $ docker save -o fedora-latest.tar fedora:latest

如果想要把映象存出到本地檔案,可以使用docker save命令,例如,存出本地的剛才建立的testimage:lastest為映象檔案testimage.tar檔案:

[[email protected] ~]# docker save -o /data/centos7.tar centos7 [[email protected] ~]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos7 latest 562987ba2b7e 3 minutes ago 589.4 MB centos latest 9baab0af79c4 2 weeks ago 196.8 MB

載入映象的話,要先刪除: docker rmi centos7 docker load --input /data/centos7.tar docker images

執行defects4j的一些問題

1)編碼 docker裡面不支援ascii編碼,好像。 我在下載math_35_buggy的時候,編譯出錯(defects4j compile): [javac] /home/deheng/SimFix/buggyprograms/math_35_buggy/src/test/java/org/apache/commons/math3/exception/util/LocalizedFormatsTest.java:21: error: unmappable character for encoding ASCII [javac] * Copyright 2010 CS Communication & Syst??mes [javac] ^ [javac] /home/deheng/SimFix/buggyprograms/math_35_buggy/src/test/java/org/apache/commons/math3/exception/util/LocalizedFormatsTest.java:21: error: unmappable character for encoding ASCII [javac] * Copyright 2010 CS Communication & Syst??mes [javac] ^ [javac] 2 errors

把這個systems改正常之後,就可以了。