xref: /illumos-gate/usr/src/test/libc-tests/tests/aligned_alloc.ksh (revision 3448eae2e9d99e7fadeb43056eb8e788c7ea93be)
1#! /usr/bin/ksh
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright 2024 Oxide Computer Company
15#
16
17#
18# Wrap up the aligned_alloc() tests with the different malloc libraries
19# that make sense to test as this calls into their implementation of
20# memalign. Currently we test libc, libumem, and libmtmalloc. mapmalloc
21# is skipped because it doesn't implement memalign. libmtmalloc
22# currently doesn't have an ENOMEM/EAGAIN test strategy.
23#
24
25unalias -a
26set -o pipefail
27export LANG=C.UTF-8
28
29alloc_arg0="$(basename $0)"
30alloc_dir="$(dirname $0)"
31alloc_exit=0
32alloc_file="aligned_alloc"
33alloc_libraries="none
34libumem.so
35libmtmalloc.so"
36alloc_archs="32
3764"
38
39function warn
40{
41	typeset msg="$*"
42	echo "TEST FAILED: $msg" >&2
43	alloc_exit=1
44}
45
46function run_one
47{
48	typeset preload="$1"
49	typeset suffix="$2"
50
51	if [[ "$1" != none ]]; then
52		export LD_PRELOAD=$preload
53	fi
54
55	printf "Running %u-bit tests with library %s\n" $suffix "$preload"
56
57	if ! $alloc_dir/$alloc_file.$suffix; then
58		alloc_exit=1
59	fi
60
61	unset LD_PRELOAD
62}
63
64for lib in ${alloc_libraries[@]}; do
65	for arch in ${alloc_archs[@]}; do
66		run_one "$lib" "$arch"
67	done
68done
69
70if ((alloc_exit != 0)); then
71	printf "Some library/architecture variants failed!\n" >&2
72fi
73
74exit $alloc_exit
75