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 ############################################################
21 ############################################################
22 # configurations (you may adjust)
23 ############################################################
25 # number of threads to use
26 my $threads = $ARGV[0] || 8;
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";
33 ############################################################
35 ############################################################
42 use List::Util qw(shuffle);
44 ############################################################
46 ############################################################
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 $?;
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 $?;
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 $?;
69 ############################################################
71 ############################################################
73 my $root = "../sass-spec/spec";
74 my @files = File::Find::Rule->file()
75 ->name('input.scss')->in($root);
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;
82 print "##########################\n";
83 print "Testing $#files spec files\n";
84 print "##########################\n";
86 foreach my $file (shuffle @files) {
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
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";