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