1
0
mirror of https://github.com/golang/go synced 2024-11-26 07:47:57 -07:00

misc/ios,cmd/go, runtime/cgo: fix iOS test harness (again)

The iOS test harness was recently changed in response to lldb bugs
to replace breakpoints with the SIGUSR2 signal (CL 34926), and to
pass the current directory in the test binary arguments (CL 35152).
Both the signal sending and working directory setup is done from
the go test driver.

However, the new method doesn't work with tests where a C program is
the test driver instead of go test: the current working directory
will not be changed and SIGUSR2 is not raised.

Instead of copying that logic into any C test program, rework the
test harness (again) to move the setup logic to the early runtime
cgo setup code. That way, the harness will run even in the library
build modes.

Then, use the app Info.plist file to pass the working
directory, removing the need to alter the arguments after running.

Finally, use the SIGINT signal instead of SIGUSR2 to avoid
manipulating the signal masks or handlers.

Fixes the testcarchive tests on iOS.

With this CL, both darwin/arm and darwin/arm64 passes all.bash.

This CL replaces CL 34926, CL 35152 as well as the fixup CL
35123 and CL 35255. They are reverted in CLs earlier in the
relation chain.

Change-Id: I8485c7db1404fbd8daa261efd1ea89e905121a3e
Reviewed-on: https://go-review.googlesource.com/36090
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Elias Naur 2017-02-01 16:04:07 +01:00
parent fec40bd106
commit 7523baed09
3 changed files with 49 additions and 39 deletions

View File

@ -147,22 +147,22 @@ func run(bin string, args []string) (err error) {
return err return err
} }
pkgpath, err := copyLocalData(appdir)
if err != nil {
return err
}
entitlementsPath := filepath.Join(tmpdir, "Entitlements.plist") entitlementsPath := filepath.Join(tmpdir, "Entitlements.plist")
if err := ioutil.WriteFile(entitlementsPath, []byte(entitlementsPlist()), 0744); err != nil { if err := ioutil.WriteFile(entitlementsPath, []byte(entitlementsPlist()), 0744); err != nil {
return err return err
} }
if err := ioutil.WriteFile(filepath.Join(appdir, "Info.plist"), []byte(infoPlist()), 0744); err != nil { if err := ioutil.WriteFile(filepath.Join(appdir, "Info.plist"), []byte(infoPlist(pkgpath)), 0744); err != nil {
return err return err
} }
if err := ioutil.WriteFile(filepath.Join(appdir, "ResourceRules.plist"), []byte(resourceRules), 0744); err != nil { if err := ioutil.WriteFile(filepath.Join(appdir, "ResourceRules.plist"), []byte(resourceRules), 0744); err != nil {
return err return err
} }
pkgpath, err := copyLocalData(appdir)
if err != nil {
return err
}
cmd := exec.Command( cmd := exec.Command(
"codesign", "codesign",
"-f", "-f",
@ -244,20 +244,9 @@ func run(bin string, args []string) (err error) {
return nil return nil
} }
s.do(`breakpoint set -n getwd`) // in runtime/cgo/gcc_darwin_arm.go
started = true started = true
s.doCmd("run", "stop reason = breakpoint", 20*time.Second) s.doCmd("run", "stop reason = signal SIGINT", 20*time.Second)
// Move the current working directory into the faux gopath.
if pkgpath != "src" {
s.do(`breakpoint delete 1`)
s.do(`expr char* $mem = (char*)malloc(512)`)
s.do(`expr $mem = (char*)getwd($mem, 512)`)
s.do(`expr $mem = (char*)strcat($mem, "/` + pkgpath + `")`)
s.do(`call (void)chdir($mem)`)
}
startTestsLen := s.out.Len() startTestsLen := s.out.Len()
fmt.Fprintln(s.in, `process continue`) fmt.Fprintln(s.in, `process continue`)
@ -579,7 +568,7 @@ func subdir() (pkgpath string, underGoRoot bool, err error) {
) )
} }
func infoPlist() string { func infoPlist(pkgpath string) string {
return `<?xml version="1.0" encoding="UTF-8"?> return `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
@ -592,6 +581,7 @@ func infoPlist() string {
<key>CFBundleResourceSpecification</key><string>ResourceRules.plist</string> <key>CFBundleResourceSpecification</key><string>ResourceRules.plist</string>
<key>LSRequiresIPhoneOS</key><true/> <key>LSRequiresIPhoneOS</key><true/>
<key>CFBundleDisplayName</key><string>gotest</string> <key>CFBundleDisplayName</key><string>gotest</string>
<key>GoExecWrapperWorkingDirectory</key><string>` + pkgpath + `</string>
</dict> </dict>
</plist> </plist>
` `

View File

@ -107,30 +107,40 @@ init_working_dir()
return; return;
} }
CFStringRef url_str_ref = CFURLGetString(url_ref); CFStringRef url_str_ref = CFURLGetString(url_ref);
char url[MAXPATHLEN]; char buf[MAXPATHLEN];
if (!CFStringGetCString(url_str_ref, url, sizeof(url), kCFStringEncodingUTF8)) { if (!CFStringGetCString(url_str_ref, buf, sizeof(buf), kCFStringEncodingUTF8)) {
fprintf(stderr, "runtime/cgo: cannot get URL string\n"); fprintf(stderr, "runtime/cgo: cannot get URL string\n");
return; return;
} }
// url is of the form "file:///path/to/Info.plist". // url is of the form "file:///path/to/Info.plist".
// strip it down to the working directory "/path/to". // strip it down to the working directory "/path/to".
int url_len = strlen(url); int url_len = strlen(buf);
if (url_len < sizeof("file://")+sizeof("/Info.plist")) { if (url_len < sizeof("file://")+sizeof("/Info.plist")) {
fprintf(stderr, "runtime/cgo: bad URL: %s\n", url); fprintf(stderr, "runtime/cgo: bad URL: %s\n", buf);
return; return;
} }
url[url_len-sizeof("/Info.plist")+1] = 0; buf[url_len-sizeof("/Info.plist")+1] = 0;
char *dir = &url[0] + sizeof("file://")-1; char *dir = &buf[0] + sizeof("file://")-1;
if (chdir(dir) != 0) { if (chdir(dir) != 0) {
fprintf(stderr, "runtime/cgo: chdir(%s) failed\n", dir); fprintf(stderr, "runtime/cgo: chdir(%s) failed\n", dir);
} }
// No-op to set a breakpoint on, immediately after the real chdir. // The test harness in go_darwin_arm_exec passes the relative working directory
// Gives the test harness in go_darwin_arm_exec (which uses lldb) a // in the GoExecWrapperWorkingDirectory property of the app bundle.
// chance to move the working directory. CFStringRef wd_ref = CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("GoExecWrapperWorkingDirectory"));
getwd(dir); if (wd_ref != NULL) {
if (!CFStringGetCString(wd_ref, buf, sizeof(buf), kCFStringEncodingUTF8)) {
fprintf(stderr, "runtime/cgo: cannot get GoExecWrapperWorkingDirectory string\n");
return;
}
if (chdir(buf) != 0) {
fprintf(stderr, "runtime/cgo: chdir(%s) failed\n", buf);
}
// Notify the test harness that we're correctly set up
raise(SIGINT);
}
} }
void void

