How to use loadSeqFile method of state Package

Best Syzkaller code snippet using state.loadSeqFile

state.go

Source:state.go Github

copy

Full Screen

...120 corpusSeqFile: filepath.Join(dir, "seq"),121 reproSeqFile: filepath.Join(dir, "repro.seq"),122 ownRepros: make(map[string]bool),123 }124 mgr.corpusSeq = loadSeqFile(mgr.corpusSeqFile)125 if st.corpusSeq < mgr.corpusSeq {126 st.corpusSeq = mgr.corpusSeq127 }128 mgr.reproSeq = loadSeqFile(mgr.reproSeqFile)129 if mgr.reproSeq == 0 {130 mgr.reproSeq = st.reproSeq131 }132 if st.reproSeq < mgr.reproSeq {133 st.reproSeq = mgr.reproSeq134 }135 corpus, _, err := loadDB(mgr.corpusFile, name)136 if err != nil {137 return nil, fmt.Errorf("failed to open manager corpus %v: %v", mgr.corpusFile, err)138 }139 mgr.Corpus = corpus140 log.Logf(0, "created manager %v: corpus=%v, corpusSeq=%v, reproSeq=%v",141 mgr.name, len(mgr.Corpus.Records), mgr.corpusSeq, mgr.reproSeq)142 st.Managers[name] = mgr143 return mgr, nil144}145func (st *State) Connect(name string, fresh bool, calls []string, corpus [][]byte) error {146 mgr := st.Managers[name]147 if mgr == nil {148 var err error149 mgr, err = st.createManager(name)150 if err != nil {151 return err152 }153 }154 mgr.Connected = time.Now()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}...

Full Screen

Full Screen

loadSeqFile

Using AI Code Generation

copy

Full Screen

