Skip to content
Permalink
Browse files

pkg/runtest: make tests pass on freebsd

The problem is stupid: <endian.h> should be included as <sys/endian.h> on freebsd.
Pass actual host OS to executor build as HOSTGOOS and use it to figure out
how we should include this header.
  • Loading branch information...
dvyukov committed Mar 7, 2019
1 parent 5fb683f commit 4b69c3cbaccd51b7ea719e7bd756d680e825988d
Showing with 21 additions and 6 deletions.
  1. +2 −1 Makefile
  2. +1 −1 executor/common.h
  3. +2 −0 pkg/csource/build.go
  4. +2 −0 pkg/csource/common.go
  5. +1 −1 pkg/csource/generated.go
  6. +6 −0 pkg/runtest/run.go
  7. +7 −3 sys/targets/targets.go
@@ -122,7 +122,8 @@ ifneq ("$(NO_CROSS_COMPILER)", "")
else
mkdir -p ./bin/$(TARGETOS)_$(TARGETARCH)
$(CC) -o ./bin/$(TARGETOS)_$(TARGETARCH)/syz-executor$(EXE) executor/executor.cc \
$(ADDCFLAGS) $(CFLAGS) -DGOOS_$(TARGETOS)=1 -DGOARCH_$(TARGETARCH)=1 -DGIT_REVISION=\"$(REV)\"
$(ADDCFLAGS) $(CFLAGS) -DGOOS_$(TARGETOS)=1 -DGOARCH_$(TARGETARCH)=1 \
-DHOSTGOOS_$(HOSTOS)=1 -DGIT_REVISION=\"$(REV)\"
endif
endif

@@ -15,7 +15,7 @@
#define _GNU_SOURCE
#endif

#if GOOS_freebsd
#if GOOS_freebsd || GOOS_test && HOSTGOOS_freebsd
#include <sys/endian.h> // for htobe*.
#else
#include <endian.h> // for htobe*.
@@ -9,6 +9,7 @@ import (
"io/ioutil"
"os"
"os/exec"
"runtime"

"github.com/google/syzkaller/pkg/osutil"
"github.com/google/syzkaller/prog"
@@ -42,6 +43,7 @@ func build(target *prog.Target, src []byte, file string) (string, error) {
"-o", bin,
"-DGOOS_" + target.OS + "=1",
"-DGOARCH_" + target.Arch + "=1",
"-DHOSTGOOS_" + runtime.GOOS + "=1",
}
if file == "" {
flags = append(flags, "-x", "c", "-")
@@ -8,6 +8,7 @@ package csource
import (
"bytes"
"fmt"
"runtime"
"sort"
"strings"

@@ -70,6 +71,7 @@ func defineList(p, mmapProg *prog.Prog, opts Options) (defines []string) {
enabled := map[string]bool{
"GOOS_" + p.Target.OS: true,
"GOARCH_" + p.Target.Arch: true,
"HOSTGOOS_" + runtime.GOOS: true,
"SYZ_USE_BITMASKS": bitmasks,
"SYZ_USE_CHECKSUMS": csums,
"SYZ_SANDBOX_NONE": opts.Sandbox == sandboxNone,
@@ -9,7 +9,7 @@ var commonHeader = `
#define _GNU_SOURCE
#endif
#if GOOS_freebsd
#if GOOS_freebsd || GOOS_test && HOSTGOOS_freebsd
#include <sys/endian.h>
#else
#include <endian.h>
@@ -18,6 +18,7 @@ import (
"os"
"path/filepath"
"regexp"
"runtime"
"sort"
"strconv"
"strings"
@@ -422,6 +423,11 @@ func checkResult(req *RunRequest) error {
// C code does not detect when a call was blocked.
continue
}
if runtime.GOOS == "freebsd" && flag == ipc.CallBlocked {
// Blocking detection is flaky on freebsd.
// TODO(dvyukov): try to increase the timeout in executor to make it non-flaky.
continue
}
if (inf.Flags^want.Flags)&flag != 0 {
not := " not"
if inf.Flags&flag != 0 {
@@ -383,6 +383,13 @@ func init() {
for _, target := range List["test"] {
target.CCompiler = List[goos][runtime.GOARCH].CCompiler
target.CPP = List[goos][runtime.GOARCH].CPP
target.BuildOS = goos
if runtime.GOOS == "freebsd" && runtime.GOARCH == "amd64" && target.PtrSize == 4 {
// -m32 alone does not work on freebsd with gcc.
// TODO(dvyukov): consider switching to clang on freebsd instead.
target.CFlags = append(target.CFlags, "-B/usr/lib32")
target.CrossCFlags = append(target.CrossCFlags, "-B/usr/lib32")
}
}
}

@@ -410,9 +417,6 @@ func initTarget(target *Target, OS, arch string) {
if target.BuildOS == "" {
target.BuildOS = OS
}
if OS == "test" {
target.BuildOS = "linux"
}
if runtime.GOOS != target.BuildOS {
// Spoil native binaries if they are not usable, so that nobody tries to use them later.
target.CCompiler = fmt.Sprintf("cant-build-%v-on-%v", target.OS, runtime.GOOS)

2 comments on commit 4b69c3c

@dvyukov

This comment has been minimized.

Copy link
Collaborator Author

replied Mar 7, 2019

@markjdb FYI
I've added TODO's for the things you asked to briefly explain why things are done this way.

@markjdb

This comment has been minimized.

Copy link
Collaborator

replied Mar 7, 2019

Thanks. Once the syzbot integration is done I'll see if we can just add an endian.h to FreeBSD so that we can get rid of this special case.

Please sign in to comment.
You can’t perform that action at this time.