|
| 1 | +############################################################################## |
| 2 | +# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC. |
| 3 | +# Produced at the Lawrence Livermore National Laboratory. |
| 4 | +# |
| 5 | +# This file is part of Spack. |
| 6 | +# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. |
| 7 | +# LLNL-CODE-647188 |
| 8 | +# |
| 9 | +# For details, see https://github.com/llnl/spack |
| 10 | +# Please also see the LICENSE file for our notice and the LGPL. |
| 11 | +# |
| 12 | +# This program is free software; you can redistribute it and/or modify |
| 13 | +# it under the terms of the GNU Lesser General Public License (as |
| 14 | +# published by the Free Software Foundation) version 2.1, February 1999. |
| 15 | +# |
| 16 | +# This program is distributed in the hope that it will be useful, but |
| 17 | +# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF |
| 18 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and |
| 19 | +# conditions of the GNU Lesser General Public License for more details. |
| 20 | +# |
| 21 | +# You should have received a copy of the GNU Lesser General Public |
| 22 | +# License along with this program; if not, write to the Free Software |
| 23 | +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | +############################################################################## |
| 25 | +from StringIO import StringIO |
| 26 | + |
| 27 | +from spack.spec import Spec |
| 28 | +from spack.graph import AsciiGraph, topological_sort, graph_dot |
| 29 | + |
| 30 | + |
| 31 | +def test_topo_sort(builtin_mock): |
| 32 | + """Test topo sort gives correct order.""" |
| 33 | + s = Spec('mpileaks').normalized() |
| 34 | + |
| 35 | + topo = topological_sort(s) |
| 36 | + |
| 37 | + assert topo.index('mpileaks') < topo.index('callpath') |
| 38 | + assert topo.index('mpileaks') < topo.index('mpi') |
| 39 | + assert topo.index('mpileaks') < topo.index('dyninst') |
| 40 | + assert topo.index('mpileaks') < topo.index('libdwarf') |
| 41 | + assert topo.index('mpileaks') < topo.index('libelf') |
| 42 | + |
| 43 | + assert topo.index('callpath') < topo.index('mpi') |
| 44 | + assert topo.index('callpath') < topo.index('dyninst') |
| 45 | + assert topo.index('callpath') < topo.index('libdwarf') |
| 46 | + assert topo.index('callpath') < topo.index('libelf') |
| 47 | + |
| 48 | + assert topo.index('dyninst') < topo.index('libdwarf') |
| 49 | + assert topo.index('dyninst') < topo.index('libelf') |
| 50 | + |
| 51 | + assert topo.index('libdwarf') < topo.index('libelf') |
| 52 | + |
| 53 | + |
| 54 | +def test_static_graph_mpileaks(builtin_mock): |
| 55 | + """Test a static spack graph for a simple package.""" |
| 56 | + s = Spec('mpileaks').normalized() |
| 57 | + |
| 58 | + stream = StringIO() |
| 59 | + graph_dot([s], static=True, out=stream) |
| 60 | + |
| 61 | + dot = stream.getvalue() |
| 62 | + |
| 63 | + assert ' "mpileaks" [label="mpileaks"]\n' in dot |
| 64 | + assert ' "dyninst" [label="dyninst"]\n' in dot |
| 65 | + assert ' "callpath" [label="callpath"]\n' in dot |
| 66 | + assert ' "libelf" [label="libelf"]\n' in dot |
| 67 | + assert ' "libdwarf" [label="libdwarf"]\n' in dot |
| 68 | + |
| 69 | + assert ' "dyninst" -> "libdwarf"\n' in dot |
| 70 | + assert ' "callpath" -> "dyninst"\n' in dot |
| 71 | + assert ' "mpileaks" -> "mpi"\n' in dot |
| 72 | + assert ' "libdwarf" -> "libelf"\n' in dot |
| 73 | + assert ' "callpath" -> "mpi"\n' in dot |
| 74 | + assert ' "mpileaks" -> "callpath"\n' in dot |
| 75 | + assert ' "dyninst" -> "libelf"\n' in dot |
| 76 | + |
| 77 | + |
| 78 | +def test_dynamic_dot_graph_mpileaks(builtin_mock): |
| 79 | + """Test dynamically graphing the mpileaks package.""" |
| 80 | + s = Spec('mpileaks').normalized() |
| 81 | + |
| 82 | + stream = StringIO() |
| 83 | + graph_dot([s], static=False, out=stream) |
| 84 | + |
| 85 | + dot = stream.getvalue() |
| 86 | + |
| 87 | + mpileaks_hash, mpileaks_lbl = s.dag_hash(), s.format('$_$#') |
| 88 | + mpi_hash, mpi_lbl = s['mpi'].dag_hash(), s['mpi'].format('$_$#') |
| 89 | + callpath_hash, callpath_lbl = ( |
| 90 | + s['callpath'].dag_hash(), s['callpath'].format('$_$#')) |
| 91 | + dyninst_hash, dyninst_lbl = ( |
| 92 | + s['dyninst'].dag_hash(), s['dyninst'].format('$_$#')) |
| 93 | + libdwarf_hash, libdwarf_lbl = ( |
| 94 | + s['libdwarf'].dag_hash(), s['libdwarf'].format('$_$#')) |
| 95 | + libelf_hash, libelf_lbl = ( |
| 96 | + s['libelf'].dag_hash(), s['libelf'].format('$_$#')) |
| 97 | + |
| 98 | + assert ' "%s" [label="%s"]\n' % (mpileaks_hash, mpileaks_lbl) in dot |
| 99 | + assert ' "%s" [label="%s"]\n' % (callpath_hash, callpath_lbl) in dot |
| 100 | + assert ' "%s" [label="%s"]\n' % (mpi_hash, mpi_lbl) in dot |
| 101 | + assert ' "%s" [label="%s"]\n' % (dyninst_hash, dyninst_lbl) in dot |
| 102 | + assert ' "%s" [label="%s"]\n' % (libdwarf_hash, libdwarf_lbl) in dot |
| 103 | + assert ' "%s" [label="%s"]\n' % (libelf_hash, libelf_lbl) in dot |
| 104 | + |
| 105 | + assert ' "%s" -> "%s"\n' % (dyninst_hash, libdwarf_hash) in dot |
| 106 | + assert ' "%s" -> "%s"\n' % (callpath_hash, dyninst_hash) in dot |
| 107 | + assert ' "%s" -> "%s"\n' % (mpileaks_hash, mpi_hash) in dot |
| 108 | + assert ' "%s" -> "%s"\n' % (libdwarf_hash, libelf_hash) in dot |
| 109 | + assert ' "%s" -> "%s"\n' % (callpath_hash, mpi_hash) in dot |
| 110 | + assert ' "%s" -> "%s"\n' % (mpileaks_hash, callpath_hash) in dot |
| 111 | + assert ' "%s" -> "%s"\n' % (dyninst_hash, libelf_hash) in dot |
| 112 | + |
| 113 | + |
| 114 | +def test_ascii_graph_mpileaks(builtin_mock): |
| 115 | + """Test dynamically graphing the mpileaks package.""" |
| 116 | + s = Spec('mpileaks').normalized() |
| 117 | + |
| 118 | + stream = StringIO() |
| 119 | + graph = AsciiGraph() |
| 120 | + graph.write(s, out=stream, color=False) |
| 121 | + string = stream.getvalue() |
| 122 | + |
| 123 | + # Some lines in spack graph still have trailing space |
| 124 | + # TODO: fix this. |
| 125 | + string = '\n'.join([line.rstrip() for line in string.split('\n')]) |
| 126 | + |
| 127 | + assert string == r'''o mpileaks |
| 128 | +|\ |
| 129 | +| o callpath |
| 130 | +|/| |
| 131 | +o | mpi |
| 132 | + / |
| 133 | +o dyninst |
| 134 | +|\ |
| 135 | +| o libdwarf |
| 136 | +|/ |
| 137 | +o libelf |
| 138 | +''' |
0 commit comments