]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: make strace test more robust
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 15 Feb 2012 00:05:51 +0000 (11:05 +1100)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 15 Feb 2012 00:05:51 +0000 (11:05 +1100)
Apparently some distros don't let you ptrace attach
to your own existing processes.

Run strace on the child directly, instead, which
reportedly is more often allowed, and makes the
code simpler too.

R=golang-dev, n13m3y3r
CC=golang-dev
https://golang.org/cl/5675050

src/pkg/net/http/fs_test.go

index 11ca786fce0a577a3fa57ce9d4095e77baa2947e..143617e95fc62c22a33e5a36b8b2075cc74cd077 100644 (file)
@@ -18,7 +18,6 @@ import (
        "path/filepath"
        "regexp"
        "runtime"
-       "strconv"
        "strings"
        "testing"
        "time"
@@ -387,24 +386,15 @@ func TestLinuxSendfile(t *testing.T) {
        }
        defer ln.Close()
 
-       child := exec.Command(os.Args[0], "-test.run=TestLinuxSendfileChild")
+       var buf bytes.Buffer
+       child := exec.Command("strace", "-f", os.Args[0], "-test.run=TestLinuxSendfileChild")
        child.ExtraFiles = append(child.ExtraFiles, lnf)
        child.Env = append([]string{"GO_WANT_HELPER_PROCESS=1"}, os.Environ()...)
-
+       child.Stdout = &buf
+       child.Stderr = &buf
        err = child.Start()
        if err != nil {
-               t.Fatal(err)
-       }
-
-       pid := child.Process.Pid
-
-       var buf bytes.Buffer
-       strace := exec.Command("strace", "-f", "-p", strconv.Itoa(pid))
-       strace.Stdout = &buf
-       strace.Stderr = &buf
-       err = strace.Start()
-       if err != nil {
-               t.Logf("skipping; failed to start strace: %v", err)
+               t.Logf("skipping; failed to start straced child: %v", err)
                return
        }
 
@@ -417,7 +407,6 @@ func TestLinuxSendfile(t *testing.T) {
        // Force child to exit cleanly.
        Get(fmt.Sprintf("http://%s/quit", ln.Addr()))
        child.Wait()
-       strace.Wait()
 
        rx := regexp.MustCompile(`sendfile(64)?\(\d+,\s*\d+,\s*NULL,\s*\d+\)\s*=\s*\d+\s*\n`)
        rxResume := regexp.MustCompile(`<\.\.\. sendfile(64)? resumed> \)\s*=\s*\d+\s*\n`)