out-of-tree kernel {module, exploit} development tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pew_test.go 958B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2018 Mikhail Klementev. All rights reserved.
  2. // Use of this source code is governed by a AGPLv3 license
  3. // (or later) that can be found in the LICENSE file.
  4. package main
  5. import (
  6. "fmt"
  7. "io/ioutil"
  8. "os"
  9. "strings"
  10. "testing"
  11. "time"
  12. )
  13. func TestDockerCommand(t *testing.T) {
  14. tmp, err := ioutil.TempDir("/tmp/", "out-of-tree_test_")
  15. if err != nil {
  16. t.Fatal(err)
  17. }
  18. defer os.RemoveAll(tmp)
  19. start := time.Now()
  20. c := dockerCommand("ubuntu", tmp, "1s", "sleep 5s")
  21. _, err = c.CombinedOutput()
  22. if err == nil {
  23. t.Fatal("docker is not killed by timeout")
  24. }
  25. if time.Since(start) > 3*time.Second {
  26. t.Fatal(fmt.Sprintf("timeout failed (%v instead of %v)",
  27. time.Since(start), time.Second))
  28. }
  29. c = dockerCommand("ubuntu", tmp, "1m", "echo hello")
  30. rawOutput, err := c.CombinedOutput()
  31. if err != nil {
  32. t.Fatal(err)
  33. }
  34. if !strings.Contains(string(rawOutput), "hello") {
  35. t.Fatal("wrong output (" + string(rawOutput) + ")")
  36. }
  37. }