static verification framework for go
play

Static verification framework for Go Overview 2 Model checking - PowerPoint PPT Presentation

Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Static verification framework for Go Overview 2 Model checking Behavioural mCRL2 model checker Types Transform Check safety and


  1. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Static verification framework for Go Overview 2 Model checking Behavioural mCRL2 model checker Types Transform Check safety and liveness and verify Type inference 1 3 Termination checking KITTeL termination prover SSA IR Go source code Address type $ program gap 19 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

  2. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Concurrency in Go Goroutines 1 func main() { 2 ch := make(chan string) 3 go send(ch) go keyword + function call 4 print(<-ch) Spawns function as goroutine 5 close(ch) 6 } Runs in parallel to parent 7 8 func send(ch chan string) { 9 ch <- "Hello Kent!" 10 } 20 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

  3. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Concurrency in Go Channels Create new channel 1 func main() { Synchronous by default 2 ch := make(chan string) 3 go send(ch) Receive from channel 4 print(<-ch) Close a channel 5 close(ch) 6 } No more values sent to it 7 Can only close once 8 func send(ch chan string) { 9 ch <- "Hello Kent!" Send to channel 10 } 21 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

  4. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Concurrency in Go Channels 1 func main() { 2 ch := make(chan string) Also select-case : 3 go send(ch) Wait on multiple channel 4 print(<-ch) operations 5 close(ch) 6 } switch-case for 7 communication 8 func send(ch chan string) { 9 ch <- "Hello Kent!" 10 } 21 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

  5. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Concurrency in Go Deadlock detection 1 func main() { 2 Send message thru channel ch := make(chan string) 3 go send(ch) Print message on screen 4 print(<-ch) 5 close(ch) Output: 6 } $ go run hello.go 7 Hello Kent! 8 func send(ch chan string) { $ 9 ch <- "Hello Kent!" 10 } 22 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

  6. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Concurrency in Go Deadlock detection Missing ’go’ keyword Only one (main) goroutine 1 // import _ "net" 2 func main() { Send without receive - blocks 3 ch := make(chan string) 4 send(ch) // Oops Output: 5 print(<-ch) $ go run deadlock.go 6 close(ch) fatal error: all goroutines 7 } are asleep - deadlock! 8 $ 9 func send(ch chan string) { 10 ch <- "Hello Kent!" 11 } 23 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

  7. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Concurrency in Go Deadlock detection Missing ’go’ keyword 1 // import _ "net" Go’s runtime deadlock detector 2 func main() { Checks if all goroutines are 3 ch := make(chan string) 4 send(ch) // Oops blocked (‘global’ deadlock) 5 print(<-ch) Print message then crash 6 close(ch) 7 Some packages disable it } 8 (e.g. net ) 9 func send(ch chan string) { 10 ch <- "Hello Kent!" 11 } 23 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

  8. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Concurrency in Go Deadlock detection Missing ’go’ keyword 1 import _ "net" // unused 2 func main() { 3 ch := make(chan string) 4 send(ch) // Oops Import unused, unrelated package 5 print(<-ch) 6 close(ch) 7 } 8 9 func send(ch chan string) { 10 ch <- "Hello Kent" 11 } 23 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

  9. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Concurrency in Go Deadlock detection Missing ’go’ keyword 1 import _ "net" // unused Only one (main) goroutine 2 func main() { Send without receive - blocks 3 ch := make(chan string) 4 send(ch) // Oops Output: 5 print(<-ch) 6 close(ch) $ go run deadlock2.go 7 } 8 Hangs: Deadlock NOT detected 9 func send(ch chan string) { 10 ch <- "Hello Kent" 11 } 23 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

  10. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Our goal Check liveness/safety properties in addition to global deadlocks Apply process calculi techniques to Go Use model checking to statically analyse Go programs 24 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

  11. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Behavioural type inference Abstract Go communication as Behavioural Types 2 Model checking Behavioural mCRL2 model checker Types Transform Check safety and liveness and verify 1 Type inference 3 Termination checking KITTeL termination prover SSA IR Go source code Address type $ program gap 25 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

  12. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Infer Behavioural Types from Go program Behavioural Types Go source code Types of CCS-like [Milner ’80] 1 func main() { process calculus 2 ch := make(chan int) 3 go send(ch) Send/Receive 4 print(<-ch) new (channel) 5 close(ch) 6 } parallel composition (spawn) 7 Go-specific 8 func send(c chan int) { 9 Close channel c <- 1 10 } Select (guarded choice) 26 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

  13. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Infer Behavioural Types from Go program Go source code Inferred Behavioural Types 1 func main() { main() = ( new ch ); 8 9 2 ch := make(chan int) > > (send h ch i | > > 3 go send(ch) > > > > > > 4 ch; print(<-ch) > > < = 5 ! close(ch) close ch) , 6 } > > > > > > 7 > > > > > > 8 func send(c chan int) { send( ch ) = ch : ; 9 c <- 1 10 } 26 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

  14. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Infer Behavioural Types from Go program Go source code Inferred Behavioural Types create channel 1 func main() { main() = ( new ch ); 8 9 2 ch := make(chan int) > > spawn (send h ch i | > > 3 go send(ch) > > > > > > 4 receive ch; print(<-ch) > > < = 5 close(ch) close close ch) , 6 } > > > > > > 7 > > > > > > 8 func send(c chan int) { send( ch ) = ch : ; 9 c <- 1 10 } send 26 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

  15. Concurrency in Go Behavioural type inference Model checking behavioural types Termination checking Summary Infer Behavioural Types from Go program 1 func main() { 2 ch := make(chan int) // Create channel 3 go sendFn(ch) // Run as goroutine 4 x := recvVal(ch) // Function call 5 for i := 0; i < x; i++ { 6 print(i) 7 } 8 close(ch) // Close channel 9 } 10 func sendFn(c chan int) { c <- 3 } // Send to c 11 func recvVal(c chan int) int { return <-c } // Recv from c 27 /46 Julien Lange, Nicholas Ng, Bernardo Toninho, Nobuko Yoshida mrg.doc.ic.ac.uk A Static Verification Framework for Message Passing in Go using Behavioural Types

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend