Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/VM_Test/SharedClassesSysVTesting/testSC_SysV_Java7_Tests.pl
6004 views
1
#!/usr/bin/perl
2
##############################################################################
3
# Copyright (c) 2016, 2019 IBM Corp. and others
4
#
5
# This program and the accompanying materials are made available under
6
# the terms of the Eclipse Public License 2.0 which accompanies this
7
# distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
# or the Apache License, Version 2.0 which accompanies this distribution and
9
# is available at https://www.apache.org/licenses/LICENSE-2.0.
10
#
11
# This Source Code may also be made available under the following
12
# Secondary Licenses when the conditions for such availability set
13
# forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
# General Public License, version 2 with the GNU Classpath
15
# Exception [1] and GNU General Public License, version 2 with the
16
# OpenJDK Assembly Exception [2].
17
#
18
# [1] https://www.gnu.org/software/classpath/license.html
19
# [2] http://openjdk.java.net/legal/assembly-exception.html
20
#
21
# 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-exception
22
##############################################################################
23
24
use strict;
25
use IPC::SysV qw(IPC_STAT IPC_SET);
26
use Fcntl qw(SEEK_SET);
27
28
#
29
# FWD DECLARES
30
#
31
sub cleanupSysV;
32
sub cleanupSysVMem;
33
sub cleanupSysVSem;
34
sub listSysVSemaphores;
35
sub listSysVMemory;
36
sub forkAndRunInBackGround;
37
sub listFilesInFolder;
38
sub getSemaphoreCntlFile;
39
sub getMemoryCntlFile;
40
sub removeCntrlFiles;
41
sub Test1;
42
sub Test2;
43
sub Test3;
44
sub Test4;
45
sub Test5;
46
sub Test6;
47
sub Test7;
48
sub Test8;
49
sub Test9;
50
sub Test10;
51
sub Test11;
52
sub Test12;
53
sub Test13;
54
sub Test14;
55
sub Test15;
56
sub Test16;
57
sub Test17;
58
sub Test18;
59
sub Test19;
60
sub Test20;
61
sub Test21;
62
sub Test22;
63
64
65
#
66
# MAIN ...
67
#
68
my $osname = "";
69
my $numargs = @ARGV;
70
my @semaphoreList;
71
my @memoryList;
72
my $ITER;
73
my $verbose = 0; #0 for false, 1 for true
74
my $numprocs = 15;
75
my $READONLY = 0400;
76
my $testcachname = "SysVCacheTestFileName";
77
my $cacheDirectory = "/tmp/";
78
# No need to use "javasharedresources" cacheDirectory, as it will be automatically appended when using nonpersistent.
79
my $java = "./java";
80
81
#
82
# Java commands for testing ...
83
#
84
my $cmd = $java. " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$testcachname." -version 2>&1";
85
my $cmddumpdisabled = $java. " -Xshareclasses:cacheDir=".$cacheDirectory.",disablecorruptcachedumps,nonpersistent,name=".$testcachname." -version 2>&1";
86
my $destroycmd = $java. " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$testcachname.",destroy 2>&1";
87
my $cmdNonfal = $java. " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$testcachname.",nonfatal -version 2>&1";
88
89
#
90
# Script argument handling ...
91
#
92
if ($numargs != 1) {
93
print("Error: incorrect useage!\n");
94
print("\tscriptname.pl zos|aix|linux\n");
95
die ("Invalid arguments!");
96
} elsif ($numargs == 1) {
97
$osname = $ARGV[0];
98
}
99
100
#
101
# Start tests
102
#
103
my $semPermIndex = &getIPCObjPermIndex($osname);
104
my $shmPermIndex = &getIPCObjPermIndex($osname);
105
my $passedTestCount = 0;
106
my $failedTestCount = 0;
107
108
&cleanupSysV($osname,$verbose);
109
&removeCntrlFiles($testcachname);
110
if (&Test1($osname, $cmd, $numprocs) == 1) {
111
$passedTestCount+=1;
112
} else {
113
$failedTestCount+=1;
114
}
115
116
&cleanupSysV($osname,$verbose);
117
&removeCntrlFiles($testcachname);
118
if (&Test2($osname, $cmd, $numprocs) == 1) {
119
$passedTestCount+=1;
120
} else {
121
$failedTestCount+=1;
122
}
123
124
&cleanupSysV($osname,$verbose);
125
&removeCntrlFiles($testcachname);
126
if (&Test3($osname, $cmd, $numprocs) == 1) {
127
$passedTestCount+=1;
128
} else {
129
$failedTestCount+=1;
130
}
131
132
&cleanupSysV($osname,$verbose);
133
&removeCntrlFiles($testcachname);
134
if (&Test4($osname, $cmd, $numprocs) == 1) {
135
$passedTestCount+=1;
136
} else {
137
$failedTestCount+=1;
138
}
139
140
&cleanupSysV($osname,$verbose);
141
&removeCntrlFiles($testcachname);
142
if (&Test5($osname, $cmd, $numprocs) == 1) {
143
$passedTestCount+=1;
144
} else {
145
$failedTestCount+=1;
146
}
147
148
&cleanupSysV($osname,$verbose);
149
&removeCntrlFiles($testcachname);
150
if (&Test6($osname, $cmd, $numprocs) == 1) {
151
$passedTestCount+=1;
152
} else {
153
$failedTestCount+=1;
154
}
155
156
&cleanupSysV($osname,$verbose);
157
&removeCntrlFiles($testcachname);
158
if (&Test7($osname, $cmd, $numprocs) == 1) {
159
$passedTestCount+=1;
160
} else {
161
$failedTestCount+=1;
162
}
163
164
&cleanupSysV($osname,$verbose);
165
&removeCntrlFiles($testcachname);
166
if (&Test8($osname, $cmd, $numprocs) == 1) {
167
$passedTestCount+=1;
168
} else {
169
$failedTestCount+=1;
170
}
171
172
&cleanupSysV($osname,$verbose);
173
&removeCntrlFiles($testcachname);
174
if (&Test9($osname, $cmd, $numprocs) == 1) {
175
$passedTestCount+=1;
176
} else {
177
$failedTestCount+=1;
178
}
179
180
181
&cleanupSysV($osname,$verbose);
182
&removeCntrlFiles($testcachname);
183
if (&Test10($osname, $cmd, $destroycmd, $numprocs) == 1) {
184
$passedTestCount+=1;
185
} else {
186
$failedTestCount+=1;
187
}
188
189
&cleanupSysV($osname,$verbose);
190
&removeCntrlFiles($testcachname);
191
if (&Test11($osname, $cmd, $destroycmd, $numprocs) == 1) {
192
$passedTestCount+=1;
193
} else {
194
$failedTestCount+=1;
195
}
196
197
&cleanupSysV($osname,$verbose);
198
&removeCntrlFiles($testcachname);
199
if (&Test12($osname, $cmd, $destroycmd, $numprocs) == 1) {
200
$passedTestCount+=1;
201
} else {
202
$failedTestCount+=1;
203
}
204
205
&cleanupSysV($osname,$verbose);
206
&removeCntrlFiles($testcachname);
207
if (&Test13($osname, $cmd, $destroycmd, $numprocs) == 1) {
208
$passedTestCount+=1;
209
} else {
210
$failedTestCount+=1;
211
}
212
213
&cleanupSysV($osname,$verbose);
214
&removeCntrlFiles($testcachname);
215
if (&Test14($osname, $cmd, $numprocs) == 1) {
216
$passedTestCount+=1;
217
} else {
218
$failedTestCount+=1;
219
}
220
221
&cleanupSysV($osname,$verbose);
222
&removeCntrlFiles($testcachname);
223
if (&Test15($osname, $cmd, $cmdNonfal, $numprocs) == 1) {
224
$passedTestCount+=1;
225
} else {
226
$failedTestCount+=1;
227
}
228
229
&cleanupSysV($osname,$verbose);
230
&removeCntrlFiles($testcachname);
231
if (&Test16($osname, $cmd, 100) == 1) {
232
$passedTestCount+=1;
233
} else {
234
$failedTestCount+=1;
235
}
236
&cleanupSysV($osname,$verbose);
237
&removeCntrlFiles($testcachname);
238
if (&Test17($osname, $java, $numprocs) == 1) {
239
$passedTestCount+=1;
240
} else {
241
$failedTestCount+=1;
242
}
243
244
&cleanupSysV($osname,$verbose);
245
&removeCntrlFiles($testcachname);
246
if (&Test18($osname, $java, $numprocs) == 1) {
247
$passedTestCount+=1;
248
} else {
249
$failedTestCount+=1;
250
}
251
252
&cleanupSysV($osname,$verbose);
253
&removeCntrlFiles($testcachname);
254
if (&Test19($osname, $cmd, $numprocs) == 1) {
255
$passedTestCount+=1;
256
} else {
257
$failedTestCount+=1;
258
}
259
260
&cleanupSysV($osname,$verbose);
261
&removeCntrlFiles($testcachname);
262
if (&Test20($osname, $cmd, $numprocs) == 1) {
263
$passedTestCount+=1;
264
} else {
265
$failedTestCount+=1;
266
}
267
&cleanupSysV($osname,$verbose);
268
&removeCntrlFiles($testcachname);
269
if (&Test21($osname, $cmddumpdisabled, $numprocs) == 1) {
270
$passedTestCount+=1;
271
} else {
272
$failedTestCount+=1;
273
}
274
&cleanupSysV($osname,$verbose);
275
&removeCntrlFiles($testcachname);
276
if (&Test22($osname, $cmddumpdisabled) == 1) {
277
$passedTestCount+=1;
278
} else {
279
$failedTestCount+=1;
280
}
281
282
print("COMPLETE (".$passedTestCount." PASSED TESTS ... ".$failedTestCount." FAILED TESTS.)"."\n");
283
284
exit 0;
285
286
287
sub getSemaphoreCntlFile
288
{
289
my ($testcachname) = @_;
290
my $testdir = "/tmp/javasharedresources/";
291
my @listfolders = &listFilesInFolder($testdir, $numprocs);
292
foreach $ITER (@listfolders) {
293
#print "\t".$ITER."\n";
294
if ($ITER =~ /$testcachname/) {
295
if ($ITER =~ /semaphore/) {
296
return $testdir . $ITER;
297
}
298
}
299
}
300
return "";
301
}
302
303
sub getMemoryCntlFile
304
{
305
my ($testcachname) = @_;
306
my $testdir = "/tmp/javasharedresources/";
307
my @listfolders = &listFilesInFolder($testdir, $numprocs);
308
foreach $ITER (@listfolders) {
309
#print "\t".$ITER."\n";
310
if ($ITER =~ /$testcachname/) {
311
if ($ITER =~ /memory/) {
312
return $testdir . $ITER;
313
}
314
}
315
}
316
return "";
317
}
318
319
sub removeCntrlFiles
320
{
321
#
322
# Ruthless clean up of any cache using the same cache name as we
323
# use for this test
324
#
325
my ($testcachname) = @_;
326
my $testdir = "/tmp/javasharedresources/";
327
my @listfolders = &listFilesInFolder($testdir, $numprocs);
328
foreach $ITER (@listfolders) {
329
#print "\t".$ITER."\n";
330
if ($ITER =~ /$testcachname/) {
331
my $cmd = "rm -f ". $testdir . $ITER;
332
#print $cmd . "\n";
333
`$cmd`;
334
}
335
}
336
}
337
338
sub Test1
339
{
340
my ($osname, $cmd, $numprocs) = @_;
341
my @pidList;
342
my $count = 0;
343
my $waitedfor=0;
344
345
print "Test 1: verify 1 only semaphore created\n";
346
347
my @semaphoreList = &listSysVSemaphores($osname);
348
my $startCount = scalar(@semaphoreList);
349
my $endCount = 0;
350
351
for ($count = 0; $count < $numprocs; $count++) {
352
my $pid = &forkAndRunInBackGround($cmd);
353
push(@pidList, $pid);
354
}
355
356
while (wait() != -1) {
357
$waitedfor = $waitedfor + 1;
358
}
359
printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");
360
361
@semaphoreList = &listSysVSemaphores($osname);
362
$endCount = scalar(@semaphoreList);
363
364
if ($endCount == $startCount+1) {
365
print "\tThere is only one semaphore (as expected)\n";
366
print "\tTEST PASS\n";
367
return 1;
368
} else {
369
print "\tThere are ".$endCount." semaphores (we expect 1)\n";
370
print "\tTEST FAIL\n";
371
return 0;
372
}
373
}
374
375
sub Test2
376
{
377
my ($osname, $cmd, $numprocs) = @_;
378
my @pidList;
379
my $count = 0;
380
my $waitedfor=0;
381
382
print "Test 2: verify 1 only shared memory created\n";
383
384
my @memoryList = &listSysVMemory($osname);
385
my $startCount = scalar(@memoryList);
386
my $endCount = 0;
387
388
for ($count = 0; $count < $numprocs; $count++) {
389
my $pid = &forkAndRunInBackGround($cmd);
390
push(@pidList, $pid);
391
}
392
393
while (wait() != -1) {
394
$waitedfor = $waitedfor + 1;
395
}
396
printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");
397
398
@memoryList = &listSysVMemory($osname);
399
$endCount = scalar(@memoryList);
400
401
if ($endCount == $startCount+1) {
402
print "\tThere is only one shared memory (as expected)\n";
403
print "\tTEST PASS\n";
404
return 1;
405
} else {
406
print "\tThere are ".$endCount." shared memories (we expect 1)\n";
407
print "\tTEST FAIL\n";
408
return 0;
409
}
410
}
411
412
413
sub Test3
414
{
415
my ($osname, $cmd, $numprocs) = @_;
416
my @pidList;
417
my $count = 0;
418
my $waitedfor=0;
419
420
print "Test 3: verify no new shared memory are created on 2nd run of JVM\n";
421
422
for ($count = 0; $count < $numprocs; $count++) {
423
my $pid = &forkAndRunInBackGround($cmd);
424
push(@pidList, $pid);
425
}
426
427
$waitedfor = 0;
428
while (wait() != -1) {
429
$waitedfor = $waitedfor + 1;
430
}
431
printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");
432
433
434
my $semCount = scalar(&listSysVSemaphores($osname));
435
my $memCount = scalar(&listSysVMemory($osname));
436
437
for ($count = 0; $count < $numprocs; $count++) {
438
my $pid = &forkAndRunInBackGround($cmd);
439
push(@pidList, $pid);
440
}
441
442
$waitedfor = 0;
443
while (wait() != -1) {
444
$waitedfor = $waitedfor + 1;
445
}
446
printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");
447
448
if ($semCount != scalar(&listSysVSemaphores($osname))) {
449
print "\tTEST FAIL\n";
450
return 0;
451
} elsif ($memCount != scalar(&listSysVMemory($osname))) {
452
print "\tTEST FAIL\n";
453
return 0;
454
} else {
455
print "\tTEST PASS\n";
456
}
457
return 1;
458
459
}
460
461
sub Test4
462
{
463
my ($osname, $cmd, $numprocs) = @_;
464
my @pidList;
465
my $count = 0;
466
my $waitedfor=0;
467
468
print "Test 4: Create semaphore successfully when stale semaphores exist\n";
469
`$cmd`;
470
&removeCntrlFiles($testcachname);
471
`$cmd`;
472
&removeCntrlFiles($testcachname);
473
`$cmd`;
474
&removeCntrlFiles($testcachname);
475
476
if (&getSemaphoreCntlFile($testcachname) ne "") {
477
print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." found\n";
478
return 0;
479
}
480
if (&getMemoryCntlFile($testcachname) ne "") {
481
print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." found\n";
482
return 0;
483
}
484
485
my $semCount = scalar(&listSysVSemaphores($osname));
486
my $memCount = scalar(&listSysVMemory($osname));
487
488
#print "\t".$cmd."\n";
489
`$cmd`;
490
491
if ($memCount == scalar(&listSysVMemory($osname))) {
492
print "\tTEST FAIL mem count ".$memCount."\n";
493
return 0;
494
}
495
496
if ($semCount == scalar(&listSysVSemaphores($osname))) {
497
print "\tTEST FAIL sem count ".$semCount." vs ".scalar(&listSysVSemaphores($osname))."\n";
498
return 0;
499
}
500
501
print "\tTEST PASS\n";
502
return 1;
503
504
}
505
506
507
sub Test5
508
{
509
my ($osname, $cmd, $numprocs) = @_;
510
my @pidList;
511
my $count = 0;
512
my $waitedfor=0;
513
my $touchcmd;
514
515
516
print "Test 5: Test empty control files.\n";
517
`$cmd`;
518
my $semfile = &getSemaphoreCntlFile($testcachname);
519
my $memfile = &getMemoryCntlFile($testcachname);
520
&removeCntrlFiles($testcachname);
521
522
$touchcmd = "touch ".$semfile;
523
`$touchcmd`;
524
$touchcmd = "touch ".$memfile;
525
`$touchcmd`;
526
my $semCount = scalar(&listSysVSemaphores($osname));
527
my $memCount = scalar(&listSysVMemory($osname));
528
`$cmd`;
529
if ($memCount == scalar(&listSysVMemory($osname))) {
530
print "\tTEST FAIL mem count ".$memCount."\n";
531
return 0;
532
}
533
if ($semCount == scalar(&listSysVSemaphores($osname))) {
534
print "\tTEST FAIL sem count ".$semCount." vs ".scalar(&listSysVSemaphores($osname))."\n";
535
return 0;
536
}
537
print "\tTEST PASS\n";
538
return 1;
539
540
}
541
542
sub Test6
543
{
544
my ($osname, $cmd, $numprocs) = @_;
545
my @pidList;
546
my $count = 0;
547
my $waitedfor=0;
548
my $chmodcmd;
549
550
551
print "Test 6: Open cache with readonly control file.\n";
552
`$cmd`;
553
my $semfile = &getSemaphoreCntlFile($testcachname);
554
my $memfile = &getMemoryCntlFile($testcachname);
555
556
$chmodcmd = "chmod a-wx ".$semfile;
557
`$chmodcmd`;
558
$chmodcmd = "chmod a-wx ".$memfile;
559
`$chmodcmd`;
560
my $semCount = scalar(&listSysVSemaphores($osname));
561
my $memCount = scalar(&listSysVMemory($osname));
562
563
`$cmd`;
564
565
$chmodcmd = "chmod ug+w ".$semfile;
566
`$chmodcmd`;
567
$chmodcmd = "chmod ug+w ".$memfile;
568
`$chmodcmd`;
569
570
if ($memCount != scalar(&listSysVMemory($osname))) {
571
print "\tTEST FAIL mem count ".$memCount."\n";
572
return 0;
573
}
574
if ($semCount != scalar(&listSysVSemaphores($osname))) {
575
print "\tTEST FAIL sem count ".$semCount." vs ".scalar(&listSysVSemaphores($osname))."\n";
576
return 0;
577
}
578
print "\tTEST PASS\n";
579
return 1;
580
581
}
582
583
584
sub Test7
585
{
586
my ($osname, $cmd, $numprocs) = @_;
587
my @pidList;
588
my $count = 0;
589
my $waitedfor=0;
590
my $chmodcmd;
591
592
593
print "Test 7: Open cache with readonly control file and no corresponding SysV objs.\n";
594
`$cmd`;
595
my $semfile = &getSemaphoreCntlFile($testcachname);
596
my $memfile = &getMemoryCntlFile($testcachname);
597
598
$chmodcmd = "chmod a-wx ".$semfile;
599
`$chmodcmd`;
600
$chmodcmd = "chmod a-wx ".$memfile;
601
`$chmodcmd`;
602
603
&cleanupSysV($osname,$verbose);
604
my $semCount = scalar(&listSysVSemaphores($osname));
605
my $memCount = scalar(&listSysVMemory($osname));
606
607
608
`$cmd`;
609
610
$chmodcmd = "chmod ug+w ".$semfile;
611
`$chmodcmd`;
612
$chmodcmd = "chmod ug+w ".$memfile;
613
`$chmodcmd`;
614
615
if ($memCount != scalar(&listSysVMemory($osname))) {
616
print "\tTEST FAIL mem count ".$memCount." vs ".scalar(&listSysVMemory($osname))."\n";
617
return 0;
618
}
619
if ($semCount != scalar(&listSysVSemaphores($osname))) {
620
print "\tTEST FAIL sem count ".$semCount." vs ".scalar(&listSysVSemaphores($osname))."\n";
621
return 0;
622
}
623
624
$cmd = "unlink ".$semfile;
625
`$cmd`;
626
$cmd = "unlink ".$memfile;
627
`$cmd`;
628
629
print "\tTEST PASS\n";
630
return 1;
631
632
}
633
634
sub Test8
635
{
636
my ($osname, $cmd, $numprocs) = @_;
637
my @pidList;
638
my $count = 0;
639
my $waitedfor=0;
640
my @semaphoreListBefore;
641
my @semaphoreListAfter;
642
my $ITER;
643
my $ITER2;
644
645
print "Test 8: when no permissions to access a semaphore make sure do not we create a new one.\n";
646
#system("ipcs");
647
@semaphoreListBefore = &listSysVSemaphores($osname);
648
`$cmd`;
649
@semaphoreListAfter = &listSysVSemaphores($osname);
650
651
#we expect one semaphore to be created
652
if (scalar(@semaphoreListBefore)+1 != scalar(@semaphoreListAfter)) {
653
print "\tTEST FAIL (bad sem count)\n";
654
return 0;
655
}
656
657
#find the newly created semaphore
658
my $semid = 0;
659
BREAK_FROM_LOOP: {
660
foreach $ITER (@semaphoreListAfter) {
661
my $found = 0;
662
foreach $ITER2 (@semaphoreListBefore) {
663
if ($ITER == $ITER2) {
664
$found = $ITER;
665
}
666
}
667
if ($found == 0) {
668
$semid = $ITER;
669
#this equivalent to a break statement in C ...
670
last BREAK_FROM_LOOP;
671
}
672
}
673
}
674
675
if ($semid == 0) {
676
print "\tTEST FAIL (not found)\n";
677
return 0;
678
}
679
680
681
my $statInfo;
682
semctl($semid, 0, IPC_STAT, $statInfo);
683
my @mdata = unpack("l*",$statInfo);
684
685
#my $key = @mdata[0];
686
#my $ uid = @mdata[1];
687
#my $gid = @mdata[2];
688
#my $cuid = @mdata[3];
689
#my $cgid = @mdata[4];
690
#my $mode = @mdata[5];
691
#my $seq = @mdata[6];
692
693
#set permissions to O000 (no permissions) ...
694
my $oldperm = @mdata[$semPermIndex];
695
print "\tChange permissions from ".sprintf("O%o",$oldperm)." to ".$READONLY."\n";
696
@mdata[$semPermIndex] = $READONLY;
697
$statInfo = pack("l*",@mdata);
698
semctl($semid, 0, IPC_SET, $statInfo);
699
700
#system("ipcs");
701
@semaphoreListBefore = @semaphoreListAfter;
702
#print $cmd."\n";
703
`$cmd`;
704
@semaphoreListAfter = &listSysVSemaphores($osname);
705
#system("ipcs");
706
707
#No new semaphore should be created ... and nothing deleted ...
708
if (scalar(@semaphoreListBefore) != scalar(@semaphoreListAfter)) {
709
print "\tTEST FAIL (bad sem count ... before:".scalar(@semaphoreListBefore)." after:".scalar(@semaphoreListAfter).")\n";
710
return 0;
711
}
712
713
# Set the permission back here
714
@mdata[$semPermIndex] = $oldperm;
715
$statInfo = pack("l*",@mdata);
716
semctl($semid, 0, IPC_SET, $statInfo) or die('Can not change permissions back');
717
print "\tTEST PASS\n";
718
return 1;
719
720
}
721
722
723
sub Test9
724
{
725
my ($osname, $cmd, $numprocs) = @_;
726
my @pidList;
727
my $count = 0;
728
my $waitedfor=0;
729
my @memListBefore;
730
my @memListAfter;
731
my $ITER;
732
my $ITER2;
733
734
print "Test 9: when no permissions to access a shared memory make sure we create a new one. ";
735
print "\n";
736
737
@memListBefore = &listSysVMemory($osname);
738
`$cmd`;
739
@memListAfter = &listSysVMemory($osname);
740
741
#we expect one semaphore to be created
742
if (scalar(@memListBefore)+1 != scalar(@memListAfter)) {
743
print "\tTEST FAIL (bad sem count)\n";
744
return 0;
745
}
746
747
#find the newly created mem
748
my $shmid = 0;
749
BREAK_FROM_LOOP: {
750
foreach $ITER (@memListAfter) {
751
my $found = 0;
752
foreach $ITER2 (@memListBefore) {
753
if ($ITER == $ITER2) {
754
$found = $ITER;
755
}
756
}
757
if ($found == 0) {
758
$shmid = $ITER;
759
#this equivalent to a break statement in C ...
760
last BREAK_FROM_LOOP;
761
}
762
}
763
}
764
if ($shmid == 0) {
765
print "\tTEST FAIL (not found)\n";
766
return 0;
767
}
768
769
my $statInfo;
770
shmctl($shmid, IPC_STAT, $statInfo);
771
my @mdata = unpack("l*",$statInfo);
772
773
#set permissions to 0400 (no permissions) ...
774
my $oldperm = @mdata[$shmPermIndex];
775
print "\tChange permissions from ".sprintf("O%o",$oldperm)." to ".$READONLY."\n";
776
@mdata[$shmPermIndex] = $READONLY;
777
$statInfo = pack("l*",@mdata);
778
shmctl($shmid, IPC_SET, $statInfo);
779
780
781
@memListBefore = @memListAfter;
782
#print $cmd."\n";
783
#return 0;
784
my @stdout = `$cmd`;
785
#print @stdout, "\n";
786
@memListAfter = &listSysVMemory($osname);
787
788
789
# No new memory should be created if current is read only
790
if (scalar(@memListBefore) != scalar(@memListAfter)) {
791
print "\tTEST FAIL (bad mem count ... before:".scalar(@memListBefore)." after:".scalar(@memListAfter).")\n";
792
return 0;
793
}
794
795
# Set the permission back here
796
@mdata[$shmPermIndex] = $oldperm;
797
$statInfo = pack("l*",@mdata);
798
shmctl($shmid, IPC_SET, $statInfo) or die('Can not change permissions back');
799
800
print "\tTEST PASS\n";
801
return 1;
802
803
}
804
805
sub Test10
806
{
807
my ($osname, $cmd, $destroycmd, $numprocs) = @_;
808
my @pidList;
809
my $count = 0;
810
my $waitedfor=0;
811
my @memListBefore;
812
my @memListAfter;
813
my @semListBefore;
814
my @semListAfter;
815
my $ITER;
816
my $ITER2;
817
818
print "Test 10: Verify a simple case of destroy";
819
print "\n";
820
821
#
822
# Create a cache
823
#
824
@memListBefore = &listSysVMemory($osname);
825
@semListBefore = &listSysVSemaphores($osname);
826
`$cmd`;
827
@memListAfter = &listSysVMemory($osname);
828
@semListAfter = &listSysVSemaphores($osname);
829
830
if (scalar(@memListBefore)+1 != scalar(@memListAfter)) {
831
print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";
832
return 0;
833
}
834
if (scalar(@semListBefore)+1 != scalar(@semListAfter)) {
835
print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";
836
return 0;
837
}
838
if (&getSemaphoreCntlFile($testcachname) eq "") {
839
print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";
840
return 0;
841
}
842
if (&getMemoryCntlFile($testcachname) eq "") {
843
print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";
844
return 0;
845
}
846
847
#
848
# Destroy the cache
849
#
850
@memListBefore = &listSysVMemory($osname);
851
@semListBefore = &listSysVSemaphores($osname);
852
`$destroycmd`;
853
@memListAfter = &listSysVMemory($osname);
854
@semListAfter = &listSysVSemaphores($osname);
855
856
if (scalar(@memListBefore)-1 != scalar(@memListAfter)) {
857
print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";
858
return 0;
859
}
860
if (scalar(@semListBefore)-1 != scalar(@semListAfter)) {
861
print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";
862
return 0;
863
}
864
if (&getSemaphoreCntlFile($testcachname) ne "") {
865
print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." found\n";
866
return 0;
867
}
868
if (&getMemoryCntlFile($testcachname) ne "") {
869
print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." found\n";
870
return 0;
871
}
872
873
print "\tTEST PASS\n";
874
return 1;
875
}
876
877
sub Test11
878
{
879
my ($osname, $cmd, $destroycmd, $numprocs) = @_;
880
my @pidList;
881
my $count = 0;
882
my $waitedfor=0;
883
my @memListBefore;
884
my @memListAfter;
885
my @semListBefore;
886
my @semListAfter;
887
my $ITER;
888
my $ITER2;
889
890
print "Test 11: Call destroy with read only semaphore";
891
print "\n";
892
893
#
894
# Create a cache
895
#
896
@memListBefore = &listSysVMemory($osname);
897
@semListBefore = &listSysVSemaphores($osname);
898
`$cmd`;
899
@memListAfter = &listSysVMemory($osname);
900
@semListAfter = &listSysVSemaphores($osname);
901
902
if (scalar(@memListBefore)+1 != scalar(@memListAfter)) {
903
print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";
904
return 0;
905
}
906
if (scalar(@semListBefore)+1 != scalar(@semListAfter)) {
907
print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";
908
return 0;
909
}
910
if (&getSemaphoreCntlFile($testcachname) eq "") {
911
print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";
912
return 0;
913
}
914
if (&getMemoryCntlFile($testcachname) eq "") {
915
print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";
916
return 0;
917
}
918
919
920
#find the newly created semaphore
921
my $semid = 0;
922
BREAK_FROM_LOOP: {
923
foreach $ITER (@semListAfter) {
924
my $found = 0;
925
foreach $ITER2 (@semListBefore) {
926
if ($ITER == $ITER2) {
927
$found = $ITER;
928
}
929
}
930
if ($found == 0) {
931
$semid = $ITER;
932
#this equivalent to a break statement in C ...
933
last BREAK_FROM_LOOP;
934
}
935
}
936
}
937
938
if ($semid == 0) {
939
print "\tTEST FAIL (not found)\n";
940
return 0;
941
}
942
943
# mod to be read only
944
my $statInfo;
945
semctl($semid, 0, IPC_STAT, $statInfo);
946
my @mdata = unpack("l*",$statInfo);
947
my $oldperm = @mdata[$semPermIndex];
948
print "\tChange permissions from ".sprintf("O%o",$oldperm)." to ".$READONLY."\n";
949
@mdata[$semPermIndex] = $READONLY;
950
$statInfo = pack("l*",@mdata);
951
semctl($semid, 0, IPC_SET, $statInfo);
952
953
#
954
# Destroy the cache
955
#
956
@memListBefore = &listSysVMemory($osname);
957
@semListBefore = &listSysVSemaphores($osname);
958
`$destroycmd`;
959
@memListAfter = &listSysVMemory($osname);
960
@semListAfter = &listSysVSemaphores($osname);
961
962
#NOTE:
963
# - the vm will not create a new semaphore or shared memory
964
# - the vm will fail to destroy semaphore but will remove the shared memory
965
if (scalar(@memListBefore)-1 != scalar(@memListAfter)) {
966
print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";
967
return 0;
968
}
969
if (scalar(@semListBefore) != scalar(@semListAfter)) {
970
print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";
971
return 0;
972
}
973
if (&getSemaphoreCntlFile($testcachname) eq "") {
974
print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";
975
return 0;
976
}
977
if (&getMemoryCntlFile($testcachname) ne "") {
978
print "\tTEST FAIL shared memory control file ".&getMemoryCntlFile($testcachname)." was not deleted\n";
979
return 0;
980
}
981
982
# Set the permission back here
983
@mdata[$semPermIndex] = $oldperm;
984
$statInfo = pack("l*",@mdata);
985
semctl($semid, 0, IPC_SET, $statInfo) or die('Can not change permissions back');
986
print "\tTEST PASS\n";
987
return 1;
988
}
989
990
sub Test12
991
{
992
my ($osname, $cmd, $destroycmd, $numprocs) = @_;
993
my @pidList;
994
my $count = 0;
995
my $waitedfor=0;
996
my @memListBefore;
997
my @memListAfter;
998
my @semListBefore;
999
my @semListAfter;
1000
my $ITER;
1001
my $ITER2;
1002
1003
print "Test 12: Call destroy with read only memory";
1004
print "\n";
1005
1006
#
1007
# Create a cache
1008
#
1009
@memListBefore = &listSysVMemory($osname);
1010
@semListBefore = &listSysVSemaphores($osname);
1011
`$cmd`;
1012
@memListAfter = &listSysVMemory($osname);
1013
@semListAfter = &listSysVSemaphores($osname);
1014
1015
if (scalar(@memListBefore)+1 != scalar(@memListAfter)) {
1016
print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";
1017
return 0;
1018
}
1019
if (scalar(@semListBefore)+1 != scalar(@semListAfter)) {
1020
print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";
1021
return 0;
1022
}
1023
if (&getSemaphoreCntlFile($testcachname) eq "") {
1024
print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";
1025
return 0;
1026
}
1027
if (&getMemoryCntlFile($testcachname) eq "") {
1028
print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";
1029
return 0;
1030
}
1031
1032
1033
#find the newly created semaphore
1034
my $objid = 0;
1035
BREAK_FROM_LOOP: {
1036
foreach $ITER (@memListAfter) {
1037
my $found = 0;
1038
foreach $ITER2 (@memListBefore) {
1039
if ($ITER == $ITER2) {
1040
$found = $ITER;
1041
}
1042
}
1043
if ($found == 0) {
1044
$objid = $ITER;
1045
#this equivalent to a break statement in C ...
1046
last BREAK_FROM_LOOP;
1047
}
1048
}
1049
}
1050
1051
if ($objid == 0) {
1052
print "\tTEST FAIL (not found)\n";
1053
return 0;
1054
}
1055
1056
# mod to be read only
1057
my $statInfo;
1058
shmctl($objid, IPC_STAT, $statInfo);
1059
my @mdata = unpack("l*",$statInfo);
1060
my $oldperm = @mdata[$shmPermIndex];
1061
print "\tChange permissions from ".sprintf("O%o",$oldperm)." to ".$READONLY."\n";
1062
@mdata[$shmPermIndex] = $READONLY;
1063
$statInfo = pack("l*",@mdata);
1064
shmctl($objid, IPC_SET, $statInfo);
1065
1066
#
1067
# Destroy the cache
1068
#
1069
@memListBefore = &listSysVMemory($osname);
1070
@semListBefore = &listSysVSemaphores($osname);
1071
print "\t".$destroycmd."\n";
1072
`$destroycmd`;
1073
@memListAfter = &listSysVMemory($osname);
1074
@semListAfter = &listSysVSemaphores($osname);
1075
1076
#NOTE:
1077
# -
1078
if (scalar(@memListBefore) != scalar(@memListAfter)) {
1079
print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";
1080
return 0;
1081
}
1082
if (scalar(@semListBefore)-1 != scalar(@semListAfter)) {
1083
print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";
1084
return 0;
1085
}
1086
if (&getSemaphoreCntlFile($testcachname) ne "") {
1087
print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." found\n";
1088
return 0;
1089
}
1090
if (&getMemoryCntlFile($testcachname) eq "") {
1091
print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";
1092
return 0;
1093
}
1094
1095
# Set the permission back here
1096
@mdata[$shmPermIndex] = $oldperm;
1097
$statInfo = pack("l*",@mdata);
1098
shmctl($objid, IPC_SET, $statInfo) or die('Can not change permissions back');
1099
print "\tTEST PASS\n";
1100
return 1;
1101
}
1102
1103
sub Test13
1104
{
1105
my ($osname, $cmd, $destroycmd, $numprocs) = @_;
1106
my @pidList;
1107
my $count = 0;
1108
my $waitedfor=0;
1109
my @memListBefore;
1110
my @memListAfter;
1111
my @semListBefore;
1112
my @semListAfter;
1113
my $ITER;
1114
my $ITER2;
1115
my $chmodcmd;
1116
1117
print "Test 13: Verify a simple case of destroy with readonly control files";
1118
print "\n";
1119
1120
#
1121
# Create a cache
1122
#
1123
@memListBefore = &listSysVMemory($osname);
1124
@semListBefore = &listSysVSemaphores($osname);
1125
`$cmd`;
1126
@memListAfter = &listSysVMemory($osname);
1127
@semListAfter = &listSysVSemaphores($osname);
1128
1129
if (scalar(@memListBefore)+1 != scalar(@memListAfter)) {
1130
print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";
1131
return 0;
1132
}
1133
if (scalar(@semListBefore)+1 != scalar(@semListAfter)) {
1134
print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";
1135
return 0;
1136
}
1137
if (&getSemaphoreCntlFile($testcachname) eq "") {
1138
print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";
1139
return 0;
1140
}
1141
if (&getMemoryCntlFile($testcachname) eq "") {
1142
print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";
1143
return 0;
1144
}
1145
1146
1147
my $semfile = &getSemaphoreCntlFile($testcachname);
1148
my $memfile = &getMemoryCntlFile($testcachname);
1149
1150
$chmodcmd = "chmod a-wx ".$semfile;
1151
`$chmodcmd`;
1152
$chmodcmd = "chmod a-wx ".$memfile;
1153
`$chmodcmd`;
1154
#system("ls -la /tmp/javasharedresources/");
1155
1156
#
1157
# Destroy the cache
1158
#
1159
@memListBefore = &listSysVMemory($osname);
1160
@semListBefore = &listSysVSemaphores($osname);
1161
`$destroycmd`;
1162
@memListAfter = &listSysVMemory($osname);
1163
@semListAfter = &listSysVSemaphores($osname);
1164
1165
#
1166
# Destroy will kill control files regardless if they are readonly
1167
#
1168
if (scalar(@memListBefore)-1 != scalar(@memListAfter)) {
1169
print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";
1170
return 0;
1171
}
1172
if (scalar(@semListBefore)-1 != scalar(@semListAfter)) {
1173
print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";
1174
return 0;
1175
}
1176
if (&getSemaphoreCntlFile($testcachname) eq "") {
1177
print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";
1178
return 0;
1179
}
1180
if (&getMemoryCntlFile($testcachname) eq "") {
1181
print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";
1182
return 0;
1183
}
1184
1185
$cmd = "unlink ".$semfile;
1186
`$cmd`;
1187
$cmd = "unlink ".$memfile;
1188
`$cmd`;
1189
1190
print "\tTEST PASS\n";
1191
return 1;
1192
}
1193
1194
1195
sub Test14
1196
{
1197
my ($osname, $cmd, $numprocs) = @_;
1198
my @pidList;
1199
my $count = 0;
1200
my $waitedfor=0;
1201
my @memListBefore;
1202
my @memListAfter;
1203
my @semListBefore;
1204
my @semListAfter;
1205
my $ITER;
1206
my $ITER2;
1207
my $chmodcmd;
1208
1209
print "Test 14: Verify a simple case of start up with readonly control files, readonly memory";
1210
print "\n";
1211
1212
#
1213
# Create a cache
1214
#
1215
@memListBefore = &listSysVMemory($osname);
1216
@semListBefore = &listSysVSemaphores($osname);
1217
`$cmd`;
1218
@memListAfter = &listSysVMemory($osname);
1219
@semListAfter = &listSysVSemaphores($osname);
1220
1221
if (scalar(@memListBefore)+1 != scalar(@memListAfter)) {
1222
print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";
1223
return 0;
1224
}
1225
if (scalar(@semListBefore)+1 != scalar(@semListAfter)) {
1226
print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";
1227
return 0;
1228
}
1229
if (&getSemaphoreCntlFile($testcachname) eq "") {
1230
print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";
1231
return 0;
1232
}
1233
if (&getMemoryCntlFile($testcachname) eq "") {
1234
print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";
1235
return 0;
1236
}
1237
1238
#find the newly created shared memory
1239
my $objid = 0;
1240
BREAK_FROM_LOOP: {
1241
foreach $ITER (@memListAfter) {
1242
my $found = 0;
1243
foreach $ITER2 (@memListBefore) {
1244
if ($ITER == $ITER2) {
1245
$found = $ITER;
1246
}
1247
}
1248
if ($found == 0) {
1249
$objid = $ITER;
1250
#this equivalent to a break statement in C ...
1251
last BREAK_FROM_LOOP;
1252
}
1253
}
1254
}
1255
1256
if ($objid == 0) {
1257
print "\tTEST FAIL (not found)\n";
1258
return 0;
1259
}
1260
1261
# mod to be read only
1262
my $statInfo;
1263
shmctl($objid, IPC_STAT, $statInfo);
1264
my @mdata = unpack("l*",$statInfo);
1265
my $oldperm = @mdata[$shmPermIndex];
1266
print "\tChange permissions from ".sprintf("O%o",$oldperm)." to ".$READONLY."\n";
1267
@mdata[$shmPermIndex] = $READONLY;
1268
$statInfo = pack("l*",@mdata);
1269
shmctl($objid, IPC_SET, $statInfo);
1270
1271
my $semfile = &getSemaphoreCntlFile($testcachname);
1272
my $memfile = &getMemoryCntlFile($testcachname);
1273
1274
$chmodcmd = "chmod a-wx ".$semfile;
1275
`$chmodcmd`;
1276
$chmodcmd = "chmod a-wx ".$memfile;
1277
`$chmodcmd`;
1278
#system("ls -la /tmp/javasharedresources/");
1279
1280
#
1281
# Open the cache
1282
#
1283
@memListBefore = &listSysVMemory($osname);
1284
@semListBefore = &listSysVSemaphores($osname);
1285
`$cmd`;
1286
@memListAfter = &listSysVMemory($osname);
1287
@semListAfter = &listSysVSemaphores($osname);
1288
1289
#
1290
# Open of the cache will cause 'permission denied' on control file and memory ...
1291
# OSCache.cpp will then attempt to delete it ... only the semaphore will be deleted
1292
#
1293
if (scalar(@memListBefore) != scalar(@memListAfter)) {
1294
print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";
1295
return 0;
1296
}
1297
if (scalar(@semListBefore)-1 != scalar(@semListAfter)) {
1298
print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";
1299
return 0;
1300
}
1301
if (&getSemaphoreCntlFile($testcachname) eq "") {
1302
print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";
1303
return 0;
1304
}
1305
if (&getMemoryCntlFile($testcachname) eq "") {
1306
print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";
1307
return 0;
1308
}
1309
1310
# Set the permission back here
1311
@mdata[$shmPermIndex] = $oldperm;
1312
$statInfo = pack("l*",@mdata);
1313
shmctl($objid, IPC_SET, $statInfo) or die('Can not change permissions back');
1314
$chmodcmd = "chmod a+w ".$semfile;
1315
`$chmodcmd`;
1316
$chmodcmd = "chmod a+w ".$memfile;
1317
`$chmodcmd`;
1318
1319
$cmd = "unlink ".$semfile;
1320
`$cmd`;
1321
$cmd = "unlink ".$memfile;
1322
`$cmd`;
1323
1324
print "\tTEST PASS\n";
1325
return 1;
1326
}
1327
1328
sub Test15
1329
{
1330
my ($osname, $cmd, $cmd2, $numprocs) = @_;
1331
my @pidList;
1332
my $count = 0;
1333
my $waitedfor=0;
1334
my @memListBefore;
1335
my @memListAfter;
1336
my @semListBefore;
1337
my @semListAfter;
1338
my $ITER;
1339
my $ITER2;
1340
my $chmodcmd;
1341
1342
print "Test 15: Same test as 14 ... but we run 2nd command with non fatal and check stdout/err for dump of vm version info ...";
1343
print "\n";
1344
1345
#
1346
# Create a cache
1347
#
1348
@memListBefore = &listSysVMemory($osname);
1349
@semListBefore = &listSysVSemaphores($osname);
1350
`$cmd`;
1351
@memListAfter = &listSysVMemory($osname);
1352
@semListAfter = &listSysVSemaphores($osname);
1353
1354
if (scalar(@memListBefore)+1 != scalar(@memListAfter)) {
1355
print "\tTEST FAIL (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";
1356
return 0;
1357
}
1358
if (scalar(@semListBefore)+1 != scalar(@semListAfter)) {
1359
print "\tTEST FAIL (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";
1360
return 0;
1361
}
1362
if (&getSemaphoreCntlFile($testcachname) eq "") {
1363
print "\tTEST FAIL file ".&getSemaphoreCntlFile($testcachname)." not found\n";
1364
return 0;
1365
}
1366
if (&getMemoryCntlFile($testcachname) eq "") {
1367
print "\tTEST FAIL file ".&getMemoryCntlFile($testcachname)." not found\n";
1368
return 0;
1369
}
1370
1371
#find the newly created semaphore
1372
my $objid = 0;
1373
BREAK_FROM_LOOP: {
1374
foreach $ITER (@memListAfter) {
1375
my $found = 0;
1376
foreach $ITER2 (@memListBefore) {
1377
if ($ITER == $ITER2) {
1378
$found = $ITER;
1379
}
1380
}
1381
if ($found == 0) {
1382
$objid = $ITER;
1383
#this equivalent to a break statement in C ...
1384
last BREAK_FROM_LOOP;
1385
}
1386
}
1387
}
1388
1389
if ($objid == 0) {
1390
print "\tTEST FAIL (not found)\n";
1391
return 0;
1392
}
1393
1394
# mod to be read only
1395
my $statInfo;
1396
shmctl($objid, IPC_STAT, $statInfo);
1397
my @mdata = unpack("l*",$statInfo);
1398
my $oldperm = @mdata[$shmPermIndex];
1399
print "\tChange permissions from ".sprintf("O%o",$oldperm)." to ".$READONLY."\n";
1400
@mdata[$shmPermIndex] = $READONLY;
1401
$statInfo = pack("l*",@mdata);
1402
shmctl($objid, IPC_SET, $statInfo);
1403
1404
my $semfile = &getSemaphoreCntlFile($testcachname);
1405
my $memfile = &getMemoryCntlFile($testcachname);
1406
1407
$chmodcmd = "chmod a-wx ".$semfile;
1408
`$chmodcmd`;
1409
$chmodcmd = "chmod a-wx ".$memfile;
1410
`$chmodcmd`;
1411
#system("ls -la /tmp/javasharedresources/");
1412
1413
#
1414
# Open the cache
1415
#
1416
#system("ipcs");
1417
@memListBefore = &listSysVMemory($osname);
1418
@semListBefore = &listSysVSemaphores($osname);
1419
#print $cmd2."\n";
1420
my @stdout = `$cmd2`;
1421
#print @stdout,"\n";
1422
#system("ipcs");
1423
@memListAfter = &listSysVMemory($osname);
1424
@semListAfter = &listSysVSemaphores($osname);
1425
1426
my $found = 0;
1427
foreach $ITER (@stdout) {
1428
if ($ITER =~ /java version/) {
1429
$found = 1;
1430
}
1431
}
1432
if ($found == 0) {
1433
print "\tTEST FAIL success string not found in output\n";
1434
return 0;
1435
}
1436
1437
#
1438
# Open of the cache will cause 'permission denied' on control file and memory ...
1439
# OSCache.cpp will then attempt to delete it ... only the semaphore will be deleted
1440
#
1441
if (scalar(@memListBefore) != scalar(@memListAfter)) {
1442
print "\tTEST FAIL(2) (bad mem count before: ".scalar(@memListBefore)." after:". scalar(@memListAfter)." )\n";
1443
return 0;
1444
}
1445
#not minus one b/c retries readonly with nonfatal
1446
if (scalar(@semListBefore) != scalar(@semListAfter)) {
1447
print "\tTEST FAIL(2) (bad sem count before: ".scalar(@semListBefore)." after:". scalar(@semListAfter)." )\n";
1448
return 0;
1449
}
1450
if (&getSemaphoreCntlFile($testcachname) eq "") {
1451
print "\tTEST FAIL(2) file ".&getSemaphoreCntlFile($testcachname)." not found\n";
1452
return 0;
1453
}
1454
if (&getMemoryCntlFile($testcachname) eq "") {
1455
print "\tTEST FAIL(2) file ".&getMemoryCntlFile($testcachname)." not found\n";
1456
return 0;
1457
}
1458
1459
# Set the permission back here
1460
@mdata[$shmPermIndex] = $oldperm;
1461
$statInfo = pack("l*",@mdata);
1462
shmctl($objid, IPC_SET, $statInfo) or die('Can not change permissions back');
1463
#semaphore control file should be deleted
1464
#$chmodcmd = "chmod a+w ".$semfile;
1465
#`$chmodcmd`;
1466
$chmodcmd = "chmod a+w ".$memfile;
1467
`$chmodcmd`;
1468
1469
$cmd = "unlink ".$semfile;
1470
`$cmd`;
1471
$cmd = "unlink ".$memfile;
1472
`$cmd`;
1473
1474
print "\tTEST PASS\n";
1475
return 1;
1476
}
1477
1478
sub Test16
1479
{
1480
my ($osname, $cmd, $numprocs) = @_;
1481
my @pidList;
1482
my $count = 0;
1483
my $waitedfor=0;
1484
my $chmodcmd;
1485
1486
1487
print "Test 16: Same as test 7 but with multiple threads (its a tinch random).\n";
1488
`$cmd`;
1489
my $semfile = &getSemaphoreCntlFile($testcachname);
1490
my $memfile = &getMemoryCntlFile($testcachname);
1491
1492
&cleanupSysV($osname,$verbose);
1493
1494
my $semCount = scalar(&listSysVSemaphores($osname));
1495
my $memCount = scalar(&listSysVMemory($osname));
1496
1497
for ($count = 0; $count < $numprocs; $count++) {
1498
$chmodcmd = "chmod a-wx ".$semfile . " 2>&1";
1499
`$chmodcmd`;
1500
$chmodcmd = "chmod a-wx ".$memfile . " 2>&1";
1501
`$chmodcmd`;
1502
&cleanupSysV($osname,$verbose);
1503
my $pid = &forkAndRunInBackGround($cmd);
1504
push(@pidList, $pid);
1505
}
1506
1507
while (wait() != -1) {
1508
$waitedfor = $waitedfor + 1;
1509
}
1510
printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");
1511
1512
#$chmodcmd = "chmod ug+w ".$semfile;
1513
#`$chmodcmd`;
1514
#$chmodcmd = "chmod ug+w ".$memfile;
1515
#`$chmodcmd`;
1516
1517
#we can't create new sysv obj if cntrl file is readonly
1518
if ($memCount != scalar(&listSysVMemory($osname))) {
1519
print "\tTEST FAIL mem count ".$memCount." vs ".scalar(&listSysVMemory($osname))."\n";
1520
return 0;
1521
}
1522
if ($semCount != scalar(&listSysVSemaphores($osname))) {
1523
print "\tTEST FAIL sem count ".$semCount." vs ".scalar(&listSysVSemaphores($osname))."\n";
1524
return 0;
1525
}
1526
1527
$cmd = "unlink ".$semfile;
1528
`$cmd`;
1529
$cmd = "unlink ".$memfile;
1530
`$cmd`;
1531
1532
print "\tTEST PASS (we wrote a new control file)\n";
1533
return 1;
1534
1535
}
1536
1537
sub Test17
1538
{
1539
my ($osname, $javabin, $numprocs) = @_;
1540
my @pidList;
1541
my $count = 0;
1542
my $waitedfor=0;
1543
my $cacheDirectory = "/tmp/";
1544
my $cachename = "testSCSysVTest17num";
1545
1546
print "Test 17: Run ".$numprocs." JVMs and create same number of caches. The try again and make sure no new ones show up\n";
1547
1548
&cleanupSysV($osname,$verbose);
1549
1550
for ($count = 0; $count < $numprocs; $count++) {
1551
my $cmd = $javabin . " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$cachename.$count." -version ". " 2>&1";;
1552
my $pid = &forkAndRunInBackGround($cmd);
1553
push(@pidList, $pid);
1554
}
1555
1556
while (wait() != -1) {
1557
$waitedfor = $waitedfor + 1;
1558
}
1559
printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");
1560
1561
my @memList = &listSysVMemory($osname);
1562
my @semList = &listSysVSemaphores($osname);
1563
1564
if (scalar(@memList) == 0) {
1565
print "\tTEST FAIL mem count ".scalar(@memList)." vs 0"."\n";
1566
return 0;
1567
}
1568
if (scalar(@semList) == 0) {
1569
print "\tTEST FAIL sem count ".scalar(@semList)." vs 0"."\n";
1570
return 0;
1571
}
1572
1573
for ($count = 0; $count < $numprocs; $count++) {
1574
my $cmd = $javabin . " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$cachename.$count." -version ". " 2>&1";
1575
#print $cmd."\n";
1576
my $pid = &forkAndRunInBackGround($cmd);
1577
push(@pidList, $pid);
1578
}
1579
1580
$waitedfor = 0;
1581
while (wait() != -1) {
1582
$waitedfor = $waitedfor + 1;
1583
}
1584
printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");
1585
1586
my $cleanupCmd = "rm -f /tmp/javasharedresources/*".$cachename."*";
1587
`$cleanupCmd`;
1588
1589
if (scalar(@memList) != scalar(&listSysVMemory($osname))) {
1590
print "\tTEST FAIL mem count ".scalar(@memList)." vs ".scalar(&listSysVMemory($osname))."\n";
1591
return 0;
1592
}
1593
1594
if (scalar(@semList) != scalar(&listSysVSemaphores($osname))) {
1595
print "\tTEST FAIL sem count ".scalar(@semList)." vs ".scalar(&listSysVSemaphores($osname))."\n";
1596
return 0;
1597
}
1598
1599
print "\tTEST PASS\n";
1600
print "\t\tmem count ".scalar(@memList)."\n";
1601
print "\t\tsem count ".scalar(@semList)."\n";
1602
1603
return 1;
1604
1605
}
1606
1607
sub Test18
1608
{
1609
my ($osname, $javabin, $numprocs) = @_;
1610
my @pidList;
1611
my $count = 0;
1612
my $waitedfor=0;
1613
my $cacheDirectory = "/tmp/";
1614
my $cachename = "testSCSysVTest18num";
1615
1616
print "Test 18: Run ".$numprocs." JVMs and create same number of caches. Delete the control files and try again. \n";
1617
1618
&cleanupSysV($osname,$verbose);
1619
1620
for ($count = 0; $count < $numprocs; $count++) {
1621
my $cmd = $javabin . " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$cachename.$count." -version ". " 2>&1";;
1622
my $pid = &forkAndRunInBackGround($cmd);
1623
push(@pidList, $pid);
1624
}
1625
1626
while (wait() != -1) {
1627
$waitedfor = $waitedfor + 1;
1628
}
1629
printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");
1630
1631
#my @stdout = `ipcs`;
1632
#print @stdout,"\n";
1633
1634
my @memList = &listSysVMemory($osname);
1635
my @semList = &listSysVSemaphores($osname);
1636
my $cleanupCmd = "rm -f /tmp/javasharedresources/*".$cachename."*";
1637
`$cleanupCmd`;
1638
1639
for ($count = 0; $count < $numprocs; $count++) {
1640
my $cmd = $javabin . " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$cachename.$count." -version ". " 2>&1";;
1641
my $pid = &forkAndRunInBackGround($cmd);
1642
push(@pidList, $pid);
1643
#print $cmd."\n";
1644
#my @stdout = `$cmd`;
1645
#print @stdout,"\n";
1646
1647
}
1648
1649
$waitedfor = 0;
1650
while (wait() != -1) {
1651
$waitedfor = $waitedfor + 1;
1652
}
1653
printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");
1654
1655
#my @stdout = `ipcs`;
1656
#print @stdout,"\n";
1657
1658
my $cleanupCmd = "rm -f /tmp/javasharedresources/*".$cachename."*";
1659
`$cleanupCmd`;
1660
1661
if ((scalar(@memList)+$numprocs) != scalar(&listSysVMemory($osname))) {
1662
print "\tTEST FAIL mem count ".scalar(@memList)." vs ".scalar(&listSysVMemory($osname))."\n";
1663
return 0;
1664
}
1665
1666
if ((scalar(@semList)+$numprocs) != scalar(&listSysVSemaphores($osname))) {
1667
print "\tTEST FAIL sem count ".scalar(@semList)." vs ".scalar(&listSysVSemaphores($osname))."\n";
1668
return 0;
1669
}
1670
1671
print "\tTEST PASS\n";
1672
print "\t\tmem count ".scalar(&listSysVMemory($osname))."\n";
1673
print "\t\tsem count ".scalar(&listSysVSemaphores($osname))."\n";
1674
1675
return 1;
1676
1677
}
1678
1679
sub Test19
1680
{
1681
my ($osname, $cmd, $numprocs) = @_;
1682
my @pidList;
1683
my $count = 0;
1684
my $waitedfor=0;
1685
my $touchcmd;
1686
1687
1688
print "Test 19: Test non empty corrupted control files.\n";
1689
`$cmd`;
1690
my $semfile = &getSemaphoreCntlFile($testcachname);
1691
my $memfile = &getMemoryCntlFile($testcachname);
1692
&removeCntrlFiles($testcachname);
1693
1694
$touchcmd = "echo \"abcdefghijklmnopqrstuvwxyz\" > ".$semfile;
1695
`$touchcmd`;
1696
$touchcmd = "echo \"abcdefghijklmnopqrstuvwxyz\" > ".$memfile;
1697
`$touchcmd`;
1698
1699
my $semCount = scalar(&listSysVSemaphores($osname));
1700
my $memCount = scalar(&listSysVMemory($osname));
1701
#printf $cmd."\n";
1702
my @stdout = `$cmd`;
1703
#printf @stdout,"\n";
1704
if ($memCount == scalar(&listSysVMemory($osname))) {
1705
print "\tTEST FAIL mem count ".$memCount."\n";
1706
return 0;
1707
}
1708
if ($semCount == scalar(&listSysVSemaphores($osname))) {
1709
print "\tTEST FAIL sem count ".$semCount." vs ".scalar(&listSysVSemaphores($osname))."\n";
1710
return 0;
1711
}
1712
print "\tTEST PASS\n";
1713
return 1;
1714
1715
}
1716
1717
sub Test20
1718
{
1719
my ($osname, $javabin, $numprocs) = @_;
1720
my @pidList;
1721
my $count = 0;
1722
my $waitedfor=0;
1723
my $cacheDirectory = "/tmp/";
1724
my $cachename = "testSCSysVTest20num";
1725
1726
print "Test 20: Run ".$numprocs." JVMs and create same number of caches. Delete the ipcs objs and try again. \n";
1727
1728
&cleanupSysV($osname,$verbose);
1729
1730
for ($count = 0; $count < $numprocs; $count++) {
1731
my $cmd = $javabin . " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$cachename.$count." -version &> ./out.txt";
1732
my $cmd = $javabin . " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$cachename.$count." -version";
1733
my $pid = &forkAndRunInBackGround($cmd);
1734
push(@pidList, $pid);
1735
}
1736
1737
while (wait() != -1) {
1738
$waitedfor = $waitedfor + 1;
1739
}
1740
printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");
1741
1742
my @memList = &listSysVMemory($osname);
1743
my @semList = &listSysVSemaphores($osname);
1744
&cleanupSysV($osname,$verbose);
1745
1746
1747
for ($count = 0; $count < $numprocs; $count++) {
1748
my $cmd = $javabin . " -Xshareclasses:cacheDir=".$cacheDirectory.",nonpersistent,name=".$cachename.$count." -version &> ./out.txt";
1749
my $pid = &forkAndRunInBackGround($cmd);
1750
push(@pidList, $pid);
1751
}
1752
1753
$waitedfor = 0;
1754
while (wait() != -1) {
1755
$waitedfor = $waitedfor + 1;
1756
}
1757
printf("\tWe successfully ran " . $waitedfor . " JVMs with shared classes.\n");
1758
1759
my $cleanupCmd = "rm -f /tmp/javasharedresources/*".$cachename."*";
1760
`$cleanupCmd`;
1761
1762
if (scalar(@memList) != scalar(&listSysVMemory($osname))) {
1763
print "\tTEST FAIL mem count ".scalar(@memList)." vs ".scalar(&listSysVMemory($osname))."\n";
1764
return 0;
1765
}
1766
1767
if (scalar(@semList) != scalar(&listSysVSemaphores($osname))) {
1768
print "\tTEST FAIL sem count ".scalar(@semList)." vs ".scalar(&listSysVSemaphores($osname))."\n";
1769
return 0;
1770
}
1771
1772
print "\tTEST PASS\n";
1773
print "\t\tmem count ".scalar(&listSysVMemory($osname))."\n";
1774
print "\t\tsem count ".scalar(&listSysVSemaphores($osname))."\n";
1775
1776
return 1;
1777
1778
}
1779
1780
sub Test21
1781
{
1782
my ($osname, $cmd, $numprocs) = @_;
1783
my @pidList;
1784
my $count = 0;
1785
my $waitedfor=0;
1786
my $chmodcmd;
1787
my $ITER;
1788
1789
print "Test 21: Check semid in memory is valid ... it should not be!\n";
1790
`$cmd`;
1791
my $semfile = &getSemaphoreCntlFile($testcachname);
1792
my $memfile = &getMemoryCntlFile($testcachname);
1793
1794
&cleanupSysVSem($osname,$verbose);
1795
1796
my @stdout = `$cmd`;
1797
#print @stdout,"\n";
1798
1799
my $found = 0;
1800
foreach $ITER (@stdout) {
1801
if ($ITER =~ /different semaphore/) {
1802
$found = 1;
1803
}
1804
}
1805
if ($found == 0) {
1806
print "\tTEST FAIL success string not found in output\n";
1807
return 0;
1808
}
1809
1810
my $semCount = scalar(&listSysVSemaphores($osname));
1811
my $memCount = scalar(&listSysVMemory($osname));
1812
1813
# if semid mismatch is found the shared memory is destroyed ...
1814
if ($memCount != scalar(&listSysVMemory($osname))) {
1815
print "\tTEST FAIL mem count ".$memCount." vs ".scalar(&listSysVMemory($osname))."\n";
1816
return 0;
1817
}
1818
if ($semCount != scalar(&listSysVSemaphores($osname))) {
1819
print "\tTEST FAIL sem count ".$semCount." vs ".scalar(&listSysVSemaphores($osname))."\n";
1820
return 0;
1821
}
1822
print "\tTEST PASS\n";
1823
return 1;
1824
}
1825
1826
sub Test22
1827
{
1828
my ($osname, $cmd) = @_;
1829
my $chmodcmd;
1830
1831
print "Test 22: Check that JVM removes read-only control files having modlevel such that major level=0 and minor level=1.\n";
1832
`$cmd`;
1833
my $semfile = &getSemaphoreCntlFile($testcachname);
1834
my $memfile = &getMemoryCntlFile($testcachname);
1835
1836
&cleanupSysVSem($osname,$verbose);
1837
&cleanupSysVMem($osname,$verbose);
1838
1839
my $semCount = scalar(&listSysVSemaphores($osname));
1840
my $memCount = scalar(&listSysVMemory($osname));
1841
1842
# update control files such that major level=0 and minor level=1
1843
&updateSemControlFileModLevel($semfile);
1844
&updateShmControlFileModLevel($memfile);
1845
1846
# make control files read-only
1847
$chmodcmd = "chmod a-wx ".$semfile;
1848
`$chmodcmd`;
1849
$chmodcmd = "chmod a-wx ".$memfile;
1850
`$chmodcmd`;
1851
1852
# Using read-only control files having major level=0 and minor level=1 without any SysV objects
1853
# will cause JVM to remove the control files and recreate new shared class cache.
1854
`$cmd`;
1855
1856
if ($memCount+1 != scalar(&listSysVMemory($osname))) {
1857
print "\tTEST FAIL mem count expected ".($memCount+1)." vs found ".scalar(&listSysVMemory($osname))."\n";
1858
return 0;
1859
}
1860
if ($semCount+1 != scalar(&listSysVSemaphores($osname))) {
1861
print "\tTEST FAIL sem count expected ".($semCount+1)." vs found ".scalar(&listSysVSemaphores($osname))."\n";
1862
return 0;
1863
}
1864
1865
`$destroycmd`;
1866
1867
print "\tTEST PASS\n";
1868
return 1;
1869
}
1870
1871
#-----------------------------------------------------
1872
# listFilesInFolder()
1873
#-----------------------------------------------------
1874
sub listFilesInFolder
1875
{
1876
my ($folder) = @_;
1877
my @FILES;
1878
opendir(DIR, $folder) or return @FILES;
1879
@FILES= readdir(DIR);
1880
closedir(DIR) or die ("can not close dir");
1881
return @FILES;
1882
}
1883
1884
#-----------------------------------------------------
1885
# forkAndRunInBackGround()
1886
#-----------------------------------------------------
1887
sub forkAndRunInBackGround
1888
{
1889
my ($cmd) = @_;
1890
my $child_pid;
1891
if (!defined($child_pid = fork())) {
1892
die "cannot fork: $!";
1893
} elsif ($child_pid) {
1894
return $child_pid;
1895
} else {
1896
`$cmd`;
1897
exit 0;
1898
}
1899
}
1900
1901
#-----------------------------------------------------
1902
# cleanupSysV()
1903
#-----------------------------------------------------
1904
sub cleanupSysV
1905
{
1906
my ($osname, $verbose) = @_;
1907
&cleanupSysVSem($osname,$verbose);
1908
&cleanupSysVMem($osname,$verbose);
1909
}
1910
1911
#-----------------------------------------------------
1912
# cleanupSysV()
1913
#-----------------------------------------------------
1914
sub cleanupSysVSem
1915
{
1916
my ($osname,$verbose) = @_;
1917
my @semaphoreList;
1918
my @memoryList;
1919
my $ITER;
1920
1921
@semaphoreList = &listSysVSemaphores($osname);
1922
if ($verbose == 1) {
1923
print "Semaphores Being Removed: ".scalar(@semaphoreList)."\n";
1924
}
1925
foreach $ITER (@semaphoreList) {
1926
my $cmd = "ipcrm -s " . $ITER . " 2>&1";
1927
if ($verbose == 1) {
1928
print "\t".$cmd."\n";
1929
}
1930
`$cmd`;
1931
}
1932
}
1933
1934
#-----------------------------------------------------
1935
# cleanupSysV()
1936
#-----------------------------------------------------
1937
sub cleanupSysVMem
1938
{
1939
my ($osname,$verbose) = @_;
1940
my @memoryList;
1941
my $ITER;
1942
1943
@memoryList = &listSysVMemory($osname);
1944
if ($verbose == 1) {
1945
print "Shared Memory Being Removed: ".scalar(@memoryList)."\n";
1946
}
1947
foreach $ITER (@memoryList) {
1948
my $cmd = "ipcrm -m " . $ITER . " 2>&1";
1949
if ($verbose == 1) {
1950
print "\t".$cmd."\n";
1951
}
1952
`$cmd`;
1953
}
1954
}
1955
1956
#-----------------------------------------------------
1957
# listSysVSemaphores()
1958
#-----------------------------------------------------
1959
sub listSysVSemaphores
1960
{
1961
my $osname = $_[0];
1962
my @retval;
1963
my $semaphoreProjid = "(0x81|0x81|0x82|0x83|0x84|0x85|0x86|0x87|0x88|0x89|0x8a|0x8b|0x8c|0x8d|0x8e|0x8f|0x90|0x91|0x92|0x93|0x94)";
1964
my $memoryProjid = "(0x61|0x61|0x62|0x63|0x64|0x65|0x66|0x67|0x68|0x69|0x6a|0x6b|0x6c|0x6d|0x6e|0x6f|0x70|0x71|0x72|0x73|0x74)";
1965
my $keyindex = 0;
1966
my $idindex = 1;
1967
my $ownerindex = 2;
1968
1969
my @stdoutvar = ();
1970
my $iter = "";
1971
my $foundSemaphoreHeader = 0;
1972
my $foundMemoryHeader = 0;
1973
1974
my $memsremoved=0;
1975
my $semsremoved=0;
1976
1977
if ($osname =~ /zos/)
1978
{
1979
$keyindex=2;
1980
$idindex=1;
1981
$ownerindex=4;
1982
}
1983
1984
if ($osname =~ /aix/)
1985
{
1986
$keyindex=2;
1987
$idindex=1;
1988
$ownerindex=4;
1989
}
1990
1991
1992
#
1993
# GET LIST OF SEMAPHORES:
1994
# - Call ipcs and store stdout in a local variable.
1995
# - If the command fails we exit ASAP
1996
#
1997
@stdoutvar = `ipcs -s` or die("Error: could not execute ipcs!");
1998
1999
2000
$iter = "";
2001
$foundSemaphoreHeader = 0;
2002
$foundMemoryHeader = 0;
2003
foreach $iter (@stdoutvar) {
2004
2005
if ($iter =~ /Semaphore/) {
2006
$foundSemaphoreHeader=1;
2007
}
2008
if (($iter =~ /$semaphoreProjid/) && ($foundSemaphoreHeader==1)) {
2009
#remove any sequence of whitespace and insert a :
2010
$iter =~s/[\s]+/:/g;
2011
2012
#split the string around :
2013
my @vals = split(/:/,$iter);
2014
2015
#we expect 3 entries in this row ... the 1st three are kei,id,owner ...
2016
#the rest are don't cares ...
2017
if (@vals<3) {
2018
die("ipcs did not return expected output");
2019
}
2020
my $key = $vals[$keyindex];
2021
my $id = $vals[$idindex];
2022
my $owner = $vals[$ownerindex];
2023
push(@retval,$id);
2024
}
2025
}
2026
return @retval;
2027
}
2028
2029
2030
#-----------------------------------------------------
2031
# listSysVMemory()
2032
#-----------------------------------------------------
2033
sub listSysVMemory
2034
{
2035
my $osname = $_[0];
2036
my @retval;
2037
my $semaphoreProjid = "(0x81|0x81|0x82|0x83|0x84|0x85|0x86|0x87|0x88|0x89|0x8a|0x8b|0x8c|0x8d|0x8e|0x8f|0x90|0x91|0x92|0x93|0x94)";
2038
my $memoryProjid = "(0x61|0x61|0x62|0x63|0x64|0x65|0x66|0x67|0x68|0x69|0x6a|0x6b|0x6c|0x6d|0x6e|0x6f|0x70|0x71|0x72|0x73|0x74)";
2039
2040
my $keyindex = 0;
2041
my $idindex = 1;
2042
my $ownerindex = 2;
2043
2044
my @stdoutvar = ();
2045
my $iter = "";
2046
my $foundHeader = 0;
2047
2048
my $memsremoved=0;
2049
my $semsremoved=0;
2050
2051
if ($osname =~ /zos/)
2052
{
2053
$keyindex=2;
2054
$idindex=1;
2055
$ownerindex=4;
2056
}
2057
2058
if ($osname =~ /aix/)
2059
{
2060
$keyindex=2;
2061
$idindex=1;
2062
$ownerindex=4;
2063
}
2064
2065
2066
#
2067
# GET LIST OF MEMS:
2068
# - Call ipcs and store stdout in a local variable.
2069
# - If the command fails we exit ASAP
2070
#
2071
@stdoutvar = `ipcs -m` or die("Error: could not execute ipcs!");
2072
2073
2074
$iter = "";
2075
$foundHeader = 0;
2076
foreach $iter (@stdoutvar) {
2077
2078
if ($iter =~ /Memory/) {
2079
$foundHeader=1;
2080
}
2081
if (($iter =~ /$memoryProjid/) && ($foundHeader==1)) {
2082
#remove any sequence of whitespace and insert a :
2083
$iter =~s/[\s]+/:/g;
2084
2085
#split the string around :
2086
my @vals = split(/:/,$iter);
2087
2088
#we expect 3 entries in this row ... the 1st three are kei,id,owner ...
2089
#the rest are don't cares ...
2090
if (@vals<3) {
2091
die("ipcs did not return expected output");
2092
}
2093
my $key = $vals[$keyindex];
2094
my $id = $vals[$idindex];
2095
my $owner = $vals[$ownerindex];
2096
push(@retval,$id);
2097
}
2098
}
2099
return @retval;
2100
}
2101
2102
sub getIPCObjPermIndex
2103
{
2104
my $osname = $_[0];
2105
if ($osname =~ /zos/)
2106
{
2107
return 4;
2108
}
2109
2110
if ($osname =~ /aix/)
2111
{
2112
return 4;
2113
}
2114
return 5;
2115
}
2116
2117
#-----------------------------------------------------
2118
# updateSemControlFileModLevel() - updates the modlevel of control file to major level=0 and minor level=1.
2119
# Such readonly control files can be unlinked by JVM which creates control files with higher modlevel.
2120
#-----------------------------------------------------
2121
sub updateSemControlFileModLevel
2122
{
2123
my ($controlFile) = @_;
2124
my $modlevel;
2125
my $oldMajorLevel = 0;
2126
my $oldMinorLevel = 1;
2127
my $modLevelOffset = 4; # modlevel in semaphore control file is at offset 4
2128
2129
open my $fh, '+<', $controlFile or die("failed to open semaphore control file".$controlFile."\n");
2130
2131
$modlevel = ($oldMajorLevel << 16) | $oldMinorLevel;
2132
$modlevel = pack("I", $modlevel);
2133
sysseek($fh, $modLevelOffset, SEEK_SET);
2134
syswrite($fh, $modlevel) == 4 or die("failed to update semaphore control file".$controlFile."\n");
2135
close $fh;
2136
return 0;
2137
}
2138
2139
#-----------------------------------------------------
2140
# updateShmControlFileModLevel() - updates the modlevel of control file to major level=0 and minor level=1.
2141
# Such readonly control files can be unlinked by JVM which creates control files with higher modlevel.
2142
#-----------------------------------------------------
2143
sub updateShmControlFileModLevel
2144
{
2145
my ($controlFile) = @_;
2146
my $modlevel;
2147
my $oldMajorLevel = 0;
2148
my $oldMinorLevel = 1;
2149
my $modLevelOffset = 4; # modlevel in shared memory control file is at offset 4
2150
my $majorLevelMask = 0xFFFF0000;
2151
2152
open my $fh, '+<', $controlFile or die("failed to open shared memory control file".$controlFile."\n");
2153
2154
$modlevel = ($oldMajorLevel << 16) | $oldMinorLevel;
2155
$modlevel = pack("I", $modlevel);
2156
sysseek($fh, $modLevelOffset, SEEK_SET);
2157
syswrite($fh, $modlevel) == 4 or die("failed to update shared memory control file".$controlFile."\n");
2158
close $fh;
2159
return 0;
2160
}
2161
2162