Intel ControlFlag とは?
レポジトリ
https://github.com/IntelLabs/control-flag
"A system to flag anomalous source code expressions by learning typical expressions from training data" ということで、機械学習によって生成されたデータを使って、ソースコードのパターン異常(要はおかしい箇所)を検出してくれるらしいです。
参考:
機械学習でコードの問題を自動検出、オープンソース化されたインテルの「ControlFlag」
https://japan.zdnet.com/article/35178435/
Intelの自動コードデバッグツール「ControlFlag」がオープンソースとして公開され、無料で利用できるようになった。この動きは、潜んでいる異常を見つけるためにプログラムを精査することに疲れた多くの人にとって救いとなるだろう。… Gottschlich氏によれば、ControlFlagをたった2つの自社のソフトウェアのリポジトリーに使用しただけで、製品レベルの品質を備えた、実際に使われているプログラムに300以上の欠陥を発見することができたという
準備
手元で使ったサーバ。CentOS 7.9 minimalを使用。
[root@localhost control-flag]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
cmake3, gcc10が必要、ということで、とりあえず下記を。
手順が抜けていたらすみません。指摘お願いします。
yum install epel-release
yum install scl-utils centos-release-scl
yum install devtoolset-10
scl enable devtoolset-10 'gcc -v'
source scl_source enable devtoolset-10
gcc -v
yum install epel-release
yum remove cmake
yum install cmake3
ln -s /usr/bin/cmake3 /usr/bin/cmake
cmake --version
インストール
cd /home
yum install git
git clone https://github.com/IntelLabs/control-flag.git
cd control-flag/
現状、"cmake ."だと失敗したので下記のようにしたらビルドできたのですが、これで正しいのですかね…。
cmake -H. -Bbuild
cd build
make -j
make test
データを準備
https://github.com/IntelLabs/control-flag
のページから、Medium のデータをとりあえず取得。公開されているのはC用のデータです。
とりあえずどんな方法ででも、ダウンロードしてサーバに配置すればOK。
いざ検査
/home/control-flag/build/binの下に実行ファイルができているので安直にコピー。
cd /home/control-flag/build/bin
cp * /home/control-flag/bin/
検査方法:
[root@localhost control-flag]# ./scripts/scan_for_anomalies.sh -d /home/★検査したいソースコードのディレクトリ★ -t c_lang_if_stmts_6000_gitrepos_medium.ts -o /home/logs
検査時の様子
Training: start.
Trie L1 build took: 55.360s
Trie L2 build took: 18.067s
Training: complete.
Storing logs in /home/logs
Scan progress:3/36 ... in progress
Scan progress:6/36 ... in progress
Scan progress:9/36 ... in progress
Scan progress:12/36 ... in progress
Scan progress:15/36 ... in progress
Scan progress:18/36 ... in progress
Scan progress:21/36 ... in progress
Scan progress:24/36 ... in progress
Scan progress:27/36 ... in progress
Scan progress:30/36 ... in progress
Scan progress:33/36 ... in progress
Scan progress:36/36 ... in progress
[root@localhost control-flag]#
ログの確認
ログを見ると、結果が色々書いてあります。
手元のC++コードはみんな "Expression is Okay"で完了。