• 沒有找到結果。

針對信息遞送程式 做可及性測試的研究

N/A
N/A
Protected

Academic year: 2021

Share "針對信息遞送程式 做可及性測試的研究"

Copied!
74
0
0

加載中.... (立即查看全文)

全文

(1)國立臺灣師範大學 資訊工程研究所碩士論文. 指導教授:黃冠寰博士. 針對信息遞送程式 做可及性測試的研究. A General Model to Perform Reachability Testing for Message Passing Programs. 研究生:. 顏文賢. 撰. 中華民國九十九年 一月.

(2) 中文摘要 軟體測試一直是我們最重要的課題,因為軟體出錯的比率不只是我們人類所 撰寫的程式語言會出錯,就連系統執行所有程式時所不可能預期的錯誤也會發生。 在現實的情況中,通常我們所執行的程式都是 concurrent program,很少程式是 單一直行的程序,所以軟體出錯的機會很大。 黃冠寰博士提出了 reachability testing[1],此篇主要的研究是根據 reachability testing 做 一個 核 心的 延 伸, 所用 的 架構 為 message passing 的模 型 , 依 照 reachability resting 的精神下去做研究,並且提出一個解法,利用 unique message id 和 filter 增 進 reachability testing 的 功 能 , 專 門 針 對 multiple receiver 的 synchronization sequence 產生 race variants 做過濾,進而得出符合 synchronization model 的 race variants,此篇論文主要針對兩種 message passing 模型進行分析, 分別為 synchronous message passing 和 asynchronous message passing,並且針對 Richard H. Carver 和 Yu Lei 的 work[5][17]提出一些不同的看法和質疑,另外我 們發現改良 Richard H. Carver 提出的 race table 的方式去解決 multiple receiver 的 問題。 關鍵字: software testing、concurrent program、reachability testing、message passing、 multiple receiver、synchronous message passing、asynchronous message passing、 unique message id、filter。. I.

(3) ABSTRACT Software testing is always an important problem during our life, because the big chance of software which has errors is not only in our writing programs, but also in the machine system programs which execute all the times, and then all the nondeterministic errors occur. In the reality world, we usually execute concurrent programs, the very few times to execute a sequential program, It is the big chance that errors will occur. Dr. Gwan-Hwan Hwang has proposed “Reachability testing”, this paper is follow this work and view this major study is based on a core of reachability testing an extension of the framework used by the message passing model, reachability testing in accordance with the spirit of this research, and propose a solution, using unique message id and filter to enhance the function of reachability testing ,we focus on the race variants of synchronization sequences of multiple receiver, this paper mainly two kinds of message passing model for analysis of synchronous message passing and asynchronous message passing, and for Richard H. Carver and Yu Lei’s work[5][17] to make some different views and queries. In addition, we found that improvement of Richard H. Carver made race table approach to deal with multiple receiver problems.. II.

(4) Key word: software testing、concurrent program、reachability testing、message passing、 multiple receiver、synchronous message passing、asynchronous message passing、 unique message id、filter.. III.

(5) 誌謝 在大學的時候覺得資訊領域範圍實在廣大,很多課程學習不夠深入,想要更 深入的學習,後來報名碩士班的考試,有幸來到師大念研究所跟隨黃冠寰教授, 因為對於研究領域基礎不足,剛開始不適應,很感謝黃冠寰老師很有耐心的指導 給予一個正確的研究方向讓我可以遵循,還會給我做人處事的建議,我希望能學 習到老師思考問題和解決問題的方法還有做事的態度,這將會是我人生中可以依 循的方向,我會多加努力。 在研究方面遇到不少困難,常常會遇到不懂的地方,很感謝有林哲生學長的 幫忙,時常一起討論問題,給予我很多問題上的意見和可以思考的方向,感覺他 就是實驗室的大家長,對於我們學弟妹們的事情,他都很有耐心的給予幫助和解 答,很感謝他。感謝蕭宇呈學長,時常請教他程式的問題,也很熱心的提供不少 的資料給我,有他的幫忙對於程式上了解很多。對於我的同學們,招政、李祺、 彥佑、笠德和光耀,很高興能夠認識你們,很感謝有你們在實驗室的日子裡大家 能夠互相幫忙。雖然研究上很忙碌,但我一直覺得我們實驗室的氣份很和諧很融 洽。 最後我要感謝我的父母親,他們很辛苦的栽培我到研究所這個階段,除了感 激還是感激。在研究所的這些日子,可以算一種磨練,但也有緣分能夠認識很多 人,在我人生中會是個很難忘的一站。. 顏文賢 誌於 國立台灣師範大學資訊工程研究所 民國九十九年一月. IV.

(6) 目錄 中文摘要 .................................................................................................................................... I ABSTRACT .............................................................................................................................. II 1.. 簡介 ................................................................................................................................... 1 1.1. Software Testing..................................................................................................... 2. 1.2. Static analysis ......................................................................................................... 3. 1.3. Dynamic Testing..................................................................................................... 3. 1.4. Nondeterministic Testing ...................................................................................... 4. 1.5. Deterministic Testing ............................................................................................. 4. 1.6. Model checking ....................................................................................................... 5. 1.7. Reachability Testing .............................................................................................. 6. 1.8. A General model to perform reachability testing for message passing. programs .............................................................................................................................. 9 2.. 文獻探討 ......................................................................................................................... 11 2.1. Technology for Testing Nondeterministic Client/ /Server Database. Applications ....................................................................................................................... 11. 3.. 4.. 2.2. Dynamic Effective Testing................................................................................... 12. 2.3. Richard H. Carver’s work: A general model of Reachability Testing ............ 15. 2.4. The Discussion for Richard H Carver’s work ................................................... 28. 實作方法 ......................................................................................................................... 36 3.1. Framework ............................................................................................................. 36. 3.2. Synchronization Model ........................................................................................ 37. 3.3. Reachability Testing Concept for Message Passing Programs ........................ 39. 3.4. Race Variant Filter .............................................................................................. 42. 3.5. Monitor ................................................................................................................. 44. 3.6. An Example of Our Solution ............................................................................... 45. 實驗結果 ......................................................................................................................... 51 V.

(7) 5.. 6.. 4.1. Framework ........................................................................................................... 51. 4.2. 實驗數據................................................................................................................ 52. 結論與未來展望 ............................................................................................................. 59 5.1. 結論........................................................................................................................ 59 結論. 5.2. 未來展望................................................................................................................ 61. REFERENCES .................................................................................................................... 62. VI.

(8) 圖目錄 圖.1. Nondeterministic Testing 架構圖............................................................. 4. 圖.2. Concept of Reachability testing ................................................................ 9. 圖.3. Concept of reachability testing for message passing programs ................. 11. 圖.4 圖.5. 利用 race graph 產生 race variant .......................................................... 12 造成 Reachability testing 問題的受測程式之一 .................................... 13. 圖.6 圖.7 圖.8. 造成 Reachability testing 問題的受測程式之二 .................................... 13 造成 Reachability testing 問題的受測程式之三 .................................... 15 Example of Reachability testing of message passing program ................. 17. 圖.9 圖.10 圖.11 圖.12 圖.13 圖.14 圖.15 圖.16 圖.17 圖.18 圖.19 圖.20 圖.21 圖.22 圖.23 圖.24 圖.25 圖.26 圖.27 圖.28 圖.29 圖.30 圖.31 圖.32 圖.33 圖.34 圖.35 圖.36. Send/receive using a port ........................................................................ 17 Timestamp scheme for asynchronous message passing model................. 19 Traditional timestamp assign scheme ...................................................... 21 Time stamp scheme for race analysis ...................................................... 22 Coustruct-Race-Table algorithm ............................................................. 24 Proposition condition of finding race set ................................................. 25 An Example of race table........................................................................ 25 Race variants derived from race table ..................................................... 25 The problem of timestamp assignment scheme ....................................... 26 An Example to find race sets and construct a race table .......................... 27 Derived race variant................................................................................ 28 Synchronous message passing of timestamp of single receiver................ 29 Asynchronous message passing of timestamp of single receiver ............. 30 The timestamp can’t be compared........................................................... 30 Three groups........................................................................................... 32 Three groups with a shared object ........................................................... 33 The problem of construction of a race table ............................................ 33 沒有找出所有可能的 topological sort 會發生可能的情況................... 34 所產生的 race variant 1.......................................................................... 34 所產生的 race variant 2.......................................................................... 35 A reachability testing for message passing framework ............................ 36 Two Message Passing Model .................................................................. 37 Unique message ID 結構 ........................................................................ 37 An array of a SYN-sequence .................................................................. 38 Timestamp vs. Unique Message ID......................................................... 39 Algorithm 1 ............................................................................................ 39 Algorithm 2 ............................................................................................ 40 Algorithm 3 ............................................................................................ 40 VII.

