xref: /openbsd-src/gnu/usr.bin/perl/cpan/Win32/t/GetCurrentThreadId.t (revision 91f110e064cd7c194e59e019b83bb7496c1c84d4)
1*b39c5158Smillertuse strict;
2*b39c5158Smillertuse Config qw(%Config);
3*b39c5158Smillertuse Test;
4*b39c5158Smillertuse Win32;
5*b39c5158Smillert
6*b39c5158Smillertmy $fork_emulation = $Config{ccflags} =~ /PERL_IMPLICIT_SYS/;
7*b39c5158Smillert
8*b39c5158Smillertmy $tests = $fork_emulation ? 4 : 2;
9*b39c5158Smillertplan tests => $tests;
10*b39c5158Smillert
11*b39c5158Smillertmy $pid = $$+0; # make sure we don't copy any magic to $pid
12*b39c5158Smillert
13*b39c5158Smillertif ($^O eq "cygwin") {
14*b39c5158Smillert    skip(!defined &Cygwin::pid_to_winpid,
15*b39c5158Smillert	 Cygwin::pid_to_winpid($pid),
16*b39c5158Smillert	 Win32::GetCurrentProcessId());
17*b39c5158Smillert}
18*b39c5158Smillertelse {
19*b39c5158Smillert    ok($pid, Win32::GetCurrentProcessId());
20*b39c5158Smillert}
21*b39c5158Smillert
22*b39c5158Smillertif ($fork_emulation) {
23*b39c5158Smillert    # This test relies on the implementation detail that the fork() emulation
24*b39c5158Smillert    # uses the negative value of the thread id as a pseudo process id.
25*b39c5158Smillert    if (my $child = fork) {
26*b39c5158Smillert	waitpid($child, 0);
27*b39c5158Smillert	exit 0;
28*b39c5158Smillert    }
29*b39c5158Smillert    ok(-$$, Win32::GetCurrentThreadId());
30*b39c5158Smillert
31*b39c5158Smillert    # GetCurrentProcessId() should still return the real PID
32*b39c5158Smillert    ok($pid, Win32::GetCurrentProcessId());
33*b39c5158Smillert    ok($$ != Win32::GetCurrentProcessId());
34*b39c5158Smillert}
35*b39c5158Smillertelse {
36*b39c5158Smillert    # here we just want to see something.
37*b39c5158Smillert    ok(Win32::GetCurrentThreadId() > 0);
38*b39c5158Smillert}
39