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