(9) 圖.37 Algorithm 4 ............................................................................................ 40 圖.38 Algorithm 5 ............................................................................................ 41 圖.39 Algorithm 8 :Blocking send + Blocking receive Filter ............................ 43 圖.40 Algorithm 7 :Non-blocking send + Blocking receive Filter ..................... 44 圖.41 Monitor SYN-sequence .......................................................................... 44 圖.42 Multiple receiver using unique message id .............................................. 46 圖.43 All of the topological sorts of SYN-sequence ......................................... 46 圖.44 Partial order graph(上) Race graph(下) ................................................... 47 圖.45 Derived race variants .............................................................................. 48 圖.46 16 Distinct race variants ......................................................................... 49 圖.47 透過 blocking send + blocking receive Filter 過濾 ................................ 50 圖.48 透過 non-blocking send + blocking receive Filter 過濾 ........................ 51 圖.49 A SYN-sequence of synchronous message passing ................................. 51 圖.50 SYN-sequence ........................................................................................ 52 圖.51 不同先後順序的 receiving event 所得到的 race table 之一................... 53 圖.52 不同先後順序的 receiving event 所得到的 race table 之二................... 53 圖.53 不同先後順序的 receiving event 所得到的 race table 之三................... 54 圖.54 Algorithm 8 ............................................................................................ 55 圖.55 Algorithm 9 ............................................................................................ 55. VIII.

(10) 表目錄 Table.1 SYN-sequence 實驗結果 ......................................................................... 58. IX.

(11) A General Model to Perform Reachability Testing for Concurrent Programs. 1. 簡介 現在的軟體十分盛行,我們常常需要使用到軟體,像是上網、玩遊戲,或者 是使用應用程式讓我們生活更方便,但是我們時常會因為軟體在使用時所出現錯 誤而困擾著,這不只是使用者的困擾,對於程式設計師也是個困擾的問題,所以 軟體的品質一直是我們所追求的目標,但是常常軟體會出現我們不可預知的錯誤 ,有時候這個錯誤需要幾十萬次的執行才會出現一次,這種錯誤對於軟體測試的 工程師來書非常頭痛的,又在於現在的程式都是以多執行緒來進行,也就是說每 個執行緒都以並行的方式進行,而這種進行方式對於軟體的出錯又更難掌握,常 常需要經過幾十萬次的測試才可以找到錯誤,我們實驗室此一問題做了進一步的 研究,針對並行的執行緒根據某些共用資源會產生競爭的狀況下進行研究,並且 對此問題做了一些討論。 此篇論文第一章介紹軟體測試的發展和過去所研究過的問題和目前我所做 的研究,第二章介紹 reachability testing 相關的文獻和 Richard H Carver 他們所 做的 work 和他們所遇到的問題,第三章針對他們的問題介紹我們所提出的方法, 使用 unique message ID 解決 multiple receiver 和如何使用 filter 去過濾不合法的. 1.

(12) race variant 的功能,第四章是所歸納出的結論和未來可以進行研究的方向。. 1.1 Software Testing 不論是軟體專案、工程專案或是其它各類的專案,在整個專案進行的過程中 或是結案前,都存在著大大小小的測試。我們以軟體專案為例,從元件開發過程 中 的 單 元 測 試 (Unit Test) 、 到 功 能 測 試 (Function Test) 、 然 後 是 整 合 測 試 (Integration Test)、最後還有個使用者驗收測試(UAT, User Acceptance Test)等等, 一堆的測試。這些測試最終目的就是為了讓整個系統能夠正常順利的運作,只要 測試的項目涵蓋範圍夠廣泛夠完整,那麼就可以精確掌握各種可能的狀況,讓系 統出錯機率降到最低。 不過,既然測試那麼重要,但是軟體界一項常見的問題是,軟體產品往往沒 有經過足夠的測試。原因在於,測試的成本非常高,不管是人力的成本或是其它 相關資源的成本。雖然有許多的測試工具軟體可以輔助我們做測試的工作,但是 要測哪些項目、怎麼測以及有些操作還是得靠人力才行。程式設計師自行測試 會 很自然地用他們認為最佳的方式來操作這套系統,這會產生許多盲點,導致成品 出現許多 bug。 本實驗室最主要是針對測試並行程式的研究為主軸,在並行程式裡面就會有 共享的資源,透過作業系統對這些並行程式的工作安排,有可能會產生一些不一 樣的結果,對共享資源有著不一樣順序的存取而導致不同的結果我們稱之為 race. 2.

(13) condition[2],我們的系統最主要就是對這些會對共享資源存取的事件裡,針對這 些事件找出一些可能的交錯組合行徑,且一一的把他找出來再進行分析。. 1.2 Static analysis 對解決並行程式的 nondeterministic behavior,一些研究人員已經發展針對在 並行程式內的異常種類檢測之靜態分析技術[10,12].並不會對程式執行 ,而是針對程式碼、演算法作一些驗證的動作。 Static analysis 常被用來在檢測 並行程式裡的 synchronization 和資料用法的錯誤,同步錯誤如 deadlock 和“wait forever”, 資料用法的錯誤包括一般性 sequential 資料用法錯誤,例如讀取未初 始化的變數,以及平行的資料用法錯誤。. 1.3 Dynamic Testing 動態分析最主要就是程式是有實際在執行的,然後在針對他執行完的結果作 分析。針對執行程式的順序不同有著不同的變化,或針對其值的不同也會造成不 同 的 結 果產 生。 Dynamic testing最 主 要 的 解 法 就 是在 我 們實 驗室 所 研 究 的 reachability testing[1],此系統可以驗證non-deterministic的情況,可以找出每一條 interleave且都有去實際執行過。. 3.

(14) 1.4 Nondeterministic Testing Nondeterministic Testing 也是最常見的一種測試,是針對一組 input 對此並行 根據這些結果來判斷 程式一直作重覆的執行,讓它有可能產生不同的結果出來 讓它有可能產生不同的結果出來,根據這些結果來判斷 如圖 1 所示。 此程式是否正確與否,如圖 但是此方式最主要缺點的 但是此方式最主要缺點的: (1) 相同的 SYN-sequence sequence 很有可能會一直執行到的。 (2) 有些 SYN-sequences sequences 很可能永遠沒辦法執行到的。 所以 nondeterministic testing 是永遠沒辦法保證達成 exhaustive testing 的 的。. 圖.1 Nondeterministic Testing Testin 架構圖. 1.5 Deterministic Testing 跟 1.4 nondeterministic testing 不 同 之 處 是 會 在 執 行 的 時 候 多 一 項 SYN-sequence S 輸入,針對這個 針對這個 SYN-sequence S 作 replay 的動作,這項強迫的 這項強迫的 執行用來確定 S 和 Input 是不是符合這項程式 P 的,如圖.1 所示。 這項最主要的缺點就是 這項最主要的缺點就是,再取決這個在於選擇那一個 feasible SYN--sequence 和 input 是非常困難的,有些相關問題解決方法的詳細論文在 有些相關問題解決方法的詳細論文在[6][7][8][9] [6][7][8][9],所以. 4.

(15) 在之後我的指導教授才會研發 reachability testing 來解決 nondeterministic testing 和 deterministic testing 的缺點。. 1.6 Model checking 有一個很好的方式去驗證電腦系統的正確性,無論是硬體、軟體或是軟硬體。 這種最顯著的例子就是 safty-critical systems,但是要適用在那些關鍵性的業界產 品上,像是大規模生產的晶片、mission critical 等。正規的驗證方法在工業界上 很實用,並有愈來愈多的專業人員可以適用。形式化驗證技術可以被看作是包括 三部分: a.一個框架模型系統,通常是某種順序的描述語言;b.規格語言描述的 屬性進行驗證; c.驗證方法,以確定此系統是否滿足系統的規格驗證的方法可以 根據以下的標準:Proof-based vs. model-based.以證明為基礎的方法,系統描述了 一套公式和規格是另一個公式。驗證的方法是試圖找到證明這個 Γ├ψ。這通常 需要使用指南和專家使用者。 在一個模型為基礎的方法,該系統是由 model M 對於一個適當的邏輯。規格再次派一個公式和核查方法包括計算是否模型滿足 M。 對於有限的模型這通常是自動計算的。 我們可以看到,邏輯證明系統往往健全和完善,這意味著擁有 Γ├ψ ,若且 唯若 Γ├ψ 也擁有。我們可以看到以模型為基礎的方法比以證據為基礎的方法簡 單,因為它是一個單一的模型 M 而不是無限制的。Degree of automation。此方法 自動化的程度是如何;極端的全自動和完全手動。許多計算機輔助技術在中間的 某處。. 5.

(16) Full- vs. property-verification。規格可描述一個單一屬性,也可能說明其全部 行為。那個後者通常是昂貴的驗證方式。Intended domain of application,這可能 是硬件或軟件;順序或並行;反應或終止;等被動系統是一個有反應的環境和並不 意味著終止 (例如,操作系統,嵌入式系統和計算機硬件) 。 Pre- vs. post-development。核查是更大的優勢,如果推出在早期的過程中系統的發展, 錯誤發現較早對於生產週期是成本較低的。(宣稱英特爾公司失去了數百萬美元 的釋放他們的奔騰晶片與 FDIV 錯誤。). 核查方法稱為模型檢查。在上述條. 款的分類,模型檢驗是一種自動的,以模型為基礎的。它的目的是用於並行的反 應系統。並行發生的錯誤是最困難的測試(可能要模擬好幾次),因為他們往往 將非重複性或沒有涉及的測試案例,因此這是非常值得擁有檢查的技術。常見的 model checking 有 SPIN[13]、NuSMV[14]、JPF[15]、LTL[16]和 CTL[16]等等。. 1.7 Reachability Testing 並行程式在現代的程式設計中愈來愈普遍,一個並行程式有 2 個以上的程序 或是線程並行執行來完成一些任務,對於相同的輸入(程式執行時需要的輸入)多 次執行的結果會有不一樣的情形,這種情形叫做 non-deterministic behavior,意 思就是說一個並行程有一固定輸入的序列單一執行的結果部不能代滿足此程式 執行的正確性,甚至多次成功執行並行程式 P,在未來的情況可能會產生有不正 確的結果,一個並行程式執行的所執行所產生的並行事件叫做 Synchronization. 6.

