11.8Sriastrad#	$NetBSD: t_hello.sh,v 1.8 2025/04/16 01:52:42 riastradh 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.8Sriastrad	case `uname -m` in
1001.8Sriastrad	riscv)	atf_expect_fail "PR port-riscv/59301:" \
1011.8Sriastrad		    " riscv: missing MKPROFILE=yes support"
1021.8Sriastrad		;;
1031.8Sriastrad	esac
1041.8Sriastrad
1051.2Smartin	cat > test.cpp << EOF
1061.2Smartin#include <stdio.h>
1071.2Smartin#include <stdlib.h>
1081.2Smartinint main(void) {printf("hello world\n");exit(0);}
1091.2SmartinEOF
1101.7Sskrll	atf_check -s exit:0 -o ignore -e ignore c++ -static -pg -o hello test.cpp
1111.2Smartin	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1121.2Smartin}
1131.2Smartin
1141.3Skamilhello_profile_32_body() {
1151.3Skamil	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
1161.3Skamil		atf_skip "this is not a 64 bit architecture"
1171.3Skamil	fi
1181.3Skamil	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
1191.3Skamil		atf_skip "c++ -m32 not supported on this architecture"
1201.3Skamil	else
1211.3Skamil		if fgrep -q _LP64 ./def32; then
1221.3Skamil			atf_fail "c++ -m32 does not generate netbsd32 binaries"
1231.3Skamil		fi
1241.3Skamil	fi
1251.3Skamil
1261.8Sriastrad	case `uname -m` in
1271.8Sriastrad	riscv)	atf_expect_fail "PR port-riscv/59301:" \
1281.8Sriastrad		    " riscv: missing MKPROFILE=yes support"
1291.8Sriastrad		;;
1301.8Sriastrad	esac
1311.8Sriastrad
1321.3Skamil	cat > test.cpp << EOF
1331.3Skamil#include <stdio.h>
1341.3Skamil#include <stdlib.h>
1351.3Skamilint main(void) {printf("hello world\n");exit(0);}
1361.3SkamilEOF
1371.7Sskrll	atf_check -s exit:0 -o ignore -e ignore c++ -static  -m32 -pg -o hello test.cpp
1381.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1391.3Skamil}
1401.3Skamil
1411.3Skamil
1421.3Skamilhello_static_body() {
1431.3Skamil	cat > test.cpp << EOF
1441.3Skamil#include <stdio.h>
1451.3Skamil#include <stdlib.h>
1461.3Skamilint main(void) {printf("hello world\n");exit(0);}
1471.3SkamilEOF
1481.3Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -static -o hello test.cpp
1491.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1501.3Skamil}
1511.3Skamil
1521.1Skamilhello_pic_body() {
1531.1Skamil	cat > test.cpp << EOF
1541.1Skamil#include <stdlib.h>
1551.1Skamilint callpic(void);
1561.1Skamilint main(void) {callpic();exit(0);}
1571.1SkamilEOF
1581.1Skamil	cat > pic.cpp << EOF
1591.1Skamil#include <stdio.h>
1601.1Skamilint callpic(void) {printf("hello world\n");return 0;}
1611.1SkamilEOF
1621.1Skamil
1631.1Skamil	atf_check -s exit:0 -o ignore -e ignore \
1641.1Skamil	    c++ -fPIC -shared -o libtest.so pic.cpp
1651.1Skamil	atf_check -s exit:0 -o ignore -e ignore \
1661.1Skamil	    c++ -o hello test.cpp -L. -ltest
1671.1Skamil
1681.1Skamil	export LD_LIBRARY_PATH=.
1691.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
1701.1Skamil}
1711.1Skamil
1721.3Skamilhello_pic_32_body() {
1731.3Skamil	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
1741.3Skamil		atf_skip "this is not a 64 bit architecture"
1751.3Skamil	fi
1761.3Skamil	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
1771.3Skamil		atf_skip "c++ -m32 not supported on this architecture"
1781.3Skamil	else
1791.3Skamil		if fgrep -q _LP64 ./def32; then
1801.3Skamil			atf_fail "c++ -m32 does not generate netbsd32 binaries"
1811.3Skamil		fi
1821.3Skamil	fi
1831.3Skamil	cat > test.cpp << EOF
1841.3Skamil#include <stdlib.h>
1851.3Skamilint callpic(void);
1861.3Skamilint main(void) {callpic();exit(0);}
1871.3SkamilEOF
1881.3Skamil	cat > pic.cpp << EOF
1891.3Skamil#include <stdio.h>
1901.3Skamilint callpic(void) {printf("hello world\n");return 0;}
1911.3SkamilEOF
1921.3Skamil
1931.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
1941.3Skamil	    c++ -m32 -fPIC -shared -o libtest.so pic.cpp
1951.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
1961.3Skamil	    c++ -m32 -o hello test.cpp -L. -ltest
1971.3Skamil
1981.3Skamil	export LD_LIBRARY_PATH=.
1991.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
2001.3Skamil}
2011.3Skamil
2021.3Skamilhello_pic_profile_body() {
2031.8Sriastrad	case `uname -m` in
2041.8Sriastrad	riscv)	atf_expect_fail "PR port-riscv/59301:" \
2051.8Sriastrad		    " riscv: missing MKPROFILE=yes support"
2061.8Sriastrad		;;
2071.8Sriastrad	esac
2081.8Sriastrad
2091.3Skamil	cat > test.cpp << EOF
2101.3Skamil#include <stdlib.h>
2111.3Skamilint callpic(void);
2121.3Skamilint main(void) {callpic();exit(0);}
2131.3SkamilEOF
2141.3Skamil	cat > pic.cpp << EOF
2151.3Skamil#include <stdio.h>
2161.3Skamilint callpic(void) {printf("hello world\n");return 0;}
2171.3SkamilEOF
2181.3Skamil
2191.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
2201.3Skamil	    c++ -pg -fPIC -shared -o libtest.so pic.cpp
2211.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
2221.3Skamil	    c++ -pg -o hello test.cpp -L. -ltest
2231.3Skamil
2241.3Skamil	export LD_LIBRARY_PATH=.
2251.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
2261.3Skamil}
2271.3Skamil
2281.3Skamilhello_pic_profile_32_body() {
2291.3Skamil	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
2301.3Skamil		atf_skip "this is not a 64 bit architecture"
2311.3Skamil	fi
2321.3Skamil	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
2331.3Skamil		atf_skip "c++ -m32 not supported on this architecture"
2341.3Skamil	else
2351.3Skamil		if fgrep -q _LP64 ./def32; then
2361.3Skamil			atf_fail "c++ -m32 does not generate netbsd32 binaries"
2371.3Skamil		fi
2381.3Skamil	fi
2391.3Skamil
2401.8Sriastrad	case `uname -m` in
2411.8Sriastrad	riscv)	atf_expect_fail "PR port-riscv/59301:" \
2421.8Sriastrad		    " riscv: missing MKPROFILE=yes support"
2431.8Sriastrad		;;
2441.8Sriastrad	esac
2451.8Sriastrad
2461.3Skamil	cat > test.cpp << EOF
2471.3Skamil#include <stdlib.h>
2481.3Skamilint callpic(void);
2491.3Skamilint main(void) {callpic();exit(0);}
2501.3SkamilEOF
2511.3Skamil	cat > pic.cpp << EOF
2521.3Skamil#include <stdio.h>
2531.3Skamilint callpic(void) {printf("hello world\n");return 0;}
2541.3SkamilEOF
2551.3Skamil
2561.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
2571.3Skamil	    c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp
2581.3Skamil	atf_check -s exit:0 -o ignore -e ignore \
2591.3Skamil	    c++ -m32 -pg -o hello test.cpp -L. -ltest
2601.3Skamil
2611.3Skamil	export LD_LIBRARY_PATH=.
2621.3Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
2631.3Skamil}
2641.3Skamil
2651.1Skamilhello_pie_body() {
2661.1Skamil	# check whether this arch supports -pie
2671.1Skamil	if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
2681.1Skamil		atf_skip "c++ -pie not supported on this architecture"
2691.1Skamil	fi
2701.1Skamil	cat > test.cpp << EOF
2711.1Skamil#include <stdio.h>
2721.1Skamil#include <stdlib.h>
2731.1Skamilint main(void) {printf("hello world\n");exit(0);}
2741.1SkamilEOF
2751.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o hello test.cpp
2761.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello
2771.1Skamil}
2781.1Skamil
2791.1Skamilhello32_body() {
2801.1Skamil	# check whether this arch is 64bit
2811.1Skamil	if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then
2821.1Skamil		atf_skip "this is not a 64 bit architecture"
2831.1Skamil	fi
2841.1Skamil	if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
2851.1Skamil		atf_skip "c++ -m32 not supported on this architecture"
2861.1Skamil	else
2871.1Skamil		if fgrep -q _LP64 ./def32; then
2881.1Skamil			atf_fail "c++ -m32 does not generate netbsd32 binaries"
2891.1Skamil		fi
2901.1Skamil	fi
2911.1Skamil
2921.1Skamil	cat > test.cpp << EOF
2931.1Skamil#include <stdio.h>
2941.1Skamil#include <stdlib.h>
2951.1Skamilint main(void) {printf("hello world\n");exit(0);}
2961.1SkamilEOF
2971.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello32 -m32 test.cpp
2981.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello64 test.cpp
2991.1Skamil	file -b ./hello32 > ./ftype32
3001.1Skamil	file -b ./hello64 > ./ftype64
3011.1Skamil	if diff ./ftype32 ./ftype64 >/dev/null; then
3021.1Skamil		atf_fail "generated binaries do not differ"
3031.1Skamil	fi
3041.1Skamil	echo "32bit binaries on this platform are:"
3051.1Skamil	cat ./ftype32
3061.1Skamil	echo "While native (64bit) binaries are:"
3071.1Skamil	cat ./ftype64
3081.1Skamil	atf_check -s exit:0 -o inline:"hello world\n" ./hello32
3091.1Skamil
3101.1Skamil	# do another test with static 32bit binaries
3111.1Skamil	cat > test.cpp << EOF
3121.1Skamil#include <stdio.h>
3131.1Skamil#include <stdlib.h>
3141.1Skamilint main(void) {printf("hello static world\n");exit(0);}
3151.1SkamilEOF
3161.1Skamil	atf_check -s exit:0 -o ignore -e ignore c++ -o hello -m32 \
3171.1Skamil	    -static test.cpp
3181.1Skamil	atf_check -s exit:0 -o inline:"hello static world\n" ./hello
3191.1Skamil}
3201.1Skamil
3211.1Skamilatf_init_test_cases()
3221.1Skamil{
3231.1Skamil
3241.1Skamil	atf_add_test_case hello
3251.2Smartin	atf_add_test_case hello_profile
3261.1Skamil	atf_add_test_case hello_pic
3271.1Skamil	atf_add_test_case hello_pie
3281.1Skamil	atf_add_test_case hello32
3291.3Skamil	atf_add_test_case hello_static
3301.3Skamil	atf_add_test_case hello_pic_32
3311.3Skamil	atf_add_test_case hello_pic_profile
3321.3Skamil	atf_add_test_case hello_pic_profile_32
3331.3Skamil	atf_add_test_case hello_profile_32
3341.1Skamil}
335