1 Type Sensitive Application of Mutation Operators for Dynamically Typed Programs Leonardo Bottaci...

10
1 Type Sensitive Application of Mutation Operators for Dynamically Typed Programs Leonardo Bottaci Department of Computer Science University of Hull, Hull, UK

Transcript of 1 Type Sensitive Application of Mutation Operators for Dynamically Typed Programs Leonardo Bottaci...

Page 1: 1 Type Sensitive Application of Mutation Operators for Dynamically Typed Programs Leonardo Bottaci Department of Computer Science University of Hull, Hull,

1

Type Sensitive Application of Mutation Operators for Dynamically

Typed Programs

Leonardo BottaciDepartment of Computer ScienceUniversity of Hull, Hull, UK

Page 2: 1 Type Sensitive Application of Mutation Operators for Dynamically Typed Programs Leonardo Bottaci Department of Computer Science University of Hull, Hull,

2

Mutation of Strongly typed Programs

• Variables and operators in expressions are typed.

• Mutation operators can be applied in a type sensitive manner.

original program mutant program

String s; String s

int i, j; int i, j;

… …

i abs(i), … j

Page 3: 1 Type Sensitive Application of Mutation Operators for Dynamically Typed Programs Leonardo Bottaci Department of Computer Science University of Hull, Hull,

3

Mutation of Weakly Typed Programs

• Variables and operators in expressions are not typed.

• How can mutation operators can be applied in a type sensitive manner?

original program mutant program

var s; var s

var i, j; var i, j;

… …

i abs(i), abs(s) … j… s

Page 4: 1 Type Sensitive Application of Mutation Operators for Dynamically Typed Programs Leonardo Bottaci Department of Computer Science University of Hull, Hull,

4

Basic Idea• Generate mutants dynamically.• Represent mutants of the original

program using a meta-mutant, (mutant schemata, parameterised mutant.)

orig program meta-mutant x = y + z; assign(m(x), arith(m(y), m(z)))

m(x) mutates variable x, e.g. abs(x) , y

arith(y, z) mutates arithmetic operator, e.g. z - y

assign(x, e) mutates assign operator, e.g. x += e, x -= e

Page 5: 1 Type Sensitive Application of Mutation Operators for Dynamically Typed Programs Leonardo Bottaci Department of Computer Science University of Hull, Hull,

5

Meta-mutant for Strongly Typed Program

m(x) { switch(mutantOfx) { none: return x; abs: return abs(x); inc: return x + 1; y: return y; … }}

x is known to be of type int, say, this allowscases to be determined at meta-mutant

generation time.

Page 6: 1 Type Sensitive Application of Mutation Operators for Dynamically Typed Programs Leonardo Bottaci Department of Computer Science University of Hull, Hull,

6

Meta-mutant for Weakly Typed Program

m(x) {

if (none) {

return x;

}

else {

determine, from the value of x, the appropriate mutants

update mutants in mutant table for x

set nextMutant in table

return mutantTable[nextMutant]

}}

Page 7: 1 Type Sensitive Application of Mutation Operators for Dynamically Typed Programs Leonardo Bottaci Department of Computer Science University of Hull, Hull,

7

Object Value Mutations• In JavaScript, members of object are

dynamic.

x = {student: {name: "John", number: "0232"}, grade: 45};

x.student.name = "Jane";

• Mutate the terminal or leaf properties only.– Property deletion, property value

mutation.• Again, discover these properties at

mutant execution time.

Page 8: 1 Type Sensitive Application of Mutation Operators for Dynamically Typed Programs Leonardo Bottaci Department of Computer Science University of Hull, Hull,

8

Variable Replacement Mutations

• To replace variable x with variable y, they should hold values of compatible type.

• m(x) can determine the type of x only.• Hence perform mutation in two phases

– Value mutation phase, e.g. return abs(x)

• Record types of all variables in this phase

– Replacement mutation phase, e.g. return y

• Use types recorded in value mutation phase

Page 9: 1 Type Sensitive Application of Mutation Operators for Dynamically Typed Programs Leonardo Bottaci Department of Computer Science University of Hull, Hull,

9

Summary

• Weakly typed languages are popular, especially for web programming, (e.g. JavaScript).

• In such languages, type errors are not caught by the compiler and so additional testing is required.

• Investigate advantages and disadvantages of mutation testing for weakly typed languages.

• A prototype tool has been developed for mutating JavaScript programs.

Page 10: 1 Type Sensitive Application of Mutation Operators for Dynamically Typed Programs Leonardo Bottaci Department of Computer Science University of Hull, Hull,

10

Issues

• JavaScript programs make use large objects created outside of the program, e.g. browser document objects, - to what extent should these be mutated?

• The JavaScript execution environments, language implementations, vary – good source for mutations.

• How weakly typed are programs in practice?