(17) sequence , 例 如 同 步 像 是 Synchronous 像 是 Semaphore , 或 是 monitor-entry procedure 或是 sending 和 receiving message passing 和一些 很普遍的 shared memory 都是。一個並行程式執行 concurrent program P 因為有不一樣的執行會產 生不同的 Synchronization sequence。 Duplicating test 說明一個不一樣的 concurrent program P 的測試會有不一樣 的測試會產生不一樣的 SYN-sequence。Exhaustive testing 並行程式 P 完成很多 次 的 執 行 所 有 可 能 的 SYN-sequence 的 測 試 , 一 個 簡 單 的 方 法 去 解 決 nondeterministic behavior 當測試一個 concurrent program P 就是去執行並行程式 P 一個固定的輸入很多次希望有一次會產稱錯誤,這種型態的測試叫做 nondeterministic testing,這個方法很好去達成,敗是他通常沒有效率,而且有兩 種問題(1)一些並行程式 P 可行的 SYN-sequence 可能被執行很多次 (2)一些可行 的執行 sequence 可能從未被執行過 。 為了去解決分散式程式中不可預測性的行為一些研究員已經設計Static analysis technique 去偵測並行程式某些類別的異常。而不是去執行目標程式, 去企圖給一個保證的程式並不能進去某些知道先前定義好的狀態產稱error,static analysis 被用來偵測並行程式同步(synchronzation) 和 資料使用(data-usage ) 上 的錯誤,像是同步錯誤包含deadlock 和 “wait forever”,資料使用錯誤包含資料 使用常用序列錯誤,像是讀取 未先初始化的變數和 平行的資料錯誤。 一個並行程式 P 可以被決定性測試. 7.

(18) (1) 在測試組中選擇一個集合(X,S),每一個測試從(X,S),X 是 input 和 S 是並行 程式的 SYN-sequence (2) 對 於 每 一 個 選 擇 的 測 試 (X,S) , 完 成 一 個 輸 入 為 X 並 行 程 式 P 根 據 SYN-sequence s 決 定 的 測 試。 去 強 迫 P 根 據 S 去 執 行 , 這 個 強 迫 的 SYN-sequence 去執行表示 S 是否在 concurrent program 中可行,決定性測試 並行程式允許使用此 SYN-sequence 被選擇根據 P 的實作和規格。無論如何, 決定性測試會有額外的問題去解決。其中一個主要的問題就是去決定哪種型 態的 input 和 SYN-sequence 選擇給並行程是去執行。 先前已經有work被發表出來,黃冠寰博士發表Reachability testing 去解決並 行程式P的 nondeterministic behavior,假設S是一個並行程式P的SYN-sequence, Reachability testing of P with X 和 SYN-sequence S 有下列步驟要完成: (1) 使用S去產生prefix其他可行的SYN-sequence,這些prefix被產生由改變race condition 的結果,一個執行會依循一個SYN-sequence的race variant將會產生 同於的SYN-sequence。 (2) 對於每次從步驟(1)所產生的race variant,從prefix-based replay和race variant 去執行和收集增加的SYN-sequence。並行程式P的Prefix-based replay 有兩個 步驟 (i) Replay phase: 回放 所有可 能的 Synchronization event phase: 在回放R之後,紀錄subsequence Synchronization event。 重複步驟(1)和步驟(2),有新的 SYN-sequence 在步驟(2)收集。. 8. (ii)Monitor.

(19) 圖.2 Concept of Reachability testing. 1.8 A General model to perform reachability testing for message passing programs 我們會提到 Richard H Carver 他們的 work(A general model of reachability testing [5] 和 Reachability testing of concurrent programs[11])所使用 timestamp assignment scheme 去得到每個 thread 的 event 先後順序,並且提出他們所使用的 timestamp assignment scheme 只能使用在 single receiver 上面,在此我們提出了新 的方法,使用 Unique Message ID,使用林哲生學長的 race generator software package 可以解決 multiple receiver 的問題。 為什麼我們要使用 Unique Message ID,因為我們針對兩種 message passing. 9.

(20) 的模式,分別以 blocking send + blocking receive 和 non-blocking send + blocking receive 的模型為基礎,我們以 blocking receive 為接收訊息的一端,所以我們可 以使用 Unique Message ID 保證收訊息的一方收到 Unique Message ID。根據 Unique message ID 收的一方可以知道從哪個 event 送來的訊息,並且訊息會帶著 屬於哪一個 thread、所執行的運算(send or receive)、此運算在所屬的 thread 是第 幾個 event 和使用哪一個 port,這麼一來 send 和 receive 變成為一對的運算 (operation pair)。 此所收集到所有的 Unique Message ID 為一組 Synchronization Sequence,然 後我們再把此 Synchronous Sequence 找尋所有可能的 topological order,並且編 上 version number,輸入到林哲生學長的 Race Variant Generate software package 去產生 race variant,並且經過兩個種類的 filter 過濾掉不合法的 race variant 使得 程式在執行 prefix-based replay 時,不會 block 住,完整跑完 reachability testing 的程序,完成 testing 的動作。. 10.

(21) 圖.3 Concept oncept of reachability testing for message passing programs. 2. 文獻探討 2.1 Technology for Testing Tes Nondeterministic Client/ / Server Database Applications 黃冠寰 博士在 2004 年於 IEEE Transaction on Software Engineering 發表以 race graph 的方式,直接更改 直接更改 Synchronization events 間 partially order 的關係 的關係。在 race graph 中 每 一 個 節 點 都 代 表 程 式 中 某 一 個 synchronization event , synchronization events 建立 partially order 關係使用 directed edge 表示。 。產生 race. 11.

(22) variants 時,僅需要分別就某一節點的 in-edge 作反向即可;若某一節點一共有 k 個 in-edge,則在此節點的位置上,至多會產生(sk-1)個 race variants,如圖 a 所示。 實驗 上相 較於 RV-diagram ,race graph 的方法 能大 幅提高 效能,對 於某個 SYN-sequences 總數為 117 的並行程式,RV-diagram 的方式一共需要 3,537 次的 執行,而 race graph 僅僅需要 152 次。那是因為 RV-diagram 所產生的 race variants 容易造成重複的測試,即產生相同的 SYN-sequence。. Reverse direction of in-edges. A race-graph of a SYN-sequence. (1) There is a loop.. i=1=[1,0]2. E. P1. P0. Remove some nodes. (2). e1. i=2=[0,1]2. e2. E. E. E. (3) i=3=[1,1]2. E. E. 圖.4 利用 race graph 產生 race variant. 2.2 Dynamic Effective Testing 雖然 reachability testing 已實證能完整地測試並行程式的非決定性行為,並 在效能上取得長足的進步,但其基礎架構上卻存在一種嚴重的不足。在前面提到, reachability testing 在 monitor 的過程中並不對受測程式的執行進行任何干預,因 此當程式中出現無窮迴圈或忙碌等待迴圈(busy-waiting loops)時,reachability 12.

(23) testing 很容易因為執行無法順利結束,導致 prefix-based replay 的過程中失敗。 “a” is a shared variable. Process 0. Process 1. .... .... S0,0. a=1;. S1,0. S0,1. DO { ... }. .... S0,2. WHILE (a==0). a=0;. .... 圖.5 造成 Reachability testing 問題的受測程式之一. 是一個由兩個程序 process 0 與 process 1 組成的並行程式,在 process 0 中有三行 程式碼:S0,0, S0,1 與 S0,2,而 process 1 中由一行程式碼 S1,0 組成。這邊很明顯 地可以看到:程式的執行將會在 S0,1 與 S0,2 不斷地來回,{S0,0, S1,0, S0,1, S0,2, …}是其中一個可能產生的執行順序。就如前面所敘述 reachability testing 的 架構,執行時產生的順序將會被記錄下來,提供後續的 race analyzer 作分析的動 作;但在以{S0,0, S1,0, S0,1, S0,2, …}為首的執行順序時,程式將會進入無窮的 等待迴圈之中,不斷地記錄的執行順序,最終耗盡系統所有可用的記憶體空間。 “a” is a shared variable and its initial value is 0. Process 0. Process 1. .... .... S0,0. DO { ... }. S1,0. S0,1. WHILE(a==0). .... a=1;. .... 圖.6 造成 Reachability testing 問題的受測程式之二. 另外一個潛在的問題是:有時程式的執行並沒有進入無窮迴圈之中。以圖.6 為例:. 13.

