t_hello.sh revision 1.2
11.2Smartin#	$NetBSD: t_hello.sh,v 1.2 2017/05/18 10:29:47 martin Exp $
21.1Skamil#
31.1Skamil# Copyright (c) 2011 The NetBSD Foundation, Inc.
41.1Skamil# All rights reserved.
51.1Skamil#
61.1Skamil# Redistribution and use in source and binary forms, with or without
71.1Skamil# modification, are permitted provided that the following conditions
81.1Skamil# are met:
91.1Skamil# 1. Redistributions of source code must retain the above copyright
101.1Skamil#    notice, this list of conditions and the following disclaimer.
111.1Skamil# 2. Redistributions in binary form must reproduce the above copyright
121.1Skamil#    notice, this list of conditions and the following disclaimer in the
131.1Skamil#    documentation and/or other materials provided with the distribution.
141.1Skamil#
151.1Skamil# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
161.1Skamil# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
171.1Skamil# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
181.1Skamil# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
191.1Skamil# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
201.1Skamil# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
211.1Skamil# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
221.1Skamil# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
231.1Skamil# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
241.1Skamil# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
251.1Skamil# POSSIBILITY OF SUCH DAMAGE.
261.1Skamil#
271.1Skamil
281.1Skamilatf_test_case hello
291.1Skamilhello_head() {
301.1Skamil	atf_set "descr" "compile and run \"hello world\""
311.1Skamil	atf_set "require.progs" "c++"
321.1Skamil}
331.1Skamil
341.2Smartinatf_test_case hello_profile
351.2Smartinhello_head() {
361.2Smartin	atf_set "descr" "compile and run \"hello world\" with profiling option"
371.2Smartin	atf_set "require.progs" "c++"
381.2Smartin}
391.2Smartin
401.1Skamilatf_test_case hello_pic
411.1Skamilhello_pic_head() {
421.1Skamil	atf_set "descr" "compile and run PIC \"hello world\""
431.1Skamil	atf_set "require.progs" "c++"
441.1Skamil}
451.1Skamil
461.1Skamilatf_test_case hello_pie
471.1Skamilhello_pie_head() {
481.1Skamil	atf_set "descr" "compile and run position independent (PIE) \"hello world\""
491.1Skamil	atf_set "require.progs" "c++"
501.1Skamil}
511.1Skamil
521.1Skamilatf_test_case hello32
531.1Skamilhello32_head() {
541.1Skamil	atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation"
551.1Skamil	atf_set "require.progs" "c++ file diff cat"
561.1Skamil}
571.1Skamil
581.1Skamilhello_body() {
591.1Skamil	cat > test.cpp << EOF
601.1Skamil#include <stdio.h>
611.1Skamil#include <stdlib.h>
621.1Skamilint main(void) {printf("hello world\n");exit(0);}
631.1SkamilEOF
641.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello test.cpp
651.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
661.1Skamil}
671.1Skamil
681.2Smartinhello_profile_body() {
691.2Smartin	cat > test.cpp << EOF
701.2Smartin#include <stdio.h>
711.2Smartin#include <stdlib.h>
721.2Smartinint main(void) {printf("hello world\n");exit(0);}
731.2SmartinEOF
741.2Smartin	atf_check -s exit:0 -o ignore -e ignore c++ -pg -o hello test.cpp
751.2Smartin	atf_check -s exit:0 -o inline:"hello world\n" ./hello
761.2Smartin}
771.2Smartin
781.1Skamilhello_pic_body() {
791.1Skamil	cat > test.cpp << EOF
801.1Skamil#include <stdlib.h>
811.1Skamilint callpic(void);
821.1Skamilint main(void) {callpic();exit(0);}
831.1SkamilEOF
841.1Skamil	cat > pic.cpp << EOF
851.1Skamil#include <stdio.h>
861.1Skamilint callpic(void) {printf("hello world\n");return 0;}
871.1SkamilEOF
881.1Skamil
891.1Skamil	atf_check -s exit:0 -o ignore -e ignore \
901.1Skamil	    c++ -fPIC -shared -o libtest.so pic.cpp
911.1Skamil	atf_check -s exit:0 -o ignore -e ignore \
921.1Skamil	    c++ -o hello test.cpp -L. -ltest
931.1Skamil
941.1Skamil	export LD_LIBRARY_PATH=.
951.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
961.1Skamil}
971.1Skamil
981.1Skamilhello_pie_body() {
991.1Skamil	# check whether this arch supports -pie
1001.1Skamil	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
1011.1Skamil		atf_skip "c++ -pie not supported on this architecture"
1021.1Skamil	fi
1031.1Skamil	cat > test.cpp << EOF
1041.1Skamil#include <stdio.h>
1051.1Skamil#include <stdlib.h>
1061.1Skamilint main(void) {printf("hello world\n");exit(0);}
1071.1SkamilEOF
1081.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o hello test.cpp
1091.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1101.1Skamil}
1111.1Skamil
1121.1Skamilhello32_body() {
1131.1Skamil	# check whether this arch is 64bit
1141.1Skamil	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
1151.1Skamil		atf_skip "this is not a 64 bit architecture"
1161.1Skamil	fi
1171.1Skamil	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
1181.1Skamil		atf_skip "c++ -m32 not supported on this architecture"
1191.1Skamil	else
1201.1Skamil		if fgrep -q _LP64 ./def32; then
1211.1Skamil			atf_fail "c++ -m32 does not generate netbsd32 binaries"
1221.1Skamil		fi
1231.1Skamil	fi
1241.1Skamil
1251.1Skamil	cat > test.cpp << EOF
1261.1Skamil#include <stdio.h>
1271.1Skamil#include <stdlib.h>
1281.1Skamilint main(void) {printf("hello world\n");exit(0);}
1291.1SkamilEOF
1301.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello32 -m32 test.cpp
1311.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello64 test.cpp
1321.1Skamil	file -b ./hello32 > ./ftype32
1331.1Skamil	file -b ./hello64 > ./ftype64
1341.1Skamil	if diff ./ftype32 ./ftype64 >/dev/null; then
1351.1Skamil		atf_fail "generated binaries do not differ"
1361.1Skamil	fi
1371.1Skamil	echo "32bit binaries on this platform are:"
1381.1Skamil	cat ./ftype32
1391.1Skamil	echo "While native (64bit) binaries are:"
1401.1Skamil	cat ./ftype64
1411.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello32
1421.1Skamil
1431.1Skamil	# do another test with static 32bit binaries
1441.1Skamil	cat > test.cpp << EOF
1451.1Skamil#include <stdio.h>
1461.1Skamil#include <stdlib.h>
1471.1Skamilint main(void) {printf("hello static world\n");exit(0);}
1481.1SkamilEOF
1491.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello -m32 \
1501.1Skamil	    -static test.cpp
1511.1Skamil	atf_check -s exit:0 -o inline:"hello static world\n" ./hello
1521.1Skamil}
1531.1Skamil
1541.1Skamilatf_init_test_cases()
1551.1Skamil{
1561.1Skamil
1571.1Skamil	atf_add_test_case hello
1581.2Smartin	atf_add_test_case hello_profile
1591.1Skamil	atf_add_test_case hello_pic
1601.1Skamil	atf_add_test_case hello_pie
1611.1Skamil	atf_add_test_case hello32
1621.1Skamil}
163