Best Syzkaller code snippet using state.saveSeqFile
state.go
Source:state.go
...155 if fresh {156 mgr.corpusSeq = 0157 mgr.reproSeq = st.reproSeq158 }159 saveSeqFile(mgr.corpusSeqFile, mgr.corpusSeq)160 saveSeqFile(mgr.reproSeqFile, mgr.reproSeq)161 mgr.Calls = make(map[string]struct{})162 for _, c := range calls {163 mgr.Calls[c] = struct{}{}164 }165 os.Remove(mgr.corpusFile)166 var err error167 mgr.Corpus, err = db.Open(mgr.corpusFile)168 if err != nil {169 log.Logf(0, "failed to open corpus database: %v", err)170 return err171 }172 st.addInputs(mgr, corpus)173 st.purgeCorpus()174 return nil175}176func (st *State) Sync(name string, add [][]byte, del []string) ([][]byte, int, error) {177 mgr := st.Managers[name]178 if mgr == nil || mgr.Connected.IsZero() {179 return nil, 0, fmt.Errorf("unconnected manager %v", name)180 }181 if len(del) != 0 {182 for _, sig := range del {183 mgr.Corpus.Delete(sig)184 }185 if err := mgr.Corpus.Flush(); err != nil {186 log.Logf(0, "failed to flush corpus database: %v", err)187 }188 st.purgeCorpus()189 }190 st.addInputs(mgr, add)191 progs, more, err := st.pendingInputs(mgr)192 mgr.Added += len(add)193 mgr.Deleted += len(del)194 mgr.New += len(progs)195 return progs, more, err196}197func (st *State) AddRepro(name string, repro []byte) error {198 mgr := st.Managers[name]199 if mgr == nil || mgr.Connected.IsZero() {200 return fmt.Errorf("unconnected manager %v", name)201 }202 if _, _, err := prog.CallSet(repro); err != nil {203 log.Logf(0, "manager %v: failed to extract call set: %v, program:\n%v",204 mgr.name, err, string(repro))205 return nil206 }207 sig := hash.String(repro)208 if _, ok := st.Repros.Records[sig]; ok {209 return nil210 }211 mgr.ownRepros[sig] = true212 mgr.SentRepros++213 if mgr.reproSeq == st.reproSeq {214 mgr.reproSeq++215 saveSeqFile(mgr.reproSeqFile, mgr.reproSeq)216 }217 st.reproSeq++218 st.Repros.Save(sig, repro, st.reproSeq)219 if err := st.Repros.Flush(); err != nil {220 log.Logf(0, "failed to flush repro database: %v", err)221 }222 return nil223}224func (st *State) PendingRepro(name string) ([]byte, error) {225 mgr := st.Managers[name]226 if mgr == nil || mgr.Connected.IsZero() {227 return nil, fmt.Errorf("unconnected manager %v", name)228 }229 if mgr.reproSeq == st.reproSeq {230 return nil, nil231 }232 var repro []byte233 minSeq := ^uint64(0)234 for key, rec := range st.Repros.Records {235 if mgr.reproSeq >= rec.Seq {236 continue237 }238 if mgr.ownRepros[key] {239 continue240 }241 calls, _, err := prog.CallSet(rec.Val)242 if err != nil {243 return nil, fmt.Errorf("failed to extract call set: %v\nprogram: %s", err, rec.Val)244 }245 if !managerSupportsAllCalls(mgr.Calls, calls) {246 continue247 }248 if minSeq > rec.Seq {249 minSeq = rec.Seq250 repro = rec.Val251 }252 }253 if repro == nil {254 mgr.reproSeq = st.reproSeq255 saveSeqFile(mgr.reproSeqFile, mgr.reproSeq)256 return nil, nil257 }258 mgr.RecvRepros++259 mgr.reproSeq = minSeq260 saveSeqFile(mgr.reproSeqFile, mgr.reproSeq)261 return repro, nil262}263func (st *State) pendingInputs(mgr *Manager) ([][]byte, int, error) {264 if mgr.corpusSeq == st.corpusSeq {265 return nil, 0, nil266 }267 var records []db.Record268 for key, rec := range st.Corpus.Records {269 if mgr.corpusSeq >= rec.Seq {270 continue271 }272 if _, ok := mgr.Corpus.Records[key]; ok {273 continue274 }275 calls, _, err := prog.CallSet(rec.Val)276 if err != nil {277 return nil, 0, fmt.Errorf("failed to extract call set: %v\nprogram: %s", err, rec.Val)278 }279 if !managerSupportsAllCalls(mgr.Calls, calls) {280 continue281 }282 records = append(records, rec)283 }284 maxSeq := st.corpusSeq285 more := 0286 const (287 // Send at most that many records (rounded up to next seq number).288 maxRecords = 100289 // If we have way too many records to send (more than capRecords),290 // cap total number to capRecords and give up sending all.291 // Otherwise new managers will never chew all this on a busy hub.292 capRecords = 100000293 )294 if len(records) > maxRecords {295 sort.Slice(records, func(i, j int) bool {296 return records[i].Seq < records[j].Seq297 })298 if len(records) > capRecords {299 records = records[len(records)-capRecords:]300 }301 pos := maxRecords302 maxSeq = records[pos].Seq303 for pos+1 < len(records) && records[pos+1].Seq == maxSeq {304 pos++305 }306 pos++307 more = len(records) - pos308 records = records[:pos]309 }310 progs := make([][]byte, len(records))311 for _, rec := range records {312 progs = append(progs, rec.Val)313 }314 mgr.corpusSeq = maxSeq315 saveSeqFile(mgr.corpusSeqFile, mgr.corpusSeq)316 return progs, more, nil317}318func (st *State) addInputs(mgr *Manager, inputs [][]byte) {319 if len(inputs) == 0 {320 return321 }322 st.corpusSeq++323 for _, input := range inputs {324 st.addInput(mgr, input)325 }326 if err := mgr.Corpus.Flush(); err != nil {327 log.Logf(0, "failed to flush corpus database: %v", err)328 }329 if err := st.Corpus.Flush(); err != nil {330 log.Logf(0, "failed to flush corpus database: %v", err)331 }332}333func (st *State) addInput(mgr *Manager, input []byte) {334 _, ncalls, err := prog.CallSet(input)335 if err != nil {336 log.Logf(0, "manager %v: failed to extract call set: %v, program:\n%v", mgr.name, err, string(input))337 return338 }339 if want := prog.MaxCalls; ncalls > want {340 log.Logf(0, "manager %v: too long program, ignoring (%v/%v)", mgr.name, ncalls, want)341 return342 }343 sig := hash.String(input)344 mgr.Corpus.Save(sig, nil, 0)345 if _, ok := st.Corpus.Records[sig]; !ok {346 st.Corpus.Save(sig, input, st.corpusSeq)347 }348}349func (st *State) purgeCorpus() {350 used := make(map[string]bool)351 for _, mgr := range st.Managers {352 for sig := range mgr.Corpus.Records {353 used[sig] = true354 }355 }356 for key := range st.Corpus.Records {357 if used[key] {358 continue359 }360 st.Corpus.Delete(key)361 }362 if err := st.Corpus.Flush(); err != nil {363 log.Logf(0, "failed to flush corpus database: %v", err)364 }365}366func managerSupportsAllCalls(mgr, prog map[string]struct{}) bool {367 for c := range prog {368 if _, ok := mgr[c]; !ok {369 return false370 }371 }372 return true373}374func writeFile(name string, data []byte) {375 if err := osutil.WriteFile(name, data); err != nil {376 log.Logf(0, "failed to write file %v: %v", name, err)377 }378}379func saveSeqFile(filename string, seq uint64) {380 writeFile(filename, []byte(fmt.Sprint(seq)))381}382func loadSeqFile(filename string) uint64 {383 str, _ := ioutil.ReadFile(filename)384 seq, _ := strconv.ParseUint(string(str), 10, 64)385 return seq386}...
saveSeqFile
Using AI Code Generation
1import (2func main() {3 db, _ := ethdb.NewMemDatabase()4 account := common.HexToAddress("0x1234567890123456789012345678901234567890")5 stateObject := state.NewStateObject(account, db)6 stateObject.SetNonce(0x1234)7 stateObject.SetBalance(0x1234)8 stateObject.SetCode(crypto.Keccak256Hash([]byte("code")), []byte("code"))9 stateObject.SetState(common.HexToHash("0x1234"), common.HexToHash("0x5678"))10 stateObject.SetState(common.HexToHash("0x5678"), common.HexToHash("0x1234"))11 stateObject.SetState(common.HexToHash("0x9abc"), common.HexToHash("0xdef0"))12 stateObject.SetState(common.HexToHash("0xdef0"), common.HexToHash("0x9abc"))13 stateObject.SetState(common.HexToHash("0x1234"), common.HexToHash("0x5678"))14 stateObject.SetState(common.HexToHash("0x5678"), common.HexToHash("0x1234"))15 stateObject.SetState(common.HexToHash("0x9abc"), common.HexToHash("0xdef0"))16 stateObject.SetState(common.HexToHash("0xdef0"), common.HexToHash("0x9abc"))17 stateObject.SetState(common.HexToHash("0x1234"), common.HexToHash("0x5678"))18 stateObject.SetState(common.HexToHash("0x5678"), common.HexToHash("0x1234"))19 stateObject.SetState(common.HexToHash("0x9abc"), common.HexToHash("0xdef0"))20 stateObject.SetState(common.HexToHash("0xdef0"), common.HexToHash("0x9abc"))21 stateObject.SetState(common.HexToHash("0x1234"), common.HexToHash("0x5678"))22 stateObject.SetState(common.HexToHash("0x5678"), common.HexToHash("
saveSeqFile
Using AI Code Generation
1func main() {2 state := NewState()3 state.saveSeqFile()4}5func main() {6 state := NewState()7 state.saveSeqFile()8}9func main() {10 state := NewState()11 state.saveSeqFile()12}13func main() {14 state := NewState()15 state.saveSeqFile()16}17func main() {18 state := NewState()19 state.saveSeqFile()20}21func main() {22 state := NewState()23 state.saveSeqFile()24}25func main() {26 state := NewState()27 state.saveSeqFile()28}29func main() {30 state := NewState()31 state.saveSeqFile()32}33func main() {34 state := NewState()35 state.saveSeqFile()36}37func main() {38 state := NewState()39 state.saveSeqFile()40}
saveSeqFile
Using AI Code Generation
1import (2func main() {3 file, err := os.Open("input.txt")4 if err != nil {5 panic(err)6 }7 defer file.Close()8 scanner := bufio.NewScanner(file)9 scanner.Scan()10 firstLine := scanner.Text()11 splitFirstLine := strings.Split(firstLine, " ")12 firstLineInt := []int{}13 for _, i := range splitFirstLine {14 j, err := strconv.Atoi(i)15 if err != nil {16 panic(err)17 }18 firstLineInt = append(firstLineInt, j)19 }20 seq := make([]int, length)21 s := state{seq, 0, 0}22 for scanner.Scan() {23 line := scanner.Text()24 splitLine := strings.Split(line, " ")25 lineInt := []int{}26 for _, i := range splitLine {27 j, err := strconv.Atoi(i)28 if err != nil {29 panic(err)30 }31 lineInt = append(lineInt, j)32 }33 if queryType == 1 {34 s.performQuery1(x, y)35 } else if queryType == 2 {36 s.performQuery2(x, y)37 } else {38 fmt.Println("Invalid Query Type")39 }40 }41}42type state struct {43}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!