(24) 受測程式最快可能只執行三行的程式碼{S1,0, S0,0, S0,1}就結束,也有可能多在迴 圈裡執行一次,得到{S0,0, S0,1, S1,0, S0,0, S0,1}這樣的執行順序。很明顯地,process 0 中的迴圈 S0,0, S0,1 必須不斷地執行忙碌等待迴圈直到 process 1 中的 S1,0 獲得執 行;有別於無窮迴圈的例子最終必定會因為操作系統排程給 process 1 而執行結 束。但是在 reachability testing 的架構之下,race analyzer 為達到完整測試的目的, 會將所有程式可能的執行順序全部產生,因此無論是執行迴圈 S0,0, S0,1 一次、 兩次,甚至是無限多次的執行順序,都會因為 race analyzer 視作相異的 race variants 而逐一地付予執行。我們可以把這些產生的 race variants 表達成{(S0,0, S0,1,)i S1,0, S0,0, S0,1}的形式,其中 i 可以是大於或等於零的任意整數,而這些 race variants 將使得存放 race variants 的佇列永遠無法被清空,整個 reachability testing 將因而沒有結束的時候。 前面以一個最簡單的例子說明非無窮迴圈可能的問題,其中反覆執行的部分 S0,0, S0,1 都在同一個程序中。另一個較複雜的例子,反覆執行的部份將橫跨兩個 不同的程序。在圖.7 造成 Reachability testing 問題的受測程式之三中最短的可能 執行序列是{S1,0, S0,0, S0,1, S1,1},和前述例子類似,這個例子中所有可能的執行 序列可以表達成:{(S0,0, S1,0, S0,1, S1,1,)i S1,0, S0,0, S0,1, S1,1},其中 i 是大於或等 於零的任意整數;可能重複執行的部分為 S0,0, S1,0, S0,1, S1,1,分別屬於 process 0 與 process 1。. 14.

(25) “a” is a shared variable. Process 0. Process 1. .... .... S0,0. DO { a = 1;}. S1,0. DO { a = 0;}. S0,1. WHILE(a==0). S1,1. WHILE(a==0). .... .... 圖.7 造成 Reachability testing 問題的受測程式之三. Multi-thread 系統的測試驗證有以下困難點: Shared variables 的存取造成 race condition 除了、具迴圈,還有 Task priority,分成以下三個部分來進行研究: 處理迴圈程式可能造成的問題,在 prefix-based replay 時要能將已陷入無窮迴圈 的受測程式強制結束,並回報可能造成無窮迴圈的部分程式碼與特定的執行順序 。其次,在 race analyzer 的部分應發展能處理忙碌等待迴圈的演算法,避免產出 過多的 race variants,導致無窮的測試。. 2.3 Richard H. Carver’s work: A general model of Reachability Testing Richard H. carver 主要也是使用 reachability testing 的方式去完成[5][11]。分 別 model 了許多種 synchronization event。圖.8 表一個擁有四個線程(thread) 的並行程式 CP,每個 thread 藉由透過 port 傳送訊息和收到訊息互相溝通, 15.

(26) 每一個 send 運算會指定一個 port 為訊息的目的地,每一個 receive 運算會指 定一個 port 為收訊息的來源。圖.8 為收訊息的來源 Example of Reachability testing of message passing program 表對於 concurrent program 的 reachability testing 程式。他開 程式 始是由不可預測性的執行 CP,我們假設會產生 SYN-sequence Q0。 。我們表 示 Q0 是一個 space time diagram diagram,垂直表示一個線程(thread),一個單一箭 一個單一箭 頭表是一個訊息由非同步的方式從 send event 被傳遞到 receive event。Q0 的 Race condition 被辨別和使用去產生”race 被辨別和使用去產生 variants”,有 V1,V2 和 V3 V3。每一 個 race variant 是 Q0 的 prefix,當結果改變時 Q0 會產生不同的 race variant, variant 每一個 variant 被用來處理一個 prefix-based test run,強迫依照 race variant 執行,由圖.9 send/receive using a port 可得知 Q0 是一個 SYN-sequence sequence,V1 是由 Q0 所產生的 race variant,由 variant V1 產生 Q1,V1 為 Q1 的 prefix prefix,V2 是 Q1 產生的 race variant, ,V2 為 Q2 的 prefix,沒有新的 race variant 產生 產生,所 以 reachability testing 會停止。 會停止. Concurrent message passing programs. 16.

(27) 圖.8 Example of Reachability testing of message passing program. 使用 timestamp 去 assign 一個 vector timestamp,分別對 Asynchronous message passing model 和 Synchronous message passing model。Richard model Richard H Carver 在此假設 Asynchronous message passing model 是 Non-blocking blocking send operation + Blocking receive operation。一個 thread 執行 blocking receive operation 直到 message 被收到為止。每一個 send operation 都指定一個 port 當 message 被 send 出去的目 的地,每一個 receive 指定一個 port 當作 source 的來源。port 允許有很多的 sender 使用但是只允許有一個 receiver。 receiver. 圖.9 send/receive using a port. 假設使用的 port 是 FIFO(First-In-First-Out)訊息傳送的方式,當有兩 FIFO(First thread 一起 。 做 send 的動作時,port 裡的訊息是依照兩個 thread 做 send 的先後順序。 如圖.10 Timestamp scheme for asynchronous message passing model 有三個 17.

(28) thread,T1 做有兩個 event 做 send,分別為 S2 和 S4,T2 有兩個 event 做 receive, 分別為 r1 和 r2,T3 有兩個 event 做 send,分別為 S1 和 S3,每一個 Thread 都有 一個 vector clock 去記錄時間,T3 先執行 send event,所以 T3 的 vector clock 的 第三個欄位更新為 1,然後把 vector clock 一並傳遞到 thread 2,當 T2 收到 T3 的 message,T2 的 vector clock 的第二個欄位更新為 1,並且把 T2 自己的 vector clock 和 T3 所送來的 vector clock 來做比較,所以較大的欄位的值當作更新,第三個欄 位的值更新為 1,T1 做 send 的動作,把第一個 vector 欄位更新為 1,並且把 vector clock 一並傳遞到 thread 2,當 T2 收到 T1 時,T2 的 vector clock 第二個欄位更新 為 2,並且把 T1 所送過來的 vector clock 和 T2 的 vector clock 做比較,取得較大 的欄位值並更新,所以 T2 的 vector clock 的第一個欄位會更新為 1,隨後 T3 做 send event,並且把 T3 自己的 vector clock 欄位更新為 2,一並把 T3 的 vector clock 送過去,當 T2 的 r3 event 收到 T3 的訊息後,T2 把自己 vector clock 的欄位更新 為 3,然後比較 T2 的 vector clock 欄位和 T3 的 vector clock 欄位,欄位較大的值 當作更新,T2 的第二個欄位更新為 2,T1 繼續執行 S4 event,T1 的 vector clock 欄位更新為 2,把 vector clock 一並傳送到 T2,當 T2 做 r4 event 的把欄位更新為 3,並且把 T1 傳送過來的 vector clock 較大值當作更新,所以 T2 的第一個欄位 更新為 2。 A vector timestamp for asynchronous message passing 在 timestamp 上更新: 1. 當一個 thread Ti 執行一個 non-blocking send event s,他完成了以下的運算:. 18.

(29) a) Ti.v[i] = Ti.v[i]+1 b) s.ts = Ti.v 。訊息也帶著 timestamp s.ts。 。 2. 當一個 thread Tj 執行一個 receive event r 由 s event 傳送 message,他完成 了以下的運算:: a)Tj.v[j] = Tj.v[j]+1,. b)Tj.v = max(Tj.v , s.ts) c)r.ts =. Tj.v。. 圖.10 Timestamp scheme for asynchronous message passing model. 如圖.11 traditional timestamp assign scheme 有三個 thread,T1 做有兩個 event 做 send,分別為 S2 和 S4, ,T2 有兩個 event 做 receive,分別為 r1 和 r2, ,T3 有兩 個 event 做 send,分別為 S1 和 S3,每一個 Thread 都有一個 vector clock ock 去記錄 時間,T3 先執行 send event event,所以 T3 的 vector clock 的第三個欄位更新為 1,然 後把 vector clock 一並傳遞到 thread 2,當 T2 收到 T3 的 message,T2 的 vector clock 的第二個欄位更新為 1,並且把 T2 自己的 vector clock 和 T3 所送來的 vector clock 19.

(30) 來做比較,所以較大的欄位的值當作更新,第三個欄位的值更新為 1,再把所更 新 T2 vector clock 傳遞到 T3, 把 vector 欄位較大值當作更新,所以此時 T3 的 vector clock 和 T2 的 vector clock 是一樣的。T1 做 send 的動作,把第一個 vector 欄位更新為 1,並且把 vector clock 一並傳遞到 thread 2,當 T2 收到 T1 時,T2 的 vector clock 第二個欄位更新為 2, 並且把 T1 所送過來的 vector clock 和 T2 的 vector clock 做比較,取得較大的欄位 值並更新,所以 T2 的 vector clock 的第一個欄位會更新為 1 再把所更新 T2 vector clock 傳遞到 T1,把 vector clock 欄位較大值當作更新,所以此時 T1 的 vector clock 和 T2 的 vector clock 是一樣的。隨後 T3 做 send event,並且把 T3 自己的 vector clock 欄位更新為 2,一並把 T3 的 vector clock 送過去,當 T2 的 r3 event 收到 T3 的訊息後,T2 把自己 vector clock 的欄位更新為 3,然後比較 T2 的 vector clock 欄位和 T3 的 vector clock 欄位,欄位較大的值當作更新,T2 的第二個欄位更新 為 2,再把所更新 T2 vector clock 傳遞到 T3,把 vector 欄位較大值當作更新, 所以此時 T3 的 vector clock 和 T2 的 vector clock 是一樣的。T1 繼續執行 S4 event, T1 的 vector clock 欄位更新為 2,把 vector clock 一並傳送到 T2,當 T2 做 r4 event 的把欄位更新為 3,並且把 T1 傳送過來的 vector clock 較大值當作更新,所以 T2 的第一個欄位更新為 2,再把所更新 T2 vector clock 傳遞到 T1,把 vector clock 欄位較大值當作更新,所以此時 T1 的 vector clock 和 T2 的 vector clock 是一樣的。 A vector timestamp for synchronous message passing 1.當一個 thread Ti 執行一個 blocking send event s,他完成了以下的運算: Ti.v[i] 20.

