diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/data/Makefile.am | 2 | ||||
-rw-r--r-- | tests/data/test1132 | 24 | ||||
-rw-r--r-- | tests/mem-include-scan.pl | 96 |
4 files changed, 122 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index c655ba239..42f89dcea 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -28,7 +28,7 @@ EXTRA_DIST = ftpserver.pl httpserver.pl secureserver.pl runtests.pl getpart.pm \ sshserver.pl sshhelp.pm testcurl.1 runtests.1 $(HTMLPAGES) $(PDFPAGES) \ CMakeLists.txt certs/scripts/*.sh certs/Server* certs/EdelCurlRoot* \ serverhelp.pm tftpserver.pl rtspserver.pl directories.pm symbol-scan.pl \ - certs/srp-verifier-conf certs/srp-verifier-db + certs/srp-verifier-conf certs/srp-verifier-db mem-include-scan.pl # we have two variables here to make sure DIST_SUBDIRS won't get 'unit' # added twice as then targets such as 'distclean' misbehave and try to diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 31b56f417..9210404a5 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -75,7 +75,7 @@ test1094 test1095 test1096 test1097 test1098 test1099 test1100 test1101 \ test1102 test1103 test1104 test1105 test1106 test1107 test1108 test1109 \ test1110 test1111 test1112 test1113 test1114 test1115 test1116 test1117 \ test1118 test1119 test1120 test1121 test1122 test1123 test1124 test1125 \ -test1126 test1127 test1128 test1129 test1130 test1131 \ +test1126 test1127 test1128 test1129 test1130 test1131 test1132 \ test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 \ test1208 test1209 test1210 test1211 \ test1220 \ diff --git a/tests/data/test1132 b/tests/data/test1132 new file mode 100644 index 000000000..366ffc77c --- /dev/null +++ b/tests/data/test1132 @@ -0,0 +1,24 @@ +<testcase> +<info> +<keywords> +memory-includes +</keywords> +</info> + +# +# Client-side +<client> +<server> +none +</server> + + <name> +Verify memory #include files in libcurl's C source files + </name> + +<command type="perl"> +%SRCDIR/mem-include-scan.pl %SRCDIR/../lib +</command> +</client> + +</testcase> diff --git a/tests/mem-include-scan.pl b/tests/mem-include-scan.pl new file mode 100644 index 000000000..676df25e9 --- /dev/null +++ b/tests/mem-include-scan.pl @@ -0,0 +1,96 @@ +#!/usr/bin/env perl +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# Copyright (C) 2010-2012, Daniel Stenberg, <daniel@haxx.se>, et al. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at http://curl.haxx.se/docs/copyright.html. +# +# You may opt to use, copy, modify, merge, publish, distribute and/or sell +# copies of the Software, and permit persons to whom the Software is +# furnished to do so, under the terms of the COPYING file. +# +# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +# KIND, either express or implied. +# +########################################################################### +# +# This script scans C source files. If they seem to use memory functions, +# it also makes sure that it #includes the correct two header files! +# +# You can also mark a C source as fine by using 'mem-include-scan' anywhere in +# it. +# + +use strict; +use warnings; + +my $dir = $ARGV[0] || die "specify directory!"; + +sub scanfile { + my ($file) = @_; + my $memfunc; + my $memdebug; + my $curlmem; + + print STDERR "checking $file...\n"; + + open(F, "<$file"); + while(<F>) { + if($_ =~ /(free|alloc|strdup)\(/) { + $memfunc++; + } + elsif($_ =~ /^ *# *include \"memdebug.h\"/) { + $memdebug++; + } + elsif($_ =~ /^ *# *include \"curl_memory.h\"/) { + $curlmem++; + } + elsif($_ =~ /mem-include-scan/) { + # free pass + close(F); + return 0; + } + if($memfunc && $memdebug && $curlmem) { + last; + } + } + close(F); + + + if($memfunc) { + if($memdebug && $curlmem) { + return 0; + } + else { + if(!$memdebug) { + print STDERR "$file doesn't include \"memdebug.h\"!\n"; + } + if(!$curlmem) { + print STDERR "$file doesn't include \"curl_memory.h\"!\n"; + } + return 1; + } + } + return 0; +} + +opendir(my $dh, $dir) || die "can't opendir $dir: $!"; +my @cfiles = grep { /\.c\z/ && -f "$dir/$_" } readdir($dh); +closedir $dh; + +my $errs; +for(@cfiles) { + $errs += scanfile("$dir/$_"); +} + +if($errs) { + print STDERR "----\n$errs errors detected!\n"; + exit 2; +} |