California, Berkeley. • Test generation for compilers • Existing works: • Program generation (Csmith) • Generate test from scratch • Program mutation (EMI) • Randomly remove statements Random Opportunistic Favor large/complex programs 2
of California, Berkeley. • Observation • Bug-triggering programs are small • ~30 LOC (Sun et al. ISSTA’16) • Program mutation • mutations of statements • Change variable names • Search space is bounded enumeration • Confirmed Bugs: • GCC/Clang (217),CompCert (29), Scala (42) 3
of California, Berkeley. Goal: Enumerate all identifier mutations • Step-1: Convert an existing test into skeleton 8 Syntax rule of program Correspond rule of transformation
of California, Berkeley. Goal: Enumerate all identifier mutations • Step-2: fill in the holes in a skeleton 10 Generated Test Skeleton Generated Test <b, a, b, b, b, a> <a, b, b, b, a, b> 2 1 3 4 5 6
of California, Berkeley. Goal: Enumerate all identifier mutations • Step-2: fill in the holes in a skeleton 11 Generated Test Skeleton Generated Test 2 1 3 4 5 6 <b, a, b, b, b, a> <a, b, a, a, a, b> α-equivalent
of California, Berkeley. Goal: Enumerate all identifier mutations • Step-2: fill in the holes in a skeleton • Formulate as a set partition problem (well-known) 12 Generated Test Skeleton Generated Test 2 1 3 4 5 6 <b, a, b, b, b, a> <a, b, a, a, a, b> { {1,3,4,5}, {2, 6} } { {1,3,4,5}, {2, 6} } 64 (naive) 31 (set partition)
University of California, Berkeley. 18 Partition n+1 elements into k subsets • The selected element is partitioned to a set s, where | s | = 1 • The selected element is partitioned to a set s, where | s | > 1
University of California, Berkeley. 19 • Now we can get all partitions recursively: function par(n, k) { ... // handle base cases return union( add(n, par(n-1, k)), par(n-1, k-1)); }
too large in practice • Throw away tests with > 10K variants Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. 34
too large in practice • Throw away tests with > 10K variants Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. 35
too large in practice • Throw away tests with > 10K variants • Retained 90% of the original tests Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. 36
variants • Retained 90% of the original tests Characteristics of tests after filtering Liang Gong, Electric Engineering & Computer Science, University of California, Berkeley. 37