(31) = Ti.v[i] + 1。傳送的訊息有帶著 傳送的訊息有帶著 s.ts。 2.當一個 thread Tj 執行一個 receive event r 收到由 s 所發出來的訊息 所發出來的訊息,他完成 下列的步驟: a) Tj.v[j] = Tj.v[j] + 1 , b)Tj.v = max(Tj.v , s.ts) , c) r.ts = Tj.v。 Thread Tj 也把 Tj.v 送回給 Ti。 3. Thread Ti 收到 Tj.v 完成以下的運算: 完成以下的運算 a)Ti.v = max(Ti.v , Tj.v) b)s.ts = Ti.v。. 圖.11 traditional timestamp assign scheme. New scheme for synchronous message passing: 1. 當一個 thread Ti 執行一個 blocking send event s,他完成了以下的運算 他完成了以下的運算: a) Ti.v[i] = Ti.v[i] + 1 b) s.ts = Ti.v 傳送的訊息有帶著 s.ts。 21.

(32) 2. 當一個 thread Tj 執行一個 receive event r 所收到的訊息由 s 所發出的,他 所發出的 完成以下的運算: a) Ti.v[i] = Ti.v[i] +1 b) Tj.v = max(Tj.v , s.ts) , c) r.ts = Tj.v.. Thread Tj 也把訊息傳回給 thread Ti。. 3. Thread Ti 收到 thread Tj.v 而且完成 Ti.v = max(Ti.v , Tj.v)。. 圖.12 Time stamp scheme for race analysis. 如圖.12. Time stamp scheme for race analysis 是一個新的 timestamp scheme scheme,. 有三個 thread,T1 做有兩個 event 做 send,分別為 S2 和 S4,T2 有兩個 event 做 receive,分別為 r1 和 r2,T3 r2 有兩個 event 做 send,分別為 S1 和 S3, ,每一個. 22.

(33) Thread 都有一個 vector clock 去記錄時間,T3 先執行 send event,所以 T3 的 vector clock 的第三個欄位更新為 1,然後把 vector clock 一並傳遞到 thread 2,當 T2 收 到 T3 的 message,T2 的 vector clock 的第二個欄位更新為 1,並且把 T2 自己的 vector clock 和 T3 所送來的 vector clock 來做比較,所以較大的欄位的值當作更 新,第三個欄位的值更新為 1,再把所更新 T2 vector clock 傳遞到 T3,但是 T3 的 vector clock 會先保持在原來 timestamp,從 T2 所傳遞過來的 vector clock 會用 另外的 vector 把他存起來,等待下次要更新的時候從這裡更新,所以我們可以得 到線再 T2 第一個 event 的 vector time clock 和 T3 的第一個 vector time clock 不一 樣,有先後順序可以比較,這就是新的 timestamp scheme,可以比較出兩兩的先 後順序。 此篇對於並行程式和同步物件提出了一個主要模型,對於常常使用的同步結 構,像是 Synchronous message passing 和 Asynchronous message passing 的同步 模型,甚至包含 semaphore 和 monitors。第二就是如何把傳統的 timestamp assignment scheme 延伸為可以辨別是否有 race condition 產生的 timestamp assignment scheme,使用一套 race set 機制(圖.14 proposition condition of finding race set)根據 timestamp 去找出對於 receiving event 所產生的 race condition 有哪 些 sending event。第三點,提出 race table(圖.13 Coustruct-Race-Table algorithm) 架構去計算 SYN-sequence 的 race variant。圖.15. An Example of race table 是一. 個簡單的例子根據圖.12 Time stamp scheme for race analysis 所建構出來的。. 23.

(34) 圖.12 Time stamp scheme for race analysis 中有三個 thread T1、T2、 T3 做 synchronous message passing,然後依照 event timestamp assignment scheme 訂出先 後順序,再使用找 race set 的方試找出 race condition 的 event,再根據 race table 畫出 race table,找出圖.16 Race variants derived from race table 得到的 race variants。. 圖.13 Coustruct-Race-Table algorithm. 24.

(35) 圖.14 proposition condition of finding race set. 圖.15 圖. 圖..16. An Example of race table. Race variants derived from race table. 25.

(36) 圖.17 The problem of timestamp assignment scheme. 圖.18 An Example to find race sets and construct a race table 是一個較複雜的例 子說明如何找出 race set 和建 race table。先在有四個 thread T1、T2、T3 和 T4。 每 個 event 都先標上 timestamp,根據 timestamp timestamp 我們可以找出對應 receiving event 所對應的 sending event 產生的 race event 有哪些。根據圖.15 的 proposition 我們 可以找出 race set 有四組,其中三組是非空的集合,race(r1)是根據使用同一個 是根據使用同一個 port 不同 thread 的 sending event 找出來的,所以有 s2、s3 和 s4,但是 s3 必須等 s1 執行完之後她才可以執行(因為程式 因為程式 event 的先後順序),所以 r1 的發生 race 的 sending event 是 s2 和 s4。同理 同理 race(r2) = {s3,s4}、race(r3) = {s4},現在要來見 現在要來見 race 分別為 r1,r2 table,race table 的第一行是填入非空集合的 行是填入非空集合的 race set,所以有三個,分別為 26.

(37) 和 r3,由左到右的順序為先到後 由左到右的順序為先到後(根據 timestamp),然後再依照各個 race set 所得 到的 sending event 改變其所對應的夥伴(一個 改變其所對應的夥伴 send 配一個 receive),在 table 中的 變數 v 我們可以看成有三種情況(圖.14 我們可以看成有三種情況 proposition condition of finding race set), set 第一種 v=0 是沒有改變他的夥伴,第二種 是沒有改變他的夥伴 v=1 是改變到他的夥伴所對應的集合 是哪一個 event,第三種 v=-1 v= 表示此 event 要被移除,所以我們可以看到 所以我們可以看到 table 有 我們可以看到圖.18 An Example to find race sets and construct a 這三種情形發生,我們可以看到 race table 所建出來的 race table,此 table race table 所產生出來的每一行就是一個 race variant,所以此 table 產生五個 race variant(圖.19 Derived race variant),再根據此 再根據此 五個 race variant 再繼續做完 testing 的動作。另外他們也提出 race table 去解決 semaphore 的問題[20]。. 圖.18 An Example to find race sets and construct a race table. 27.

(38) 圖.19 Derived race variant. 2.4 The Discussion for Richard H Carver’s work 由 reachability eachability testing of concurrent program(Richard H Carver 的 paper)所提出 paper) 例子均可以明顯看出 timestamp 的所運用的地方,都是針對 receiving event 的先 後關系所設計的。根據 paper 上所提到的 proposition,要先找 race set 才能建 race table,而且 race table 列的 receiving event 有先後順序關係,也就是說單一的 也就是說單一的 receiver 才會有先後順序關係,如圖,若是多個 才會有先後順序關係 receiver 話,會有平行 會有平行(parallel) 的現象發生,如圖.20 synchronous message passing of timestamp of single receiver 和圖.21 Asynchronous message passing of timestamp of single receiver 說明。 說明. 28.

(39) 圖.20 synchronous message passing of timestamp of single receiver 說明 synchronous message passing 在 single receiver 可以到達大家都有可以比較的 timestamp。. Synchronous message passing (vector time clock) Port: P1 T1. T2. T3. r1 [0,1,1]. s1 [0,0,1] [0,1,1]. s2 [1,0,0]. r2 [1,2,1]. [1,2,1]. Sending event 完成時的time clock. r3 [1,3,2]. s3 [0,1,2] [1,3,2]. s4 [2,2,1]. r4 [2,4,2]. [2,4,2]. 以single receiver來看,sending event 會有total order S1 ->S2->S3->S4. 圖.20 synchronous message passing of timestamp of single receiver. 圖.21 Asynchronous message passing of timestamp of single receiver 說明在 Asynchronous message passing 在 single receiver 中不可以比較 timestamp,event 之間會有 parallel 的情形發生,像是 s1 和 s2 的 timestamp 不能比較,s3 和 s4 的 timestamp 不能比較。. 29.

(40) Asynchronous message passing (vector time clock) Port: P1 T1. T2 r1 [0,1,1]. s2 [1,0,0]. s1 [0,0,1] r2 [1,2,1]. r3 [1,3,2] s4 [2,0,0]. T3. s3 [0,0,2] r4 [2,4,2]. 以single receiver來看,sending sending event 會有parallel S1 ->S3 S2->S4. 圖.21 Asynchronous message passing of timestamp of single receiver. 圖.22 The timestamp can’t be compared. 圖.22 The he timestamp can’t be compared 是一個 Synchronous message passing, passing. 30.

