xref: /openbsd-src/gnu/usr.bin/perl/t/perf/taint.t (revision 3d61058aa5c692477b6d18acfbbdb653a9930ff9)
1fb8aa749Safresh1#!./perl -T
2fb8aa749Safresh1#
3fb8aa749Safresh1# All the tests in this file are ones that run exceptionally slowly
4fb8aa749Safresh1# (each test taking seconds or even minutes) in the absence of particular
5fb8aa749Safresh1# optimisations. Thus it is a sort of canary for optimisations being
6fb8aa749Safresh1# broken.
7fb8aa749Safresh1#
8fb8aa749Safresh1# Although it includes a watchdog timeout, this is set to a generous limit
9fb8aa749Safresh1# to allow for running on slow systems; therefore a broken optimisation
10fb8aa749Safresh1# might be indicated merely by this test file taking unusually long to
11fb8aa749Safresh1# run, rather than actually timing out.
12fb8aa749Safresh1#
13fb8aa749Safresh1# This is similar to t/perf/speed.t but tests performance regressions specific
14fb8aa749Safresh1# to taint.
15fb8aa749Safresh1#
16fb8aa749Safresh1
17fb8aa749Safresh1BEGIN {
18fb8aa749Safresh1    chdir 't' if -d 't';
19fb8aa749Safresh1    @INC = ('../lib');
20*3d61058aSafresh1    require Config; Config->import;
21fb8aa749Safresh1    require './test.pl';
22b8851fccSafresh1    skip_all_if_miniperl("No Scalar::Util under miniperl");
23eac174f2Safresh1    if (exists($Config{taint_support}) && !$Config{taint_support}) {
24eac174f2Safresh1        skip_all("built without taint support");
25eac174f2Safresh1    }
26fb8aa749Safresh1}
27fb8aa749Safresh1
28fb8aa749Safresh1use strict;
29fb8aa749Safresh1use warnings;
30fb8aa749Safresh1use Scalar::Util qw(tainted);
31fb8aa749Safresh1
32fb8aa749Safresh1$| = 1;
33fb8aa749Safresh1
349f11ffb7Safresh1plan tests => 4;
35fb8aa749Safresh1
36fb8aa749Safresh1watchdog(60);
37fb8aa749Safresh1
389f11ffb7Safresh1my $taint = substr($ENV{PATH}, 0, 0); # and empty tainted string
399f11ffb7Safresh1
40fb8aa749Safresh1{
419f11ffb7Safresh1    my $in = $taint . ( "ab" x 200_000 );
42fb8aa749Safresh1    utf8::upgrade($in);
43fb8aa749Safresh1    ok(tainted($in), "performance issue only when tainted");
44fb8aa749Safresh1    while ($in =~ /\Ga+b/g) { }
45fb8aa749Safresh1    pass("\\G on tainted string");
46fb8aa749Safresh1}
47fb8aa749Safresh1
489f11ffb7Safresh1# RT #130584
499f11ffb7Safresh1# tainted string caused the utf8 pos cache to be cleared each time
509f11ffb7Safresh1
519f11ffb7Safresh1{
529f11ffb7Safresh1    my $repeat = 30_000;
539f11ffb7Safresh1    my $in = $taint . ("abcdefghijklmnopqrstuvwxyz" x $repeat);
549f11ffb7Safresh1    utf8::upgrade($in);
559f11ffb7Safresh1    ok(tainted($in), "performance issue only when tainted");
569f11ffb7Safresh1    local ${^UTF8CACHE} = 1;  # defeat debugging
579f11ffb7Safresh1    for my $i (1..$repeat) {
589f11ffb7Safresh1        $in =~ /abcdefghijklmnopqrstuvwxyz/g or die;
599f11ffb7Safresh1        my $p = pos($in); # this was slow
609f11ffb7Safresh1    }
619f11ffb7Safresh1    pass("RT #130584 pos on tainted utf8 string");
629f11ffb7Safresh1}
639f11ffb7Safresh1
64fb8aa749Safresh11;
65