隨想錄(形式化驗證小結)

【 聲明:版權所有,歡迎轉載,請勿用於商業用途。  聯繫信箱:feixiaoxing @163.com】

 

    形式化驗證,英文是formal verification,是驗證軟硬件邏輯很重要的一種方法。特別是對於芯片開發、高安全性的系統開發來說,是非常必要。這主要是因爲系統失敗的代價很高,傳統的測試也無法驗證整個系統的安全性和可靠性。

 

1、目前主要的測試方法

    當前,驗證的主要方法就是將軟件、或者硬件代碼轉變成邏輯代碼,接着用專門的邏輯驗證軟件來執行這些邏輯代碼。

 

2、編程語言和工具

    現在使用比較多的工具有Isabelle/HOL、CSP/PAT等,其中pat是新加坡的一所大學開發的,推薦大家作爲入門使用。

 

3、已經使用形式化驗證的軟件

    sel4,一個用形式化驗證的操作系統內核

 

4、適合用作入門資料的幾個鏈接

a,https://www.cnblogs.com/LoganChen/p/7729820.html

b,https://www.cnblogs.com/LoganChen/p/7735802.html

c,https://www.cnblogs.com/LoganChen/p/7741785.html

d,https://www.cnblogs.com/juandx/p/4225373.html

e,https://www.bbsmax.com/A/kPzOx2V7Jx/

f,https://github.com/seL4/seL4,形式化驗證的os

g,https://github.com/AbsInt/CompCert,形式化驗證工具

h,https://pat.comp.nus.edu.sg/,形式化驗證的c編譯器

 

5,形式化驗證的幾個注意點

a,形式化驗證最難的部分就是需要將c&彙編語言轉變成邏輯語言

b,形式化驗證其實是一個白盒驗證,它不僅需要了解軟件的寫法,還要做出抽象和提煉,對測試者要求很高

c,形式化驗證不能保證100%的正確,但是會大幅度較少出錯的風險

 

6,怎麼簡單地理解形式化

  就好比c語言大家都會寫,但是如何保證C語言都是正確的、沒有二義性,窮舉是沒有用的。那麼需要對c語言的bnf範式進行驗證和確認,這纔是驗證的根本。

 

7,形式化驗證的主要方法

a,等效性檢驗

b,定理證明

c,模型檢驗

 

8,形式化中的assert

    目前看來形式化中的assert是需要自己設計的,除此之外,還需要自己確認哪些狀態可達、哪些路徑可以執行、哪些語句沒有二義性,這個也比較複雜。看上去,形式化驗證有點像單元測試,但是兩者的內容還是不一樣的。

 

9,最簡單的形式化驗證

    這個例子來自https://www.cnblogs.com/LoganChen/p/7741785.html

    代碼爲,

//The classic Readers/Writers Example model multiple processes accessing a shared file.

////////////////The Model//////////////////
//the maximun size of the readers that can read concurrently
#define M 2;
var writing = false;
var noOfReading = 0;

Writer()     = [noOfReading == 0 && !writing]startwrite{writing = true;} -> stopwrite{writing = false;} -> Writer();
Reader()     = [noOfReading < M && !writing]startread{noOfReading = noOfReading+1;} -> 
                          //the following guard condition is important to avoid infinite state space, because noOfReading can go negtively infinitely
                          ([noOfReading > 0]stopread{noOfReading = noOfReading-1;} -> Reader());

//there are infinite number of Readers and Writers
ReadersWriters() = |||{..} @ (Reader() ||| Writer());

////////////////The Properties//////////////////
#assert ReadersWriters() deadlockfree;
#define exclusive !(writing == true && noOfReading > 0); 
#assert ReadersWriters() |= [] exclusive;
#define someonereading noOfReading > 0;
#assert ReadersWriters() |= []<>someonereading;
#define someonewriting writing == true;
#assert ReadersWriters() |= []<>someonewriting;

 

10,形式化驗證的另外一個戰場

    金融領域,特別是虛擬數字貨幣。

 

PS:

    目前形式化驗證國內的資料比較少,大家可以看一些論文、或者直接用bing搜國外的文章,用pat軟件來學習也可以。只要有一些數理邏輯、離散數學的抽象思維和思想,理解起來沒那麼複雜。

 

    後續如果發現更好的資料,我也會在這個page下面進行更新。

 

 

發佈了558 篇原創文章 · 獲贊 3631 · 訪問量 475萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章