1N/A#! /usr/perl5/bin/perl
1N/A#
1N/A# CDDL HEADER START
1N/A#
1N/A# The contents of this file are subject to the terms of the
1N/A# Common Development and Distribution License (the "License").
1N/A# You may not use this file except in compliance with the License.
1N/A#
1N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1N/A# or http://www.opensolaris.org/os/licensing.
1N/A# See the License for the specific language governing permissions
1N/A# and limitations under the License.
1N/A#
1N/A# When distributing Covered Code, include this CDDL HEADER in each
1N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1N/A# If applicable, add the following below this CDDL HEADER, with the
1N/A# fields enclosed by brackets "[]" replaced with your own identifying
1N/A# information: Portions Copyright [yyyy] [name of copyright owner]
1N/A#
1N/A# CDDL HEADER END
1N/A#
1N/A
1N/A#
1N/A# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
1N/A#
1N/A
1N/A#
1N/A# Tests for Sun::Solaris::Lgrp API.
1N/A#
1N/A# Before `make install' is performed this script should be runnable with
1N/A# `make test'. After `make install' it should work as `perl Lgrp.t'
1N/A#
1N/A# The test uses Test module which is available on Perl 5.6 and later.
1N/A#
1N/A
1N/A
1N/Ause strict;
1N/Ause warnings;
1N/Ause Test;
1N/A
1N/A# Tests to run
1N/ABEGIN { plan tests => 65 }
1N/A
1N/Ause Sun::Solaris::Lgrp ':ALL';
1N/A
1N/A#
1N/A######################################################################
1N/A
1N/Amy ($home, $fail);
1N/A
1N/A######################################################################
1N/A# Check that all exported constants can be accessed.
1N/A$fail = 0;
1N/Aforeach my $constname (qw(
1N/A LGRP_AFF_NONE LGRP_AFF_STRONG LGRP_AFF_WEAK LGRP_CONTENT_DIRECT
1N/A LGRP_CONTENT_HIERARCHY LGRP_MEM_SZ_FREE
1N/A LGRP_MEM_SZ_INSTALLED LGRP_VER_CURRENT LGRP_VER_NONE
1N/A LGRP_VIEW_CALLER LGRP_VIEW_OS LGRP_RSRC_CPU LGRP_RSRC_MEM
1N/A LGRP_CONTENT_ALL LGRP_LAT_CPU_TO_MEM)) {
1N/A next if (eval "my \$a = $constname; 1");
1N/A $fail++;
1N/A}
1N/A
1N/Aok($fail, 0, 'All Constants defined' );
1N/A
1N/A#########################
1N/A
1N/A######################################################################
1N/A# Verify lgrp_version
1N/A##
1N/Amy $version = lgrp_version(-1);
1N/Aok($version, LGRP_VER_NONE, 'incorrect lgrp version unsupported');
1N/A
1N/A$version = lgrp_version(LGRP_VER_NONE);
1N/Aok($version, LGRP_VER_CURRENT, 'lgrp version is current');
1N/A
1N/A$version = lgrp_version(LGRP_VER_CURRENT);
1N/Aok($version, LGRP_VER_CURRENT, 'support LGRP_VER_CURRENT version');
1N/A#
1N/A#######################################################################
1N/A
1N/A######################################################################
1N/A# Verify that lgrp_init()/lgrp_fini work.
1N/A##
1N/Amy $c = lgrp_init(LGRP_VIEW_CALLER);
1N/Aok($c) or
1N/A die("lgrp_init: $!");
1N/A
1N/Amy $view = lgrp_view($c);
1N/A
1N/Aok($view, LGRP_VIEW_CALLER, 'View is LGRP_VIEW_CALLER');
1N/A
1N/Amy $fin = lgrp_fini($c);
1N/Aok($fin);
1N/A
1N/A# Try to free it again, it should fail.
1N/A$fin = lgrp_fini($c);
1N/Aok($fin, undef, 'lgrp_fini second time should fail');
1N/A
1N/A$c = lgrp_init(LGRP_VIEW_OS);
1N/Aok($c) or
1N/A die("lgrp_init: $!");
1N/A
1N/A$view = lgrp_view($c);
1N/A
1N/Aok($view, LGRP_VIEW_OS, 'View is LGRP_VIEW_OS');
1N/A#
1N/A######################################################################
1N/A
1N/A######################################################################
1N/A# root should have ID 0.
1N/A##
1N/Amy $root = lgrp_root($c);
1N/Aok($root, 0, 'root should have id zero');
1N/A#
1N/A######################################################################
1N/A# Verify lgrp_nlgrps()
1N/A##
1N/Amy $nlgrps = lgrp_nlgrps($c);
1N/Aok($nlgrps);
1N/A
1N/Amy @lgrps = lgrp_lgrps($c);
1N/Aok(@lgrps);
1N/Aok(scalar @lgrps, $nlgrps, 'lgrp_nlgrps() should match number of lgrps');
1N/Aok($nlgrps, lgrp_lgrps($c), 'lgrp_lgrps() in scalar context is sane');
1N/A
1N/A######################################################################
1N/A# All root children should have root as their one and only one parent
1N/A##
1N/A$fail = 0;
1N/Amy @children = lgrp_children($c, $root);
1N/Aok(scalar @children, lgrp_children($c, $root), 'lgrp_children as scalar');
1N/Amy @leaves = lgrp_leaves $c;
1N/Aok(scalar @leaves);
1N/Aok(scalar @leaves, lgrp_leaves $c);
1N/Aok(scalar @children <= scalar @leaves);
1N/A
1N/Amy @parents;
1N/A
1N/Amy $fail_lgrp_parents = 0;
1N/A
1N/Aforeach my $l (@children) {
1N/A @parents = lgrp_parents($c, $l) or
1N/A (print STDERR "# lgrp_parents: $!\n"), $fail++, last;
1N/A my $nparents = @parents;
1N/A my ($parent, @rest) = @parents;
1N/A $fail++ if $parent != $root;
1N/A $fail++ unless $nparents == 1;
1N/A $fail_lgrp_parents++ if $nparents != lgrp_parents($c, $l);
1N/A}
1N/Aok($fail, 0, 'correct parents for children');
1N/Aok($fail_lgrp_parents, 0, 'correct lgrp_parents() as scalar');
1N/A
1N/A######################################################################
1N/A# Illegal parents have no children
1N/A##
1N/A@children = lgrp_children($c, -1);
1N/Amy $nchildren = lgrp_children($c, -1);
1N/Aok(scalar @children, 0, 'Illegal parents have no children');
1N/A# Same in scalar context
1N/Aok($nchildren, undef, 'No children means undef as scalar');
1N/A
1N/A######################################################################
1N/A# root should have no parents.
1N/A##
1N/A@parents = lgrp_parents($c, $root);
1N/Aok(scalar @parents, 0, 'root should have no parents');
1N/A# Same in scalar context
1N/Aok(lgrp_parents($c, $root), 0);
1N/A#
1N/A######################################################################
1N/A# Illegal children have no paremts
1N/A##
1N/A@parents = lgrp_parents($c, -1);
1N/Amy $nparents = lgrp_parents($c, -1);
1N/Aok(scalar @parents, 0, 'Illegal children have no paremts');
1N/A# Same in scalar context
1N/Aok($nparents, undef, 'No parents means undef as scalar');
1N/A#
1N/A######################################################################
1N/A# Root should have non-zero CPUs and memory size
1N/A##
1N/Amy @cpus = lgrp_cpus($c, $root, LGRP_CONTENT_HIERARCHY);
1N/Amy $ncpus = lgrp_cpus($c, $root, LGRP_CONTENT_HIERARCHY);
1N/Aok(scalar @cpus, $ncpus);
1N/Aok($ncpus);
1N/Aok(lgrp_mem_size($c, $root, LGRP_MEM_SZ_INSTALLED, LGRP_CONTENT_HIERARCHY));
1N/Amy @ncpus_bad = lgrp_cpus($c, $root, -1);
1N/Aok(scalar @ncpus_bad, 0, 'Bad argument to lgrp_cpus should return empty');
1N/Amy $ncpus_bad = lgrp_cpus($c, $root, -1);
1N/Aok($ncpus_bad, undef, 'Bad argument to lgrp_cpus should return undef');
1N/A#
1N/A######################################################################
1N/A
1N/A######################################################################
1N/A# The cookie should not be stale
1N/A#
1N/Aok(! lgrp_cookie_stale($c));
1N/A#
1N/A######################################################################
1N/A
1N/A######################################################################
1N/A# Can we call lgrp_latency?
1N/A# The latencies from lgrp_latency and lgrp_latency_cookie should match.
1N/A##
1N/Amy $latency = lgrp_latency($root, $root);
1N/Aok(defined $latency);
1N/A
1N/Amy $latency1 = lgrp_latency_cookie($c, $root, $root);
1N/Aok(defined $latency1);
1N/Aok($latency, $latency1, 'Latencies should match');
1N/A#
1N/A######################################################################
1N/A# Can we call lgrp_resources?
1N/A##
1N/Amy @lgrps_c = lgrp_resources($c, $root, LGRP_RSRC_CPU);
1N/Amy $nresources = lgrp_resources($c, $root, LGRP_RSRC_CPU);
1N/Aok(!defined $nresources) if $version < 2;
1N/Aok(scalar @lgrps_c, 0) if $version < 2;
1N/Aok($nresources) if $version >= 2;
1N/Aok(@lgrps_c) if $version >= 2;
1N/A
1N/A##
1N/A# lgrp_fini should always succeed.
1N/Aok(lgrp_fini($c));
1N/A
1N/A
1N/A######################################################################
1N/A# Now test Object-Oriented interface.
1N/A##
1N/A$c = Sun::Solaris::Lgrp->new(LGRP_VIEW_OS) or
1N/A die "Lgrp->new(LGRP_VIEW_OS): $!";
1N/A
1N/Amy $c_caller = Sun::Solaris::Lgrp->new(LGRP_VIEW_CALLER) or
1N/A die "Lgrp->new(LGRP_VIEW_CALLER): $!";
1N/A
1N/Amy $c_default = Sun::Solaris::Lgrp->new() or
1N/A die "Lgrp->new(): $!";
1N/A
1N/Aok($c->view, LGRP_VIEW_OS);
1N/Aok($c_caller->view, LGRP_VIEW_CALLER);
1N/Aok($c_default->view, LGRP_VIEW_OS);
1N/Aok($c->stale, 0, 'cookie is not stale');
1N/Aok($nlgrps, $c->nlgrps, 'nlgrps');
1N/Amy @lg1 = $c->lgrps;
1N/Aok(@lgrps, @lg1);
1N/Amy@leaves1 = $c->leaves;
1N/Aok(@leaves, @leaves1) or
1N/A print STDERR "# \@leaves: @leaves, \@leaves1: @leaves\n";
1N/Aok($root, $c->root);
1N/A@cpus = lgrp_cpus($c->cookie, $root, LGRP_CONTENT_HIERARCHY);
1N/Amy @cpus1 = $c->cpus($root, LGRP_CONTENT_HIERARCHY);
1N/Aok(@cpus, @cpus1) or
1N/A print STDERR "# \@cpus: @cpus, \@cpus1: @cpus1\n";
1N/Aok(lgrp_latency($root, $root), $c->latency($root, $root));
1N/Amy @lgrps_c1 = $c->resources($root, LGRP_RSRC_CPU);
1N/Aok(@lgrps_c, @lgrps_c1);
1N/Aok(lgrp_version(LGRP_VER_NONE), $c->version);
1N/A
1N/A#
1N/A######################################################################
1N/A# Can we call lgrp_home?
1N/A##
1N/A$home = lgrp_home(P_PID, P_MYID);
1N/Aok(defined($home));
1N/Amy $home1 = $c->home(P_PID, P_MYID);
1N/Aok($home1 == $home);
1N/A$home1 = lgrp_home(P_LWPID, 1);
1N/Aok($home1 == $home);
1N/A$home1 = $c->home(P_LWPID, 1);
1N/Aok($home1 == $home);
1N/A
1N/A#
1N/A######################################################################
1N/A# Can we call lgrp_affinity_set?
1N/A##
1N/Amy $affinity;
1N/A
1N/Aok(LGRP_AFF_WEAK);
1N/Aok(P_LWPID);
1N/A
1N/A$affinity = $c->affinity_set(P_PID, P_MYID, $home, LGRP_AFF_WEAK);
1N/Aok($affinity);
1N/A
1N/A$affinity = $c->affinity_set(P_LWPID, 1, $home, LGRP_AFF_WEAK);
1N/Aok($affinity);
1N/A
1N/A$affinity = lgrp_affinity_set(P_PID, P_MYID, $home, LGRP_AFF_WEAK);
1N/Aok($affinity);
1N/A
1N/A$affinity = lgrp_affinity_set(P_LWPID, 1, $home, LGRP_AFF_WEAK);
1N/Aok($affinity);
1N/A
1N/A#
1N/A######################################################################
1N/A# Can we call lgrp_affinity_get?
1N/A##
1N/A$affinity = lgrp_affinity_get(P_PID, P_MYID, $home);
1N/Aok($affinity = LGRP_AFF_WEAK);
1N/A
1N/A$affinity = lgrp_affinity_get(P_LWPID, 1, $home);
1N/Aok($affinity == LGRP_AFF_WEAK);
1N/A
1N/A$affinity = $c->affinity_get(P_PID, P_MYID, $home);
1N/Aok($affinity == LGRP_AFF_WEAK);
1N/A
1N/A$affinity = $c->affinity_get(P_LWPID, 1, $home);
1N/Aok($affinity == LGRP_AFF_WEAK);
1N/A
1N/A#
1N/A######################################################################
1N/A# THE END!
1N/A#########