slice- based testing

32
Csci 565 Spring 2009

Upload: ismet

Post on 31-Jan-2016

136 views

Category:

Documents


5 download

DESCRIPTION

Csci 565 Spring 2009. Slice- Based Testing. Slice Based Testing (SBT). Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance Useful for Software Debugging Software Maintenance Program understanding Quantification of functional cohesion. Program Slicing. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Slice- Based Testing

Csci 565Spring 2009

Page 2: Slice- Based Testing

Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance

Useful for Software Debugging Software Maintenance Program understanding Quantification of functional cohesion

Page 3: Slice- Based Testing

A complementary method of program decomposition that applied after the program is written/designed

Purpose Debugging (subset of behavior is fixed) Maintenance (subset of program is

improved) Works on actual program

Specify program behaviors using a sets of variables at some set of statements

Page 4: Slice- Based Testing

Slicing criterion for a program specifies a windows for observing its behavior Where a window

▪ specified as a statement and a set of variables

▪ Allows the observations of values of the specified variables before execution of particular statement

▪ E.g., S(x, 24) (i.e., value of x at line 24)

Page 5: Slice- Based Testing

The Commission Problem Statement Rifle salesperson in the Arizona Territory sold rifle locks, stocks, and barrels made by

a gunsmith in Missouri. Locks cost $45.00, stocks cost $30.00, and barrels cost Locks cost $45.00, stocks cost $30.00, and barrels cost $25.00$25.00. Salespersons had to sell at least one complete rifle per month, and production limits are such that the most one salesperson could sell in one month is 70 locks, 80 stocks, 90 barrels. Each rifle salesperson sent a telegram to the Missouri company with the total order for each town s/he visits; salespersons visit at least one town per month, but travel difficulties made ten towns the upper limit. At the end of each month, the company computed commission as follows:▪ 10% on sales up to $100010% on sales up to $1000▪ 15% on the next $80015% on the next $800▪ 20% on any sales in excess of $1800.20% on any sales in excess of $1800.

The company had four salespersons. The telegram from each salesperson were sorted into piles (by person) and at the end of each month a data file is prepared, containing the salesperson's name, followed by one line for each telegram order, showing the number of locks, stocks, and barrels in that order. At the end of the sales data lines, there is an entry of “-1” in the position where the number of locks would be to signal the end of input for that salesperson. The program produces a monthly sales report that gives the salesperson’s name, the total number of locks, stocks, and barrels sold, the salesperson's total dollar sales, and finally his/her commission.

Page 6: Slice- Based Testing
Page 7: Slice- Based Testing
Page 8: Slice- Based Testing
Page 9: Slice- Based Testing

Lock has a predicate usage

Page 10: Slice- Based Testing

Slice-based Testing technique divide a program into components (or

slices)A program slice?

Refers to a set of program statements that may affect the computation of variable v at statement s

Page 11: Slice- Based Testing
Page 12: Slice- Based Testing
Page 13: Slice- Based Testing
Page 14: Slice- Based Testing

Given a program P, a program graph G(P) in which statements are numbered, and a set V of variables in P, the slice on the variable set V at statement n, S(V,n) the set node (or line) numbers of all

statements fragments in P prior to nprior to n that contribute tocontribute to the values of variables in V at statement fragment n

Page 15: Slice- Based Testing

For statement s and variable v, the slice of program P w.r.t. the slicing criterion <s, v > includes only those statements of P needed to contribute (or influence) to the behavior of v at s.

Page 16: Slice- Based Testing

1 Y := X2 Z := Y

The value of X before the first statement can contribute to the value of Z after second▪ S(Z,2)

Page 17: Slice- Based Testing

The notion of contribution can be described by the USE relationship (e.g., C-use and P-use) P-use: used in a P-use: used in a predicatepredicate (decision) (decision) C-use: used in C-use: used in computationcomputation (assignment) (assignment) O-use: used for O-use: used for outputoutput (write/print, etc.) (write/print, etc.) L-use: used for L-use: used for locationlocation (e.g., (e.g.,

pointers/subscripts)pointers/subscripts) I-use: I-use: iterationiteration (e.g., internal counter) (e.g., internal counter)

Page 18: Slice- Based Testing

Definition nodes can be refined I-defI-def: defined by input (e.g., read) A-defA-def: defined by assignment

statements (e.g., a:= x + y)

Page 19: Slice- Based Testing

There are two properties in a slice The slice must have been obtained from

the original program by statement deletion

The behavior of the slice must correspond to the behavior of program as observed through the window of the slicing criterion

Page 20: Slice- Based Testing

By removing the source code of a program, we may obtain slice that is not grammatically correct E.g. removing the THEN clause from an

IF-THEN-ELSE block

Page 21: Slice- Based Testing

Important guideline for node inclusion in the slice:

1. If statement n is a defining node for v, the n is included in the slice

2. If statement n is a usage node for v, then n is NOT included in the slice

3. P-use/c-use of other variables are included if they their execution has some affects on the value of the variable v

loop

Page 22: Slice- Based Testing
Page 23: Slice- Based Testing
Page 24: Slice- Based Testing
Page 25: Slice- Based Testing
Page 26: Slice- Based Testing
Page 27: Slice- Based Testing

Consider the slice S5, which is S(locks,23)={22,23,24,29,30}

This slice contains the following statements:

Page 28: Slice- Based Testing

If we add statement 1-14 and 53, then we can compile the slice as follows:

Page 29: Slice- Based Testing

Using SBT, Program is decomposed into set of mini-

programs or functions which are easier to test

The focus can be made on the most interesting parts of a program (smaller and/or simpler) or parts that implements properties

difficult using du-paths because du-paths are sequences that include both statements and variables

Page 30: Slice- Based Testing

1. Never make a slice S(V,n) for which variables v V do not appear in statement fragment n

2. Make slices on one variable3. Make slices for all A-def nodes

e.g.,

SS2727:S(sales,36)={3,4,5,19,20,21,22,23,24,25,:S(sales,36)={3,4,5,19,20,21,22,23,24,25,26,27,28,29,30,36}26,27,28,29,30,36}

4. Make slices for P-use nodeP-use node because the slice shows how the predicate variable gets its value

5. Stay away from non P-use slices6. Consider making slices compile-able

(executable)`

Page 31: Slice- Based Testing

Metrics may include Coverage: compares the lengths of slices

to the length of the entire program▪ Ratio of mean slice length to program length▪ a low coverage value indicates a long program

with many shorts slices (or properties ) Coupling (statements common to all slices) Parallelism ( slices having a very few

elements in common)

Page 32: Slice- Based Testing

[Rapps 85] S. Rapps and E. Weyuker. Selecting software test data using data flow information. IEEE Transaction on Software Eng., vol.se-11, no.4, pp:367-375, April, 1985.

[Frankl 88] P. Frankl and E. Weyuker. An Applicable Family of Data Flow Testing Criteria. IEEE Transaction on software eng., vol.14, no.10, October 1988.

[Weyuker 88] E. Weyuker. The evaluation of Program-based software test data adequacy criteria. Communication of the ACM, vol.31, no.6, June 1988.

[Jorgenson 95]. Software Testing: A Craftsman’s Approach. CRC publication, 1995.

[Jorgenson 02]. Software Testing: A Craftsman’s Approach. CRC publication, 2002, 2nd edition.

[Weiser 88]. M. D. Weiser. Program slicing. IEEE Transaction on software eng. Vol.10, no.4, pg:352-357, April 1988.

[Gallagher 91] K. B. Gallagher , and J. R. Lye. Using program slicing in software maintenance. IEEE Transaction on Software Eng., vol.17, no.8, pg: 751-761.