Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /proc/thread-self/root/proc/self/root/usr/share/doc/perl-GTop/t/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/thread-self/root/proc/self/root/usr/share/doc/perl-GTop/t/threads.t
use strict;
use warnings;

# should load threads.pm before Test::Builder in
# other case Test::Builder wouldn't share test number
BEGIN {
    use Config;
    use constant USETHREADS => ($] >= 5.008 && $Config{useithreads});
    require threads if USETHREADS;
}

# XXX: at the moment testing only the survival of GTop objects with
# threads, see the TODO file for remaining parts

my $threads;
BEGIN {
    use Test::More;
    if (USETHREADS) {
        $threads = 3;
        plan tests => 2 + ($threads+1);
    }
    else {
        plan skip_all => 'perl 5.8+ w/ ithreads is required';
    }
}

BEGIN { use_ok('GTop') };

# the object is intentionally global, so perl won't destroy it right
# away
our $gtop = GTop->new;

access_test();

# as the new threads are spawned they will inherit the count from the
# main thread
threads->new(\&access_test)->detach for 1..$threads;

sub access_test {
    print "# $$ mem size: \n";
    my $proc_mem = $gtop->proc_mem($$);
    my $mem_size = $proc_mem->size;
    print "# $$ mem size: $mem_size\n";

    ok $mem_size > 0;
}

# workaround the situations where the main thread exits before the
# child threads, which shouldn't be a problem since all threads are
# detached, but something is broken in perl
select(undef, undef, undef, 0.25); # sleep 0.25sec

END { ok 1; }


Hry