How to use pollLoop method of main Package

Best Syzkaller code snippet using main.pollLoop

android_run_app.go

Source:android_run_app.go Github

copy

Full Screen

1// Copyright (c) 2015 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4/*5 Run a Skia app to completion, piping the log to stdout.6*/7package main8import (9 "flag"10 "fmt"11 "io"12 "os"13 "os/exec"14 "os/signal"15 "strconv"16 "strings"17 "time"18 "github.com/skia-dev/glog"19 "go.skia.org/infra/go/common"20)21const (22 COM_SKIA = "com.skia"23)24var (25 adbPath = flag.String("adb", "", "Path to the ADB executable.")26 app = flag.String("app", "VisualBench", "Name of the app to run.")27 serial = flag.String("s", "", "Serial number for the Android device to use.")28)29// Struct used for running ADB commands.30type ADB struct {31 path string32 serial string33}34// ADBFromFlags returns an ADB instance based on flags passed to the program.35func ADBFromFlags() *ADB {36 rv := &ADB{37 path: *adbPath,38 serial: *serial,39 }40 if rv.path == "" {41 rv.path = "adb"42 }43 return rv44}45// Cmd creates an exec.Cmd object for the given ADB command.46func (adb *ADB) Cmd(log bool, args ...string) *exec.Cmd {47 cmd := []string{}48 if adb.serial != "" {49 cmd = append(cmd, "-s", adb.serial)50 }51 cmd = append(cmd, args...)52 if log {53 glog.Infof("Exec `%s %s`", adb.path, strings.Join(cmd, " "))54 }55 return exec.Command(adb.path, cmd...)56}57// KillSkia kills any running process.58func (adb *ADB) Kill(proc string) error {59 return adb.Cmd(false, "shell", "am", "force-stop", proc).Run()60}61// PollSkia checks to see if the given process is running. If so, return the pid, otherwise return -1.62func (adb *ADB) Poll(proc string) (int64, error) {63 output, err := adb.Cmd(false, "shell", "ps").Output()64 if err != nil {65 return -1, fmt.Errorf("Failed to check the running processes on the device: %v", err)66 }67 for _, line := range strings.Split(string(output), "\n") {68 if strings.Contains(line, proc) {69 fields := strings.Fields(line)70 pid, err := strconv.ParseInt(fields[1], 10, 32)71 if err != nil {72 return -1, fmt.Errorf("Failed to parse \"%s\" to an integer: %v", fields[1], err)73 }74 return pid, nil75 }76 }77 return -1, nil78}79// ReadLinesFromPipe reads from the given pipe and logs its output.80func ReadLinesFromPipe(pipe io.Reader, lines chan string) {81 buf := []byte{}82 // writeLine recovers from a panic when writing to the channel.83 writeLine := func(s string) {84 defer func() {85 if r := recover(); r != nil {86 glog.Warningf("Panic writing to channel... are we exiting?")87 }88 }()89 lines <- s90 }91 // readLines reads output lines from the buffer and pushes them into the channel.92 readlines := func() {93 readIdx := 094 // Read lines from buf.95 for i, b := range buf {96 if b == '\n' {97 s := string(buf[readIdx:i])98 writeLine(s)99 readIdx = i + 1100 }101 }102 // Remove the lines we read.103 buf = buf[readIdx:]104 }105 // Loop forever, reading bytes from the pipe.106 readbuf := make([]byte, 4096)107 for {108 read, err := pipe.Read(readbuf)109 if read > 0 {110 buf = append(buf, readbuf[:read]...)111 // Read lines from the buffers.112 readlines()113 }114 if err != nil {115 if err == io.EOF {116 break117 } else {118 glog.Error(err)119 }120 } else if read == 0 {121 time.Sleep(20 * time.Millisecond)122 }123 }124 // Read any remaining lines from the buffers.125 readlines()126 // "Flush" any incomplete lines from the buffers.127 writeLine(string(buf))128}129// RunApp launches the given app on the device, pipes its log output to stdout,130// and returns when the app finishes running, with an error if the app did not131// complete successfully.132func RunApp(adb *ADB, appName string, args []string) error {133 // Kill any running instances of the app.134 if err := adb.Kill(COM_SKIA); err != nil {135 return fmt.Errorf("Failed to kill app: %v", err)136 }137 // Clear the ADB log.138 if err := adb.Cmd(false, "logcat", "-c").Run(); err != nil {139 return fmt.Errorf("Failed to clear ADB log: %v", err)140 }141 // Prepare to read the subprocess output.142 logProc := adb.Cmd(false, "logcat")143 defer func() {144 // Cleanup.145 if err := logProc.Process.Kill(); err != nil {146 glog.Errorf("Failed to kill logcat process: %v", err)147 }148 }()149 stdout, err := logProc.StdoutPipe()150 if err != nil {151 return fmt.Errorf("Failed to obtain stdout pipe: %v", err)152 }153 stdoutLines := make(chan string)154 stderr, err := logProc.StderrPipe()155 if err != nil {156 return fmt.Errorf("Failed to obtain stderr pipe: %v", err)157 }158 stderrLines := make(chan string)159 go ReadLinesFromPipe(stdout, stdoutLines)160 go ReadLinesFromPipe(stderr, stderrLines)161 if err := logProc.Start(); err != nil {162 return fmt.Errorf("Failed to start logcat process.")163 }164 // Launch the app.165 stop := make(chan bool, 1)166 activity := fmt.Sprintf("%s.%s/%s.%sActivity", COM_SKIA, strings.ToLower(appName), COM_SKIA, appName)167 flags := strings.Join(args, " ")168 cmd := []string{"shell", "am", "start", "-S", "-n", activity, "--es", "cmdLineFlags", flags}169 output, err := adb.Cmd(true, cmd...).Output()170 if err != nil {171 return fmt.Errorf("Failed to launch app: %v", err)172 }173 glog.Info(string(output))174 // Make a handler for SIGINT so that we can kill the app if this script is interrupted.175 go func() {176 interrupt := make(chan os.Signal, 1)177 signal.Notify(interrupt, os.Interrupt)178 for _ = range interrupt {179 glog.Infof("Received SIGINT; killing app.")180 stop <- true181 close(stdoutLines)182 close(stderrLines)183 if err := adb.Kill(COM_SKIA); err != nil {184 glog.Errorf("Failed to kill app: %v", err)185 }186 if err := logProc.Process.Kill(); err != nil {187 glog.Errorf("Failed to kill logcat process: %v", err)188 }189 }190 }()191 // Loop until the app finishes or we're interrupted, writing output as appropriate.192 // TODO(borenet): VisualBench should print its exit code. This script should exit193 // with that code, or a non-zero code if the process ended without printing any code.194 second := time.Tick(time.Second)195PollLoop:196 for {197 select {198 case <-second:199 // Poll the Skia process every second to make sure it's still running.200 pid, err := adb.Poll(COM_SKIA)201 if err != nil {202 glog.Errorf("Failed to poll Skia process: %v", err)203 } else if pid < 0 {204 glog.Infof("Skia process is no longer running!")205 break PollLoop206 }207 case <-stop:208 break PollLoop209 case line := <-stdoutLines:210 glog.Info(line)211 case line := <-stderrLines:212 glog.Error(line)213 }214 }215 return nil216}217func main() {218 common.Init()219 args := flag.Args()220 if err := RunApp(ADBFromFlags(), *app, args); err != nil {221 glog.Fatal(err)222 }223}...

