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