(41) 我們可以明顯的看出來這裡有五個 thread,thread T1 和 thread T2 和 thread T3 形成一個單一互相傳遞訊息的群組,thread T4 和 thread T5 形成一個單一互相 溝通的群組,變成兩個群組,thread group 1 和 thread group 2,當有兩群的情形 發生的時候,我們可以得知 thread group 1 的 vector clock 會互相更新,所以 send event s1、s2、s3、s4 和 receive event r1、r2、r3、r4 的 vector clock 便會註記所有 相互傳遞訊息後更新的情況。同樣的,send event s5、s6 和 receive event r5、r6, 也會註記所有相互傳遞訊息後更新的情況,圖 B 可以明顯得到 thread group 1 上 event 的 vector clock 相互有先後順序關係,thread group 2 上 event 的 vector clock 相互有先後順序關係,但是 thread group 1 的 event 和 thread group 的 event 並沒 有先後順序關係,因為他們的 vector clock 並未更新到相對應 thread 的欄位,例 如 Thread T1 event s2 的 vector clock[1,0,0,0,0] 和 Thread T4 event r5 的 vector clock [0,0,0,1,1] 沒 辦 法 比 較 先 後 順 序 , Thread T2 event r2 的 vector clock[1,2,1,0,0] 和 Thread T4 event r6 的 vector clock [0,0,0,2,2] 沒辦法比較先後 順序,沒辦法比較先後順序的 event 便違反 Richard H. Carver 所提出的 proposition 中的第三點找 race set,若一定要找的話,會少找 race set。如圖.22 The timestamp can’t be compared 的淺色字體部分,我們可以依照 proposition 去找 race set,得 到 race (r1) ={s2},但是平行的 event s5、s6 也會競爭 port,所以正確的 race(r1) ={s2,s5,s6},同理 race(r2) = {s3,s5,s6}、race(r3) = {s4,s5,s6}、race(r4) = {s5,s6}。 因此下個步驟並不能正確建立 race table,以此例子突顯 receiving event 在平行的. 31.

(42) 時候使用 Richard H. Carver 所提出了尋找 race variant 方式並不可行。. 圖.23. Three groups. 當我們要找所有 event 先後順序的關係,最直接的方式就是透過一個共用物 最直接的方式就是透過一個共用物 件(shared object),圖.24 three groups with a shared oobject,共用物件可以記載所有 共用物件可以記載所有 使用此物件的 event 先後順序,讓所有 先後順序 event 有 order,的如共用的變數和共用的 的如共用的變數和共用的 記憶體。. 32.

