Blame script/test-leaks.pl

Packit Service 7770af
#!/usr/bin/perl
Packit Service 7770af
############################################################
Packit Service 7770af
# this perl script is meant for developers only!
Packit Service 7770af
# it will run all spec-tests (without verifying the
Packit Service 7770af
# results) via valgrind to detect possible leaks.
Packit Service 7770af
# expect that it takes 1h or more to finish!
Packit Service 7770af
############################################################
Packit Service 7770af
# Prerequisite install: `cpan Parallel::Runner`
Packit Service 7770af
# You may also need to install `cpan File::Find`
Packit Service 7770af
# You may also need to install `cpan IPC::Run3`
Packit Service 7770af
############################################################
Packit Service 7770af
# usage: `perl test-leaks.pl [threads]`
Packit Service 7770af
# example: `time perl test-leaks.pl 4`
Packit Service 7770af
############################################################
Packit Service 7770af
# leaks will be reported in "mem-leaks.log"
Packit Service 7770af
############################################################
Packit Service 7770af
Packit Service 7770af
use strict;
Packit Service 7770af
use warnings;
Packit Service 7770af
Packit Service 7770af
############################################################
Packit Service 7770af
# configurations (you may adjust)
Packit Service 7770af
############################################################
Packit Service 7770af
Packit Service 7770af
# number of threads to use
Packit Service 7770af
my $threads = $ARGV[0] || 8;
Packit Service 7770af
Packit Service 7770af
# the github repositories to checkout
Packit Service 7770af
# if you need other branch, clone manually!
Packit Service 7770af
my $sassc = "https://www.github.com/sass/sassc";
Packit Service 7770af
my $specs = "https://www.github.com/sass/sass-spec";
Packit Service 7770af
Packit Service 7770af
############################################################
Packit Service 7770af
# load modules
Packit Service 7770af
############################################################
Packit Service 7770af
Packit Service 7770af
use IPC::Run3;
Packit Service 7770af
use IO::Handle;
Packit Service 7770af
use Fcntl qw(:flock);
Packit Service 7770af
use File::Find::Rule;
Packit Service 7770af
use Parallel::Runner;
Packit Service 7770af
use List::Util qw(shuffle);
Packit Service 7770af
Packit Service 7770af
############################################################
Packit Service 7770af
# check prerequisites
Packit Service 7770af
############################################################
Packit Service 7770af
Packit Service 7770af
unless (-d "../sassc") {
Packit Service 7770af
  warn "sassc folder not found\n";
Packit Service 7770af
  warn "trying to checkout via git\n";
Packit Service 7770af
  system("git", "clone", $sassc, "../sassc");
Packit Service 7770af
  die "git command did not exit gracefully" if $?;
Packit Service 7770af
}
Packit Service 7770af
Packit Service 7770af
unless (-d "../sass-spec") {
Packit Service 7770af
  warn "sass-spec folder not found\n";
Packit Service 7770af
  warn "trying to checkout via git\n";
Packit Service 7770af
  system("git", "clone", $specs, "../sass-spec");
Packit Service 7770af
  die "git command did not exit gracefully" if $?;
Packit Service 7770af
}
Packit Service 7770af
Packit Service 7770af
unless (-f "../sassc/bin/sassc") {
Packit Service 7770af
  warn "sassc executable not found\n";
Packit Service 7770af
  warn "trying to compile via make\n";
Packit Service 7770af
  system("make", "-C", "../sassc", "-j", $threads);
Packit Service 7770af
  die "make command did not exit gracefully" if $?;
Packit Service 7770af
}
Packit Service 7770af
Packit Service 7770af
############################################################
Packit Service 7770af
# main runner code
Packit Service 7770af
############################################################
Packit Service 7770af
Packit Service 7770af
my $root = "../sass-spec/spec";
Packit Service 7770af
my @files = File::Find::Rule->file()
Packit Service 7770af
            ->name('input.scss')->in($root);
Packit Service 7770af
Packit Service 7770af
open(my $leaks, ">", "mem-leaks.log");
Packit Service 7770af
die "Cannot open log" unless $leaks;
Packit Service 7770af
my $runner = Parallel::Runner->new($threads);
Packit Service 7770af
die "Cannot start runner" unless $runner;
Packit Service 7770af
Packit Service 7770af
print "##########################\n";
Packit Service 7770af
print "Testing $#files spec files\n";
Packit Service 7770af
print "##########################\n";
Packit Service 7770af
Packit Service 7770af
foreach my $file (shuffle @files) {
Packit Service 7770af
  $runner->run(sub {
Packit Service 7770af
    $| = 1; select STDOUT;
Packit Service 7770af
    my $cmd = sprintf('../sassc/bin/sassc %s', $file);
Packit Service 7770af
    my $check = sprintf('valgrind --leak-check=yes %s', $cmd);
Packit Service 7770af
    run3($check, undef, \ my $out, \ my $err);
Packit Service 7770af
    if ($err =~ m/in use at exit: 0 bytes in 0 blocks/) {
Packit Service 7770af
      print "."; # print success indicator
Packit Service 7770af
    } else {
Packit Service 7770af
      print "F"; # print error indicator
Packit Service 7770af
      flock($leaks, LOCK_EX) or die "Cannot lock log";
Packit Service 7770af
      $leaks->printflush("#" x 80, "\n", $err, "\n");
Packit Service 7770af
      flock($leaks, LOCK_UN) or die "Cannot unlock log";
Packit Service 7770af
    }
Packit Service 7770af
  });
Packit Service 7770af
}
Packit Service 7770af
Packit Service 7770af
$runner->finish;