1#!/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# Copyright 2012, Richard Lowe.
14
15function grep_test {
16    name=$1
17    pattern=$2
18
19    if /usr/bin/grep -q "${pattern}"; then
20	print -u2 "pass: $name"
21        else
22        print -u2 "FAIL: $name"
23        exit 1
24    fi
25}
26
27function dis_test {
28    name=${1}
29    func=${2}
30    file=${3}
31    pattern=${4}
32
33    dis -F${func} ${file} | grep_test "${name}" "${pattern}"
34}
35
36TESTDIR=$(dirname $0)
37
38make -f ${TESTDIR}/Makefile.test TESTDIR=${TESTDIR}
39
40# if we fail, the addend won't be applied, the leaq with be -0x10(%rax)
41dis_test "addend is preserved" main ld-with-addend \
42    'main+0x10: 48 8d b0 f2 ff ff  leaq   -0xe(%rax),%rsi'
43
44# We have an addend of 2, a failure will print 'incorrect'
45./ld-with-addend | grep_test 'ld-with-addend execution' \
46    '^foo: correct ([a-f0-9]*)$'
47