| 1 |
#!/usr/bin/perl |
| 2 |
############################################################ |
| 3 |
# this perl script is meant for developers only! |
| 4 |
# it will run all spec-tests (without verifying the |
| 5 |
# results) via valgrind to detect possible leaks. |
| 6 |
# expect that it takes 1h or more to finish! |
| 7 |
############################################################ |
| 8 |
# Prerequisite install: `cpan Parallel::Runner` |
| 9 |
# You may also need to install `cpan File::Find` |
| 10 |
# You may also need to install `cpan IPC::Run3` |
| 11 |
############################################################ |
| 12 |
# usage: `perl test-leaks.pl [threads]` |
| 13 |
# example: `time perl test-leaks.pl 4` |
| 14 |
############################################################ |
| 15 |
# leaks will be reported in "mem-leaks.log" |
| 16 |
############################################################ |
| 17 |
|
| 18 |
use strict; |
| 19 |
use warnings; |
| 20 |
|
| 21 |
############################################################ |
| 22 |
# configurations (you may adjust) |
| 23 |
############################################################ |
| 24 |
|
| 25 |
# number of threads to use |
| 26 |
my $threads = $ARGV[0] || 8; |
| 27 |
|
| 28 |
# the github repositories to checkout |
| 29 |
# if you need other branch, clone manually! |
| 30 |
my $sassc = "https://www.github.com/sass/sassc"; |
| 31 |
my $specs = "https://www.github.com/sass/sass-spec"; |
| 32 |
|
| 33 |
############################################################ |
| 34 |
# load modules |
| 35 |
############################################################ |
| 36 |
|
| 37 |
use IPC::Run3; |
| 38 |
use IO::Handle; |
| 39 |
use Fcntl qw(:flock); |
| 40 |
use File::Find::Rule; |
| 41 |
use Parallel::Runner; |
| 42 |
use List::Util qw(shuffle); |
| 43 |
|
| 44 |
############################################################ |
| 45 |
# check prerequisites |
| 46 |
############################################################ |
| 47 |
|
| 48 |
unless (-d "../sassc") { |
| 49 |
warn "sassc folder not found\n"; |
| 50 |
warn "trying to checkout via git\n"; |
| 51 |
system("git", "clone", $sassc, "../sassc"); |
| 52 |
die "git command did not exit gracefully" if $?; |
| 53 |
} |
| 54 |
|
| 55 |
unless (-d "../sass-spec") { |
| 56 |
warn "sass-spec folder not found\n"; |
| 57 |
warn "trying to checkout via git\n"; |
| 58 |
system("git", "clone", $specs, "../sass-spec"); |
| 59 |
die "git command did not exit gracefully" if $?; |
| 60 |
} |
| 61 |
|
| 62 |
unless (-f "../sassc/bin/sassc") { |
| 63 |
warn "sassc executable not found\n"; |
| 64 |
warn "trying to compile via make\n"; |
| 65 |
system("make", "-C", "../sassc", "-j", $threads); |
| 66 |
die "make command did not exit gracefully" if $?; |
| 67 |
} |
| 68 |
|
| 69 |
############################################################ |
| 70 |
# main runner code |
| 71 |
############################################################ |
| 72 |
|
| 73 |
my $root = "../sass-spec/spec"; |
| 74 |
my @files = File::Find::Rule->file() |
| 75 |
->name('input.scss')->in($root); |
| 76 |
|
| 77 |
open(my $leaks, ">", "mem-leaks.log"); |
| 78 |
die "Cannot open log" unless $leaks; |
| 79 |
my $runner = Parallel::Runner->new($threads); |
| 80 |
die "Cannot start runner" unless $runner; |
| 81 |
|
| 82 |
print "##########################\n"; |
| 83 |
print "Testing $#files spec files\n"; |
| 84 |
print "##########################\n"; |
| 85 |
|
| 86 |
foreach my $file (shuffle @files) { |
| 87 |
$runner->run(sub { |
| 88 |
$| = 1; select STDOUT; |
| 89 |
my $cmd = sprintf('../sassc/bin/sassc %s', $file); |
| 90 |
my $check = sprintf('valgrind --leak-check=yes %s', $cmd); |
| 91 |
run3($check, undef, \ my $out, \ my $err); |
| 92 |
if ($err =~ m/in use at exit: 0 bytes in 0 blocks/) { |
| 93 |
print "."; # print success indicator |
| 94 |
} else { |
| 95 |
print "F"; # print error indicator |
| 96 |
flock($leaks, LOCK_EX) or die "Cannot lock log"; |
| 97 |
$leaks->printflush("#" x 80, "\n", $err, "\n"); |
| 98 |
flock($leaks, LOCK_UN) or die "Cannot unlock log"; |
| 99 |
} |
| 100 |
}); |
| 101 |
} |
| 102 |
|
| 103 |
$runner->finish; |