Module Name: src Committed By: christos Date: Fri Jun 7 21:18:16 UTC 2019
Modified Files: src/tests/kernel: Makefile Added Files: src/tests/kernel: t_origin.sh Log Message: Add a $ORIGIN test To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/tests/kernel/Makefile cvs rdiff -u -r0 -r1.1 src/tests/kernel/t_origin.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/kernel/Makefile diff -u src/tests/kernel/Makefile:1.59 src/tests/kernel/Makefile:1.60 --- src/tests/kernel/Makefile:1.59 Sat Jun 1 15:49:02 2019 +++ src/tests/kernel/Makefile Fri Jun 7 17:18:16 2019 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.59 2019/06/01 19:49:02 kamil Exp $ +# $NetBSD: Makefile,v 1.60 2019/06/07 21:18:16 christos Exp $ NOMAN= # defined @@ -25,6 +25,7 @@ TESTS_SH+= t_umountstress TESTS_SH+= t_ps_strings TESTS_SH+= t_trapsignal TESTS_SH+= t_interp +TESTS_SH+= t_origin TESTS_SH+= t_procpath BINDIR= ${TESTSDIR} Added files: Index: src/tests/kernel/t_origin.sh diff -u /dev/null src/tests/kernel/t_origin.sh:1.1 --- /dev/null Fri Jun 7 17:18:16 2019 +++ src/tests/kernel/t_origin.sh Fri Jun 7 17:18:16 2019 @@ -0,0 +1,122 @@ +# $NetBSD: t_origin.sh,v 1.1 2019/06/07 21:18:16 christos Exp $ +# +# Copyright (c) 2019 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Christos Zoulas. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +atf_test_case origin_simple +origin_simple_head() { + atf_set "descr" 'test native $ORIGIN support' + atf_set "require.progs" "cc" +} + +atf_test_case origin_simple_32 +origin_simple_32_head() { + atf_set "descr" 'test $ORIGIN support in 32 bit mode' + atf_set "require.progs" "cc" +} + +make_code() { + cat > origin$1.c << _EOF +#include <stdio.h> +#include <err.h> +#include <stdlib.h> +#include <dlfcn.h> + +static const char lib[] = "libfoo$1.so"; +int +main(void) +{ + void *h = dlopen(lib, RTLD_NOW); + if (h == NULL) + errx(EXIT_FAILURE, "dlopen: %s", dlerror()); + dlclose(h); + return EXIT_SUCCESS; +} +_EOF + +cat > libfoo$1.c << EOF +void foo(void); +void foo(void) +{ +} +EOF +} + +test_code() { + local m32 + if [ -z "$1" ]; then + m32= + else + m32=-m32 + fi + atf_check -s exit:0 -o empty -e empty \ + cc -fPIC $m32 -o origin$1 origin$1.c -Wl,-R'$ORIGIN' + atf_check -s exit:0 -o empty -e empty \ + cc -shared -fPIC $m32 -o libfoo$1.so libfoo$1.c + atf_check -s exit:0 -o empty -e empty ./origin$1 +} + +check32() { + # check whether this arch is 64bit + if ! cc -dM -E - < /dev/null | fgrep -q _LP64; then + atf_skip "this is not a 64 bit architecture" + return 1 + fi + if ! cc -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then + atf_skip "c++ -m32 not supported on this architecture" + return 1 + else + if fgrep -q _LP64 ./def32; then + atf_fail "c++ -m32 does not generate netbsd32 binaries" + return 1 + fi + return 0 + fi +} + +origin_simple_body() { + make_code "" + test_code "" + +} + +origin_simple_32_body() { + if ! check32; then + return + fi + make_code "32" + test_code "32" +} + + +atf_init_test_cases() +{ + + atf_add_test_case origin_simple + atf_add_test_case origin_simple_32 +}