View File

@ -109,30 +109,40 @@ init_working_dir()
return; return;
} }
CFStringRef url_str_ref = CFURLGetString(url_ref); CFStringRef url_str_ref = CFURLGetString(url_ref);
char url[MAXPATHLEN]; char buf[MAXPATHLEN];
if (!CFStringGetCString(url_str_ref, url, sizeof(url), kCFStringEncodingUTF8)) { if (!CFStringGetCString(url_str_ref, buf, sizeof(buf), kCFStringEncodingUTF8)) {
fprintf(stderr, "runtime/cgo: cannot get URL string\n"); fprintf(stderr, "runtime/cgo: cannot get URL string\n");
return; return;
} }
// url is of the form "file:///path/to/Info.plist". // url is of the form "file:///path/to/Info.plist".
// strip it down to the working directory "/path/to". // strip it down to the working directory "/path/to".
int url_len = strlen(url); int url_len = strlen(buf);
if (url_len < sizeof("file://")+sizeof("/Info.plist")) { if (url_len < sizeof("file://")+sizeof("/Info.plist")) {
fprintf(stderr, "runtime/cgo: bad URL: %s\n", url); fprintf(stderr, "runtime/cgo: bad URL: %s\n", buf);
return; return;
} }
url[url_len-sizeof("/Info.plist")+1] = 0; buf[url_len-sizeof("/Info.plist")+1] = 0;
char *dir = &url[0] + sizeof("file://")-1; char *dir = &buf[0] + sizeof("file://")-1;
if (chdir(dir) != 0) { if (chdir(dir) != 0) {
fprintf(stderr, "runtime/cgo: chdir(%s) failed\n", dir); fprintf(stderr, "runtime/cgo: chdir(%s) failed\n", dir);
} }
// No-op to set a breakpoint on, immediately after the real chdir. // The test harness in go_darwin_arm_exec passes the relative working directory
// Gives the test harness in go_darwin_arm_exec (which uses lldb) a // in the GoExecWrapperWorkingDirectory property of the app bundle.
// chance to move the working directory. CFStringRef wd_ref = CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("GoExecWrapperWorkingDirectory"));
getwd(dir); if (wd_ref != NULL) {
if (!CFStringGetCString(wd_ref, buf, sizeof(buf), kCFStringEncodingUTF8)) {
fprintf(stderr, "runtime/cgo: cannot get GoExecWrapperWorkingDirectory string\n");
return;
}
if (chdir(buf) != 0) {
fprintf(stderr, "runtime/cgo: chdir(%s) failed\n", buf);
}
// Notify the test harness that we're correctly set up
raise(SIGINT);
}
} }
void void