Full Screen

Full Screen

pollLoop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 rand.Seed(time.Now().UnixNano())4 pollLoop()5}6import (7func main() {8 rand.Seed(time.Now().UnixNano())9 pollLoop()10}11import (12func main() {13 rand.Seed(time.Now().UnixNano())14 pollLoop()15}16import (17func main() {18 rand.Seed(time.Now().UnixNano())19 pollLoop()20}21import (22func main() {23 rand.Seed(time.Now().UnixNano())24 pollLoop()25}26import (27func main() {28 rand.Seed(time.Now().UnixNano())29 pollLoop()30}31import (32func main() {33 rand.Seed(time.Now().UnixNano())34 pollLoop()35}36import (37func main() {38 rand.Seed(time.Now().UnixNano())39 pollLoop()40}41import (42func main() {43 rand.Seed(time.Now().UnixNano())44 pollLoop()45}46import (47func main() {48 rand.Seed(time.Now().UnixNano())49 pollLoop()50}

Full Screen

Full Screen

pollLoop

Using AI Code Generation

copy

Full Screen

1import java.io.*;2import java.util.*;3import java.util.concurrent.*;4{5 public static void main(String[] args) throws Exception6 {7 Scanner in = new Scanner(System.in);8 int n = in.nextInt();9 int m = in.nextInt();10 int s = in.nextInt() - 1;11 int t = in.nextInt() - 1;12 int[] a = new int[m];13 int[] b = new int[m];14 int[] c = new int[m];15 for (int i = 0; i < m; i++) {16 a[i] = in.nextInt() - 1;17 b[i] = in.nextInt() - 1;18 c[i] = in.nextInt();19 }20 int[] d = new int[n];21 Arrays.fill(d, Integer.MAX_VALUE);22 d[s] = 0;23 int[] p = new int[n];24 Arrays.fill(p, -1);25 int[] q = new int[n];26 int qt = 0;27 q[qt++] = s;28 for (int qh = 0; (qh - qt) % n != 0; qh++) {29 int cur = q[qh % n];30 for (int i = 0; i < m; i++) {31 if (c[i] > 0 && d[a[i]] > d[cur] + 1) {32 d[a[i]] = d[cur] + 1;33 p[a[i]] = i;34 q[qt++ % n] = a[i];35 }36 if (c[i] > 0 && d[b[i]] > d[cur] + 1) {37 d[b[i]] = d[cur] + 1;38 p[b[i]] = i;39 q[qt++ % n] = b[i];40 }41 }42 }43 int[] f = new int[n];44 f[t] = Integer.MAX_VALUE;45 for (int u = t; u != s; u = a[p[u]]) {46 f[u] = Math.min(f[a[p[u]]], c[p[u]]);47 c[p[u]] -= f[t];48 c[p[u] ^ 1] += f[t];49 }50 int flow = 0;51 int[] cur = new int[n];52 int[] qh = new int[n];

Full Screen

Full Screen

pollLoop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 pollLoop := pollLoop(2)4 for i := 0; i < 10; i++ {5 fmt.Println(<-pollLoop)6 }7}8import (9func pollLoop(interval int) <-chan string {10 c := make(chan string)11 go func() {12 for {13 c <- fmt.Sprint(time.Now())14 time.Sleep(time.Duration(interval) * time.Second)15 }16 }()17}

Full Screen

Full Screen

pollLoop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter a string")4 fmt.Scanln(&x)5 fmt.Println(x)6 pollLoop()7}8import (9func pollLoop() {10 for i := 0; i < 5; i++ {11 fmt.Println(i)12 time.Sleep(time.Second * 1)13 }14}

Full Screen

Full Screen

pollLoop

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p.init()4 go p.pollLoop()5 fmt.Println("poll loop finished")6}7import (8func main() {9 p.init()10 go p.pollLoop()11 fmt.Println("poll loop finished")12}13import (14func main() {15 p.init()16 go p.pollLoop()17 fmt.Println("poll loop finished")18}19import (20func main() {21 p.init()22 go p.pollLoop()23 fmt.Println("poll loop finished")24}25import (26func main() {27 p.init()28 go p.pollLoop()29 fmt.Println("poll loop finished")30}31import (32func main() {33 p.init()34 go p.pollLoop()35 fmt.Println("poll loop finished")36}37import (38func main() {39 p.init()40 go p.pollLoop()

Full Screen

Full Screen

pollLoop

Using AI Code Generation

copy

Full Screen

1public class main{2 public static void main(String[] args){3 pollLoop();4 }5}6import "fmt"7func pollLoop(){8 fmt.Println("polling")9}10public class main{11 public static void main(String[] args){12 pollLoop();13 }14}15import "fmt"16func pollLoop(){17 fmt.Println("polling")18}19public class main{20 public static void main(String[] args){21 pollLoop();22 }23}24import "fmt"25func pollLoop(){26 fmt.Println("polling")27}28public class main{29 public static void main(String[] args){30 pollLoop();31 }32}33import "fmt"34func pollLoop(){35 fmt.Println("polling")36}37public class main{38 public static void main(String[] args){39 pollLoop();40 }41}42import "fmt"43func pollLoop(){44 fmt.Println("polling")45}46public class main{47 public static void main(String[] args){48 pollLoop();49 }50}51import "fmt"52func pollLoop(){53 fmt.Println("polling")54}55public class main{56 public static void main(String[] args){57 pollLoop();58 }59}60import "fmt"61func pollLoop(){62 fmt.Println("polling")63}64public class main{65 public static void main(String[] args){66 pollLoop();

Full Screen

Full Screen

pollLoop

Using AI Code Generation

copy

Full Screen

1func main() {2}3import (4func main() {5 for {6 fmt.Println("Hello World")7 time.Sleep(1 * time.Second)8 }9}10import (11func main() {12 for {13 fmt.Println("Hello World")14 time.Sleep(1 * time.Second)15 }16}17import (18func main() {19 for {20 fmt.Println("Hello World")21 time.Sleep(1 * time.Second)22 }23}24import (25func main() {26 for {27 fmt.Println("Hello World")28 time.Sleep(1 * time.Second)29 }30}31import (32func main() {33 for {34 fmt.Println("Hello World")35 time.Sleep(1 * time.Second)36 }37}38import (39func main() {40 for {41 fmt.Println("Hello World")42 time.Sleep(1 * time.Second)43 }44}45import (46func main() {47 for {48 fmt.Println("Hello World")49 time.Sleep(1 * time.Second)50 }51}52import (53func main() {54 for {55 fmt.Println("Hello World")56 time.Sleep(1 * time.Second)57 }58}59import (60func main() {61 for {62 fmt.Println("Hello World")63 time.Sleep(1 * time.Second)64 }65}66import (67func main() {68 for {69 fmt.Println("Hello World")70 time.Sleep(1 * time.Second)71 }72}73import (74func main() {75 for {76 fmt.Println("Hello World")77 time.Sleep(1 * time.Second)78 }79}80import (81func main() {82 for {83 fmt.Println("Hello World")84 time.Sleep(1 * time

Full Screen

Full Screen

pollLoop

Using AI Code Generation

copy

Full Screen

1func main() {2 for {3 s = pollLoop(s)4 if s != "" {5 }6 }7}8import (9func main() {10 for {11 s = pollLoop(s)12 if s != "" {13 }14 }15}16import (17func main() {18 for {19 s = pollLoop(s)20 if s != "" {21 }22 }23}

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.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful