1 /* 2 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import jdk.test.lib.cds.CDSTestUtils; 25 import jdk.test.lib.process.OutputAnalyzer; 26 27 28 // This class contains methods common to all transformation test cases 29 public class TransformTestCommon { 30 31 // get parameters to an agent depending on the test case 32 // these parameters will instruct the agent which classes should be 33 // transformed 34 public static String getAgentParams(TestEntry entry, 35 String parent, String child) { 36 37 if (entry.transformParent && entry.transformChild) 38 return parent + "," + child; 39 if (entry.transformParent) 40 return parent; 41 if (entry.transformChild) 42 return child; 43 44 return ""; 45 } 46 47 48 private static void checkTransformationResults(TestEntry entry, 49 OutputAnalyzer out) 50 throws Exception { 51 52 if (entry.transformParent) 53 out.shouldContain(TransformUtil.ParentCheckPattern + 54 TransformUtil.AfterPattern); 55 56 if (entry.transformChild) 57 out.shouldContain(TransformUtil.ChildCheckPattern + 58 TransformUtil.AfterPattern); 59 } 60 61 62 private static void checkSharingByClass(TestEntry entry, OutputAnalyzer out, 63 String parent, String child) 64 throws Exception { 65 66 String parentSharedMatch = " " + parent + " source: shared objects file"; 67 String childSharedMatch = " " + child + " source: shared objects file"; 68 69 if (entry.isParentExpectedShared) 70 out.shouldContain(parentSharedMatch); 71 else 72 out.shouldNotContain(parentSharedMatch); 73 74 if (entry.isChildExpectedShared) 75 out.shouldContain(childSharedMatch); 76 else 77 out.shouldNotContain(childSharedMatch); 78 } 79 80 81 // Both parent and child classes should be passed to ClassFileTransformer.transform() 82 // exactly once. 83 private static void checkTransformationCounts(TestEntry entry, OutputAnalyzer out, 84 String parent, String child) 85 throws Exception { 86 87 String patternBase = "TransformerAgent: SimpleTransformer called for: "; 88 89 out.shouldContain(patternBase + child + "@1"); 90 out.shouldContain(patternBase + parent + "@1"); 91 92 out.shouldNotContain(patternBase + child + "@2"); 93 out.shouldNotContain(patternBase + parent + "@2"); 94 } 95 96 97 public static void checkResults(TestEntry entry, OutputAnalyzer out, 98 String parent, String child) 99 throws Exception { 100 101 // If we were not able to map an archive, 102 // then do not perform other checks, since 103 // there was no sharing at all 104 if (CDSTestUtils.isUnableToMap(out)) 105 return; 106 107 String childVmName = child.replace('.', '/'); 108 String parentVmName = parent.replace('.', '/'); 109 110 CDSTestUtils.checkExec(out); 111 checkTransformationCounts(entry, out, parentVmName, childVmName); 112 checkTransformationResults(entry, out); 113 checkSharingByClass(entry, out, parent, child); 114 } 115 }