Skip to content

Commit

Permalink
cmd/gomobile: allow tests to pass on ios builder
Browse files Browse the repository at this point in the history
There are several tests are skipped for Android but they may still be
tested on iOS. This will leads to trybot failure.

This CL skips those tests and allow them to pass on iOS.

Furthermore, deprecated C function warning are promoted to errors on
builders, this CL also fixes a deprecated asl_log for iOS in mobileinit.

Change-Id: Ie9da57a20dd75ef3d29b393e30aef01051bab454
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/346391
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
  • Loading branch information
changkun authored and hajimehoshi committed Sep 1, 2021
1 parent 1fde1d6 commit a0f9ae5
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/gomobile/bind_test.go
Expand Up @@ -248,7 +248,7 @@ func TestBindIOSAll(t *testing.T) {
}

func TestBindWithGoModules(t *testing.T) {
if runtime.GOOS == "android" {
if runtime.GOOS == "android" || runtime.GOOS == "ios" {
t.Skipf("gomobile and gobind are not available on %s", runtime.GOOS)
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/gomobile/build_darwin_test.go
Expand Up @@ -13,6 +13,9 @@ import (
)

func TestIOSBuild(t *testing.T) {
if !xcodeAvailable() {
t.Skip("Xcode is missing")
}
defer func() {
xout = os.Stderr
buildN = false
Expand Down
6 changes: 3 additions & 3 deletions cmd/gomobile/build_test.go
Expand Up @@ -69,8 +69,8 @@ func TestAndroidPkgName(t *testing.T) {
}

func TestAndroidBuild(t *testing.T) {
if runtime.GOOS == "android" {
t.Skip("not available on Android")
if runtime.GOOS == "android" || runtime.GOOS == "ios" {
t.Skipf("not available on %s", runtime.GOOS)
}
buf := new(bytes.Buffer)
defer func() {
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestRegexImportGolangXPackage(t *testing.T) {
}

func TestBuildWithGoModules(t *testing.T) {
if runtime.GOOS == "android" {
if runtime.GOOS == "android" || runtime.GOOS == "ios" {
t.Skipf("gomobile are not available on %s", runtime.GOOS)
}

Expand Down
5 changes: 5 additions & 0 deletions cmd/gomobile/init_test.go
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
"text/template"
Expand All @@ -18,6 +19,10 @@ import (
var gopath string

func TestInit(t *testing.T) {
if runtime.GOOS == "android" || runtime.GOOS == "ios" {
t.Skipf("not available on %s", runtime.GOOS)
}

if _, err := exec.LookPath("diff"); err != nil {
t.Skip("command diff not found, skipping")
}
Expand Down
8 changes: 4 additions & 4 deletions exp/sprite/portable/affine_test.go
Expand Up @@ -21,8 +21,8 @@ import (
)

func TestAffine(t *testing.T) {
if runtime.GOOS == "android" {
t.Skip("testdata not available on Android")
if runtime.GOOS == "android" || runtime.GOOS == "ios" {
t.Skipf("testdata not available on %s", runtime.GOOS)
}
f, err := os.Open("../../../testdata/testpattern.png")
if err != nil {
Expand Down Expand Up @@ -104,8 +104,8 @@ func TestAffine(t *testing.T) {
}

func TestAffineMask(t *testing.T) {
if runtime.GOOS == "android" {
t.Skip("testdata not available on Android")
if runtime.GOOS == "android" || runtime.GOOS == "ios" {
t.Skipf("testdata not available on %s", runtime.GOOS)
}
f, err := os.Open("../../../testdata/testpattern.png")
if err != nil {
Expand Down
25 changes: 15 additions & 10 deletions internal/mobileinit/mobileinit_ios.go
Expand Up @@ -2,9 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build darwin && (arm || arm64)
// +build darwin
// +build arm arm64
//go:build ios
// +build ios

package mobileinit

Expand All @@ -16,24 +15,30 @@ import (
)

/*
#include <asl.h>
#include <stdlib.h>
#include <os/log.h>
void asl_log_wrap(const char *str) {
asl_log(NULL, NULL, ASL_LEVEL_NOTICE, "%s", str);
os_log_t create_os_log() {
return os_log_create("org.golang.mobile", "os_log");
}
void os_log_wrap(os_log_t log, const char *str) {
os_log(log, "%s", str);
}
*/
import "C"

type aslWriter struct{}
type osWriter struct {
w C.os_log_t
}

func (aslWriter) Write(p []byte) (n int, err error) {
func (o osWriter) Write(p []byte) (n int, err error) {
cstr := C.CString(string(p))
C.asl_log_wrap(cstr)
C.os_log_wrap(o.w, cstr)
C.free(unsafe.Pointer(cstr))
return len(p), nil
}

func init() {
log.SetOutput(io.MultiWriter(os.Stderr, aslWriter{}))
log.SetOutput(io.MultiWriter(os.Stderr, osWriter{C.create_os_log()}))
}

0 comments on commit a0f9ae5

Please sign in to comment.