func TestGenerateSmatCorpus(t *testing.T) { for i, actionSeq := range smatActionSeqs { byteSequence, err := actionSeq.ByteEncoding(&smatContext{}, smat.ActionID('S'), smat.ActionID('T'), actionMap) if err != nil { t.Fatalf("error from ByteEncoding, err: %v", err) } os.MkdirAll("workdir/corpus", 0700) ioutil.WriteFile(fmt.Sprintf("workdir/corpus/%d", i), byteSequence, 0600) } }
func init() { var ids []int for actionId := range actionMap { ids = append(ids, int(actionId)) } sort.Ints(ids) pct := 100 / len(actionMap) for _, actionId := range ids { runningPercentActions = append(runningPercentActions, smat.PercentAction{pct, smat.ActionID(actionId)}) } actionMap[smat.ActionID('S')] = action("SETUP", setupFunc) actionMap[smat.ActionID('T')] = action("TEARDOWN", teardownFunc) }
// Test the previous issues found by smat. func TestSmatHits(t *testing.T) { smatDebugPrev := smatDebug smatDebug = true // Use true when diagnosing a crash. for i := 0; i < len(smatHits); i += 2 { desc := smatHits[i] hit := []byte(smatHits[i+1]) log.Printf("testing smat hit: (%d) %s\n", i/2, desc) // fuzz the hit input smat.Fuzz(&smatContext{}, smat.ActionID('S'), smat.ActionID('T'), smatActionMap, hit) } smatDebug = smatDebugPrev }
// Test the previous crashers found by smat. func TestSmatCrashers(t *testing.T) { smatDebugPrev := smatDebug smatDebug = false // Use true when diagnosing a crash. // smat.Logger = log.New(os.Stderr, "smat ", log.LstdFlags) for i := 0; i < len(smatCrashers); i += 2 { desc := smatCrashers[i] crasher := []byte(smatCrashers[i+1]) log.Printf("testing smat crasher: (%d) %s", i/2, desc) // fuzz the crasher input smat.Fuzz(&smatContext{}, smat.ActionID('S'), smat.ActionID('T'), actionMap, crasher) } smatDebug = smatDebugPrev }
// fuzz test using state machine driven by byte stream. func Fuzz(data []byte) int { return smat.Fuzz(&smatContext{}, smat.ActionID('S'), smat.ActionID('T'), actionMap, data) }
} type mirrorColl struct { // Used to validate coll and snapshot entries. kvs map[string]string keys []string // Will be nil unless this is a snapshot. } type mirrorIter struct { // Used to validate iterator entries. pos int ss *mirrorColl } // ------------------------------------------------------------------ var actionMap = smat.ActionMap{ smat.ActionID('.'): action(" +batch", delta(func(c *smatContext) { c.curBatch++ })), smat.ActionID(','): action(" -batch", delta(func(c *smatContext) { c.curBatch-- })), smat.ActionID('{'): action(" +snapshot", delta(func(c *smatContext) { c.curSnapshot++ })), smat.ActionID('}'): action(" -snapshot", delta(func(c *smatContext) { c.curSnapshot-- })), smat.ActionID('['): action(" +itr", delta(func(c *smatContext) { c.curIterator++ })), smat.ActionID(']'): action(" -itr", delta(func(c *smatContext) { c.curIterator-- })), smat.ActionID(':'): action(" +key", delta(func(c *smatContext) { c.curKey++ })), smat.ActionID(';'): action(" -key", delta(func(c *smatContext) { c.curKey-- })), smat.ActionID('s'): action(" set", opSetFunc), smat.ActionID('d'): action(" del", opDelFunc), smat.ActionID('m'): action(" merge", opMergeFunc), smat.ActionID('g'): action(" get", opGetFunc), smat.ActionID('B'): action(" batchCreate", batchCreateFunc), smat.ActionID('b'): action(" batchExecute", batchExecuteFunc), smat.ActionID('H'): action(" snapshotCreate", snapshotCreateFunc), smat.ActionID('h'): action(" snapshotClose", snapshotCloseFunc),
func TestGenerateSmatCorpus(t *testing.T) { for i, actionSeq := range smatActionSeqs { byteSequence, err := actionSeq.ByteEncoding(&smatContext{}, smat.ActionID('S'), smat.ActionID('T'), smatActionMap) if err != nil { t.Fatalf("error from ByteEncoding, err: %v, i: %d, actonSeq: %#v", err, i, actionSeq) } os.MkdirAll("workdir/corpus", 0700) ioutil.WriteFile(fmt.Sprintf("workdir/corpus/%d", i), byteSequence, 0600) } } var smatActionSeqs = []smat.ActionSeq{ { smat.ActionID('X'), smat.ActionID('X'), smat.ActionID('Y'), smat.ActionID('Y'), smat.ActionID('<'), smat.ActionID('<'), smat.ActionID('*'), smat.ActionID('x'), smat.ActionID('y'), smat.ActionID('*'), smat.ActionID('['), smat.ActionID('['), smat.ActionID('B'), smat.ActionID('a'), smat.ActionID('o'), smat.ActionID('A'),
// Two registers, x & y. x int y int actions int } type smatPair struct { bm *Bitmap bs *bitset.BitSet } // ------------------------------------------------------------------ var smatActionMap = smat.ActionMap{ smat.ActionID('X'): smatAction("x++", smatWrap(func(c *smatContext) { c.x++ })), smat.ActionID('x'): smatAction("x--", smatWrap(func(c *smatContext) { c.x-- })), smat.ActionID('Y'): smatAction("y++", smatWrap(func(c *smatContext) { c.y++ })), smat.ActionID('y'): smatAction("y--", smatWrap(func(c *smatContext) { c.y-- })), smat.ActionID('*'): smatAction("x*y", smatWrap(func(c *smatContext) { c.x = c.x * c.y })), smat.ActionID('<'): smatAction("x<<", smatWrap(func(c *smatContext) { c.x = c.x << 1 })), smat.ActionID('^'): smatAction("swap", smatWrap(func(c *smatContext) { c.x, c.y = c.y, c.x })), smat.ActionID('['): smatAction(" pushPair", smatWrap(smatPushPair)), smat.ActionID(']'): smatAction(" popPair", smatWrap(smatPopPair)), smat.ActionID('B'): smatAction(" setBit", smatWrap(smatSetBit)), smat.ActionID('b'): smatAction(" removeBit", smatWrap(smatRemoveBit)), smat.ActionID('o'): smatAction(" or", smatWrap(smatOr)),
func TestGenerateSmatCorpus(t *testing.T) { for i, actionSeq := range smatActionSeqs { byteSequence, err := actionSeq.ByteEncoding(&smatContext{}, smat.ActionID('S'), smat.ActionID('T'), actionMap) if err != nil { t.Fatalf("error from ByteEncoding, err: %v", err) } os.MkdirAll("workdir/corpus", 0700) ioutil.WriteFile(fmt.Sprintf("workdir/corpus/%d", i), byteSequence, 0600) } } var smatActionSeqs = []smat.ActionSeq{ { smat.ActionID('g'), smat.ActionID('B'), smat.ActionID('s'), smat.ActionID('.'), smat.ActionID('d'), smat.ActionID('.'), smat.ActionID('s'), smat.ActionID('.'), smat.ActionID('b'), smat.ActionID('g'), smat.ActionID('H'), smat.ActionID('I'), smat.ActionID('>'), smat.ActionID('i'), smat.ActionID('h'), smat.ActionID('$'),