1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26# ident	"%Z%%M%	%I%	%E% SMI"
27
28#
29# This test verifies that we can generate the correct ordering for
30# a given dependency specification. All files either have a dependency
31# on another file or are the dependent of another file. In this way we
32# guarantee consistent ordering as no nodes in the dependency graph will
33# be isolated.
34#
35
36if [ $# != 1 ]; then
37	echo expected one argument: '<'dtrace-path'>'
38	exit 2
39fi
40
41tmpfile=/tmp/libdeporder.$$
42libdir=${TMPDIR:-/tmp}/libdep.$$
43dtrace=$1
44
45setup_libs()
46{
47	mkdir $libdir
48	cat > $libdir/liba.$$.d <<EOF
49#pragma D depends_on library libd.$$.d
50EOF
51	cat > $libdir/libb.$$.d <<EOF
52EOF
53	cat > $libdir/libc.$$.d <<EOF
54#pragma D depends_on library libe.$$.d
55EOF
56	cat > $libdir/libd.$$.d <<EOF
57#pragma D depends_on library libb.$$.d
58EOF
59	cat > $libdir/libe.$$.d <<EOF
60#pragma D depends_on library liba.$$.d
61EOF
62}
63
64
65setup_libs
66
67DTRACE_DEBUG=1 $dtrace -L$libdir -e >$tmpfile 2>&1
68
69perl /dev/stdin $tmpfile <<EOF
70
71	@order = qw(libc libe liba libd libb);
72
73	while (<>) {
74		if (\$_ =~ /lib[a-e]\.[0-9]+.d/) {
75			\$pos = length \$_;
76			for (\$i=0; \$i<=1;\$i++) {
77				\$pos = rindex(\$_, "/", \$pos);
78				\$pos--;
79			}
80
81			push(@new, substr(\$_, \$pos+2, 4));
82			next;
83		}
84		next;
85	}
86
87	exit 1 if @new != @order;
88
89	while (@new) {
90		exit 1 if pop(@new) ne pop(@order);
91	}
92
93	exit 0;
94EOF
95
96
97status=$?
98rm -rf $libdir
99rm $tmpfile
100return $status
101