1import (2type SimpleChaincode struct {3}4func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) peer.Response {5 return shim.Success(nil)6}7func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) peer.Response {8 function, args := stub.GetFunctionAndParameters()9 if function == "loadSeqFile" {10 return t.loadSeqFile(stub, args)11 }12 return shim.Error("Invalid invoke function name. Expecting \"loadSeqFile\"")13}14func (t *SimpleChaincode) loadSeqFile(stub shim.ChaincodeStubInterface, args []string) peer.Response {15 if len(args) != 1 {16 return shim.Error("Incorrect number of arguments. Expecting 1")17 }18 err := stub.PutState("hello_world", []byte(args[0]))19 if err != nil {20 return shim.Error(err.Error())21 }22 return shim.Success(nil)23}24func main() {25 err := shim.Start(new(SimpleChaincode))26 if err != nil {27 fmt.Printf("Error starting Simple chaincode: %s", err)28 }29}30{"name":"John", "age":30, "city":"New York"}31{"name":"Peter", "age":40, "city":"London"}32{"name":"Amy", "age":50, "city":"Chicago"}33import (34type SimpleChaincode struct {35}36type Person struct {37}38func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) peer.Response {39 return shim.Success(nil)40}41func (t *SimpleChaincode) Invoke(stub shim.Chaincode

Full Screen

Full Screen

loadSeqFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 db, _ := ethdb.NewMemDatabase()4 state, _ := state.New(common.Hash{}, state.NewDatabase(db))5 addr := common.HexToAddress("0x1234567890123456789012345678901234567890")6 state.AddBalance(addr, big.NewInt(100000))7 tx, _ := types.SignTx(types.NewTransaction(0, addr, big.NewInt(100), 21000, big.NewInt(1), nil), types.HomesteadSigner{}, nil)8 block := types.NewBlock(&types.Header{9 Number: big.NewInt(1),10 Time: big.NewInt(0),11 Difficulty: big.NewInt(0),12 }, []*types.Transaction{tx}, nil, nil)13 db, _ = ethdb.NewMemDatabase()14 statedb, _ := state.New(block.Root(), state.NewDatabase(db))15 trie, _ := trie.New(block.Root(), trie.NewDatabase(db))16 so := statedb.GetOrNewStateObject(addr)17 so.SetBalance(big.NewInt(9999999))18 so = statedb.GetOrNewStateObject(common.HexToAddress("0x1234567890123456789012345678901234567891"))19 so.SetBalance(big.NewInt(9999999))20 so.CommitTo(trie, false)21 trie.Commit(nil)

Full Screen

Full Screen

loadSeqFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 state.Init()4 state.LoadSeqFile("test.txt")5 fmt.Println(state)6}7import (8func main() {9 state.Init()10 state.LoadSeqFile("test.txt")11 fmt.Println(state)12}13import (14func main() {15 state.Init()16 state.LoadSeqFile("test.txt")17 fmt.Println(state)18}19import (20func main() {21 state.Init()22 state.LoadSeqFile("test.txt")23 fmt.Println(state)24}25import (26func main() {27 state.Init()28 state.LoadSeqFile("test.txt")29 fmt.Println(state)30}31import (32func main() {33 state.Init()34 state.LoadSeqFile("test.txt")35 fmt.Println(state)36}37import (38func main() {39 state.Init()40 state.LoadSeqFile("test.txt")41 fmt.Println(state)

Full Screen

Full Screen

loadSeqFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 rand.Seed(time.Now().UnixNano())4 state := NewState()5 state.LoadSeqFile("sequences.txt")6 fmt.Println(state.sequences)7 fmt.Println(state.sequences[1])8}9import (10func main() {11 rand.Seed(time.Now().UnixNano())12 state := NewState()13 state.LoadSeqFile("sequences.txt")14 fmt.Println(state.sequences)15 fmt.Println(state.sequences[1])16 fmt.Println(len(state.sequences[1]))17 fmt.Println(state.sequences[1][0])18}19import (20func main() {21 rand.Seed(time.Now().UnixNano())22 state := NewState()23 state.LoadSeqFile("sequences.txt")24 fmt.Println(state.sequences)25 fmt.Println(state.sequences[1])26 fmt.Println(len(state.sequences[1]))27 fmt.Println(state.sequences[1][0])28 fmt.Println(state.sequences[1][0][1])29}30import (31func main() {32 rand.Seed(time.Now().UnixNano())33 state := NewState()

Full Screen

Full Screen

loadSeqFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 state := State{}4 state.loadSeqFile(os.Args[1])5 fmt.Println("Loaded", state.SeqCount, "sequences")6}7import (8func main() {9 state := State{}10 state.loadSeqFile(os.Args[1])11 fmt.Println("Loaded", state.SeqCount, "sequences")12}13import (14func main() {15 state := State{}16 state.loadSeqFile(os.Args[1])17 fmt.Println("Loaded", state.SeqCount, "sequences")18}19import (20func main() {21 state := State{}22 state.loadSeqFile(os.Args[1])23 fmt.Println("Loaded", state.SeqCount, "sequences")24}25import (26func main() {27 state := State{}28 state.loadSeqFile(os.Args[1])29 fmt.Println("Loaded", state.SeqCount, "sequences")30}31import (32func main() {33 state := State{}34 state.loadSeqFile(os.Args[1])35 fmt.Println("Loaded", state.SeqCount, "sequences")36}37import (38func main() {39 state := State{}40 state.loadSeqFile(os.Args[1])41 fmt.Println("Loaded", state.SeqCount, "sequences")42}43import (44func main() {45 state := State{}46 state.loadSeqFile(os.Args[1])47 fmt.Println("Loaded", state.SeqCount, "sequences")48}

Full Screen

Full Screen

loadSeqFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 state := State.State{}5 state.LoadSeqFile("data.txt")6}7import (8func main() {9 fmt.Println("Hello, playground")10 state := State.State{}11 state.LoadSeqFile("data.txt")12 fmt.Println(state)13}14import (15func main() {16 fmt.Println("Hello, playground")17 state := State.State{}18 state.LoadSeqFile("data.txt")19 fmt.Println(state)20 fmt.Println(state.GetCount("A"))21}22import (23func main() {24 fmt.Println("Hello, playground")25 state := State.State{}26 state.LoadSeqFile("data.txt")27 fmt.Println(state)28 fmt.Println(state.GetCount("A"))29 fmt.Println(state.GetCount("B"))30}31import (32func main() {33 fmt.Println("Hello, playground")34 state := State.State{}35 state.LoadSeqFile("data.txt")36 fmt.Println(state)37 fmt.Println(state.GetCount("A"))38 fmt.Println(state.GetCount("B"))39 fmt.Println(state.GetCount("C"))40}41import (42func main() {43 fmt.Println("Hello, playground")

Full Screen

Full Screen

loadSeqFile

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 state := NewState()4 state.loadSeqFile("seq.txt")5 seq := state.getSeq()6 fmt.Println(seq)7}8import (9func main() {10 state := NewState()11 state.loadSeqFile("seq.txt")12 seq := state.getSeq()13 fmt.Println(seq)14}15import (16func main() {17 state := NewState()18 state.loadSeqFile("seq.txt")19 seq := state.getSeq()20 fmt.Println(seq)21}22import (23func main() {24 state := NewState()25 state.loadSeqFile("seq.txt")

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful