t_hello.sh revision 1.7
11.7Sskrll#	$NetBSD: t_hello.sh,v 1.7 2022/06/12 15:08:38 skrll 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.3Skamilhello_profile_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.3Skamilatf_test_case hello_profile
411.3Skamilhello_profile_32_head() {
421.3Skamil	atf_set "descr" "compile and run 32-bit \"hello world\" with profiling option"
431.3Skamil	atf_set "require.progs" "c++"
441.3Skamil}
451.3Skamil
461.3Skamilatf_test_case hello_static
471.3Skamilhello_static_head() {
481.3Skamil	atf_set "descr" "compile and run \"hello world\" with static option"
491.3Skamil	atf_set "require.progs" "c++"
501.3Skamil}
511.3Skamil
521.1Skamilatf_test_case hello_pic
531.1Skamilhello_pic_head() {
541.1Skamil	atf_set "descr" "compile and run PIC \"hello world\""
551.1Skamil	atf_set "require.progs" "c++"
561.1Skamil}
571.1Skamil
581.3Skamilatf_test_case hello_pic_32
591.3Skamilhello_pic_32_head() {
601.3Skamil	atf_set "descr" "compile and run 32-bit PIC \"hello world\""
611.3Skamil	atf_set "require.progs" "c++"
621.3Skamil}
631.3Skamil
641.3Skamilatf_test_case hello_pic_profile
651.3Skamilhello_pic_profile_head() {
661.3Skamil	atf_set "descr" "compile and run PIC \"hello world\" with profiling option"
671.3Skamil	atf_set "require.progs" "c++"
681.3Skamil}
691.3Skamil
701.3Skamilatf_test_case hello_pic_profile_32
711.3Skamilhello_pic_profile_32_head() {
721.3Skamil	atf_set "descr" "compile and run 32-bit PIC \"hello world\" with profiling option"
731.3Skamil	atf_set "require.progs" "c++"
741.3Skamil}
751.3Skamil
761.1Skamilatf_test_case hello_pie
771.1Skamilhello_pie_head() {
781.1Skamil	atf_set "descr" "compile and run position independent (PIE) \"hello world\""
791.1Skamil	atf_set "require.progs" "c++"
801.1Skamil}
811.1Skamil
821.1Skamilatf_test_case hello32
831.1Skamilhello32_head() {
841.1Skamil	atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation"
851.1Skamil	atf_set "require.progs" "c++ file diff cat"
861.1Skamil}
871.1Skamil
881.1Skamilhello_body() {
891.1Skamil	cat > test.cpp << EOF
901.1Skamil#include <stdio.h>
911.1Skamil#include <stdlib.h>
921.1Skamilint main(void) {printf("hello world\n");exit(0);}
931.1SkamilEOF
941.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello test.cpp
951.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
961.1Skamil}
971.1Skamil
981.2Smartinhello_profile_body() {
991.2Smartin	cat > test.cpp << EOF
1001.2Smartin#include <stdio.h>
1011.2Smartin#include <stdlib.h>
1021.2Smartinint main(void) {printf("hello world\n");exit(0);}
1031.2SmartinEOF
1041.7Sskrll	atf_check -s exit:0 -o ignore -e ignore c++ -static -pg -o hello test.cpp
1051.2Smartin	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1061.2Smartin}
1071.2Smartin
1081.3Skamilhello_profile_32_body() {
1091.3Skamil	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
1101.3Skamil		atf_skip "this is not a 64 bit architecture"
1111.3Skamil	fi
1121.3Skamil	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
1131.3Skamil		atf_skip "c++ -m32 not supported on this architecture"
1141.3Skamil	else
1151.3Skamil		if fgrep -q _LP64 ./def32; then
1161.3Skamil			atf_fail "c++ -m32 does not generate netbsd32 binaries"
1171.3Skamil		fi
1181.3Skamil	fi
1191.3Skamil
1201.3Skamil	cat > test.cpp << EOF
1211.3Skamil#include <stdio.h>
1221.3Skamil#include <stdlib.h>
1231.3Skamilint main(void) {printf("hello world\n");exit(0);}
1241.3SkamilEOF
1251.7Sskrll	atf_check -s exit:0 -o ignore -e ignore c++ -static  -m32 -pg -o hello test.cpp
1261.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1271.3Skamil}
1281.3Skamil
1291.3Skamil
1301.3Skamilhello_static_body() {
1311.3Skamil	cat > test.cpp << EOF
1321.3Skamil#include <stdio.h>
1331.3Skamil#include <stdlib.h>
1341.3Skamilint main(void) {printf("hello world\n");exit(0);}
1351.3SkamilEOF
1361.3Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -static -o hello test.cpp
1371.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1381.3Skamil}
1391.3Skamil
1401.1Skamilhello_pic_body() {
1411.1Skamil	cat > test.cpp << EOF
1421.1Skamil#include <stdlib.h>
1431.1Skamilint callpic(void);
1441.1Skamilint main(void) {callpic();exit(0);}
1451.1SkamilEOF
1461.1Skamil	cat > pic.cpp << EOF
1471.1Skamil#include <stdio.h>
1481.1Skamilint callpic(void) {printf("hello world\n");return 0;}
1491.1SkamilEOF
1501.1Skamil
1511.1Skamil	atf_check -s exit:0 -o ignore -e ignore \
1521.1Skamil	    c++ -fPIC -shared -o libtest.so pic.cpp
1531.1Skamil	atf_check -s exit:0 -o ignore -e ignore \
1541.1Skamil	    c++ -o hello test.cpp -L. -ltest
1551.1Skamil
1561.1Skamil	export LD_LIBRARY_PATH=.
1571.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1581.1Skamil}
1591.1Skamil
1601.3Skamilhello_pic_32_body() {
1611.3Skamil	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
1621.3Skamil		atf_skip "this is not a 64 bit architecture"
1631.3Skamil	fi
1641.3Skamil	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
1651.3Skamil		atf_skip "c++ -m32 not supported on this architecture"
1661.3Skamil	else
1671.3Skamil		if fgrep -q _LP64 ./def32; then
1681.3Skamil			atf_fail "c++ -m32 does not generate netbsd32 binaries"
1691.3Skamil		fi
1701.3Skamil	fi
1711.3Skamil	cat > test.cpp << EOF
1721.3Skamil#include <stdlib.h>
1731.3Skamilint callpic(void);
1741.3Skamilint main(void) {callpic();exit(0);}
1751.3SkamilEOF
1761.3Skamil	cat > pic.cpp << EOF
1771.3Skamil#include <stdio.h>
1781.3Skamilint callpic(void) {printf("hello world\n");return 0;}
1791.3SkamilEOF
1801.3Skamil
1811.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
1821.3Skamil	    c++ -m32 -fPIC -shared -o libtest.so pic.cpp
1831.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
1841.3Skamil	    c++ -m32 -o hello test.cpp -L. -ltest
1851.3Skamil
1861.3Skamil	export LD_LIBRARY_PATH=.
1871.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1881.3Skamil}
1891.3Skamil
1901.3Skamilhello_pic_profile_body() {
1911.3Skamil	cat > test.cpp << EOF
1921.3Skamil#include <stdlib.h>
1931.3Skamilint callpic(void);
1941.3Skamilint main(void) {callpic();exit(0);}
1951.3SkamilEOF
1961.3Skamil	cat > pic.cpp << EOF
1971.3Skamil#include <stdio.h>
1981.3Skamilint callpic(void) {printf("hello world\n");return 0;}
1991.3SkamilEOF
2001.3Skamil
2011.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
2021.3Skamil	    c++ -pg -fPIC -shared -o libtest.so pic.cpp
2031.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
2041.3Skamil	    c++ -pg -o hello test.cpp -L. -ltest
2051.3Skamil
2061.3Skamil	export LD_LIBRARY_PATH=.
2071.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
2081.3Skamil}
2091.3Skamil
2101.3Skamilhello_pic_profile_32_body() {
2111.3Skamil	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
2121.3Skamil		atf_skip "this is not a 64 bit architecture"
2131.3Skamil	fi
2141.3Skamil	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
2151.3Skamil		atf_skip "c++ -m32 not supported on this architecture"
2161.3Skamil	else
2171.3Skamil		if fgrep -q _LP64 ./def32; then
2181.3Skamil			atf_fail "c++ -m32 does not generate netbsd32 binaries"
2191.3Skamil		fi
2201.3Skamil	fi
2211.3Skamil
2221.3Skamil	cat > test.cpp << EOF
2231.3Skamil#include <stdlib.h>
2241.3Skamilint callpic(void);
2251.3Skamilint main(void) {callpic();exit(0);}
2261.3SkamilEOF
2271.3Skamil	cat > pic.cpp << EOF
2281.3Skamil#include <stdio.h>
2291.3Skamilint callpic(void) {printf("hello world\n");return 0;}
2301.3SkamilEOF
2311.3Skamil
2321.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
2331.3Skamil	    c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
2341.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
2351.3Skamil	    c++ -m32 -pg -o hello test.cpp -L. -ltest
2361.3Skamil
2371.3Skamil	export LD_LIBRARY_PATH=.
2381.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
2391.3Skamil}
2401.3Skamil
2411.1Skamilhello_pie_body() {
2421.1Skamil	# check whether this arch supports -pie
2431.1Skamil	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
2441.1Skamil		atf_skip "c++ -pie not supported on this architecture"
2451.1Skamil	fi
2461.1Skamil	cat > test.cpp << EOF
2471.1Skamil#include <stdio.h>
2481.1Skamil#include <stdlib.h>
2491.1Skamilint main(void) {printf("hello world\n");exit(0);}
2501.1SkamilEOF
2511.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o hello test.cpp
2521.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
2531.1Skamil}
2541.1Skamil
2551.1Skamilhello32_body() {
2561.1Skamil	# check whether this arch is 64bit
2571.1Skamil	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
2581.1Skamil		atf_skip "this is not a 64 bit architecture"
2591.1Skamil	fi
2601.1Skamil	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
2611.1Skamil		atf_skip "c++ -m32 not supported on this architecture"
2621.1Skamil	else
2631.1Skamil		if fgrep -q _LP64 ./def32; then
2641.1Skamil			atf_fail "c++ -m32 does not generate netbsd32 binaries"
2651.1Skamil		fi
2661.1Skamil	fi
2671.1Skamil
2681.1Skamil	cat > test.cpp << EOF
2691.1Skamil#include <stdio.h>
2701.1Skamil#include <stdlib.h>
2711.1Skamilint main(void) {printf("hello world\n");exit(0);}
2721.1SkamilEOF
2731.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello32 -m32 test.cpp
2741.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello64 test.cpp
2751.1Skamil	file -b ./hello32 > ./ftype32
2761.1Skamil	file -b ./hello64 > ./ftype64
2771.1Skamil	if diff ./ftype32 ./ftype64 >/dev/null; then
2781.1Skamil		atf_fail "generated binaries do not differ"
2791.1Skamil	fi
2801.1Skamil	echo "32bit binaries on this platform are:"
2811.1Skamil	cat ./ftype32
2821.1Skamil	echo "While native (64bit) binaries are:"
2831.1Skamil	cat ./ftype64
2841.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello32
2851.1Skamil
2861.1Skamil	# do another test with static 32bit binaries
2871.1Skamil	cat > test.cpp << EOF
2881.1Skamil#include <stdio.h>
2891.1Skamil#include <stdlib.h>
2901.1Skamilint main(void) {printf("hello static world\n");exit(0);}
2911.1SkamilEOF
2921.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello -m32 \
2931.1Skamil	    -static test.cpp
2941.1Skamil	atf_check -s exit:0 -o inline:"hello static world\n" ./hello
2951.1Skamil}
2961.1Skamil
2971.1Skamilatf_init_test_cases()
2981.1Skamil{
2991.1Skamil
3001.1Skamil	atf_add_test_case hello
3011.2Smartin	atf_add_test_case hello_profile
3021.1Skamil	atf_add_test_case hello_pic
3031.1Skamil	atf_add_test_case hello_pie
3041.1Skamil	atf_add_test_case hello32
3051.3Skamil	atf_add_test_case hello_static
3061.3Skamil	atf_add_test_case hello_pic_32
3071.3Skamil	atf_add_test_case hello_pic_profile
3081.3Skamil	atf_add_test_case hello_pic_profile_32
3091.3Skamil	atf_add_test_case hello_profile_32
3101.1Skamil}
311