1272343Sngie# $NetBSD: t_crt0.sh,v 1.4 2011/12/11 14:57:07 joerg Exp $
2272343Sngie#
3272343Sngie# Copyright (c) 2008 The NetBSD Foundation, Inc.
4272343Sngie# All rights reserved.
5272343Sngie#
6272343Sngie# Redistribution and use in source and binary forms, with or without
7272343Sngie# modification, are permitted provided that the following conditions
8272343Sngie# are met:
9272343Sngie# 1. Redistributions of source code must retain the above copyright
10272343Sngie#    notice, this list of conditions and the following disclaimer.
11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright
12272343Sngie#    notice, this list of conditions and the following disclaimer in the
13272343Sngie#    documentation and/or other materials provided with the distribution.
14272343Sngie#
15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18272343Sngie# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25272343Sngie# POSSIBILITY OF SUCH DAMAGE.
26272343Sngie#
27272343Sngie
28272343Sngieatf_test_case initfini1
29272343Sngieinitfini1_head()
30272343Sngie{
31272343Sngie	atf_set "descr" "Checks support for init/fini sections"
32272343Sngie}
33272343Sngieinitfini1_body()
34272343Sngie{
35272343Sngie	cat >expout <<EOF
36272343Sngieconstructor executed
37272343Sngiemain executed
38272343Sngiedestructor executed
39272343SngieEOF
40272343Sngie
41272343Sngie	atf_check -o file:expout "$(atf_get_srcdir)/h_initfini1"
42272343Sngie}
43272343Sngie
44272343Sngieatf_test_case initfini2
45272343Sngieinitfini2_head()
46272343Sngie{
47272343Sngie	atf_set "descr" "Checks support for init/fini sections in static binaries"
48272343Sngie}
49272343Sngieinitfini2_body()
50272343Sngie{
51272343Sngie	cat >expout <<EOF
52272343Sngieconstructor executed
53272343Sngiemain executed
54272343Sngiedestructor executed
55272343SngieEOF
56272343Sngie
57272343Sngie	atf_check -o file:expout "$(atf_get_srcdir)/h_initfini2"
58272343Sngie}
59272343Sngie
60272343Sngieatf_test_case initfini3
61272343Sngieinitfini3_head()
62272343Sngie{
63272343Sngie	atf_set "descr" "Checks support for init/fini sections in dlopen"
64272343Sngie}
65272343Sngieinitfini3_body()
66272343Sngie{
67272343Sngie	cat >expout <<EOF
68272343Sngieconstructor executed
69272343Sngiemain started
70272343Sngieconstructor2 executed
71272343Sngiemain after dlopen
72272343Sngiedestructor2 executed
73272343Sngiemain terminated
74272343Sngiedestructor executed
75272343SngieEOF
76272343Sngie
77272343Sngie	atf_check -o file:expout "$(atf_get_srcdir)/h_initfini3"
78272343Sngie}
79272343Sngie
80272343Sngieatf_test_case initfini4
81272343Sngieinitfini4_head()
82272343Sngie{
83272343Sngie	atf_set "descr" "Checks support for init/fini sections in LD_PRELOAD"
84272343Sngie}
85272343Sngieinitfini4_body()
86272343Sngie{
87272343Sngie	cat >expout <<EOF
88272343Sngieconstructor2 executed
89272343Sngieconstructor executed
90272343Sngiemain executed
91272343Sngiedestructor executed
92272343Sngiedestructor2 executed
93272343SngieEOF
94272343Sngie
95272343Sngie	atf_check -o file:expout -x "env LD_PRELOAD=$(atf_get_srcdir)/h_initfini3_dso.so $(atf_get_srcdir)/h_initfini1"
96272343Sngie}
97272343Sngie
98272343Sngieatf_init_test_cases()
99272343Sngie{
100272343Sngie	atf_add_test_case initfini1
101272343Sngie	atf_add_test_case initfini2
102272343Sngie	atf_add_test_case initfini3
103272343Sngie	atf_add_test_case initfini4
104272343Sngie}
105