查看“︁線性程式碼順序及跳轉”︁的源代码
←
線性程式碼順序及跳轉
跳转到导航
跳转到搜索
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
'''線性程式碼順序及跳轉'''(Linear code sequence and jump)簡稱'''LCSAJ''',是[[軟體測試]]相關的術語。其廣義的定義是一種程式分析方式,可以識別出要測試[[程式碼]]中的結構單元。其主要用途是用在{{le|動態程式分析|Dynamic program analysis|動態軟體分析}}中,來確認「測試到什麼程度才算是足夠?」<ref name="Quantifying the test effectiveness of Algol 68 programs">M.A.Hennell, D.Hedley and M.R.Woodward, "Quantifying the test effectiveness of Algol 68 programs", Proceedings of the Strathclyde ALGOL 68 conference 1977, pp. 36 – 41, ISSN 0362-1340</ref>。動態軟體分析用來衡量軟體測試資料的品質以及有效性,而其量化數據是由要測試程式碼中的結構單元數量來確認。動態分析若是用來量化測試資料中的結構單元數量,此分析也會稱為是[[代碼覆蓋率|結結構覆蓋率分析]]。 線性程式碼順序及跳轉也有狹義的定義,是程式碼中明確定義的一段連續程式碼,此定義下的LCSAJ也稱為跳躍—跳躍路徑(JJ-path)。 ==歷史== LCSAJ分析法是由{{le|Michael Hennell|Michael Hennell}}教授提出,目的是為了評估[[原子核物理学]]用到的數學函式庫的品質<ref name="An experimental testbed for numerical software. I. Fortran">M. A. Hennell, ''An experimental testbed for numerical software. {I}. {Fortran}'', The Computer Journal 21(4):333--336, @nov, 1978</ref><ref name="An experimental testbed for numerical software. II. ALGOL 68">M. A. Hennell and D. Hedley, ''An experimental testbed for numerical software. {II}. {ALGOL 68}'', The Computer Journal 22(1):53--56, @feb, 1979</ref>。Hennell教授後來成立了{{le|LDRA公司|Liverpool Data Research Associates}},將為計劃開發的測試平台商品化販售,也就是後來的{{le|LDRA Testbed|LDRA Testbed}}。 LCSAJ是從1976年開始的<ref name="On program analysis">M.A. Hennell, M.R.Woodward and D.Hedley, "On program analysis", Information Processing Letters, 5(5), pp. 136 – 140, 1976</ref>,現在也稱為是跳躍—跳躍路徑(JJ-path)<ref name="On the relationship between two control-flow coverage criteria: all JJ paths and MCDC">M. R. Woodward, M. A. Hennell, "On the relationship between two control-flow coverage criteria: all JJ-paths and MCDC", Information and Software Technology 48 (2006) pp. 433–440</ref>。 ==LCSAJ程式區塊的定義及特點== LCSAJ是程式路徑中的一部份,包括一段線性(連續)程式碼,後面有條件[[分支 (計算機科學)|流程跳躍]]指令,並且包括以下三部份的程式碼 <ref name="Assessing a Class of Software Tools">M.A.Hennell, D.Hedley and I.J.Riddell, "Assessing a Class of Software Tools", Proceedings of the 7th International Conference on Software Engineering March 1984, pp. 266 – 277. ISSN 0270-5257</ref>: * 線性程式碼的啟始 * 線性程式碼的結束 * 線性程式碼結束後,依控制流程會跳躍到的目的程式。 LCSAJ和(最大的)[[基礎區塊]]不同,LCSAJ可以彼此重疊,因為可能在LCSAJ程式碼中間會出現跳躍到其他程式的跳躍指令,而基礎區塊程式碼中間不允許有跳躍指令。而且,條件式跳躍就會產生互相重疊的LCSAJ,條件成立時會執行程式碼A,條件不成立時會執行程式碼B,這就產生二段重疊的LCSAJ。因此,每一個基礎區塊都是LCSAJ,但LCSAJ可能會包括一個到多個基礎區塊。根據1986年的一篇文章指出,LCSAJ的大小多半是基礎區塊的四倍<ref name="OuldTesting1986">{{cite book|editor=Martyn A. Ould and Charles Unwin|title=Testing in Software Development|url=https://archive.org/details/testinginsoftwar0000unse|year=1986|publisher=Cambridge University Press|isbn=978-0-521-33786-1|page=[https://archive.org/details/testinginsoftwar0000unse/page/102 102]}}</ref>。 以下是用到基礎區塊的正式LCSAJ定義<ref name="Henning2013">{{cite book|author=Groenda, Henning|title=Certifying Software Component Performance Specifications|year=2013|publisher=KIT Scientific Publishing|isbn=978-3-7315-0080-3|pages=198–200}} quoting from {{cite journal | doi = 10.1002/stvr.400 | title=Inclusion, subsumption, JJ-paths, and structured path testing: a Redress | journal=Software Testing, Verification and Reliability | date=2009 | volume=19 | issue=3 | pages=199–213 | first=D. F. | last=Yates}}</ref>: {{quote|text=一個到多個連續編號''p'', (''p''+1), ..., ''q''基礎區塊程式單元的序列,之後有一個控制流程的跳躍,可能是跳出此程式碼單元,或是到編號為''r''的基礎區塊,''r''≠(''q''+1)。有關編號''p'',可能''p''=1,或者有其他的基礎區塊會跳到編號為''p''的基礎區塊(在LCSAJ的跳躍指令中,會說明要跳躍到的基礎區塊)}} 根據Jorgensen 2013年版的教科書,在英國以外,且不是[[ISTQB]]以外的文獻中,會將此敘述稱為是[[决策到决策路径]](DD-path)<ref name="Jorgensen2013">{{cite book|author=Paul C. Jorgensen|title=Software Testing: A Craftsman’s Approach, Fourth Edition|year=2013|publisher=CRC Press|isbn=978-1-4665-6068-0|page=136}}</ref>。 ==有效測試的比率== 覆蓋率分析度量可以確認測試進行的程度如何。最基本的度量是有執行到敘述,相對於所有敘述的比例,有效測試比率1(TER1)<ref name="Practical Application of Automated Software Tools">J.R.Brown, "Practical Application of Automated Software Tools", TRW Report No. TRW-SS-72-05, presented at WESCON, 1972</ref>: <math>TER_\text{1} = \frac{\text{number of statements executed by the test data}}{\text{total number of executable statements}}</math> 也有較高階的覆蓋率分析度量,例如考慮執行到控制流跳躍的比例,或是執行到LCSAJ的比例<ref name="Experience with Path Analysis and Testing of Programs">M.R.Woodward, D.Hedley and M.A.Hennell, “Experience with Path Analysis and Testing of Programs”, IEEE Transactions on Software Engineering, Vol. 6, No. 3, pp. 278 – 286, May 1980</ref>: <math>TER_\text{2} = \frac{\text{number of control-flow branches executed by the test data}}{\text{total number of control-flow branches}}</math> <math>TER_\text{3} = \frac{\text{number of LCSAJs executed by the test data}}{\text{total number of LCSAJs}}</math> 上述的度量有階層的關係,若TER3 = 100%,表示TER2 = 100%,且TER1 = 100%。 TER1和TER2的度量約在1970年代初期出現,TER3則是在1970年代末期。在{{le|DO-178|DO-178}}標準剛開始時,有要求TER1 = 100%,後來在1992年加上MC/DC([[修改條件判斷覆蓋]])的額外要求<ref name="DO-178B">Software Considerations in Airborne System and Equipment Certification-RTCA/DO-178B, RTCA Inc., Washington D.C., December 1992</ref>。許多專案會強制要求更高階的 TER3 = 100%,例如航太、通訊以及銀行{{cn|date=July 2014}}。在使用TER3時,有一個實務上的問題,是許多LCSAJ有包括互相矛盾的條件,因此無法執行到。 == 例子 == 考慮以下的C語言程式: <syntaxhighlight lang=c line="GESHI_FANCY_LINE_NUMBERS"> #include <stdlib.h> #include <string.h> #include <math.h> #define MAXCOLUMNS 26 #define MAXROW 20 #define MAXCOUNT 90 #define ITERATIONS 750 int main (void) { int count = 0, totals[MAXCOLUMNS], val = 0; memset (totals, 0, MAXCOLUMNS * sizeof(int)); count = 0; while ( count < ITERATIONS ) { val = abs(rand()) % MAXCOLUMNS; totals[val] += 1; if ( totals[val] > MAXCOUNT ) { totals[val] = MAXCOUNT; } count++; } return (0); } </syntaxhighlight> 這段程式中對應的LCSAJ程式啟始、結束及跳轉目標列表如下: {| class="wikitable" style="text-align:center" border="1" ! LCSAJ編號 !! 啟始行 !! 結束行 !! 跳轉目標行 |- ! 1 | 10 || 17 || 28 |- ! 2 | 10 || 21 || 25 |- ! 3 | 10 || 26 || 17 |- ! 4 | 17 || 17 || 28 |- ! 5 | 17 || 21 || 25 |- ! 6 | 17 || 26 || 17 |- ! 7 | 25 || 26 || 17 |- ! 8 | 28 || 28 || −1 |} 從這段程式可以看出LCSAJ識別到的程式碼可能會包括決策點,表示有經過決策判斷,判斷後的結果是繼續執行後面的程式。例如例子中的LCSAJ 2就包括了<code>while</code>指令,而當時的情形是<code>(count < ITERATIONS)</code>條件成立。 每一行程式都會劃分在一個或是多個LCSAJ範圍內,因此有每一行的LCSAJ密度,例如第17行出現在6個LCSAJ範圍內,因此其LCSAJ密度為6。在評估程式的可維護性時很有幫助,每一行的LCSAJ密度也反映了修改那一行會影響的LCSAJ數量。 若測試資料可以使所有的LCSAJ都至少執行一次,就滿足TER3 = 100%的覆蓋率等級。 ==參考資料== {{reflist}} [[Category:軟體度量]]
该页面使用的模板:
Template:Cite book
(
查看源代码
)
Template:Cite journal
(
查看源代码
)
Template:Cn
(
查看源代码
)
Template:Le
(
查看源代码
)
Template:Quote
(
查看源代码
)
Template:Reflist
(
查看源代码
)
返回
線性程式碼順序及跳轉
。
导航菜单
个人工具
登录
命名空间
页面
讨论
不转换
查看
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
工具
链入页面
相关更改
页面信息