11581ec9aSEric van Gyzen#!/usr/libexec/atf-sh 21581ec9aSEric van Gyzen# 31581ec9aSEric van Gyzen# SPDX-License-Identifier: BSD-2-Clause 41581ec9aSEric van Gyzen# 51581ec9aSEric van Gyzen# Copyright (c) 2022 Eric van Gyzen 61581ec9aSEric van Gyzen# 71581ec9aSEric van Gyzen# Redistribution and use in source and binary forms, with or without 81581ec9aSEric van Gyzen# modification, are permitted provided that the following conditions 91581ec9aSEric van Gyzen# are met: 101581ec9aSEric van Gyzen# 1. Redistributions of source code must retain the above copyright 111581ec9aSEric van Gyzen# notice, this list of conditions and the following disclaimer. 121581ec9aSEric van Gyzen# 2. Redistributions in binary form must reproduce the above copyright 131581ec9aSEric van Gyzen# notice, this list of conditions and the following disclaimer in the 141581ec9aSEric van Gyzen# documentation and/or other materials provided with the distribution. 151581ec9aSEric van Gyzen# 161581ec9aSEric van Gyzen# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 171581ec9aSEric van Gyzen# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 181581ec9aSEric van Gyzen# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 191581ec9aSEric van Gyzen# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 201581ec9aSEric van Gyzen# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 211581ec9aSEric van Gyzen# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 221581ec9aSEric van Gyzen# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 231581ec9aSEric van Gyzen# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 241581ec9aSEric van Gyzen# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 251581ec9aSEric van Gyzen# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261581ec9aSEric van Gyzen# SUCH DAMAGE. 271581ec9aSEric van Gyzen 281581ec9aSEric van Gyzenatf_test_case contrib_file_tests cleanup 291581ec9aSEric van Gyzencontrib_file_tests_body() { 301581ec9aSEric van Gyzen srcdir="$(atf_get_srcdir)" 311581ec9aSEric van Gyzen 321581ec9aSEric van Gyzen for testfile in "${srcdir}"/*.testfile; do 331581ec9aSEric van Gyzen test_name="${testfile%.testfile}" 341581ec9aSEric van Gyzen result_file="${test_name}.result" 351581ec9aSEric van Gyzen file_args= 36*8f75390cSXin LI magic_files= 37*8f75390cSXin LI for magic_file in ${test_name}*.magic; do 38*8f75390cSXin LI if [ -f "${magic_file}" ]; then 39*8f75390cSXin LI if [ -z "${magic_files}" ]; then 40*8f75390cSXin LI magic_files="${magic_file}" 41*8f75390cSXin LI else 42*8f75390cSXin LI magic_files="${magic_files}:${magic_file}" 43*8f75390cSXin LI fi 44*8f75390cSXin LI fi 45*8f75390cSXin LI done 46*8f75390cSXin LI if [ -z "${magic_files}" ]; then 47*8f75390cSXin LI magic_files=/usr/share/misc/magic 48*8f75390cSXin LI fi 49*8f75390cSXin LI if [ -f "${test_name}.flags" ]; then 50*8f75390cSXin LI file_args="${file_args} -$(cat "${test_name}.flags")" 511581ec9aSEric van Gyzen fi 521581ec9aSEric van Gyzen # The result files were created in UTC. 53*8f75390cSXin LI atf_check -o save:actual_output -e ignore env TZ=Z MAGIC="${magic_files}" \ 54*8f75390cSXin LI file ${file_args} --brief "$testfile" 550d3a8756SJose Luis Duran atf_check cmp actual_output "$result_file" 561581ec9aSEric van Gyzen done 571581ec9aSEric van Gyzen} 581581ec9aSEric van Gyzen 591581ec9aSEric van Gyzencontrib_file_tests_cleanup() { 601581ec9aSEric van Gyzen rm -f actual_output trimmed_output 611581ec9aSEric van Gyzen} 621581ec9aSEric van Gyzen 631581ec9aSEric van Gyzenatf_init_test_cases() { 641581ec9aSEric van Gyzen atf_add_test_case contrib_file_tests 651581ec9aSEric van Gyzen} 66