csci 565 spring 2009. originally proposed by [weiser 88]and [gallagher 91] in software maintenance ...

32
Csci 565 Spring 2009

Upload: karen-conley

Post on 16-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

Csci 565Spring 2009

Page 2: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance
Page 7: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance
Page 8: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance
Page 9: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

Lock has a predicate usage

Page 10: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance
Page 12: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance
Page 13: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance
Page 14: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance
Page 23: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance
Page 24: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance
Page 25: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance
Page 26: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance
Page 27: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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

This slice contains the following statements:

Page 28: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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

Page 29: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

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: Csci 565 Spring 2009.  Originally proposed by [Weiser 88]and [Gallagher 91] in software maintenance  Useful for  Software Debugging  Software Maintenance

[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.