1*640235e2SEnji Cooper# $NetBSD: t_hello.sh,v 1.3 2016/04/03 14:41:30 gson Exp $ 257718be8SEnji Cooper# 357718be8SEnji Cooper# Copyright (c) 2011 The NetBSD Foundation, Inc. 457718be8SEnji Cooper# All rights reserved. 557718be8SEnji Cooper# 657718be8SEnji Cooper# Redistribution and use in source and binary forms, with or without 757718be8SEnji Cooper# modification, are permitted provided that the following conditions 857718be8SEnji Cooper# are met: 957718be8SEnji Cooper# 1. Redistributions of source code must retain the above copyright 1057718be8SEnji Cooper# notice, this list of conditions and the following disclaimer. 1157718be8SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright 1257718be8SEnji Cooper# notice, this list of conditions and the following disclaimer in the 1357718be8SEnji Cooper# documentation and/or other materials provided with the distribution. 1457718be8SEnji Cooper# 1557718be8SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1657718be8SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1757718be8SEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1857718be8SEnji Cooper# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1957718be8SEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2057718be8SEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2157718be8SEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2257718be8SEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2357718be8SEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2457718be8SEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2557718be8SEnji Cooper# POSSIBILITY OF SUCH DAMAGE. 2657718be8SEnji Cooper# 2757718be8SEnji Cooper 2857718be8SEnji Cooperatf_test_case hello 2957718be8SEnji Cooperhello_head() { 3057718be8SEnji Cooper atf_set "descr" "compile and run \"hello world\"" 3157718be8SEnji Cooper atf_set "require.progs" "cc" 3257718be8SEnji Cooper} 3357718be8SEnji Cooper 3457718be8SEnji Cooperatf_test_case hello_pic 3557718be8SEnji Cooperhello_pic_head() { 3657718be8SEnji Cooper atf_set "descr" "compile and run PIC \"hello world\"" 3757718be8SEnji Cooper atf_set "require.progs" "cc" 3857718be8SEnji Cooper} 3957718be8SEnji Cooper 4057718be8SEnji Cooperatf_test_case hello_pie 4157718be8SEnji Cooperhello_pie_head() { 42*640235e2SEnji Cooper atf_set "descr" "compile and run position independent (PIE) \"hello world\"" 4357718be8SEnji Cooper atf_set "require.progs" "cc" 4457718be8SEnji Cooper} 4557718be8SEnji Cooper 4657718be8SEnji Cooperatf_test_case hello32 4757718be8SEnji Cooperhello32_head() { 4857718be8SEnji Cooper atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation" 4957718be8SEnji Cooper atf_set "require.progs" "cc file diff cat" 5057718be8SEnji Cooper} 5157718be8SEnji Cooper 5257718be8SEnji Cooperhello_body() { 5357718be8SEnji Cooper cat > test.c << EOF 5457718be8SEnji Cooper#include <stdio.h> 5557718be8SEnji Cooper#include <stdlib.h> 5657718be8SEnji Cooperint main(void) {printf("hello world\n");exit(0);} 5757718be8SEnji CooperEOF 5857718be8SEnji Cooper atf_check -s exit:0 -o ignore -e ignore cc -o hello test.c 5957718be8SEnji Cooper atf_check -s exit:0 -o inline:"hello world\n" ./hello 6057718be8SEnji Cooper} 6157718be8SEnji Cooper 6257718be8SEnji Cooperhello_pic_body() { 6357718be8SEnji Cooper cat > test.c << EOF 6457718be8SEnji Cooper#include <stdlib.h> 6557718be8SEnji Cooperint main(void) {callpic();exit(0);} 6657718be8SEnji CooperEOF 6757718be8SEnji Cooper cat > pic.c << EOF 6857718be8SEnji Cooper#include <stdio.h> 6957718be8SEnji Cooperint callpic(void) {printf("hello world\n");} 7057718be8SEnji CooperEOF 7157718be8SEnji Cooper 7257718be8SEnji Cooper atf_check -s exit:0 -o ignore -e ignore \ 7357718be8SEnji Cooper cc -fPIC -dPIC -shared -o libtest.so pic.c 7457718be8SEnji Cooper atf_check -s exit:0 -o ignore -e ignore \ 7557718be8SEnji Cooper cc -o hello test.c -L. -ltest 7657718be8SEnji Cooper 7757718be8SEnji Cooper export LD_LIBRARY_PATH=. 7857718be8SEnji Cooper atf_check -s exit:0 -o inline:"hello world\n" ./hello 7957718be8SEnji Cooper} 8057718be8SEnji Cooper 8157718be8SEnji Cooperhello_pie_body() { 8257718be8SEnji Cooper # check whether this arch supports -pie 8357718be8SEnji Cooper if ! cc -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then 8457718be8SEnji Cooper atf_skip "cc -pie not supported on this architecture" 8557718be8SEnji Cooper fi 8657718be8SEnji Cooper cat > test.c << EOF 8757718be8SEnji Cooper#include <stdio.h> 8857718be8SEnji Cooper#include <stdlib.h> 8957718be8SEnji Cooperint main(void) {printf("hello world\n");exit(0);} 9057718be8SEnji CooperEOF 9157718be8SEnji Cooper atf_check -s exit:0 -o ignore -e ignore cc -fpie -pie -o hello test.c 9257718be8SEnji Cooper atf_check -s exit:0 -o inline:"hello world\n" ./hello 9357718be8SEnji Cooper} 9457718be8SEnji Cooper 9557718be8SEnji Cooperhello32_body() { 9657718be8SEnji Cooper # check whether this arch is 64bit 9757718be8SEnji Cooper if ! cc -dM -E - < /dev/null | fgrep -q _LP64; then 9857718be8SEnji Cooper atf_skip "this is not a 64 bit architecture" 9957718be8SEnji Cooper fi 10057718be8SEnji Cooper if ! cc -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 10157718be8SEnji Cooper atf_skip "cc -m32 not supported on this architecture" 10257718be8SEnji Cooper else 10357718be8SEnji Cooper if fgrep -q _LP64 ./def32; then 10457718be8SEnji Cooper atf_fail "cc -m32 does not generate netbsd32 binaries" 10557718be8SEnji Cooper fi 10657718be8SEnji Cooper fi 10757718be8SEnji Cooper 10857718be8SEnji Cooper cat > test.c << EOF 10957718be8SEnji Cooper#include <stdio.h> 11057718be8SEnji Cooper#include <stdlib.h> 11157718be8SEnji Cooperint main(void) {printf("hello world\n");exit(0);} 11257718be8SEnji CooperEOF 11357718be8SEnji Cooper atf_check -s exit:0 -o ignore -e ignore cc -o hello32 -m32 test.c 11457718be8SEnji Cooper atf_check -s exit:0 -o ignore -e ignore cc -o hello64 test.c 11557718be8SEnji Cooper file -b ./hello32 > ./ftype32 11657718be8SEnji Cooper file -b ./hello64 > ./ftype64 11757718be8SEnji Cooper if diff ./ftype32 ./ftype64 >/dev/null; then 11857718be8SEnji Cooper atf_fail "generated binaries do not differ" 11957718be8SEnji Cooper fi 12057718be8SEnji Cooper echo "32bit binaries on this platform are:" 12157718be8SEnji Cooper cat ./ftype32 12257718be8SEnji Cooper echo "While native (64bit) binaries are:" 12357718be8SEnji Cooper cat ./ftype64 12457718be8SEnji Cooper atf_check -s exit:0 -o inline:"hello world\n" ./hello32 12557718be8SEnji Cooper 12657718be8SEnji Cooper # do another test with static 32bit binaries 12757718be8SEnji Cooper cat > test.c << EOF 12857718be8SEnji Cooper#include <stdio.h> 12957718be8SEnji Cooper#include <stdlib.h> 13057718be8SEnji Cooperint main(void) {printf("hello static world\n");exit(0);} 13157718be8SEnji CooperEOF 13257718be8SEnji Cooper atf_check -s exit:0 -o ignore -e ignore cc -o hello -m32 \ 13357718be8SEnji Cooper -static test.c 13457718be8SEnji Cooper atf_check -s exit:0 -o inline:"hello static world\n" ./hello 13557718be8SEnji Cooper} 13657718be8SEnji Cooper 13757718be8SEnji Cooperatf_init_test_cases() 13857718be8SEnji Cooper{ 13957718be8SEnji Cooper 14057718be8SEnji Cooper atf_add_test_case hello 14157718be8SEnji Cooper atf_add_test_case hello_pic 14257718be8SEnji Cooper atf_add_test_case hello_pie 14357718be8SEnji Cooper atf_add_test_case hello32 14457718be8SEnji Cooper} 145