Algorithm-Classifier-IsolationForest

 view release on metacpan or  search on metacpan

t/04-accel-tuning.t  view on Meta::CPAN

#!perl
# 04-accel-tuning.t
#
# Verifies the C-build tuning environment variables (read once, at
# module load, in the block that compiles the Inline::C backend):
#
#   * IF_NO_C=1      -- skips building the C backend entirely
#   * IF_OPT=<level>  -- overrides the default -O3
#   * IF_ARCH=<value> -- adds -march=<value>
#   * IF_NATIVE=1     -- shorthand for IF_ARCH=native, superseded by IF_ARCH
#
# Since these are read once at load time, each combination needs its own
# fresh perl process -- this spawns one per case and inspects
# $Algorithm::Classifier::IsolationForest::{HAS_C,OPT_LEVEL} from its
# output, the same technique t/03-fit-determinism.t uses for
# OMP_NUM_THREADS.  Also checks that IF_OPT/IF_ARCH validate their input
# rather than passing it through to a compiler command line unchecked.

use strict;
use warnings;
use Test::More;
use File::Temp qw(tempfile);

use Algorithm::Classifier::IsolationForest;

my $HAS_C = $Algorithm::Classifier::IsolationForest::HAS_C ? 1 : 0;

plan skip_all => 'no Inline::C backend compiled in on this machine'
	unless $HAS_C;

my ( $fh, $path ) = tempfile( SUFFIX => '.pl', UNLINK => 1 );
print $fh <<'END_CHILD';
use Algorithm::Classifier::IsolationForest;
print "HAS_C=$Algorithm::Classifier::IsolationForest::HAS_C\n";
print "OPT_LEVEL=$Algorithm::Classifier::IsolationForest::OPT_LEVEL\n";
END_CHILD
close $fh;

# Runs the child with the given %ENV additions layered over a clean
# copy of the current environment (so leftover IF_* vars from one
# subtest can't bleed into the next), returns (out, exit_status).
sub run_child {
	my (%env) = @_;
	local %ENV = %ENV;
	delete @ENV{
		qw(IF_NO_C IF_OPT IF_ARCH IF_NATIVE
			IF_NO_OPENMP IF_RUNTIME_BUILD IF_INSTALL_BUILD)
	};
	@ENV{ keys %env } = values %env;
	my $out = `$^X -Ilib "$path" 2>&1`;
	return ( $out, $? );
} ## end sub run_child

# Expected flag composition mirrors the module's: the *defaults* come
# from the generated BuildFlags module when present (a tree configured
# with `IF_ARCH=... perl Makefile.PL` has that arch baked in as the
# default, and invalid runtime values must fall back to it, not to a
# hard-coded -O3), and any -march is always accompanied by
# -ffp-contract=off so FMA contraction can't break the C-vs-Perl
# bit-parity guarantees.
my ( $DEF_OPT, $DEF_ARCH ) = ( '-O3', '' );
{
	local $@;
	my $rec = eval {
		require Algorithm::Classifier::IsolationForest::BuildFlags;
		Algorithm::Classifier::IsolationForest::BuildFlags::flags();
	};
	if ( ref $rec eq 'HASH' ) {
		$DEF_OPT  = $rec->{opt}  if defined $rec->{opt};
		$DEF_ARCH = $rec->{arch} if defined $rec->{arch};
	}
}



( run in 1.017 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )