dpkg (1.18.25) stretch; urgency=medium
[dpkg] / scripts / t / Dpkg_Shlibs_Cppfilt.t
CommitLineData
1479465f
GJ
1#!/usr/bin/perl
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16use strict;
17use warnings;
18
19use Test::More;
20use Test::Dpkg qw(:needs);
21
22test_needs_command('c++filt');
23
24plan tests => 124;
25
26use_ok('Dpkg::Shlibs::Cppfilt');
27
28# Simple C++ demangling tests
29is ( cppfilt_demangle_cpp('_ZNSt10istrstreamC1EPKcl'),
30 'std::istrstream::istrstream(char const*, long)',
31 'demangle symbol' );
32is ( cppfilt_demangle_cpp('_ZNSt10istrstreamC1EPKcl@Base'),
33 'std::istrstream::istrstream(char const*, long)@Base',
34 'demangle symbol with extra postfix' );
35is ( cppfilt_demangle_cpp('foobar _ZNSt10istrstreamC1EPKcl@Base'),
36 'foobar std::istrstream::istrstream(char const*, long)@Base',
37 'demangle symbol with garbage around it' );
38is ( cppfilt_demangle_cpp('FoobarInvalidSymbol'), undef,
39 'non-demanglable string' );
40
41# Mass C++ demangling. Checking if c++filt does not hang and cppfilt_demangle()
42# immediately provides a correct answer to the caller (i.e. no buffering).
43my @mangledtext = split(/\n+/s, <<'END');
440000000000000000 DF *UND* 0000000000000000 GCC_3.0 _Unwind_SetIP
450000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 __towlower_l
460000000000000000 DO *UND* 0000000000000000 GLIBC_2.2.5 stdout
470000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 wmemset
480000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 fflush
490000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 getc
500000000000000000 w D *UND* 0000000000000000 pthread_join
5100000000000cfc22 g DO .rodata 0000000000000001 GLIBCXX_3.4 _ZNSt14numeric_limitsIyE17has_signaling_NaNE
520000000000088d80 w DF .text 0000000000000064 GLIBCXX_3.4 _ZNSt11__timepunctIcEC2Em
5300000000002f40a0 w DO .data.rel.ro 0000000000000020 GLIBCXX_3.4 _ZTTSt14basic_ifstreamIwSt11char_traitsIwEE
54000000000005a5f0 g DF .text 0000000000000063 GLIBCXX_3.4.11 _ZNVSt9__atomic011atomic_flag5clearESt12memory_order
5500000000000bdc20 w DF .text 0000000000000024 GLIBCXX_3.4 _ZNSbIwSt11char_traitsIwESaIwEEC1EPKwmRKS1_
560000000000063850 g DF .text 0000000000000062 GLIBCXX_3.4 _ZNSt5ctypeIwED2Ev
5700000000000898b0 w DF .text 0000000000000255 GLIBCXX_3.4 _ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_RSt8ios_basecPK2tmPKcSB_
58
5900000000000bff30 g DF .text 0000000000000019 _ZNSt18condition_variable10notify_oneEv@GLIBCXX_3.4.11
6000000000000666a0 g DF .text 000000000000003f _ZNKSt3tr14hashIRKSbIwSt11char_traitsIwESaIwEEEclES6_@GLIBCXX_3.4.10
6100000000002f6160 w DO .data.rel.ro 0000000000000050 _ZTTSt18basic_stringstreamIcSt11char_traitsIcESaIcEE@GLIBCXX_3.4
62END
63
64my @demangledtext = split(/\n+/s, <<'END');
650000000000000000 DF *UND* 0000000000000000 GCC_3.0 _Unwind_SetIP
660000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 __towlower_l
670000000000000000 DO *UND* 0000000000000000 GLIBC_2.2.5 stdout
680000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 wmemset
690000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 fflush
700000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 getc
710000000000000000 w D *UND* 0000000000000000 pthread_join
7200000000000cfc22 g DO .rodata 0000000000000001 GLIBCXX_3.4 std::numeric_limits<unsigned long long>::has_signaling_NaN
730000000000088d80 w DF .text 0000000000000064 GLIBCXX_3.4 std::__timepunct<char>::__timepunct(unsigned long)
7400000000002f40a0 w DO .data.rel.ro 0000000000000020 GLIBCXX_3.4 VTT for std::basic_ifstream<wchar_t, std::char_traits<wchar_t> >
75000000000005a5f0 g DF .text 0000000000000063 GLIBCXX_3.4.11 std::__atomic0::atomic_flag::clear(std::memory_order) volatile
7600000000000bdc20 w DF .text 0000000000000024 GLIBCXX_3.4 std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::basic_string(wchar_t const*, unsigned long, std::allocator<wchar_t> const&)
770000000000063850 g DF .text 0000000000000062 GLIBCXX_3.4 std::ctype<wchar_t>::~ctype()
7800000000000898b0 w DF .text 0000000000000255 GLIBCXX_3.4 std::time_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, tm const*, char const*, char const*) const
79
8000000000000bff30 g DF .text 0000000000000019 std::condition_variable::notify_one()@GLIBCXX_3.4.11
8100000000000666a0 g DF .text 000000000000003f std::tr1::hash<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&>::operator()(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) const@GLIBCXX_3.4.10
8200000000002f6160 w DO .data.rel.ro 0000000000000050 VTT for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4
83END
84
85for my $try (1 .. 7) {
86 for my $i (0 .. $#mangledtext) {
87 my $demangled = cppfilt_demangle_cpp($mangledtext[$i]) || $mangledtext[$i];
88 is($demangled, $demangledtext[$i], "mass c++ demangling (${try}x" . (${i} + 1) . ')');
89 }
90}