From: Waldemar Kozaczuk <[email protected]>
Committer: Waldemar Kozaczuk <[email protected]>
Branch: master

tests: add new tests-with-linux-ld module

This patch adds new module tests-with-linux-ld intended to allow
building and running unit tests with Linux dynamic linker on OSv.

The new module is similar to the original tests one except its
makefile is written to compile and link the unit test programs
with headers and shared libraries from Linux host. The resulting
executables should be runnable on Linux host as well as on OSv.
Please note that only subset of the original tests that do not
use OSv internal APIs and can be run on Linux are part of this module.

Besides new module, this patch also makes some necessary changes
(mostly #ifdef) to allow compiling with headers from host.

One can build new test image like so:

dl=linux ./scripts/build image=tests-with-linux-ld fs=rofs

Prepending with 'dl=linux' forces the relevant scripts downstream
to add standard Linux libraries from host:

/lib64/ld-linux-x86-64.so.2: /lib64/ld-linux-x86-64.so.2
/lib64/libc.so.6: /lib64/libc.so.6
/lib64/libgcc_s.so.1: /lib64/libgcc_s.so.1
/lib64/libm.so.6: /lib64/libm.so.6
/lib64/libstdc++.so.6: /lib64/libstdc++.so.6

Signed-off-by: Waldemar Kozaczuk <[email protected]>

---
diff --git a/modules/tests-with-linux-ld/.gitignore 
b/modules/tests-with-linux-ld/.gitignore
--- a/modules/tests-with-linux-ld/.gitignore
+++ b/modules/tests-with-linux-ld/.gitignore
@@ -0,0 +1,3 @@
+usr.manifest
+fs.manifest
+common.manifest
diff --git a/modules/tests-with-linux-ld/Makefile 
b/modules/tests-with-linux-ld/Makefile
--- a/modules/tests-with-linux-ld/Makefile
+++ b/modules/tests-with-linux-ld/Makefile
@@ -0,0 +1,203 @@
+module: usr.manifest common.manifest fs.manifest build_all_tests
+
+include ../common.gmk
+
+# Ask make to not delete "intermediate" results, such as the .o in the chain
+# .cc -> .o -> . Otherwise, during the first build, make considers the .o
+# to be intermediate, and deletes it, but the newly-created ".d" files lists
+# the ".o" as a target - so it needs to be created again on the second make.
+# See commit fac05c95 for a longer explanation.
+.SECONDARY:
+
+COMMON = -g -O2 -fpie -DBOOST_TEST_DYN_LINK \
+       -U _FORTIFY_SOURCE -Wall -Wformat=0 -Wno-pointer-arith
+
+INCLUDES =
+
+LIBS = $(libgcc_s_dir)/libgcc_s.so.1
+
+CXXFLAGS = -std=gnu++11 $(COMMON)
+CFLAGS = -std=gnu99 $(COMMON)
+
+$(out)/tests-with-linux-ld/%.o: $(src)/tests/%.cc
+       $(makedir)
+       $(call quiet, $(CXX) $(CXXFLAGS) -c -o $@ $<, CXX $*.cc)
+$(out)/tests-with-linux-ld/%.o: $(src)/tests/%.c
+       $(makedir)
+       $(call quiet, $(CC) $(CFLAGS) -c -o $@ $< , CC $*.c)
+$(out)/tests-with-linux-ld/rofs/%.o: $(src)/tests/%.cc
+       $(makedir)
+       $(call quiet, $(CXX) $(CXXFLAGS) -DREAD_ONLY_FS -c -o $@ $<, CXX $*.cc)
+$(out)/tests-with-linux-ld/rofs/%.o: $(src)/tests/%.c
+       $(makedir)
+       $(call quiet, $(CC) $(CFLAGS) -DREAD_ONLY_FS -c -o $@ $< , CC $*.c)
+$(out)/tests-with-linux-ld/%: $(out)/tests-with-linux-ld/%.o
+       $(call quiet, $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LIBS), LD $*)
+$(out)/%.so: $(out)/%.o
+       $(call quiet, $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $< $(LIBS), 
LD $*.so)
+
+$(out)/tests-with-linux-ld/tst-non-fpic.o: CXXFLAGS:=$(subst -fpie,-fno-pic 
-mcmodel=large,$(CXXFLAGS))
+
+$(out)/tests-with-linux-ld/tst-non-pie: CXXFLAGS:=$(subst 
-fpie,-no-pie,$(CXXFLAGS))
+$(out)/tests-with-linux-ld/tst-non-pie: $(src)/tests/tst-non-pie.cc
+       $(call quiet, $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LIBS), LD 
tests-with-linux-ld/tst-non-pie)
+
+$(out)/tests-with-linux-ld/tst-reloc.o: CFLAGS:=$(subst -fPIC,-fpie,$(CFLAGS))
+$(out)/tests-with-linux-ld/tst-reloc: $(src)/tests/tst-reloc.c
+       $(call quiet, $(CC) $(CFLAGS) $(LDFLAGS) -pie -o $@ $< $(LIBS), LD 
tests-with-linux-ld/tst-reloc)
+
+$(out)/tests-with-linux-ld/tst-bitset-iter.o: COMMON:=-I $(src)/include 
$(COMMON)
+$(out)/tests-with-linux-ld/tst-queue-mpsc.o: COMMON:=-I $(src)/include -DLINUX 
$(COMMON)
+$(out)/tests-with-linux-ld/tst-poll.o: COMMON:=-I $(src)/include $(COMMON)
+$(out)/tests-with-linux-ld/rofs/tst-readdir.o: 
COMMON:=-Wno-deprecated-declarations $(COMMON)
+$(out)/tests-with-linux-ld/tst-tcp-listen.o: COMMON:=-I $(src)/include 
$(COMMON)
+
+$(out)/tests-with-linux-ld/misc-fsx.o: COMMON:=-D__OSV__ $(COMMON)
+
+#
+# These 4 tests are compiled from the same source files but passed in 
READ_ONLY_FS
+# to switch relevant logic in those tests to exercise scenarios applicable
+# to read-only filesystem
+rofs-only-tests := rofs/tst-chdir rofs/tst-symlink rofs/tst-readdir 
rofs/tst-concurrent-read
+
+zfs-only-tests := tst-readdir tst-fallocate tst-concurrent-read
+
+specific-fs-tests := $($(fs_type)-only-tests)
+
+tests := tst-pthread misc-ramdisk tst-vblk \
+       misc-console misc-readbench misc-mmap-anon-perf \
+       tst-mmap-file misc-mmap-big-file tst-mmap tst-elf-permissions \
+       tst-queue-mpsc tst-af-local tst-pipe tst-yield \
+       misc-ctxsw tst-read tst-symlink tst-openat \
+       tst-eventfd tst-remove tst-epoll \
+       misc-fsx tst-sleep tst-resolve tst-except tst-tcp-nbwrite tst-console \
+       misc-setpriority misc-timeslice misc-tls misc-gtod \
+       tst-dns-resolver tst-kill tst-truncate \
+       misc-panic tst-utimes tst-utimensat tst-futimesat \
+       misc-tcp tst-strerror_r misc-random misc-urandom \
+       tst-threadcomplete tst-timerfd \
+       tst-memmove tst-pthread-clock misc-procfs \
+       tst-chdir tst-chmod tst-hello misc-concurrent-io \
+       tst-concurrent-init tst-shm \
+       tst-align tst-cxxlocale misc-tcp-close-without-reading \
+       tst-sigwait misc-malloc misc-memcpy misc-printf tst-hostname \
+       tst-sendfile tst-uio tst-printf \
+       tst-pthread-affinity tst-pthread-tsd tst-thread-local \
+       tst-regex tst-tcp-siocoutq \
+       tst-select-timeout tst-faccessat tst-fstatat tst-fcntl misc-mutex2 \
+       tst-pthread-setcancelstate tst-pthread-affinity-inherit \
+       tst-pthread-barrier tst-math \
+       tst-sigaltstack tst-fread tst-tcp-cork tst-tcp-v6 \
+       tst-calloc tst-non-fpic tst-feexcept tst-getopt tst-non-pie \
+       tst-semaphore tst-elf-init tst-realloc tst-setjmp \
+       libtls.so libtls_gold.so tst-tls tst-tls-gold \
+       tst-sigaction tst-syscall tst-ifaddrs tst-getdents \
+       tst-netlink tst-pthread-create misc-futex-perf \
+       misc-syscall-perf tst-reloc misc-vdso-perf
+
+ifeq ($(arch),x64)
+tests += tst-mmx-fpu
+endif
+
+# Tests with special compilation parameters needed...
+$(out)/tests-with-linux-ld/tst-mmap: COMMON += -Wl,-z,now
+$(out)/tests-with-linux-ld/tst-elf-permissions: COMMON += -Wl,-z,relro
+
+# The following tests use special linker trickery which apprarently
+# doesn't work as expected with GOLD linker, so we need to choose BFD.
+# TODO: figure out why this workaround was needed (the reason may be
+# different for each of these tests), and avoid this workaround!
+$(out)/tests-with-linux-ld/tst-mmap: COMMON += -fuse-ld=bfd
+$(out)/tests-with-linux-ld/tst-elf-permissions: COMMON += -fuse-ld=bfd
+$(out)/tests-with-linux-ld/tst-tls: COMMON += -fuse-ld=bfd
+
+$(out)/tests-with-linux-ld/tst-dlfcn: COMMON += -rdynamic -ldl -DLINUX
+$(out)/tests-with-linux-ld/tst-utimensat: COMMON += -DLINUX
+
+$(out)/tests-with-linux-ld/libtls.o: CXXFLAGS:=$(subst -fpie,-fPIC,$(CXXFLAGS))
+
+$(out)/tests-with-linux-ld/tst-tls: \
+               $(src)/tests/tst-tls.cc \
+               $(out)/tests-with-linux-ld/libtls.so
+       $(makedir)
+       $(call quiet, cd $(out); $(CXX) $(CXXFLAGS) $(LDFLAGS) -pthread 
-D__SHARED_OBJECT__=1 -o $@ $< tests-with-linux-ld/libtls.so, CXX 
tests/tst-tls.cc)
+
+$(out)/tests-with-linux-ld/libtls_gold.so: COMMON += -fuse-ld=gold
+$(out)/tests-with-linux-ld/libtls_gold.so: $(out)/tests-with-linux-ld/libtls.o
+       $(makedir)
+       $(call quiet, $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $< $(LIBS), 
LD tests-with-linux-ld/libtls_gold.so)
+
+$(out)/tests-with-linux-ld/tst-tls-gold: COMMON += -fuse-ld=gold
+$(out)/tests-with-linux-ld/tst-tls-gold: \
+               $(src)/tests/tst-tls.cc \
+               $(out)/tests-with-linux-ld/libtls_gold.so
+       $(makedir)
+       $(call quiet, cd $(out); $(CXX) $(CXXFLAGS) $(LDFLAGS) 
-D__SHARED_OBJECT__=1 -o $@ $< tests-with-linux-ld/libtls_gold.so, CXX 
tests/tst-tls.cc)
+
+common-boost-tests := tst-libc-locking misc-fs-stress \
+       tst-promise tst-dlfcn tst-stat tst-bsd-tcp1 tst-tcp-listen \
+       tst-poll tst-bitset-iter \
+       tst-seek tst-ctype tst-wctype tst-string tst-time \
+       tst-net_if_test
+
+boost-tests := $(common-boost-tests)
+
+rofs-only-boost-tests := rofs/tst-stdio
+
+zfs-only-boost-tests := tst-rename tst-stdio
+
+boost-tests += $($(fs_type)-only-boost-tests)
+
+$(boost-tests:%=$(out)/tests-with-linux-ld/%): LIBS += \
+       -lboost_unit_test_framework \
+       -lboost_filesystem
+
+boost-program-options-tests := misc-tcp
+$(boost-program-options-tests:%=$(out)/tests-with-linux-ld/%): LIBS += \
+       -lboost_program_options
+
+common-tests := $(tests) $(common-boost-tests)
+tests += $(boost-tests)
+
+all_tests := $(tests:%=tests-with-linux-ld/%)
+all_tests += $(specific-fs-tests:%=tests-with-linux-ld/%)
+
+build_all_tests: $(all_tests:%=$(out)/%)
+.PHONY: build_all_tests clean
+
+# Automatically generate usr.manifest which includes all tests.
+usr.manifest: build_all_tests $(lastword $(MAKEFILE_LIST)) usr.manifest.skel 
FORCE
+       @echo "  generating modules/tests-with-linux-ld/usr.manifest"
+       @cat [email protected] > $@
+       @case "$(CROSS_PREFIX)" in \
+               "aarch64"*) ../tests/add_aarch64_boost_libraries.sh $(OSV_BASE) 
>> $@ ;; \
+               *) LD_LIBRARY_PATH=$(boost-lib-dir) ldd $(addprefix 
$(out)/tests-with-linux-ld/,$(boost-tests)) $(addprefix 
$(out)/tests-with-linux-ld/,$(boost-program-options-tests)) | grep libboost | 
sed 's/ *[^ ] *\(.*\) => \(.*\) .*/\/lib\/x86_64-linux-gnu\/\1: \2/' | sort | 
uniq >> $@ ;; \
+       esac
+       @echo $(all_tests) | tr ' ' '\n' | grep -v 
"tests-with-linux-ld/rofs/tst-.*" | awk '{print "/" $$0 ": ./" $$0}' | sed 
's/^\/tests-with-linux-ld/\/tests/' >> $@
+       @echo $(all_tests) | tr ' ' '\n' | grep 
"tests-with-linux-ld/rofs/tst-.*" | awk 'BEGIN { FS = "/" } ; { print "/tests/" 
$$3 "-rofs: ./tests-with-linux-ld/" $$2 "/" $$3 ""}' >> $@
+       @$(OSV_BASE)/scripts/manifest_from_host.sh 
$(out)/tests-with-linux-ld/tst-threadcomplete >> $@
+       $(call very-quiet, ./create_static.sh $(out) usr.manifest $(fs_type))
+.PHONY: FORCE
+FORCE:
+
+common.manifest: build_all_tests $(lastword $(MAKEFILE_LIST)) 
usr.manifest.skel FORCE
+       @echo "  generating modules/tests-with-linux-ld/common.manifest"
+       @cat usr.manifest.skel > $@
+       @case "$(CROSS_PREFIX)" in \
+               "aarch64"*) ../tests/add_aarch64_boost_libraries.sh $(OSV_BASE) 
>> $@ ;; \
+               *) LD_LIBRARY_PATH=$(boost-lib-dir) ldd $(addprefix 
$(out)/tests-with-linux-ld/,$(boost-tests)) $(addprefix 
$(out)/tests-with-linux-ld/,$(boost-program-options-tests)) | grep libboost | 
sed 's/ *[^ ] *\(.*\) => \(.*\) .*/\/lib\/x86_64-linux-gnu\/\1: \2/' | sort | 
uniq >> $@ ;; \
+       esac
+       @echo $(common-tests) | tr ' ' '\n' | awk '{print "/tests/" $$0 ": 
./tests/" $$0}' >> $@
+
+fs.manifest: build_all_tests $(lastword $(MAKEFILE_LIST)) FORCE
+       @echo "  generating modules/tests-with-linux-ld/fs.manifest"
+       @echo $(specific-fs-tests) $($(fs_type)-only-boost-tests) | tr ' ' '\n' 
| grep -v "rofs/tst-.*" | awk '{print "/tests/" $$0 ": ./tests-with-linux-ld/" 
$$0}' > $@
+       @echo $(specific-fs-tests) $($(fs_type)-only-boost-tests) | tr ' ' '\n' 
| grep "rofs/tst-.*" | awk 'BEGIN { FS = "/" } ; { print "/tests/" $$2 "-rofs: 
./tests-with-linux-ld/" $$1 "/" $$2 ""}' >> $@
+       $(call very-quiet, ./create_static.sh $(out) fs.manifest $(fs_type))
+
+clean:
+       -rm -f usr.manifest common.manifest fs.manifest
+
+ifneq ($(MAKECMDGOALS),clean)
+include $(shell test -d $(out)/tests-with-linux-ld && find 
$(out)/tests-with-linux-ld -name '*.d')
+endif
diff --git a/modules/tests-with-linux-ld/create_static.sh 
b/modules/tests-with-linux-ld/create_static.sh
--- a/modules/tests-with-linux-ld/create_static.sh
+++ b/modules/tests-with-linux-ld/create_static.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+THIS_PATH=$(readlink -f $0)
+THIS_DIRECTORY=$(dirname ${THIS_PATH})
+OUT=$1
+MANIFEST=$2
+FS=${3-zfs}
+
+#Clean the directory
+rm -rf ${OUT}/tests-with-linux-ld/static
+
+if [ ${FS} = "rofs" ]
+then
+       mkdir -p ${OUT}/tests-with-linux-ld/static/rofs/tst-readdir-empty
+       mkdir -p ${OUT}/tests-with-linux-ld/static/rofs/tst-readdir
+       echo "Content" > ${OUT}/tests-with-linux-ld/static/rofs/tst-readdir/aaa
+
+       mkdir -p ${OUT}/tests-with-linux-ld/static/rofs/tst-chdir
+       echo "Content" > ${OUT}/tests-with-linux-ld/static/rofs/tst-chdir/f
+
+       mkdir -p ${OUT}/tests-with-linux-ld/static/rofs/tst-symlink
+       echo "Content" > ${OUT}/tests-with-linux-ld/static/rofs/tst-symlink/f1
+       cd ${OUT}/tests-with-linux-ld/static/rofs/tst-symlink && ln -s f1 f2_AAA
+
+       echo '/rofs/tst-readdir-empty: 
./tests-with-linux-ld/static/rofs/tst-readdir-empty' >> 
${THIS_DIRECTORY}/${MANIFEST}
+       echo '/rofs/tst-chdir/f: ./tests-with-linux-ld/static/rofs/tst-chdir/f' 
>> ${THIS_DIRECTORY}/${MANIFEST}
+       echo '/rofs/tst-readdir/aaa: 
./tests-with-linux-ld/static/rofs/tst-readdir/aaa' >> 
${THIS_DIRECTORY}/${MANIFEST}
+       echo '/rofs/tst-symlink/f1: 
./tests-with-linux-ld/static/rofs/tst-symlink/f1' >> 
${THIS_DIRECTORY}/${MANIFEST}
+       echo '/rofs/tst-symlink/f2_AAA: ->/rofs/tst-symlink/f1' >> 
${THIS_DIRECTORY}/${MANIFEST}
+
+       #This file is around 700K so it is a good test sample for the 
concurrent test
+       echo '/rofs/mmap-file-test1: ./core/spinlock.o' >> 
${THIS_DIRECTORY}/${MANIFEST}
+       echo '/rofs/mmap-file-test2: ./core/spinlock.o' >> 
${THIS_DIRECTORY}/${MANIFEST}
+else
+       echo '/tmp/mmap-file-test1: ./core/spinlock.o' >> 
${THIS_DIRECTORY}/${MANIFEST}
+       echo '/tmp/mmap-file-test2: ./core/spinlock.o' >> 
${THIS_DIRECTORY}/${MANIFEST}
+fi
diff --git a/modules/tests-with-linux-ld/module.py 
b/modules/tests-with-linux-ld/module.py
--- a/modules/tests-with-linux-ld/module.py
+++ b/modules/tests-with-linux-ld/module.py
@@ -0,0 +1,14 @@
+from osv.modules import api
+import os
+
+_modules_base = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
+_java_test_commands_file = _modules_base + '/java-tests/test_commands'
+
+host_arch = os.uname().machine
+if host_arch == 'x86_64' and os.getenv('ARCH') == 'aarch64':
+    if os.path.exists(_java_test_commands_file):
+        os.remove(_java_test_commands_file)
+else:
+    api.require('java-tests')
+
+api.require('dl_tests')
diff --git a/modules/tests-with-linux-ld/usr.manifest.skel 
b/modules/tests-with-linux-ld/usr.manifest.skel
--- a/modules/tests-with-linux-ld/usr.manifest.skel
+++ b/modules/tests-with-linux-ld/usr.manifest.skel
@@ -0,0 +1,6 @@
+/tests-with-linux-ld/: ->/tests
+/usr/share/zoneinfo/America/**: /usr/share/zoneinfo/America/**
+/usr/share/zoneinfo/Europe/**: /usr/share/zoneinfo/Europe/**
+/usr/share/zoneinfo/Pacific/**: /usr/share/zoneinfo/Pacific/**
+/usr/share/zoneinfo/Asia/**: /usr/share/zoneinfo/Asia/**
+/usr/lib/locale/C.utf8/**: /usr/lib/locale/C.utf8/**
diff --git a/tests/misc-fsx.c b/tests/misc-fsx.c
--- a/tests/misc-fsx.c
+++ b/tests/misc-fsx.c
@@ -20,6 +20,7 @@
  *     Checks for mmap last-page zero fill.
  */
 
