680 likes | 3.23k Views
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.
E N D
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 • 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
Slicing Criterion • 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)
Example: The Commission problem in [Jorgenson02] • 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 $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 $1000 • 15% on the next $800 • 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.
Informal definition of SBT • 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
Formal definition of SBT (AKA Slicing Criterion) • 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 n that contribute to the values of variables in V at statement fragment n
Alternative definition: Program Slice • 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.
Simple example • 1 Y := X • 2 Z := Y • The value of X before the first statement can contribute to the value of Z after second • S(Z,2)
The notion of contribution: USE • The notion of contribution can be described by the USE relationship (e.g., C-use and P-use) • P-use: used in a predicate (decision) • C-use: used in computation (assignment) • O-use: used for output (write/print, etc.) • L-use: used for location (e.g., pointers/subscripts) • I-use: iteration (e.g., internal counter)
The notion of contribution: Definitions • Definition nodes can be refined • I-def: defined by input (e.g., read) • A-def: defined by assignment statements (e.g., a:= x + y)
Properties of Slice • 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
Problem with property one • 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
the Commission Problem (1) Important guideline for node inclusion in the slice: If statement n is a defining node for v, the n is included in the slice If statement n is a usage node for v, then n is NOT included in the slice P-use/c-use of other variables are included if they their execution has some affects on the value of the variable v loop
The compilable slice (1) Consider the slice S5, which is S(locks,23)={22,23,24,29,30} This slice contains the following statements:
The compilable slice (2) If we add statement 1-14 and 53, then we can compile the slice as follows:
Style and Techniques • 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
Good rules of thumb for SBT • Never make a slice S(V,n) for which variables v V do not appear in statement fragment n • Make slices on one variable • Make slices for all A-def nodes e.g., S27:S(sales,36)={3,4,5,19,20,21,22,23,24,25,26,27,28,29,30,36} • Make slices for P-use nodebecause the slice shows how the predicate variable gets its value • Stay away from non P-use slices • Consider making slices compile-able (executable)`
Possible of SB Metrics • 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)
References • [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.