Path: blob/master/test/functional/VM_Test/SharedClassesSysVTesting/testSC_SysV_Java7_Tests.pl
6004 views
#!/usr/bin/perl1##############################################################################2# Copyright (c) 2016, 2019 IBM Corp. and others3#4# This program and the accompanying materials are made available under5# the terms of the Eclipse Public License 2.0 which accompanies this6# distribution and is available at https://www.eclipse.org/legal/epl-2.0/7# or the Apache License, Version 2.0 which accompanies this distribution and8# is available at https://www.apache.org/licenses/LICENSE-2.0.9#10# This Source Code may also be made available under the following11# Secondary Licenses when the conditions for such availability set12# forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13# General Public License, version 2 with the GNU Classpath14# Exception [1] and GNU General Public License, version 2 with the15# OpenJDK Assembly Exception [2].16#17# [1] https://www.gnu.org/software/classpath/license.html18# [2] http://openjdk.java.net/legal/assembly-exception.html19#20# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception21##############################################################################2223use strict;24use IPC::SysV qw(IPC_STAT IPC_SET);25use Fcntl qw(SEEK_SET);2627#28# FWD DECLARES29#30sub cleanupSysV;31sub cleanupSysVMem;32sub cleanupSysVSem;33sub listSysVSemaphores;34sub listSysVMemory;35sub forkAndRunInBackGround;36sub listFilesInFolder;37sub getSemaphoreCntlFile;38sub getMemoryCntlFile;39sub removeCntrlFiles;40sub Test1;41sub Test2;42sub Test3;43sub Test4;44sub Test5;45sub Test6;46sub Test7;47sub Test8;48sub Test9;49sub Test10;50sub Test11;51sub Test12;52sub Test13;53sub Test14;54sub Test15;55sub Test16;56sub Test17;57sub Test18;58sub Test19;59sub Test20;60sub Test21;61sub Test22;626364#65# MAIN ...66#67my $osname = "";68my $numargs = @ARGV;69my @semaphoreList;70my @memoryList;71my $ITER;72my $verbose = 0; #0 for false, 1 for true73my $numprocs = 15;74my $READONLY = 0400;75my $testcachname = "SysVCacheTestFileName";76my $cacheDirectory = "/tmp/";77# No need to use "javasharedresources" cacheDirectory, as it will be automatically appended when using nonpersistent.78my $java = "./java";7980#81# Java commands for testing ...82#83my $cmd = $java. " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$testcachname." -version 2>&1";84my $cmddumpdisabled = $java. " -Xshareclasses:cacheDir=".$cacheDirectory.",disablecorruptcachedumps,nonpersistent,name=".$testcachname." -version 2>&1";85my $destroycmd = $java. " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$testcachname.",destroy 2>&1";86my $cmdNonfal = $java. " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$testcachname.",nonfatal -version 2>&1";8788#89# Script argument handling ...90#91if ($numargs != 1) {92print("Error: incorrect useage!\n");93print("\tscriptname.pl zos|aix|linux\n");94die ("Invalid arguments!");95} elsif ($numargs == 1) {96$osname = $ARGV[0];97}9899#100# Start tests101#102my $semPermIndex = &getIPCObjPermIndex($osname);103my $shmPermIndex = &getIPCObjPermIndex($osname);104my $passedTestCount = 0;105my $failedTestCount = 0;106107&cleanupSysV($osname,$verbose);108&removeCntrlFiles($testcachname);109if (&Test1($osname, $cmd, $numprocs) == 1) {110$passedTestCount+=1;111} else {112$failedTestCount+=1;113}114115&cleanupSysV($osname,$verbose);116&removeCntrlFiles($testcachname);117if (&Test2($osname, $cmd, $numprocs) == 1) {118$passedTestCount+=1;119} else {120$failedTestCount+=1;121}122123&cleanupSysV($osname,$verbose);124&removeCntrlFiles($testcachname);125if (&Test3($osname, $cmd, $numprocs) == 1) {126$passedTestCount+=1;127} else {128$failedTestCount+=1;129}130131&cleanupSysV($osname,$verbose);132&removeCntrlFiles($testcachname);133if (&Test4($osname, $cmd, $numprocs) == 1) {134$passedTestCount+=1;135} else {136$failedTestCount+=1;137}138139&cleanupSysV($osname,$verbose);140&removeCntrlFiles($testcachname);141if (&Test5($osname, $cmd, $numprocs) == 1) {142$passedTestCount+=1;143} else {144$failedTestCount+=1;145}146147&cleanupSysV($osname,$verbose);148&removeCntrlFiles($testcachname);149if (&Test6($osname, $cmd, $numprocs) == 1) {150$passedTestCount+=1;151} else {152$failedTestCount+=1;153}154155&cleanupSysV($osname,$verbose);156&removeCntrlFiles($testcachname);157if (&Test7($osname, $cmd, $numprocs) == 1) {158$passedTestCount+=1;159} else {160$failedTestCount+=1;161}162163&cleanupSysV($osname,$verbose);164&removeCntrlFiles($testcachname);165if (&Test8($osname, $cmd, $numprocs) == 1) {166$passedTestCount+=1;167} else {168$failedTestCount+=1;169}170171&cleanupSysV($osname,$verbose);172&removeCntrlFiles($testcachname);173if (&Test9($osname, $cmd, $numprocs) == 1) {174$passedTestCount+=1;175} else {176$failedTestCount+=1;177}178179180&cleanupSysV($osname,$verbose);181&removeCntrlFiles($testcachname);182if (&Test10($osname, $cmd, $destroycmd, $numprocs) == 1) {183$passedTestCount+=1;184} else {185$failedTestCount+=1;186}187188&cleanupSysV($osname,$verbose);189&removeCntrlFiles($testcachname);190if (&Test11($osname, $cmd, $destroycmd, $numprocs) == 1) {191$passedTestCount+=1;192} else {193$failedTestCount+=1;194}195196&cleanupSysV($osname,$verbose);197&removeCntrlFiles($testcachname);198if (&Test12($osname, $cmd, $destroycmd, $numprocs) == 1) {199$passedTestCount+=1;200} else {201$failedTestCount+=1;202}203204&cleanupSysV($osname,$verbose);205&removeCntrlFiles($testcachname);206if (&Test13($osname, $cmd, $destroycmd, $numprocs) == 1) {207$passedTestCount+=1;208} else {209$failedTestCount+=1;210}211212&cleanupSysV($osname,$verbose);213&removeCntrlFiles($testcachname);214if (&Test14($osname, $cmd, $numprocs) == 1) {215$passedTestCount+=1;216} else {217$failedTestCount+=1;218}219220&cleanupSysV($osname,$verbose);221&removeCntrlFiles($testcachname);222if (&Test15($osname, $cmd, $cmdNonfal, $numprocs) == 1) {223$passedTestCount+=1;224} else {225$failedTestCount+=1;226}227228&cleanupSysV($osname,$verbose);229&removeCntrlFiles($testcachname);230if (&Test16($osname, $cmd, 100) == 1) {231$passedTestCount+=1;232} else {233$failedTestCount+=1;234}235&cleanupSysV($osname,$verbose);236&removeCntrlFiles($testcachname);237if (&Test17($osname, $java, $numprocs) == 1) {238$passedTestCount+=1;239} else {240$failedTestCount+=1;241}242243&cleanupSysV($osname,$verbose);244&removeCntrlFiles($testcachname);245if (&Test18($osname, $java, $numprocs) == 1) {246$passedTestCount+=1;247} else {248$failedTestCount+=1;249}250251&cleanupSysV($osname,$verbose);252&removeCntrlFiles($testcachname);253if (&Test19($osname, $cmd, $numprocs) == 1) {254$passedTestCount+=1;255} else {256$failedTestCount+=1;257}258259&cleanupSysV($osname,$verbose);260&removeCntrlFiles($testcachname);261if (&Test20($osname, $cmd, $numprocs) == 1) {262$passedTestCount+=1;263} else {264$failedTestCount+=1;265}266&cleanupSysV($osname,$verbose);267&removeCntrlFiles($testcachname);268if (&Test21($osname, $cmddumpdisabled, $numprocs) == 1) {269$passedTestCount+=1;270} else {271$failedTestCount+=1;272}273&cleanupSysV($osname,$verbose);274&removeCntrlFiles($testcachname);275if (&Test22($osname, $cmddumpdisabled) == 1) {276$passedTestCount+=1;277} else {278$failedTestCount+=1;279}280281print("COMPLETE (".$passedTestCount." PASSED TESTS ... ".$failedTestCount." FAILED TESTS.)"."\n");282283exit 0;284285286sub getSemaphoreCntlFile287{288my ($testcachname) = @_;289my $testdir = "/tmp/javasharedresources/";290my @listfolders = &listFilesInFolder($testdir, $numprocs);291foreach $ITER (@listfolders) {292#print "\t".$ITER."\n";293if ($ITER =~ /$testcachname/) {294if ($ITER =~ /semaphore/) {295return $testdir . $ITER;296}297}298}299return "";300}301302sub getMemoryCntlFile303{304my ($testcachname) = @_;305my $testdir = "/tmp/javasharedresources/";306my @listfolders = &listFilesInFolder($testdir, $numprocs);307foreach $ITER (@listfolders) {308#print "\t".$ITER."\n";309if ($ITER =~ /$testcachname/) {310if ($ITER =~ /memory/) {311return $testdir . $ITER;312}313}314}315return "";316}317318sub removeCntrlFiles319{320#321# Ruthless clean up of any cache using the same cache name as we322# use for this test323#324my ($testcachname) = @_;325my $testdir = "/tmp/javasharedresources/";326my @listfolders = &listFilesInFolder($testdir, $numprocs);327foreach $ITER (@listfolders) {328#print "\t".$ITER."\n";329if ($ITER =~ /$testcachname/) {330my $cmd = "rm -f ". $testdir . $ITER;331#print $cmd . "\n";332`$cmd`;333}334}335}336337sub Test1338{339my ($osname, $cmd, $numprocs) = @_;340my @pidList;341my $count = 0;342my $waitedfor=0;343344print "Test 1: verify 1 only semaphore created\n";345346my @semaphoreList = &listSysVSemaphores($osname);347my $startCount = scalar(@semaphoreList);348my $endCount = 0;349350for ($count = 0; $count < $numprocs; $count++) {351my $pid = &forkAndRunInBackGround($cmd);352push(@pidList, $pid);353}354355while (wait() != -1) {356$waitedfor = $waitedfor + 1;357}358printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");359360@semaphoreList = &listSysVSemaphores($osname);361$endCount = scalar(@semaphoreList);362363if ($endCount == $startCount+1) {364print "\tThere is only one semaphore (as expected)\n";365print "\tTEST PASS\n";366return 1;367} else {368print "\tThere are ".$endCount." semaphores (we expect 1)\n";369print "\tTEST FAIL\n";370return 0;371}372}373374sub Test2375{376my ($osname, $cmd, $numprocs) = @_;377my @pidList;378my $count = 0;379my $waitedfor=0;380381print "Test 2: verify 1 only shared memory created\n";382383my @memoryList = &listSysVMemory($osname);384my $startCount = scalar(@memoryList);385my $endCount = 0;386387for ($count = 0; $count < $numprocs; $count++) {388my $pid = &forkAndRunInBackGround($cmd);389push(@pidList, $pid);390}391392while (wait() != -1) {393$waitedfor = $waitedfor + 1;394}395printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");396397@memoryList = &listSysVMemory($osname);398$endCount = scalar(@memoryList);399400if ($endCount == $startCount+1) {401print "\tThere is only one shared memory (as expected)\n";402print "\tTEST PASS\n";403return 1;404} else {405print "\tThere are ".$endCount." shared memories (we expect 1)\n";406print "\tTEST FAIL\n";407return 0;408}409}410411412sub Test3413{414my ($osname, $cmd, $numprocs) = @_;415my @pidList;416my $count = 0;417my $waitedfor=0;418419print "Test 3: verify no new shared memory are created on 2nd run of JVM\n";420421for ($count = 0; $count < $numprocs; $count++) {422my $pid = &forkAndRunInBackGround($cmd);423push(@pidList, $pid);424}425426$waitedfor = 0;427while (wait() != -1) {428$waitedfor = $waitedfor + 1;429}430printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");431432433my $semCount = scalar(&listSysVSemaphores($osname));434my $memCount = scalar(&listSysVMemory($osname));435436for ($count = 0; $count < $numprocs; $count++) {437my $pid = &forkAndRunInBackGround($cmd);438push(@pidList, $pid);439}440441$waitedfor = 0;442while (wait() != -1) {443$waitedfor = $waitedfor + 1;444}445printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");446447if ($semCount != scalar(&listSysVSemaphores($osname))) {448print "\tTEST FAIL\n";449return 0;450} elsif ($memCount != scalar(&listSysVMemory($osname))) {451print "\tTEST FAIL\n";452return 0;453} else {454print "\tTEST PASS\n";455}456return 1;457458}459460sub Test4461{462my ($osname, $cmd, $numprocs) = @_;463my @pidList;464my $count = 0;465my $waitedfor=0;466467print "Test 4: Create semaphore successfully when stale semaphores exist\n";468`$cmd`;469&removeCntrlFiles($testcachname);470`$cmd`;471&removeCntrlFiles($testcachname);472`$cmd`;473&removeCntrlFiles($testcachname);474475if (&getSemaphoreCntlFile($testcachname) ne "") {476print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." found\n";477return 0;478}479if (&getMemoryCntlFile($testcachname) ne "") {480print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." found\n";481return 0;482}483484my $semCount = scalar(&listSysVSemaphores($osname));485my $memCount = scalar(&listSysVMemory($osname));486487#print "\t".$cmd."\n";488`$cmd`;489490if ($memCount == scalar(&listSysVMemory($osname))) {491print "\tTEST FAIL mem count ".$memCount."\n";492return 0;493}494495if ($semCount == scalar(&listSysVSemaphores($osname))) {496print "\tTEST FAIL sem count ".$semCount." vs ".scalar(&listSysVSemaphores($osname))."\n";497return 0;498}499500print "\tTEST PASS\n";501return 1;502503}504505506sub Test5507{508my ($osname, $cmd, $numprocs) = @_;509my @pidList;510my $count = 0;511my $waitedfor=0;512my $touchcmd;513514515print "Test 5: Test empty control files.\n";516`$cmd`;517my $semfile = &getSemaphoreCntlFile($testcachname);518my $memfile = &getMemoryCntlFile($testcachname);519&removeCntrlFiles($testcachname);520521$touchcmd = "touch ".$semfile;522`$touchcmd`;523$touchcmd = "touch ".$memfile;524`$touchcmd`;525my $semCount = scalar(&listSysVSemaphores($osname));526my $memCount = scalar(&listSysVMemory($osname));527`$cmd`;528if ($memCount == scalar(&listSysVMemory($osname))) {529print "\tTEST FAIL mem count ".$memCount."\n";530return 0;531}532if ($semCount == scalar(&listSysVSemaphores($osname))) {533print "\tTEST FAIL sem count ".$semCount." vs ".scalar(&listSysVSemaphores($osname))."\n";534return 0;535}536print "\tTEST PASS\n";537return 1;538539}540541sub Test6542{543my ($osname, $cmd, $numprocs) = @_;544my @pidList;545my $count = 0;546my $waitedfor=0;547my $chmodcmd;548549550print "Test 6: Open cache with readonly control file.\n";551`$cmd`;552my $semfile = &getSemaphoreCntlFile($testcachname);553my $memfile = &getMemoryCntlFile($testcachname);554555$chmodcmd = "chmod a-wx ".$semfile;556`$chmodcmd`;557$chmodcmd = "chmod a-wx ".$memfile;558`$chmodcmd`;559my $semCount = scalar(&listSysVSemaphores($osname));560my $memCount = scalar(&listSysVMemory($osname));561562`$cmd`;563564$chmodcmd = "chmod ug+w ".$semfile;565`$chmodcmd`;566$chmodcmd = "chmod ug+w ".$memfile;567`$chmodcmd`;568569if ($memCount != scalar(&listSysVMemory($osname))) {570print "\tTEST FAIL mem count ".$memCount."\n";571return 0;572}573if ($semCount != scalar(&listSysVSemaphores($osname))) {574print "\tTEST FAIL sem count ".$semCount." vs ".scalar(&listSysVSemaphores($osname))."\n";575return 0;576}577print "\tTEST PASS\n";578return 1;579580}581582583sub Test7584{585my ($osname, $cmd, $numprocs) = @_;586my @pidList;587my $count = 0;588my $waitedfor=0;589my $chmodcmd;590591592print "Test 7: Open cache with readonly control file and no corresponding SysV objs.\n";593`$cmd`;594my $semfile = &getSemaphoreCntlFile($testcachname);595my $memfile = &getMemoryCntlFile($testcachname);596597$chmodcmd = "chmod a-wx ".$semfile;598`$chmodcmd`;599$chmodcmd = "chmod a-wx ".$memfile;600`$chmodcmd`;601602&cleanupSysV($osname,$verbose);603my $semCount = scalar(&listSysVSemaphores($osname));604my $memCount = scalar(&listSysVMemory($osname));605606607`$cmd`;608609$chmodcmd = "chmod ug+w ".$semfile;610`$chmodcmd`;611$chmodcmd = "chmod ug+w ".$memfile;612`$chmodcmd`;613614if ($memCount != scalar(&listSysVMemory($osname))) {615print "\tTEST FAIL mem count ".$memCount." vs ".scalar(&listSysVMemory($osname))."\n";616return 0;617}618if ($semCount != scalar(&listSysVSemaphores($osname))) {619print "\tTEST FAIL sem count ".$semCount." vs ".scalar(&listSysVSemaphores($osname))."\n";620return 0;621}622623$cmd = "unlink ".$semfile;624`$cmd`;625$cmd = "unlink ".$memfile;626`$cmd`;627628print "\tTEST PASS\n";629return 1;630631}632633sub Test8634{635my ($osname, $cmd, $numprocs) = @_;636my @pidList;637my $count = 0;638my $waitedfor=0;639my @semaphoreListBefore;640my @semaphoreListAfter;641my $ITER;642my $ITER2;643644print "Test 8: when no permissions to access a semaphore make sure do not we create a new one.\n";645#system("ipcs");646@semaphoreListBefore = &listSysVSemaphores($osname);647`$cmd`;648@semaphoreListAfter = &listSysVSemaphores($osname);649650#we expect one semaphore to be created651if (scalar(@semaphoreListBefore)+1 != scalar(@semaphoreListAfter)) {652print "\tTEST FAIL (bad sem count)\n";653return 0;654}655656#find the newly created semaphore657my $semid = 0;658BREAK_FROM_LOOP: {659foreach $ITER (@semaphoreListAfter) {660my $found = 0;661foreach $ITER2 (@semaphoreListBefore) {662if ($ITER == $ITER2) {663$found = $ITER;664}665}666if ($found == 0) {667$semid = $ITER;668#this equivalent to a break statement in C ...669last BREAK_FROM_LOOP;670}671}672}673674if ($semid == 0) {675print "\tTEST FAIL (not found)\n";676return 0;677}678679680my $statInfo;681semctl($semid, 0, IPC_STAT, $statInfo);682my @mdata = unpack("l*",$statInfo);683684#my $key = @mdata[0];685#my $ uid = @mdata[1];686#my $gid = @mdata[2];687#my $cuid = @mdata[3];688#my $cgid = @mdata[4];689#my $mode = @mdata[5];690#my $seq = @mdata[6];691692#set permissions to O000 (no permissions) ...693my $oldperm = @mdata[$semPermIndex];694print "\tChange permissions from ".sprintf("O%o",$oldperm)." to ".$READONLY."\n";695@mdata[$semPermIndex] = $READONLY;696$statInfo = pack("l*",@mdata);697semctl($semid, 0, IPC_SET, $statInfo);698699#system("ipcs");700@semaphoreListBefore = @semaphoreListAfter;701#print $cmd."\n";702`$cmd`;703@semaphoreListAfter = &listSysVSemaphores($osname);704#system("ipcs");705706#No new semaphore should be created ... and nothing deleted ...707if (scalar(@semaphoreListBefore) != scalar(@semaphoreListAfter)) {708print "\tTEST FAIL (bad sem count ... before:".scalar(@semaphoreListBefore)." after:".scalar(@semaphoreListAfter).")\n";709return 0;710}711712# Set the permission back here713@mdata[$semPermIndex] = $oldperm;714$statInfo = pack("l*",@mdata);715semctl($semid, 0, IPC_SET, $statInfo) or die('Can not change permissions back');716print "\tTEST PASS\n";717return 1;718719}720721722sub Test9723{724my ($osname, $cmd, $numprocs) = @_;725my @pidList;726my $count = 0;727my $waitedfor=0;728my @memListBefore;729my @memListAfter;730my $ITER;731my $ITER2;732733print "Test 9: when no permissions to access a shared memory make sure we create a new one. ";734print "\n";735736@memListBefore = &listSysVMemory($osname);737`$cmd`;738@memListAfter = &listSysVMemory($osname);739740#we expect one semaphore to be created741if (scalar(@memListBefore)+1 != scalar(@memListAfter)) {742print "\tTEST FAIL (bad sem count)\n";743return 0;744}745746#find the newly created mem747my $shmid = 0;748BREAK_FROM_LOOP: {749foreach $ITER (@memListAfter) {750my $found = 0;751foreach $ITER2 (@memListBefore) {752if ($ITER == $ITER2) {753$found = $ITER;754}755}756if ($found == 0) {757$shmid = $ITER;758#this equivalent to a break statement in C ...759last BREAK_FROM_LOOP;760}761}762}763if ($shmid == 0) {764print "\tTEST FAIL (not found)\n";765return 0;766}767768my $statInfo;769shmctl($shmid, IPC_STAT, $statInfo);770my @mdata = unpack("l*",$statInfo);771772#set permissions to 0400 (no permissions) ...773my $oldperm = @mdata[$shmPermIndex];774print "\tChange permissions from ".sprintf("O%o",$oldperm)." to ".$READONLY."\n";775@mdata[$shmPermIndex] = $READONLY;776$statInfo = pack("l*",@mdata);777shmctl($shmid, IPC_SET, $statInfo);778779780@memListBefore = @memListAfter;781#print $cmd."\n";782#return 0;783my @stdout = `$cmd`;784#print @stdout, "\n";785@memListAfter = &listSysVMemory($osname);786787788# No new memory should be created if current is read only789if (scalar(@memListBefore) != scalar(@memListAfter)) {790print "\tTEST FAIL (bad mem count ... before:".scalar(@memListBefore)." after:".scalar(@memListAfter).")\n";791return 0;792}793794# Set the permission back here795@mdata[$shmPermIndex] = $oldperm;796$statInfo = pack("l*",@mdata);797shmctl($shmid, IPC_SET, $statInfo) or die('Can not change permissions back');798799print "\tTEST PASS\n";800return 1;801802}803804sub Test10805{806my ($osname, $cmd, $destroycmd, $numprocs) = @_;807my @pidList;808my $count = 0;809my $waitedfor=0;810my @memListBefore;811my @memListAfter;812my @semListBefore;813my @semListAfter;814my $ITER;815my $ITER2;816817print "Test 10: Verify a simple case of destroy";818print "\n";819820#821# Create a cache822#823@memListBefore = &listSysVMemory($osname);824@semListBefore = &listSysVSemaphores($osname);825`$cmd`;826@memListAfter = &listSysVMemory($osname);827@semListAfter = &listSysVSemaphores($osname);828829if (scalar(@memListBefore)+1 != scalar(@memListAfter)) {830print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";831return 0;832}833if (scalar(@semListBefore)+1 != scalar(@semListAfter)) {834print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";835return 0;836}837if (&getSemaphoreCntlFile($testcachname) eq "") {838print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";839return 0;840}841if (&getMemoryCntlFile($testcachname) eq "") {842print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";843return 0;844}845846#847# Destroy the cache848#849@memListBefore = &listSysVMemory($osname);850@semListBefore = &listSysVSemaphores($osname);851`$destroycmd`;852@memListAfter = &listSysVMemory($osname);853@semListAfter = &listSysVSemaphores($osname);854855if (scalar(@memListBefore)-1 != scalar(@memListAfter)) {856print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";857return 0;858}859if (scalar(@semListBefore)-1 != scalar(@semListAfter)) {860print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";861return 0;862}863if (&getSemaphoreCntlFile($testcachname) ne "") {864print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." found\n";865return 0;866}867if (&getMemoryCntlFile($testcachname) ne "") {868print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." found\n";869return 0;870}871872print "\tTEST PASS\n";873return 1;874}875876sub Test11877{878my ($osname, $cmd, $destroycmd, $numprocs) = @_;879my @pidList;880my $count = 0;881my $waitedfor=0;882my @memListBefore;883my @memListAfter;884my @semListBefore;885my @semListAfter;886my $ITER;887my $ITER2;888889print "Test 11: Call destroy with read only semaphore";890print "\n";891892#893# Create a cache894#895@memListBefore = &listSysVMemory($osname);896@semListBefore = &listSysVSemaphores($osname);897`$cmd`;898@memListAfter = &listSysVMemory($osname);899@semListAfter = &listSysVSemaphores($osname);900901if (scalar(@memListBefore)+1 != scalar(@memListAfter)) {902print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";903return 0;904}905if (scalar(@semListBefore)+1 != scalar(@semListAfter)) {906print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";907return 0;908}909if (&getSemaphoreCntlFile($testcachname) eq "") {910print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";911return 0;912}913if (&getMemoryCntlFile($testcachname) eq "") {914print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";915return 0;916}917918919#find the newly created semaphore920my $semid = 0;921BREAK_FROM_LOOP: {922foreach $ITER (@semListAfter) {923my $found = 0;924foreach $ITER2 (@semListBefore) {925if ($ITER == $ITER2) {926$found = $ITER;927}928}929if ($found == 0) {930$semid = $ITER;931#this equivalent to a break statement in C ...932last BREAK_FROM_LOOP;933}934}935}936937if ($semid == 0) {938print "\tTEST FAIL (not found)\n";939return 0;940}941942# mod to be read only943my $statInfo;944semctl($semid, 0, IPC_STAT, $statInfo);945my @mdata = unpack("l*",$statInfo);946my $oldperm = @mdata[$semPermIndex];947print "\tChange permissions from ".sprintf("O%o",$oldperm)." to ".$READONLY."\n";948@mdata[$semPermIndex] = $READONLY;949$statInfo = pack("l*",@mdata);950semctl($semid, 0, IPC_SET, $statInfo);951952#953# Destroy the cache954#955@memListBefore = &listSysVMemory($osname);956@semListBefore = &listSysVSemaphores($osname);957`$destroycmd`;958@memListAfter = &listSysVMemory($osname);959@semListAfter = &listSysVSemaphores($osname);960961#NOTE:962# - the vm will not create a new semaphore or shared memory963# - the vm will fail to destroy semaphore but will remove the shared memory964if (scalar(@memListBefore)-1 != scalar(@memListAfter)) {965print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";966return 0;967}968if (scalar(@semListBefore) != scalar(@semListAfter)) {969print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";970return 0;971}972if (&getSemaphoreCntlFile($testcachname) eq "") {973print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";974return 0;975}976if (&getMemoryCntlFile($testcachname) ne "") {977print "\tTEST FAIL shared memory control file ".&getMemoryCntlFile($testcachname)." was not deleted\n";978return 0;979}980981# Set the permission back here982@mdata[$semPermIndex] = $oldperm;983$statInfo = pack("l*",@mdata);984semctl($semid, 0, IPC_SET, $statInfo) or die('Can not change permissions back');985print "\tTEST PASS\n";986return 1;987}988989sub Test12990{991my ($osname, $cmd, $destroycmd, $numprocs) = @_;992my @pidList;993my $count = 0;994my $waitedfor=0;995my @memListBefore;996my @memListAfter;997my @semListBefore;998my @semListAfter;999my $ITER;1000my $ITER2;10011002print "Test 12: Call destroy with read only memory";1003print "\n";10041005#1006# Create a cache1007#1008@memListBefore = &listSysVMemory($osname);1009@semListBefore = &listSysVSemaphores($osname);1010`$cmd`;1011@memListAfter = &listSysVMemory($osname);1012@semListAfter = &listSysVSemaphores($osname);10131014if (scalar(@memListBefore)+1 != scalar(@memListAfter)) {1015print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";1016return 0;1017}1018if (scalar(@semListBefore)+1 != scalar(@semListAfter)) {1019print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";1020return 0;1021}1022if (&getSemaphoreCntlFile($testcachname) eq "") {1023print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";1024return 0;1025}1026if (&getMemoryCntlFile($testcachname) eq "") {1027print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";1028return 0;1029}103010311032#find the newly created semaphore1033my $objid = 0;1034BREAK_FROM_LOOP: {1035foreach $ITER (@memListAfter) {1036my $found = 0;1037foreach $ITER2 (@memListBefore) {1038if ($ITER == $ITER2) {1039$found = $ITER;1040}1041}1042if ($found == 0) {1043$objid = $ITER;1044#this equivalent to a break statement in C ...1045last BREAK_FROM_LOOP;1046}1047}1048}10491050if ($objid == 0) {1051print "\tTEST FAIL (not found)\n";1052return 0;1053}10541055# mod to be read only1056my $statInfo;1057shmctl($objid, IPC_STAT, $statInfo);1058my @mdata = unpack("l*",$statInfo);1059my $oldperm = @mdata[$shmPermIndex];1060print "\tChange permissions from ".sprintf("O%o",$oldperm)." to ".$READONLY."\n";1061@mdata[$shmPermIndex] = $READONLY;1062$statInfo = pack("l*",@mdata);1063shmctl($objid, IPC_SET, $statInfo);10641065#1066# Destroy the cache1067#1068@memListBefore = &listSysVMemory($osname);1069@semListBefore = &listSysVSemaphores($osname);1070print "\t".$destroycmd."\n";1071`$destroycmd`;1072@memListAfter = &listSysVMemory($osname);1073@semListAfter = &listSysVSemaphores($osname);10741075#NOTE:1076# -1077if (scalar(@memListBefore) != scalar(@memListAfter)) {1078print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";1079return 0;1080}1081if (scalar(@semListBefore)-1 != scalar(@semListAfter)) {1082print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";1083return 0;1084}1085if (&getSemaphoreCntlFile($testcachname) ne "") {1086print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." found\n";1087return 0;1088}1089if (&getMemoryCntlFile($testcachname) eq "") {1090print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";1091return 0;1092}10931094# Set the permission back here1095@mdata[$shmPermIndex] = $oldperm;1096$statInfo = pack("l*",@mdata);1097shmctl($objid, IPC_SET, $statInfo) or die('Can not change permissions back');1098print "\tTEST PASS\n";1099return 1;1100}11011102sub Test131103{1104my ($osname, $cmd, $destroycmd, $numprocs) = @_;1105my @pidList;1106my $count = 0;1107my $waitedfor=0;1108my @memListBefore;1109my @memListAfter;1110my @semListBefore;1111my @semListAfter;1112my $ITER;1113my $ITER2;1114my $chmodcmd;11151116print "Test 13: Verify a simple case of destroy with readonly control files";1117print "\n";11181119#1120# Create a cache1121#1122@memListBefore = &listSysVMemory($osname);1123@semListBefore = &listSysVSemaphores($osname);1124`$cmd`;1125@memListAfter = &listSysVMemory($osname);1126@semListAfter = &listSysVSemaphores($osname);11271128if (scalar(@memListBefore)+1 != scalar(@memListAfter)) {1129print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";1130return 0;1131}1132if (scalar(@semListBefore)+1 != scalar(@semListAfter)) {1133print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";1134return 0;1135}1136if (&getSemaphoreCntlFile($testcachname) eq "") {1137print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";1138return 0;1139}1140if (&getMemoryCntlFile($testcachname) eq "") {1141print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";1142return 0;1143}114411451146my $semfile = &getSemaphoreCntlFile($testcachname);1147my $memfile = &getMemoryCntlFile($testcachname);11481149$chmodcmd = "chmod a-wx ".$semfile;1150`$chmodcmd`;1151$chmodcmd = "chmod a-wx ".$memfile;1152`$chmodcmd`;1153#system("ls -la /tmp/javasharedresources/");11541155#1156# Destroy the cache1157#1158@memListBefore = &listSysVMemory($osname);1159@semListBefore = &listSysVSemaphores($osname);1160`$destroycmd`;1161@memListAfter = &listSysVMemory($osname);1162@semListAfter = &listSysVSemaphores($osname);11631164#1165# Destroy will kill control files regardless if they are readonly1166#1167if (scalar(@memListBefore)-1 != scalar(@memListAfter)) {1168print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";1169return 0;1170}1171if (scalar(@semListBefore)-1 != scalar(@semListAfter)) {1172print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";1173return 0;1174}1175if (&getSemaphoreCntlFile($testcachname) eq "") {1176print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";1177return 0;1178}1179if (&getMemoryCntlFile($testcachname) eq "") {1180print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";1181return 0;1182}11831184$cmd = "unlink ".$semfile;1185`$cmd`;1186$cmd = "unlink ".$memfile;1187`$cmd`;11881189print "\tTEST PASS\n";1190return 1;1191}119211931194sub Test141195{1196my ($osname, $cmd, $numprocs) = @_;1197my @pidList;1198my $count = 0;1199my $waitedfor=0;1200my @memListBefore;1201my @memListAfter;1202my @semListBefore;1203my @semListAfter;1204my $ITER;1205my $ITER2;1206my $chmodcmd;12071208print "Test 14: Verify a simple case of start up with readonly control files, readonly memory";1209print "\n";12101211#1212# Create a cache1213#1214@memListBefore = &listSysVMemory($osname);1215@semListBefore = &listSysVSemaphores($osname);1216`$cmd`;1217@memListAfter = &listSysVMemory($osname);1218@semListAfter = &listSysVSemaphores($osname);12191220if (scalar(@memListBefore)+1 != scalar(@memListAfter)) {1221print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";1222return 0;1223}1224if (scalar(@semListBefore)+1 != scalar(@semListAfter)) {1225print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";1226return 0;1227}1228if (&getSemaphoreCntlFile($testcachname) eq "") {1229print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";1230return 0;1231}1232if (&getMemoryCntlFile($testcachname) eq "") {1233print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";1234return 0;1235}12361237#find the newly created shared memory1238my $objid = 0;1239BREAK_FROM_LOOP: {1240foreach $ITER (@memListAfter) {1241my $found = 0;1242foreach $ITER2 (@memListBefore) {1243if ($ITER == $ITER2) {1244$found = $ITER;1245}1246}1247if ($found == 0) {1248$objid = $ITER;1249#this equivalent to a break statement in C ...1250last BREAK_FROM_LOOP;1251}1252}1253}12541255if ($objid == 0) {1256print "\tTEST FAIL (not found)\n";1257return 0;1258}12591260# mod to be read only1261my $statInfo;1262shmctl($objid, IPC_STAT, $statInfo);1263my @mdata = unpack("l*",$statInfo);1264my $oldperm = @mdata[$shmPermIndex];1265print "\tChange permissions from ".sprintf("O%o",$oldperm)." to ".$READONLY."\n";1266@mdata[$shmPermIndex] = $READONLY;1267$statInfo = pack("l*",@mdata);1268shmctl($objid, IPC_SET, $statInfo);12691270my $semfile = &getSemaphoreCntlFile($testcachname);1271my $memfile = &getMemoryCntlFile($testcachname);12721273$chmodcmd = "chmod a-wx ".$semfile;1274`$chmodcmd`;1275$chmodcmd = "chmod a-wx ".$memfile;1276`$chmodcmd`;1277#system("ls -la /tmp/javasharedresources/");12781279#1280# Open the cache1281#1282@memListBefore = &listSysVMemory($osname);1283@semListBefore = &listSysVSemaphores($osname);1284`$cmd`;1285@memListAfter = &listSysVMemory($osname);1286@semListAfter = &listSysVSemaphores($osname);12871288#1289# Open of the cache will cause 'permission denied' on control file and memory ...1290# OSCache.cpp will then attempt to delete it ... only the semaphore will be deleted1291#1292if (scalar(@memListBefore) != scalar(@memListAfter)) {1293print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";1294return 0;1295}1296if (scalar(@semListBefore)-1 != scalar(@semListAfter)) {1297print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";1298return 0;1299}1300if (&getSemaphoreCntlFile($testcachname) eq "") {1301print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";1302return 0;1303}1304if (&getMemoryCntlFile($testcachname) eq "") {1305print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";1306return 0;1307}13081309# Set the permission back here1310@mdata[$shmPermIndex] = $oldperm;1311$statInfo = pack("l*",@mdata);1312shmctl($objid, IPC_SET, $statInfo) or die('Can not change permissions back');1313$chmodcmd = "chmod a+w ".$semfile;1314`$chmodcmd`;1315$chmodcmd = "chmod a+w ".$memfile;1316`$chmodcmd`;13171318$cmd = "unlink ".$semfile;1319`$cmd`;1320$cmd = "unlink ".$memfile;1321`$cmd`;13221323print "\tTEST PASS\n";1324return 1;1325}13261327sub Test151328{1329my ($osname, $cmd, $cmd2, $numprocs) = @_;1330my @pidList;1331my $count = 0;1332my $waitedfor=0;1333my @memListBefore;1334my @memListAfter;1335my @semListBefore;1336my @semListAfter;1337my $ITER;1338my $ITER2;1339my $chmodcmd;13401341print "Test 15: Same test as 14 ... but we run 2nd command with non fatal and check stdout/err for dump of vm version info ...";1342print "\n";13431344#1345# Create a cache1346#1347@memListBefore = &listSysVMemory($osname);1348@semListBefore = &listSysVSemaphores($osname);1349`$cmd`;1350@memListAfter = &listSysVMemory($osname);1351@semListAfter = &listSysVSemaphores($osname);13521353if (scalar(@memListBefore)+1 != scalar(@memListAfter)) {1354print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";1355return 0;1356}1357if (scalar(@semListBefore)+1 != scalar(@semListAfter)) {1358print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";1359return 0;1360}1361if (&getSemaphoreCntlFile($testcachname) eq "") {1362print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";1363return 0;1364}1365if (&getMemoryCntlFile($testcachname) eq "") {1366print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";1367return 0;1368}13691370#find the newly created semaphore1371my $objid = 0;1372BREAK_FROM_LOOP: {1373foreach $ITER (@memListAfter) {1374my $found = 0;1375foreach $ITER2 (@memListBefore) {1376if ($ITER == $ITER2) {1377$found = $ITER;1378}1379}1380if ($found == 0) {1381$objid = $ITER;1382#this equivalent to a break statement in C ...1383last BREAK_FROM_LOOP;1384}1385}1386}13871388if ($objid == 0) {1389print "\tTEST FAIL (not found)\n";1390return 0;1391}13921393# mod to be read only1394my $statInfo;1395shmctl($objid, IPC_STAT, $statInfo);1396my @mdata = unpack("l*",$statInfo);1397my $oldperm = @mdata[$shmPermIndex];1398print "\tChange permissions from ".sprintf("O%o",$oldperm)." to ".$READONLY."\n";1399@mdata[$shmPermIndex] = $READONLY;1400$statInfo = pack("l*",@mdata);1401shmctl($objid, IPC_SET, $statInfo);14021403my $semfile = &getSemaphoreCntlFile($testcachname);1404my $memfile = &getMemoryCntlFile($testcachname);14051406$chmodcmd = "chmod a-wx ".$semfile;1407`$chmodcmd`;1408$chmodcmd = "chmod a-wx ".$memfile;1409`$chmodcmd`;1410#system("ls -la /tmp/javasharedresources/");14111412#1413# Open the cache1414#1415#system("ipcs");1416@memListBefore = &listSysVMemory($osname);1417@semListBefore = &listSysVSemaphores($osname);1418#print $cmd2."\n";1419my @stdout = `$cmd2`;1420#print @stdout,"\n";1421#system("ipcs");1422@memListAfter = &listSysVMemory($osname);1423@semListAfter = &listSysVSemaphores($osname);14241425my $found = 0;1426foreach $ITER (@stdout) {1427if ($ITER =~ /java version/) {1428$found = 1;1429}1430}1431if ($found == 0) {1432print "\tTEST FAIL success string not found in output\n";1433return 0;1434}14351436#1437# Open of the cache will cause 'permission denied' on control file and memory ...1438# OSCache.cpp will then attempt to delete it ... only the semaphore will be deleted1439#1440if (scalar(@memListBefore) != scalar(@memListAfter)) {1441print "\tTEST FAIL(2) (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";1442return 0;1443}1444#not minus one b/c retries readonly with nonfatal1445if (scalar(@semListBefore) != scalar(@semListAfter)) {1446print "\tTEST FAIL(2) (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";1447return 0;1448}1449if (&getSemaphoreCntlFile($testcachname) eq "") {1450print "\tTEST FAIL(2) file ".&getSemaphoreCntlFile($testcachname)." not found\n";1451return 0;1452}1453if (&getMemoryCntlFile($testcachname) eq "") {1454print "\tTEST FAIL(2) file ".&getMemoryCntlFile($testcachname)." not found\n";1455return 0;1456}14571458# Set the permission back here1459@mdata[$shmPermIndex] = $oldperm;1460$statInfo = pack("l*",@mdata);1461shmctl($objid, IPC_SET, $statInfo) or die('Can not change permissions back');1462#semaphore control file should be deleted1463#$chmodcmd = "chmod a+w ".$semfile;1464#`$chmodcmd`;1465$chmodcmd = "chmod a+w ".$memfile;1466`$chmodcmd`;14671468$cmd = "unlink ".$semfile;1469`$cmd`;1470$cmd = "unlink ".$memfile;1471`$cmd`;14721473print "\tTEST PASS\n";1474return 1;1475}14761477sub Test161478{1479my ($osname, $cmd, $numprocs) = @_;1480my @pidList;1481my $count = 0;1482my $waitedfor=0;1483my $chmodcmd;148414851486print "Test 16: Same as test 7 but with multiple threads (its a tinch random).\n";1487`$cmd`;1488my $semfile = &getSemaphoreCntlFile($testcachname);1489my $memfile = &getMemoryCntlFile($testcachname);14901491&cleanupSysV($osname,$verbose);14921493my $semCount = scalar(&listSysVSemaphores($osname));1494my $memCount = scalar(&listSysVMemory($osname));14951496for ($count = 0; $count < $numprocs; $count++) {1497$chmodcmd = "chmod a-wx ".$semfile . " 2>&1";1498`$chmodcmd`;1499$chmodcmd = "chmod a-wx ".$memfile . " 2>&1";1500`$chmodcmd`;1501&cleanupSysV($osname,$verbose);1502my $pid = &forkAndRunInBackGround($cmd);1503push(@pidList, $pid);1504}15051506while (wait() != -1) {1507$waitedfor = $waitedfor + 1;1508}1509printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");15101511#$chmodcmd = "chmod ug+w ".$semfile;1512#`$chmodcmd`;1513#$chmodcmd = "chmod ug+w ".$memfile;1514#`$chmodcmd`;15151516#we can't create new sysv obj if cntrl file is readonly1517if ($memCount != scalar(&listSysVMemory($osname))) {1518print "\tTEST FAIL mem count ".$memCount." vs ".scalar(&listSysVMemory($osname))."\n";1519return 0;1520}1521if ($semCount != scalar(&listSysVSemaphores($osname))) {1522print "\tTEST FAIL sem count ".$semCount." vs ".scalar(&listSysVSemaphores($osname))."\n";1523return 0;1524}15251526$cmd = "unlink ".$semfile;1527`$cmd`;1528$cmd = "unlink ".$memfile;1529`$cmd`;15301531print "\tTEST PASS (we wrote a new control file)\n";1532return 1;15331534}15351536sub Test171537{1538my ($osname, $javabin, $numprocs) = @_;1539my @pidList;1540my $count = 0;1541my $waitedfor=0;1542my $cacheDirectory = "/tmp/";1543my $cachename = "testSCSysVTest17num";15441545print "Test 17: Run ".$numprocs." JVMs and create same number of caches. The try again and make sure no new ones show up\n";15461547&cleanupSysV($osname,$verbose);15481549for ($count = 0; $count < $numprocs; $count++) {1550my $cmd = $javabin . " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$cachename.$count." -version ". " 2>&1";;1551my $pid = &forkAndRunInBackGround($cmd);1552push(@pidList, $pid);1553}15541555while (wait() != -1) {1556$waitedfor = $waitedfor + 1;1557}1558printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");15591560my @memList = &listSysVMemory($osname);1561my @semList = &listSysVSemaphores($osname);15621563if (scalar(@memList) == 0) {1564print "\tTEST FAIL mem count ".scalar(@memList)." vs 0"."\n";1565return 0;1566}1567if (scalar(@semList) == 0) {1568print "\tTEST FAIL sem count ".scalar(@semList)." vs 0"."\n";1569return 0;1570}15711572for ($count = 0; $count < $numprocs; $count++) {1573my $cmd = $javabin . " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$cachename.$count." -version ". " 2>&1";1574#print $cmd."\n";1575my $pid = &forkAndRunInBackGround($cmd);1576push(@pidList, $pid);1577}15781579$waitedfor = 0;1580while (wait() != -1) {1581$waitedfor = $waitedfor + 1;1582}1583printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");15841585my $cleanupCmd = "rm -f /tmp/javasharedresources/*".$cachename."*";1586`$cleanupCmd`;15871588if (scalar(@memList) != scalar(&listSysVMemory($osname))) {1589print "\tTEST FAIL mem count ".scalar(@memList)." vs ".scalar(&listSysVMemory($osname))."\n";1590return 0;1591}15921593if (scalar(@semList) != scalar(&listSysVSemaphores($osname))) {1594print "\tTEST FAIL sem count ".scalar(@semList)." vs ".scalar(&listSysVSemaphores($osname))."\n";1595return 0;1596}15971598print "\tTEST PASS\n";1599print "\t\tmem count ".scalar(@memList)."\n";1600print "\t\tsem count ".scalar(@semList)."\n";16011602return 1;16031604}16051606sub Test181607{1608my ($osname, $javabin, $numprocs) = @_;1609my @pidList;1610my $count = 0;1611my $waitedfor=0;1612my $cacheDirectory = "/tmp/";1613my $cachename = "testSCSysVTest18num";16141615print "Test 18: Run ".$numprocs." JVMs and create same number of caches. Delete the control files and try again. \n";16161617&cleanupSysV($osname,$verbose);16181619for ($count = 0; $count < $numprocs; $count++) {1620my $cmd = $javabin . " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$cachename.$count." -version ". " 2>&1";;1621my $pid = &forkAndRunInBackGround($cmd);1622push(@pidList, $pid);1623}16241625while (wait() != -1) {1626$waitedfor = $waitedfor + 1;1627}1628printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");16291630#my @stdout = `ipcs`;1631#print @stdout,"\n";16321633my @memList = &listSysVMemory($osname);1634my @semList = &listSysVSemaphores($osname);1635my $cleanupCmd = "rm -f /tmp/javasharedresources/*".$cachename."*";1636`$cleanupCmd`;16371638for ($count = 0; $count < $numprocs; $count++) {1639my $cmd = $javabin . " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$cachename.$count." -version ". " 2>&1";;1640my $pid = &forkAndRunInBackGround($cmd);1641push(@pidList, $pid);1642#print $cmd."\n";1643#my @stdout = `$cmd`;1644#print @stdout,"\n";16451646}16471648$waitedfor = 0;1649while (wait() != -1) {1650$waitedfor = $waitedfor + 1;1651}1652printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");16531654#my @stdout = `ipcs`;1655#print @stdout,"\n";16561657my $cleanupCmd = "rm -f /tmp/javasharedresources/*".$cachename."*";1658`$cleanupCmd`;16591660if ((scalar(@memList)+$numprocs) != scalar(&listSysVMemory($osname))) {1661print "\tTEST FAIL mem count ".scalar(@memList)." vs ".scalar(&listSysVMemory($osname))."\n";1662return 0;1663}16641665if ((scalar(@semList)+$numprocs) != scalar(&listSysVSemaphores($osname))) {1666print "\tTEST FAIL sem count ".scalar(@semList)." vs ".scalar(&listSysVSemaphores($osname))."\n";1667return 0;1668}16691670print "\tTEST PASS\n";1671print "\t\tmem count ".scalar(&listSysVMemory($osname))."\n";1672print "\t\tsem count ".scalar(&listSysVSemaphores($osname))."\n";16731674return 1;16751676}16771678sub Test191679{1680my ($osname, $cmd, $numprocs) = @_;1681my @pidList;1682my $count = 0;1683my $waitedfor=0;1684my $touchcmd;168516861687print "Test 19: Test non empty corrupted control files.\n";1688`$cmd`;1689my $semfile = &getSemaphoreCntlFile($testcachname);1690my $memfile = &getMemoryCntlFile($testcachname);1691&removeCntrlFiles($testcachname);16921693$touchcmd = "echo \"abcdefghijklmnopqrstuvwxyz\" > ".$semfile;1694`$touchcmd`;1695$touchcmd = "echo \"abcdefghijklmnopqrstuvwxyz\" > ".$memfile;1696`$touchcmd`;16971698my $semCount = scalar(&listSysVSemaphores($osname));1699my $memCount = scalar(&listSysVMemory($osname));1700#printf $cmd."\n";1701my @stdout = `$cmd`;1702#printf @stdout,"\n";1703if ($memCount == scalar(&listSysVMemory($osname))) {1704print "\tTEST FAIL mem count ".$memCount."\n";1705return 0;1706}1707if ($semCount == scalar(&listSysVSemaphores($osname))) {1708print "\tTEST FAIL sem count ".$semCount." vs ".scalar(&listSysVSemaphores($osname))."\n";1709return 0;1710}1711print "\tTEST PASS\n";1712return 1;17131714}17151716sub Test201717{1718my ($osname, $javabin, $numprocs) = @_;1719my @pidList;1720my $count = 0;1721my $waitedfor=0;1722my $cacheDirectory = "/tmp/";1723my $cachename = "testSCSysVTest20num";17241725print "Test 20: Run ".$numprocs." JVMs and create same number of caches. Delete the ipcs objs and try again. \n";17261727&cleanupSysV($osname,$verbose);17281729for ($count = 0; $count < $numprocs; $count++) {1730my $cmd = $javabin . " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$cachename.$count." -version &> ./out.txt";1731my $cmd = $javabin . " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$cachename.$count." -version";1732my $pid = &forkAndRunInBackGround($cmd);1733push(@pidList, $pid);1734}17351736while (wait() != -1) {1737$waitedfor = $waitedfor + 1;1738}1739printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");17401741my @memList = &listSysVMemory($osname);1742my @semList = &listSysVSemaphores($osname);1743&cleanupSysV($osname,$verbose);174417451746for ($count = 0; $count < $numprocs; $count++) {1747my $cmd = $javabin . " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$cachename.$count." -version &> ./out.txt";1748my $pid = &forkAndRunInBackGround($cmd);1749push(@pidList, $pid);1750}17511752$waitedfor = 0;1753while (wait() != -1) {1754$waitedfor = $waitedfor + 1;1755}1756printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");17571758my $cleanupCmd = "rm -f /tmp/javasharedresources/*".$cachename."*";1759`$cleanupCmd`;17601761if (scalar(@memList) != scalar(&listSysVMemory($osname))) {1762print "\tTEST FAIL mem count ".scalar(@memList)." vs ".scalar(&listSysVMemory($osname))."\n";1763return 0;1764}17651766if (scalar(@semList) != scalar(&listSysVSemaphores($osname))) {1767print "\tTEST FAIL sem count ".scalar(@semList)." vs ".scalar(&listSysVSemaphores($osname))."\n";1768return 0;1769}17701771print "\tTEST PASS\n";1772print "\t\tmem count ".scalar(&listSysVMemory($osname))."\n";1773print "\t\tsem count ".scalar(&listSysVSemaphores($osname))."\n";17741775return 1;17761777}17781779sub Test211780{1781my ($osname, $cmd, $numprocs) = @_;1782my @pidList;1783my $count = 0;1784my $waitedfor=0;1785my $chmodcmd;1786my $ITER;17871788print "Test 21: Check semid in memory is valid ... it should not be!\n";1789`$cmd`;1790my $semfile = &getSemaphoreCntlFile($testcachname);1791my $memfile = &getMemoryCntlFile($testcachname);17921793&cleanupSysVSem($osname,$verbose);17941795my @stdout = `$cmd`;1796#print @stdout,"\n";17971798my $found = 0;1799foreach $ITER (@stdout) {1800if ($ITER =~ /different semaphore/) {1801$found = 1;1802}1803}1804if ($found == 0) {1805print "\tTEST FAIL success string not found in output\n";1806return 0;1807}18081809my $semCount = scalar(&listSysVSemaphores($osname));1810my $memCount = scalar(&listSysVMemory($osname));18111812# if semid mismatch is found the shared memory is destroyed ...1813if ($memCount != scalar(&listSysVMemory($osname))) {1814print "\tTEST FAIL mem count ".$memCount." vs ".scalar(&listSysVMemory($osname))."\n";1815return 0;1816}1817if ($semCount != scalar(&listSysVSemaphores($osname))) {1818print "\tTEST FAIL sem count ".$semCount." vs ".scalar(&listSysVSemaphores($osname))."\n";1819return 0;1820}1821print "\tTEST PASS\n";1822return 1;1823}18241825sub Test221826{1827my ($osname, $cmd) = @_;1828my $chmodcmd;18291830print "Test 22: Check that JVM removes read-only control files having modlevel such that major level=0 and minor level=1.\n";1831`$cmd`;1832my $semfile = &getSemaphoreCntlFile($testcachname);1833my $memfile = &getMemoryCntlFile($testcachname);18341835&cleanupSysVSem($osname,$verbose);1836&cleanupSysVMem($osname,$verbose);18371838my $semCount = scalar(&listSysVSemaphores($osname));1839my $memCount = scalar(&listSysVMemory($osname));18401841# update control files such that major level=0 and minor level=11842&updateSemControlFileModLevel($semfile);1843&updateShmControlFileModLevel($memfile);18441845# make control files read-only1846$chmodcmd = "chmod a-wx ".$semfile;1847`$chmodcmd`;1848$chmodcmd = "chmod a-wx ".$memfile;1849`$chmodcmd`;18501851# Using read-only control files having major level=0 and minor level=1 without any SysV objects1852# will cause JVM to remove the control files and recreate new shared class cache.1853`$cmd`;18541855if ($memCount+1 != scalar(&listSysVMemory($osname))) {1856print "\tTEST FAIL mem count expected ".($memCount+1)." vs found ".scalar(&listSysVMemory($osname))."\n";1857return 0;1858}1859if ($semCount+1 != scalar(&listSysVSemaphores($osname))) {1860print "\tTEST FAIL sem count expected ".($semCount+1)." vs found ".scalar(&listSysVSemaphores($osname))."\n";1861return 0;1862}18631864`$destroycmd`;18651866print "\tTEST PASS\n";1867return 1;1868}18691870#-----------------------------------------------------1871# listFilesInFolder()1872#-----------------------------------------------------1873sub listFilesInFolder1874{1875my ($folder) = @_;1876my @FILES;1877opendir(DIR, $folder) or return @FILES;1878@FILES= readdir(DIR);1879closedir(DIR) or die ("can not close dir");1880return @FILES;1881}18821883#-----------------------------------------------------1884# forkAndRunInBackGround()1885#-----------------------------------------------------1886sub forkAndRunInBackGround1887{1888my ($cmd) = @_;1889my $child_pid;1890if (!defined($child_pid = fork())) {1891die "cannot fork: $!";1892} elsif ($child_pid) {1893return $child_pid;1894} else {1895`$cmd`;1896exit 0;1897}1898}18991900#-----------------------------------------------------1901# cleanupSysV()1902#-----------------------------------------------------1903sub cleanupSysV1904{1905my ($osname, $verbose) = @_;1906&cleanupSysVSem($osname,$verbose);1907&cleanupSysVMem($osname,$verbose);1908}19091910#-----------------------------------------------------1911# cleanupSysV()1912#-----------------------------------------------------1913sub cleanupSysVSem1914{1915my ($osname,$verbose) = @_;1916my @semaphoreList;1917my @memoryList;1918my $ITER;19191920@semaphoreList = &listSysVSemaphores($osname);1921if ($verbose == 1) {1922print "Semaphores Being Removed: ".scalar(@semaphoreList)."\n";1923}1924foreach $ITER (@semaphoreList) {1925my $cmd = "ipcrm -s " . $ITER . " 2>&1";1926if ($verbose == 1) {1927print "\t".$cmd."\n";1928}1929`$cmd`;1930}1931}19321933#-----------------------------------------------------1934# cleanupSysV()1935#-----------------------------------------------------1936sub cleanupSysVMem1937{1938my ($osname,$verbose) = @_;1939my @memoryList;1940my $ITER;19411942@memoryList = &listSysVMemory($osname);1943if ($verbose == 1) {1944print "Shared Memory Being Removed: ".scalar(@memoryList)."\n";1945}1946foreach $ITER (@memoryList) {1947my $cmd = "ipcrm -m " . $ITER . " 2>&1";1948if ($verbose == 1) {1949print "\t".$cmd."\n";1950}1951`$cmd`;1952}1953}19541955#-----------------------------------------------------1956# listSysVSemaphores()1957#-----------------------------------------------------1958sub listSysVSemaphores1959{1960my $osname = $_[0];1961my @retval;1962my $semaphoreProjid = "(0x81|0x81|0x82|0x83|0x84|0x85|0x86|0x87|0x88|0x89|0x8a|0x8b|0x8c|0x8d|0x8e|0x8f|0x90|0x91|0x92|0x93|0x94)";1963my $memoryProjid = "(0x61|0x61|0x62|0x63|0x64|0x65|0x66|0x67|0x68|0x69|0x6a|0x6b|0x6c|0x6d|0x6e|0x6f|0x70|0x71|0x72|0x73|0x74)";1964my $keyindex = 0;1965my $idindex = 1;1966my $ownerindex = 2;19671968my @stdoutvar = ();1969my $iter = "";1970my $foundSemaphoreHeader = 0;1971my $foundMemoryHeader = 0;19721973my $memsremoved=0;1974my $semsremoved=0;19751976if ($osname =~ /zos/)1977{1978$keyindex=2;1979$idindex=1;1980$ownerindex=4;1981}19821983if ($osname =~ /aix/)1984{1985$keyindex=2;1986$idindex=1;1987$ownerindex=4;1988}198919901991#1992# GET LIST OF SEMAPHORES:1993# - Call ipcs and store stdout in a local variable.1994# - If the command fails we exit ASAP1995#1996@stdoutvar = `ipcs -s` or die("Error: could not execute ipcs!");199719981999$iter = "";2000$foundSemaphoreHeader = 0;2001$foundMemoryHeader = 0;2002foreach $iter (@stdoutvar) {20032004if ($iter =~ /Semaphore/) {2005$foundSemaphoreHeader=1;2006}2007if (($iter =~ /$semaphoreProjid/) && ($foundSemaphoreHeader==1)) {2008#remove any sequence of whitespace and insert a :2009$iter =~s/[\s]+/:/g;20102011#split the string around :2012my @vals = split(/:/,$iter);20132014#we expect 3 entries in this row ... the 1st three are kei,id,owner ...2015#the rest are don't cares ...2016if (@vals<3) {2017die("ipcs did not return expected output");2018}2019my $key = $vals[$keyindex];2020my $id = $vals[$idindex];2021my $owner = $vals[$ownerindex];2022push(@retval,$id);2023}2024}2025return @retval;2026}202720282029#-----------------------------------------------------2030# listSysVMemory()2031#-----------------------------------------------------2032sub listSysVMemory2033{2034my $osname = $_[0];2035my @retval;2036my $semaphoreProjid = "(0x81|0x81|0x82|0x83|0x84|0x85|0x86|0x87|0x88|0x89|0x8a|0x8b|0x8c|0x8d|0x8e|0x8f|0x90|0x91|0x92|0x93|0x94)";2037my $memoryProjid = "(0x61|0x61|0x62|0x63|0x64|0x65|0x66|0x67|0x68|0x69|0x6a|0x6b|0x6c|0x6d|0x6e|0x6f|0x70|0x71|0x72|0x73|0x74)";20382039my $keyindex = 0;2040my $idindex = 1;2041my $ownerindex = 2;20422043my @stdoutvar = ();2044my $iter = "";2045my $foundHeader = 0;20462047my $memsremoved=0;2048my $semsremoved=0;20492050if ($osname =~ /zos/)2051{2052$keyindex=2;2053$idindex=1;2054$ownerindex=4;2055}20562057if ($osname =~ /aix/)2058{2059$keyindex=2;2060$idindex=1;2061$ownerindex=4;2062}206320642065#2066# GET LIST OF MEMS:2067# - Call ipcs and store stdout in a local variable.2068# - If the command fails we exit ASAP2069#2070@stdoutvar = `ipcs -m` or die("Error: could not execute ipcs!");207120722073$iter = "";2074$foundHeader = 0;2075foreach $iter (@stdoutvar) {20762077if ($iter =~ /Memory/) {2078$foundHeader=1;2079}2080if (($iter =~ /$memoryProjid/) && ($foundHeader==1)) {2081#remove any sequence of whitespace and insert a :2082$iter =~s/[\s]+/:/g;20832084#split the string around :2085my @vals = split(/:/,$iter);20862087#we expect 3 entries in this row ... the 1st three are kei,id,owner ...2088#the rest are don't cares ...2089if (@vals<3) {2090die("ipcs did not return expected output");2091}2092my $key = $vals[$keyindex];2093my $id = $vals[$idindex];2094my $owner = $vals[$ownerindex];2095push(@retval,$id);2096}2097}2098return @retval;2099}21002101sub getIPCObjPermIndex2102{2103my $osname = $_[0];2104if ($osname =~ /zos/)2105{2106return 4;2107}21082109if ($osname =~ /aix/)2110{2111return 4;2112}2113return 5;2114}21152116#-----------------------------------------------------2117# updateSemControlFileModLevel() - updates the modlevel of control file to major level=0 and minor level=1.2118# Such readonly control files can be unlinked by JVM which creates control files with higher modlevel.2119#-----------------------------------------------------2120sub updateSemControlFileModLevel2121{2122my ($controlFile) = @_;2123my $modlevel;2124my $oldMajorLevel = 0;2125my $oldMinorLevel = 1;2126my $modLevelOffset = 4; # modlevel in semaphore control file is at offset 421272128open my $fh, '+<', $controlFile or die("failed to open semaphore control file".$controlFile."\n");21292130$modlevel = ($oldMajorLevel << 16) | $oldMinorLevel;2131$modlevel = pack("I", $modlevel);2132sysseek($fh, $modLevelOffset, SEEK_SET);2133syswrite($fh, $modlevel) == 4 or die("failed to update semaphore control file".$controlFile."\n");2134close $fh;2135return 0;2136}21372138#-----------------------------------------------------2139# updateShmControlFileModLevel() - updates the modlevel of control file to major level=0 and minor level=1.2140# Such readonly control files can be unlinked by JVM which creates control files with higher modlevel.2141#-----------------------------------------------------2142sub updateShmControlFileModLevel2143{2144my ($controlFile) = @_;2145my $modlevel;2146my $oldMajorLevel = 0;2147my $oldMinorLevel = 1;2148my $modLevelOffset = 4; # modlevel in shared memory control file is at offset 42149my $majorLevelMask = 0xFFFF0000;21502151open my $fh, '+<', $controlFile or die("failed to open shared memory control file".$controlFile."\n");21522153$modlevel = ($oldMajorLevel << 16) | $oldMinorLevel;2154$modlevel = pack("I", $modlevel);2155sysseek($fh, $modLevelOffset, SEEK_SET);2156syswrite($fh, $modlevel) == 4 or die("failed to update shared memory control file".$controlFile."\n");2157close $fh;2158return 0;2159}216021612162