+#define _GNU_SOURCE
 #include <limits.h>
 #include <time.h>
 #include <strings.h>
diff --git a/tests/misc-syscall-perf.c b/tests/misc-syscall-perf.c
--- a/tests/misc-syscall-perf.c
+++ b/tests/misc-syscall-perf.c
@@ -14,15 +14,13 @@
 #include <sys/types.h>
 #include <sys/time.h>
 
-#ifdef __OSV__
-long gettid();
-#endif
+pid_t gettid();
 
 void call_gettid_syscall()
 {
     // errors are returned).
     unsigned long syscall_nr = __NR_gettid;
-    long tid = 0;
+    pid_t tid = 0;
 
 #ifdef __x86_64__
     asm ("movq %[syscall_no], %%rax\n"
diff --git a/tests/tst-feexcept.cc b/tests/tst-feexcept.cc
--- a/tests/tst-feexcept.cc
+++ b/tests/tst-feexcept.cc
@@ -9,7 +9,9 @@
 // To compile on Linux, use: c++ -std=c++11 tests/tst-feexcept.cc
 
 #include <fenv.h>
+#ifdef __OSV__
 #include <__fenv.h>
+#endif
 #include <signal.h>
 #include <assert.h>
 #include <setjmp.h>
@@ -37,6 +39,11 @@ bool do_expect(T actual, T expected, const char *actuals, 
const char *expecteds,
         do_expect(call, -1, #call, "-1", __FILE__, __LINE__) && \
         do_expect(errno, experrno, #call " errno",  #experrno, __FILE__, 
__LINE__) )
 
+#ifndef __OSV__
+extern "C" int __sigsetjmp(sigjmp_buf env, int savemask);
+#define sigsetjmp(env, savemask) __sigsetjmp (env, savemask)
+#endif
+
 thread_local sigjmp_buf env;
 template<typename Func>
 bool sig_check(Func f, int sig) {
diff --git a/tests/tst-math.cc b/tests/tst-math.cc
--- a/tests/tst-math.cc
+++ b/tests/tst-math.cc
@@ -51,7 +51,9 @@ int main(int argc, char **argv)
     expect(finitef(NAN), 0);
     expect(__finitef(NAN), 0);
 
+#ifdef __OSV__
     expect(__log10_finite(100), log10(100));
+#endif
 
     std::cout << "SUMMARY: " << tests << " tests, " << fails << " failures\n";
     return fails == 0 ? 0 : 1;
diff --git a/tests/tst-pthread-affinity.cc b/tests/tst-pthread-affinity.cc
--- a/tests/tst-pthread-affinity.cc
+++ b/tests/tst-pthread-affinity.cc
@@ -14,6 +14,13 @@
 #include <sys/sysinfo.h>
 #include <cstring>
 
+#ifndef __OSV__
+#define __CPU_SETSIZE  1024
+#define __NCPUBITS     (8 * sizeof (__cpu_mask))
+
+#define _NCPUWORDS     __CPU_SETSIZE / __NCPUBITS
+#endif
+
 static std::atomic<unsigned> tests_total(0), tests_failed(0);
 
 void report(const char* name, bool passed)
diff --git a/tests/tst-queue-mpsc.cc b/tests/tst-queue-mpsc.cc
--- a/tests/tst-queue-mpsc.cc
+++ b/tests/tst-queue-mpsc.cc
@@ -39,9 +39,9 @@ void assert(bool c) {
 }
 #else
 #include <osv/debug.hh>
+#include <osv/sched.hh> // debugging
 #endif
 
-#include <osv/sched.hh> // debugging
 int main(int argc, char **argv) {
     std::cerr << "Running lockfree multi-producer single-consumer queue 
tests\n";
 
diff --git a/tests/tst-setjmp.cc b/tests/tst-setjmp.cc
--- a/tests/tst-setjmp.cc
+++ b/tests/tst-setjmp.cc
@@ -1,5 +1,7 @@
 #include <fenv.h>
+#ifdef __OSV__
 #include <__fenv.h>
+#endif
 #include <signal.h>
 #include <assert.h>
 #include <setjmp.h>
@@ -26,6 +28,11 @@ bool do_expect(T actual, T expected, const char *actuals, 
const char *expecteds,
 //This is a simple test that verifies that setjmp/longjmp/sigsetjmp/siglongjmp
 //flow control works correctly.
 
+#ifndef __OSV__
+extern "C" int __sigsetjmp(sigjmp_buf env, int savemask);
+#define sigsetjmp(env, savemask) __sigsetjmp (env, savemask)
+#endif
+
 static jmp_buf env;
 bool setjmp_check() {
     if (setjmp(env)) {
diff --git a/tests/tst-sigaltstack.cc b/tests/tst-sigaltstack.cc
--- a/tests/tst-sigaltstack.cc
+++ b/tests/tst-sigaltstack.cc
@@ -14,6 +14,10 @@
 #include <sys/mman.h>
 
 #include <iostream>
+#ifndef __OSV__
+extern "C" int __sigsetjmp(sigjmp_buf env, int savemask);
+#define sigsetjmp(env, savemask) __sigsetjmp (env, savemask)
+#endif
 
 static int tests = 0, fails = 0;
 
diff --git a/tests/tst-syscall.cc b/tests/tst-syscall.cc
--- a/tests/tst-syscall.cc
+++ b/tests/tst-syscall.cc
@@ -17,7 +17,7 @@
 
 #include <iostream>
 
-extern "C" long gettid();
+extern "C" pid_t gettid();
 
 static int tests = 0, fails = 0;
 
@@ -45,7 +45,7 @@ int main(int argc, char **argv)
     // results as the syscall() function (with expected differences in how
     // errors are returned).
     unsigned long syscall_nr = __NR_gettid;
-    long tid = 0;
+    pid_t tid = 0;
 
 #ifdef __x86_64__
     asm ("movq %[syscall_no], %%rax\n"
@@ -70,7 +70,7 @@ int main(int argc, char **argv)
     expect(tid, gettid());
 
     // test mmap as it takes 6 parameters
-    int fd = open("/tests/tst-mmap.so", O_RDONLY, 0666);
+    int fd = open("/libenviron.so", O_RDONLY, 0666);
     assert(fd > 0);
 
     void *addr = NULL;
diff --git a/tests/tst-threadcomplete.cc b/tests/tst-threadcomplete.cc
--- a/tests/tst-threadcomplete.cc
+++ b/tests/tst-threadcomplete.cc
@@ -16,8 +16,10 @@
 // this crashing or hanging.
 
 #include <sys/types.h>
+#include <sys/sysinfo.h>
 #include <thread>
 #include <iostream>
+#include <atomic>
 #ifdef __OSV__
 #include <osv/elf.hh>
 #include <osv/sched.hh>
@@ -129,7 +131,7 @@ int main(int ac, char** av)
     do_test(true);
     std::cerr << "Starting join tests...\n";
     do_test(false);
-    if (sched::cpus.size() >= 2) {
+    if (get_nprocs() >= 2) {
         std::cerr << "Starting thread-on-heap tests... (no load)\n";
         do_heap_test(false);
         std::cerr << "Starting thread-on-heap tests... (loaded)\n";

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/000000000000b34932060c84e306%40google.com.

Reply via email to