xref: /freebsd/contrib/netbsd-tests/share/examples/t_asm.sh (revision 9268022b74279434ed6300244e3f977e56a8ceb5)
1*57718be8SEnji Cooper# $NetBSD: t_asm.sh,v 1.1 2013/02/16 12:44:26 jmmv Exp $
2*57718be8SEnji Cooper#
3*57718be8SEnji Cooper# Copyright (c) 2011 The NetBSD Foundation, Inc.
4*57718be8SEnji Cooper# All rights reserved.
5*57718be8SEnji Cooper#
6*57718be8SEnji Cooper# Redistribution and use in source and binary forms, with or without
7*57718be8SEnji Cooper# modification, are permitted provided that the following conditions are
8*57718be8SEnji Cooper# met:
9*57718be8SEnji Cooper#
10*57718be8SEnji Cooper# 1. Redistributions of source code must retain the above copyright
11*57718be8SEnji Cooper#    notice, this list of conditions and the following disclaimer.
12*57718be8SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright
13*57718be8SEnji Cooper#    notice, this list of conditions and the following disclaimer in the
14*57718be8SEnji Cooper#    documentation and/or other materials provided with the distribution.
15*57718be8SEnji Cooper#
16*57718be8SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17*57718be8SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18*57718be8SEnji Cooper# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19*57718be8SEnji Cooper# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
20*57718be8SEnji Cooper# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21*57718be8SEnji Cooper# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22*57718be8SEnji Cooper# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23*57718be8SEnji Cooper# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24*57718be8SEnji Cooper# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25*57718be8SEnji Cooper# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26*57718be8SEnji Cooper# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*57718be8SEnji Cooper#
28*57718be8SEnji Cooper
29*57718be8SEnji Cooper# check_implemented <example_name>
30*57718be8SEnji Cooper#
31*57718be8SEnji Cooper# Verifies if a particular asm example is implemented for the current
32*57718be8SEnji Cooper# platform.  The example_name argument is the name of the subdirectory
33*57718be8SEnji Cooper# of the examples/asm/ subtree that includes the code for the example
34*57718be8SEnji Cooper# under test.
35*57718be8SEnji Cooper#
36*57718be8SEnji Cooper# If the example is not implemented, the calling test is skipped.  If the
37*57718be8SEnji Cooper# check for implementation fails, the calling test is failed.
38*57718be8SEnji Coopercheck_implemented() {
39*57718be8SEnji Cooper	local name="${1}"; shift
40*57718be8SEnji Cooper
41*57718be8SEnji Cooper	local implemented=$(cd /usr/share/examples/asm/${name}/ && \
42*57718be8SEnji Cooper	                    make check-implemented)
43*57718be8SEnji Cooper	[ $? -eq 0 ] || atf_fail "Failed to determine if the sample" \
44*57718be8SEnji Cooper	    "program is supported"
45*57718be8SEnji Cooper	[ "${implemented}" = yes ] || atf_skip "Example program not" \
46*57718be8SEnji Cooper	    "implemented on this platform"
47*57718be8SEnji Cooper}
48*57718be8SEnji Cooper
49*57718be8SEnji Cooper# copy_example <example_name>
50*57718be8SEnji Cooper#
51*57718be8SEnji Cooper# Copies the example code and supporting Makefiles into the current
52*57718be8SEnji Cooper# directory.
53*57718be8SEnji Coopercopy_example() {
54*57718be8SEnji Cooper	local name="${1}"; shift
55*57718be8SEnji Cooper
56*57718be8SEnji Cooper	cp /usr/share/examples/asm/${name}/* .
57*57718be8SEnji Cooper}
58*57718be8SEnji Cooper
59*57718be8SEnji Cooperatf_test_case hello
60*57718be8SEnji Cooperhello_head() {
61*57718be8SEnji Cooper	atf_set "descr" "Builds, runs and validates the 'hello' asm example"
62*57718be8SEnji Cooper	atf_set "require.files" "/usr/share/examples/asm/hello/"
63*57718be8SEnji Cooper	atf_set "require.progs" "make"
64*57718be8SEnji Cooper}
65*57718be8SEnji Cooperhello_body() {
66*57718be8SEnji Cooper	check_implemented hello
67*57718be8SEnji Cooper	copy_example hello
68*57718be8SEnji Cooper	atf_check -s exit:0 -o ignore -e ignore make
69*57718be8SEnji Cooper	atf_check -s exit:0 -o inline:'Hello, world!\n' -e empty ./hello
70*57718be8SEnji Cooper}
71*57718be8SEnji Cooper
72*57718be8SEnji Cooperatf_init_test_cases() {
73*57718be8SEnji Cooper	atf_add_test_case hello
74*57718be8SEnji Cooper}
75