(43) 圖.24 three groups with a shared object. 另外,依照演算法的方式來看 依照演算法的方式來看,只找其中一種 topological sort 未必能滿足所 有可能的情況,以 Asynchronous message passing(non-blocking passing(non blocking send + blocking receive)來看。. 圖.25 The problem of construction of a race table. 圖.26 沒 沒有找 有找出 出所 所有 有可 可能的 能的 topological sort 會 發生 發生可 可能的 能的 情 情況 況說明 在 synchronous message passing 的情況下只取一種 topological sort 產生所產生的情形 產生所產生的情形, 依照建 time stamp assignment scheme 演算法下去做,會有如圖的兩種情況 會有如圖的兩種情況,圖為 四個 thread,各個 thread 分別為 send 、receive、send 和 receive event,以 timestamp. 33.

(44) 分別以情況一和情況 記錄各個 event 的先後順序,所以會得到情況一和情況二,分別以情況一和情況 的先後順序 二下去做 race table 演算法。 演算法. 圖.26 沒有找出所有可能的 topological sort 會發生可能的情況 圖.26 沒有找出所有可能的 topological sort 會發生可能的情況建完 race table 之 後,情況一 race table 所產生之 race variant(圖.27 所產生的 race variant 11)。. 情況一: T0. T1. s1 1000. r1 1100. T2 1. T3 2. s2 0010. r2 0011. Race set(r1) = {s2} Race set(r2) = { } r1 1. 1. topological order1: r1 r2. T0 s1. T1. T2. r1. s2. T3 r2. Race variant 1. 圖.27 27 所產生的 race variant 1. 34.

(45) 建完 race table 之後,情況二 race table 所產生之 race variant(圖.28 所產生的 race variant 2)。. 情況二: T0 s1 1000. T1 r1 1100. T2 2. T3 1. s2 0010. r2 0011. Race set(r1) = {} Race set(r2) = {s1}. r1 1. 1. topological order1: r2 r1. T0 s1. T1. T2. r1. s2. T3 r2. Race variant 1. 圖.28 所產生的 race variant 2. 依照以上的例子說明,若只有找其中一種 topological order 的話,會找不到 另一種 topological order 的 race variant,所以我們後來發現可採取的方式,就是 去找所有可能的 topological sort receiving event 的 race table(Coustruct-Race-Table algorithm)。此方法與我們提出的方法所找出的 race variant 個數是一樣的,所產 生的 race variant 也會有重複,使用多個 race table 去解決 synchronous message passing 的 multiple receiver 問題也是可行,對此方法我們有自己的解法。. 35.

(46) 3. 實作方法 3.1 Framework. 圖.29 A reachability testing for message passing framework. 圖.29 A reachability testing for message passing framework 是從 reachability testing 的架構所衍生出來的,開始執行 的架構所衍生出來的 concurrent program of message passing programs 去 monitor 一段 SYN-sequence,然後此 SYN-sequence 再找出所有的 topological order sequence, ,然後 assign version number,丟到 Race analyz analyzer 去產 生 race variant,並且根據所需求的 並且根據所需求的 message passing model 過濾到不合法的 race variant,再把這些合法的 race variant 存入 race variant queue 中,做完 prefix prefix-based 36.

(47) replay 再找出相異的 SYN-sequence sequence 一直循環到此 reachability testing 完成。 完成. 3.2 Synchronization ynchronization Model 然後送訊息和收訊息分的模式為: 主要以訊息遞送的模型下去做的,然後送訊息和收訊息分的模式為 主要以訊息遞送的模型下去做的 a.送的一方是同步的(blocking (blocking send),收的一方是同步的(blocking s (blocking receive)。 receive) b.送的一方是非同步的(non (non-blocking send),收的一方是同步的(blocking (blocking receive) receive)。 針對多個 receiver 做 Reachability testing 的研究(圖. 30. Two Message Passing. Model)。. 圖. 30. Two Message Passing Model. 我們使用 Unique message ID 來做 SYN-sequence 的資料結構,Unique message ID 可以得知此 event 所屬的 thread 是哪一個,此 event 是屬於此 thread 第幾個 event,receiver 可以知道 message 從哪個 thread 來,並且可以知道由哪個 並且可以知道由哪個 port 來 做存取(圖.31 Unique message ID 結構)。. 圖.31 Unique message ID 結構. 37.

(48) 使用一個 string array 去當作所收集到的 SYN-sequence 的資料結構(圖 圖. 32 An array of a SYN-sequence)。. 圖. 圖 32 An array of a SYN-sequence. Timestamp. Unique Message ID. message. 使 用 timestamp 得 知. 無法得知 event 完成的. passing (blocking send+. event 所屬 thread 的先後. 時間,除非只有 除非只有 single. blocking receive). 順序 順序,除此之外,還必. thread. 須得知所競爭 port 的. multiple receiver 一樣會. event 是完成的時間。. 有 parallel 的情形。 。. message. 主要使用 timestamp 得. 因 為 event 知 道 所 屬. (non-blocking. 知個 event 所屬 thread. thread 第幾個 event,再 event. 的先後順序,要找 racing. 加上使用那個 port port,跟. Synchronous. Asynchronous passing. send+ blocking receive). 38. receiver , 在.

(49) 的 event 的話,必須知道. asynchronous 情況很相. 使用哪個 port。. 似。. 圖. 33 Timestamp vs. Unique Message ID. 3.3 Reachability Testing Concept for Message Passing Programs. Algorithm 1: Generate the partial order graph of a SYN-sequence S Input: A SYN-sequence S that contains two types of synchronization events: send and receive. Output: A partial order graph PG (1) Add each synchronization event of S to PG as a vertex. (2) For the synchronization events of the same process, add an edge from the i-th event to the j-th event, where j=i+1. (3) For two synchronization events X and Y, add an edge (X,Y) to PG if (a) X and Y are not of the same process, (b) X and Y operate on the same port, and (c) X and Y are one of the following: • X and Y are S(v,i) and R(v,i+1). • X and Y are R(v,i) and S(v,i+1).. 圖.34 Algorithm 1. Algorithm 2: Derive race variants from a SYN-sequence Input: A SYN-sequence S. Each synchronization event in S is either S(T,OP,E,P) or R(T,OP,E,P), where T, OP, E, and P are the thread, 39.

(50) send/receive operation, event sequence, and port, respectively. Note that S is obtained from the prefixed-based replay of a race variant. Each event is either monitored or replayed after the prefixed-based replay. Output: A set RV that contains race variants of SYN-sequence S.. 圖.35 Algorithm 2. Algorithm 3: Generate all of the topological sort of a SYN-sequence Input: A partial order graph PG of a monitored SYN-sequence Output: A set of SYN-sequences TS (1) Apply the topology sort algorithm to nodes in PG. Store the obtained SYN-sequence in TS.. 圖.36 Algorithm 3. Algorithm 4: Generate the race graph of a SYN-sequence S Input: A total ordered SYN-sequence S Output: A race graph G (1) Add each S-event of S to G as a vertex (2) For the S-events of the same process, add an edge from the S-event with order i to the S-event with order i+1 ,where 1 ≤ i <(the maximum value of S-event order of the process). (3) Add an edge (Sx,Sy) to G if Sx and Sy .. 圖.37 Algorithm 4. Algorithm 5: Analyzing edges in the race graph of a SYN-sequence to derive race variants Input: A total order SYN-sequence S Output: A set RV which contains race variants of S (1) Invoke Algorithm to generate the race graph G from TS, i.e., G=Race-graph(S). 40.

(51) (2) RV={}. (3) Let SE be the set of S-events which have at least one in-edge in G. (4) FOR each S-event E in SE k=number of in-edges of E. Assume (e1,e2,…,ek) are k in-edges FOR i = 1 to 2k-1 Assume [b1,b2,…,bk]2 is the binary representation of i Let G’=G //Reverse the direction of in-edges FOR j=1 to k IF bj=1 THEN reverse the direction of ej in G’ END FOR //Remove some nodes IF there is no loop in G’ THEN Remove all the nodes which have not happened before E from G RV =RV ∪(the set of nodes in G’) END IF END FOR END FOR. 圖.38 Algorithm 5. Reachability testing 使用在 message passing programs(process or thread) P 和 SYN-sequence S 有下列步驟要完成: (1) 先執行message passing program P收集一段完整的SYN-sequence S,啟用 Algorithm 1產 生partial order graph, 啟用 Algorithm 3 並且 找出所有此 SYN-sequence 的 topological order , 再 啟 用 race analyzer[4](Algorithm 4, Algorithm 5)產生race variant。 (2) 根據所產生的race variant我們透過(i)blocking send and blocking receive model:. 41.

(52) 啟 用 Algorithm 6 把 不 合 法 的 race variant 濾 掉 。 (ii)non-blocking send and blocking receive model: 啟用Algorithm 7把不合法的race variant濾掉。 (3) 每次從步驟(2)所產生的race variant,從prefix-based replay和race variant 去執 行和收集增加的SYN-sequence。Message passing P的Prefix-based replay 有兩 個步驟(i) Replay phase: 回放所有可能的Synchronization event. (ii)Monitor. phase: 在回放Race variant之後,紀錄subsequence Synchronization event。 (4) 重複步驟(1)、步驟(2) 和步驟(3),若有新的SYN-sequence在步驟(3)收集。. 3.4 Race Variant Filter 為什麼我們要使用filter,因為我們在產生race variant時,會有順序的sending event和receiving event,當我們replay此race variant的event時,會碰到一種情況, 就是當此event sequence不符合此synchronization model時,就會發生系統deadlock 現象,因為我們在race analyzer時針對每個吃進來的SYN-sequence建一個race graph,根據此race graph再反轉edge,進而產生race variant,當我們針對race graph 反轉edge時,會產生一些race variant不合於所針對的message passing model,為了 不讓整個程式deadlock,我們一定採取過濾動作。 圖.39 是我們針對 blocking send + blocking receive model 和圖.40 non-blocking send + blocking-receive model 做的過濾演算法。. Algorithm 6: For blocking send and blocking receive: Filter the invalid message 42.

(53) passing race variants of a race variant queue Input: A race variant queue Qo Output: A queue of valid message passing race variants (1) Initialize Qf as an empty race variant queue (2) Let RV represent a race variant of Qo. Let RVf represent a race variant of Qf .Let e(s) and e(r) represent a sending event and a receiving event of a race variant. Let N(s) and N(r) represent number of sending events and number of receiving events. Let dif(N) represent a current number of sending event and receiving event difference. Initialize N(s)、N(r) and dif(N) are zero. (3) FOR each race variant in Qo Get a RV and remove it from Qo IF(there is a e(s) of RV) N(s) plus one dif(N) plus one END IF IF(there is a e(r) of RV) N(r) plus one dif(N) minus one END IF IF( N(s) equal N(r) and dif(N)equal to zero ) Add this RV as the RVf to Qf. END IF END FOR. 圖.39 Algorithm 8 :Blocking send + Blocking receive Filter. Algorithm 7: For non-blocking send and blocking receive: Filter the invalid message passing race variants of a race variant queue Input: A race variant queue Qo Output: A queue of valid message passing race variants (1)Initialize Qf as an empty race variant queue (2)Let RV represent a race variant of Qo. Let RVf represent a race variant of Qf .Let e(s) and e(r) represent a sending event and a receiving event of a race variant. Let N(s) and N(r) represent number of sending events and number of receiving events. Let dif(N) represent a current number of sending event and receiving event difference. Initialize N(s)、N(r) and dif(N) are zero. 43.

(54) (3)FOR each race variant in Qo Get a RV and remove it from Qo IF(there is a e(s) of RV) N(s) plus one dif(N) plus one END IF IF(there is a e(r) of RV) N(r) plus one dif(N) minus one END IF IF( N(s)greater or equal N(r) and dif(N)greater than zero or equal to zero ) Add this RV as the RVf to Qf. END IF END FOR 圖.40 Algorithm 7 ::Non-blocking send + Blocking receive Filter. 3.5 Monitor 圖.37,為收集Unique Unique Message ID SYN-sequence,每個thread在receiver receiver 收集 完後傳送到 Thread Server上一組SYN-sequence。收集SYN-sequence此為一個 Server 此為一個 monitor時所收集的SYN-sequence sequence。. 圖.41 圖 Monitor SYN-sequence. 44.

(55) 3.6 An Example of Our Solution 圖.42 Multiple receiver using unique message id為一個concurrent program,有 四個thread,我們可以看到分為兩群,第一群為T1、T2,第二群為T3、T4,使用 unique message ID 來 傳 送 , 我 們 可 以 依 照 此 SYN-sequence 來 做 一 個 all the topological sort的結果如圖.43 All of the topological sorts of SYN-sequence。 然後我們以第一組SYN-sequence當作例子,以所排出的順序給予一組version number,然後我們可以得到他們的partial order graph 和race graph如圖.44 Partial order graph(上) Race graph(下),根據race graph反轉in-edge之後產生race variants 如圖.45 Derived race variants,我們可以得到得到十六個相異的race variants如 圖.46 16 Distinct race variants,透過filter濾掉不合法的race variants如圖.47 透過 blocking send + blocking receive Filter 過濾,得到兩個合法的race variant RV6 和 RV11。所留下來的是可以replay的race variants,再繼續prefix-based replay看看是 否有相異的SYN-sequence,再做一次 all the topological order去直到testing結束。. 45.

(56) 圖.42 Multiple ultiple receiver using unique message id. 圖.43 All ll of the topological sorts of SYN-sequence. 46.

(57) 圖.44 Partial P order graph(上) Race graph(下). 47.

(58) 圖.45 Derived race variants. 48.

(59) 圖.46 16 Distinct race variants. 49.

(60) 圖.47 透過blocking send + blocking receive Filter 過濾. 50.

(61) 同樣的SYN-sequence sequence使用在asynchronous message passing上面,經過 經過 。 asynchronous message passing filter會留下不同的race filter variants,如下圖。. 圖.48 透過 non-blocking non send + blocking receive Filter 過濾. 4. 實驗結果 4.1 Framework. 圖. 49 A SYN--sequence of synchronous message passing 51.

(62) 主要針對 multiple receiver 所輸入的 SYN-sequence,由圖知道有兩個 receiver 分別為 T1 和 T3,有六個 unique message ID 組成 SYN-sequence,針對所收到的 SYN-sequence 我們丟入 race analysis 產生 RV。 我們此實驗都會根據 multiple receiver 所輸入的 SYN-sequence 產生的 RV 分 別由 synchronous message passing filter 和 asynchronous message passing filter 做實 驗。. 4.2 實驗數據 T2_s_1_P1 T1_r_1_P1 T0_s_1_P1 T1_r_2_P1 T4_s_1_P1 T3_r_1_P1 圖.50 SYN-sequence. 根據以上的 SYN-sequence(圖.50 SYN-sequence)來做實驗,我們可以得知產 生 114 個相異的 race variant,經過 race variant filter 之後,可以得到 asynchronous message passing 97 個 RV,synchronous message passing 7 個 RV。Synchronous message passing 使用的 race table 所產生的 RV 相異的個數是一樣的。. 52.

(63) r1. T0. 1. 0. 1. 2. 1. -1. 3. 2. -1. T1 r1. s2. r2. T2. T3. T4 s3. s1. race(r1) = s2,s3. r2. T0. race(r2) = s3. T1 r1. T2. T3. T4. T0. s3. s1. s2. T1 r1. T2. T3. T4 s3. s1. s2. 圖.51 不同先後順序的 receiving event 所得到的 race table 之一. r1. T0. r3. 1. 0. 1. 2. 1. -1. 3. 2. -1. T1 r1. T2 s1. T3 r3. T4 s3. race(r1) = s2,s3 race(r3) = s2. s2. race(r2) ={}. T0. T1 r1. s2. T2 s1. T3. T4. T0. s3. T1 r1. T2 s1. T3. T4 s3. s2. 圖.52 不同先後順序的 receiving event 所得到的 race table 之二. 53.

(64) r3. T0. r1. 1. 0. 1. 2. 1. -1. 3. 2. -1. T1. T2. r1. s1. T3 r3. T4 race(r3) = s1,s2. s3. race(r1) = s2 s2 race(r2) ={}. T0. T1. T2 s1. s2. T3 r3. T4. T0. s3. T1. T2 s1. T3 r3. T4 s3. s2. 圖.53 不同先後順序的 receiving event 所得到的 race table 之三. 圖.51 不同先後順序的 receiving event 所得到的 race table 之一、圖.52 不同 先後順序的 receiving event 所得到的 race table 之二、圖.53 不同先後順序的 receiving event 所得到的 race table 之三使用很多的 race table 去解決 multiple receiver 的問題(synchronous message passing),主要針對 receiving event 各種可能 的結果下去做的,我們得到 9 個 race variants,7 個相異的 race variants,跟我們 以下所實驗我們的方法的結果是一樣的。 根據 Richard H. Carver 所提供的演算法(圖.13)做為基礎,此演算方法主要解 決 synchronous message passing of multiple receiver 所造成 receiving event 有 parallel 的現象,parallel SYN-sequence 是由 multiple receiver 所得到有數個 receiving event 的 timestamp 所稱之,我們得出一個新的演算方法如下圖:. 54.

(65) Algorithm 8 : Generate race variants of race tables of a parallel SYN-sequence Input: A parallel SYN-sequence that contains two types of synchronization events: send and receive. Let Non-assign-Seq is a sequence which is generated from topological sort. Output: race variants’ queue Qv of race tables of multiple receiver (1) Generate all of the topological order sequences of receiving event of a parallel SYN-sequence and store the sequences Non-assign-Seq to a queue Qs. (2) For every Non-assign-Seq form Qs to algorithm 9 to get SYN-sequences and store the SYN-sequences to queue QSYN. (3) For SYN-sequence from QSYN use Coustruct-Race-Table algorithm(圖.13) to get race tables (4) For every race table derives race variants and store distinct race variants to queue Qv. 圖.54 Algorithm 8. Algorithm 9: Generate a SYN-sequence Input: Non-assign-Seq Output: a total order SYN-sequence using timestamp (1) Combine the vector clock of the receiver of a Non-assign-Seq and assign the new total order timestamp to the vector clock of receivers. (2) Update the acknowledge vector timestamp clock of send events. 圖. 55 Algorithm 9. 55.

(66) 另外針對 asynchronous message passing model 我們使用一樣的 SYN--sequence 得到的 race variants 比使用 Yu Lei 所提出的方法得到兩個 race variant[17] [17]還多出 許多的 race variant,原因是 原因是 Yu Lei 他所測的 program 的模式是針對每個 sending event 只能送到特定的 thread,所以說有兩個以上的 thread receiver 並不能競爭 sending event 所送出的 message,這種情況就是 這種情況就是 single receiver 的情況,而我們可以針對 而我們可以針對 兩個以上 receiver(multiple receiver) receiver)去競爭 sending event 所送出的 message message,當然 所得到的 race variant 個數比起 single receiver 多出許多,情況也複雜許多 情況也複雜許多。. Filtered race variants Type of SYN-sequence. 56. Synchronous. Asynchronous. Total. Message. Message. Distinct. Passing RVs. Passing RVs. RVs. 2. 20. 359. 281. milliseconds. milliseconds. 2. 10. 109. 94. milliseconds. milliseconds. 7. 97. 4060. 4247. milliseconds. milliseconds. 27. 16. 114.

(67) 57. 12. 189. 25721. 25824. milliseconds. milliseconds. 10. 588. 14515. 15395. milliseconds. milliseconds. 32. 9763. 1947593. 1940453. milliseconds. milliseconds. 10. 1034. 32250. 33406. milliseconds. milliseconds. 219. 672. 10651. 1107.

(68) 23. 32473. 17611797. 17601375. milliseconds. milliseconds. Table. SYN-sequence 實驗結果 Table.1. 58. 34323.

(69) 5. 結論與未來展望 5.1 結論 根據 Richard H. Carver 他們所使用的 timestamp assignment scheme 會發生 thread event 平行的現象,而沒辦法解決 multiple receiver 的情況(因為 race set 找 出來的個數不對),但是我們卻使用了 Unique message ID 來完成,因為 blocking receive 所以 receiver 端一定會收到 unique message ID,再透過 race analyzer 做 race variant 分析,透過 race variant filter 過濾不符合 message passing model 的 race variant(synchronous message passing 和 asynchronous message passing),所得到的 race variant 正式符合 message passing 模型,timestamp assignment scheme 必須要 先知道有多少個 thread,透過 Unique Message ID 的話,便不需要知道有多少個 thread 執行,而且經過 filter 把不合法的 race variant 拿掉,可以提高程式回放的 正確性,不會讓程式停擺,此技術可以 porting 到分散式架構上去做測試,不過 此篇沒有寫 socket programming,只有在單機上做 thread 之間透過 port 做訊息交 換測試,所以未來可以往這方面去著手,此論文並沒有實做完整個 reachability testing 完整過程,在 prefix-based replay 方面必須往 send protocol 和 receive protocol 方面著手,之前 read protocol 和 write protocol 有所限制是不一樣的,必須考慮 到 synchronous port 和 asynchronous port 的型態,不過我們可以知道透過找出所 有可能的拓樸排序必須花費很大的時間,因為我們必須把所有可能的 parallel event 先後順序都找出來,產生所有的 total order,再丟到 race analysis 做分析,. 59.

(70) 產生 race variant,過濾掉很多不符合模型的 race variant,所得到的 race variant 便是針對可解 multiple receiver 所產生的 race variant,並且我們發現排序所有的 parallel receiving event,使用很多的 race table 可以解決 synchronous message passing 的 multiple receiver 的問題,跟我們的解法得到結果是一樣的。至於 asynchronous message passing 的 multiple receiver 問題,Yu Lei[17]所提出的架構 還是在 single receiver 上面,因為我們的解法針對所有可能的 parallel event 做排 序,會產生 asynchronous message passing multiple receiver 的 race variants,主要 針對的方向(single receiver vs. multiple receiver )是不一樣的,至於 Yu lei 的方式是 否可以像 Richard H. Carver 一樣可以做修改成 multiple receiver 的方法,因為做 法不相同,針對所測試的 program model 也不一樣,還要進一步的探討。. 60.

(71) 5.2. 未來展望 目前 testing 的技術還有很多方面有待改進,此篇主要著墨在 blocking send. blocking receive model 和 non-blocking send blocking receive model 上面,還有兩 種模式 blocking send non-blocking receive 和 non-blocking send non-blocking receive,針對 receive 不到時該怎麼做個狀況的處理,這些也都是可行的方向。 如果遇到 message passing 的 infinite loop 時,就要加入 Dynamic Effective Testing(DET)的功能,若我們要測分散式的系統架構,因為每個 port 或是 channel 都有 over flow 的情形會發生,所以如何測出 buffer overflow 也是一個課題。不 過不管怎麼說,測試總是一個很難的學問,考驗人類的智慧,最終大家還是得往 一個通用的解法去思考。. 61.

(72) 6. REFERENCES [1] G. H. Hwang, K.C. Tai, and T.L. Huang, "Reachability Testing: An Approach To Testing Concurrent Software", Int’l J. Software Eng. and Knowledge Eng., vol. 5, no. 4, pp. 493-510, Dec. 1995. [2] Abraham Silberschatz, Peter Baer Galvin, and Greg Gagne,"Operating System Concepts", John Wiley & Sons, ISBN: 0471417432, 6th edition (June 26, 2001). [3] K.C. Tai and Richard H. Carver,"Testing of Distributed Programs", Chapter 33 in Parallel and Distributed Computing Handbook, editor A. Y. Zomaya, McGraw-Hill, 1996. [4] Gwan-Hwan Hwang, Sheng-Jen Chang, and Huey-Der Chu, "Technology for Testing. Nondeterministic. Client/Server. Database. Applications",. IEEE. Transaction on Software Engineering, Volume 30, Number 1, pp. 59-77, Jan., 2004. [5] Richard H. Carver and Yu Lei, “A General Model for Reachability Testing of Concurrent Programs,” ICFEM 2004, LNCS 3308, pp. 76-89, 200S. Y. Hsu and C. G. Chung,"A heuristic approach to path selection problem in concurrent program testing", Proc. 3rd IEEE Workshop on Future Trends of Distributed Computing System(1992) pp. 86-92. [6] K. C. Tai, R. H. Carver, "Use of sequencing constraints for specifying, testing and. 62.

參考文獻

相關文件

建模時,若我們沒有實際的物理定律、法則可以應用,我們 可以構造一個經驗模型 (empirical model) ,由所有收集到

下圖一是測量 1994 年發生於洛杉磯的 Northridge 地震所得 到的圖形。任意給定一個時間 t ,從圖上可看出此時間所對

 眼睛是心靈之窗,心靈是眼神之源。在眼球後方 感光靈敏的角膜含有 1.37 億個細胞,將收到的信 息傳送至腦部。這些感光細胞,在任何時間均可 同時處理

利用這種說法一個 vector space 的 一組 basis 利用 Proposition 1.5.4 便可以說成就是該 vector space 中所有 spanning set 的 minimal element; 也可以說是該 vector

在 abelian group 最好用的性質就是其每個 subgroup 都 是 normal subgroup, 所以每次碰到有關 abelian group 的性質時, 我們都可先找一個 nontrivial subgroup 再利用其為

另外, 以後我們要談的 decomposition theorem, 都是將一個 vector space 拆解成一些 subspaces 的 internal direct sum, 我們不會再去談 external direct sum,

在 abelian group 最好用的性質就是其每個 subgroup 都 是 normal subgroup, 所以每次碰到有關 abelian group 的性質時, 我們都可先找一個 nontrivial subgroup 再利用其為

然後利用 parametric model 來 evaluate 任何的 input image 是否為人臉的 image。我們用 PCA 來做這件事情,我們可以想像所有的 image 都是 high dimensional vector,然後 PCA 會把它