1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-07-19 23:37:12 +02:00
Files
bin
cmake
module
Base
Core
Entity
Library
Misc
Vendor
AES256
B64
Hash
MDBC
MaxmindDB
bin
cmake
dev-bin
doc
include
projects
src
t
Makefile.am
bad_databases_t.c
bad_pointers_t.c
basic_lookup_t.c
compile_c++_t.pl
data-pool-t.c
data_entry_list_t.c
data_types_t.c
dump_t.c
external_symbols_t.pl
get_value_pointer_bug_t.c
get_value_t.c
ipv4_start_cache_t.c
ipv6_lookup_in_ipv4_t.c
maxminddb_test_helper.c
maxminddb_test_helper.h
metadata_pointers_t.c
metadata_t.c
mmdblookup_t.pl
no_map_get_value_t.c
read_node_t.c
threads_t.c
version_t.c
AUTHORS
CMakeLists.txt
Changes.md
LICENSE
Makefile.am
NOTICE
README.dev.md
README.md
appveyor.yml
bootstrap
common.mk
configure.ac
PUGIXML
SQLite
SimpleIni
SimpleSocket
TinyDir
Whirlpool
CMakeLists.txt
CMakeLists.txt
Core.cpp
Core.hpp
Logger.cpp
Logger.hpp
Main.cpp
Register.cpp
SqBase.hpp
sdk
.gitignore
.gitmodules
CMakeLists.txt
LICENSE
README.md
SqMod/module/Vendor/MaxmindDB/t/external_symbols_t.pl
2020-03-22 16:33:48 +02:00

107 lines
2.2 KiB
Perl

#!/usr/bin/env perl
use strict;
use warnings;
use FindBin qw( $Bin );
_skip_tests_if_required_modules_are_not_present();
_skip_tests_if_nm_is_not_present();
_test_libs_external_symbols();
done_testing();
sub _skip_tests_if_required_modules_are_not_present {
eval <<'EOF';
use Test::More 0.88;
use IPC::Run3 qw( run3 );
EOF
if ($@) {
print
"1..0 # skip all tests skipped - these tests need the Test::More 0.88, IPC::Run3 modules:\n";
print "$@";
exit 0;
}
}
sub _skip_tests_if_nm_is_not_present {
run3(
[ 'nm', '-V' ],
\undef,
\undef,
\undef,
);
my $exit_status = $? >> 8;
if ($exit_status) {
print
"1..0 # skipp all tests skipped - this test requires the command line utility `nm`.\n";
exit 0;
}
}
sub _test_libs_external_symbols {
my @libs = _libs_to_test();
if (@libs) {
for my $lib (@libs) {
_test_lib_external_symbols($lib);
}
}
else {
fail('No libs were found to test');
}
}
sub _libs_to_test {
my $lib_dir = "$Bin/../src/.libs";
opendir my $dh, $lib_dir
or die "Failed to open the lib dir at $lib_dir for reading: $!\n";
my @libs = map { $lib_dir . q{/} . $_ }
grep { $_ =~ m/\.so$/ } readdir $dh;
closedir $dh;
return @libs;
}
sub _test_lib_external_symbols {
my $lib = shift;
my $stdout;
my $stderr;
run3(
[ 'nm', '-g', '--defined-only', $lib ],
\undef,
\$stdout,
\$stderr,
);
my $exit_status = $? >> 8;
ok( !$exit_status, 'nm returned a non-error status' )
or diag($stderr);
my @external_symbols = _extract_external_symbols($stdout);
is_deeply(
[ grep { $_ !~ m/^MMDB_/ } @external_symbols ],
[],
"$lib exports only MMDB_ symbols"
);
}
sub _extract_external_symbols {
my $nm_output = shift;
my @lines = split /\r\n|\r|\n/, $nm_output;
my @external_symbols;
for my $line (@lines) {
my @fields = split /\s+/, $line;
die "Unexpected nm output for line $line\n"
if @fields != 3;
push @external_symbols, $fields[2];
}
return @external_symbols;
}