56 recording.stop();
57
58 List<String> expectedLibs = getExpectedLibs();
59 for (RecordedEvent event : Events.fromRecording(recording)) {
60 System.out.println("Event:" + event);
61 long unsignedTopAddress = event.getValue("topAddress");
62 long unsignedBaseAddress = event.getValue("baseAddress");
63 assertValidAddresses(unsignedBaseAddress, unsignedTopAddress);
64 String lib = Events.assertField(event, "name").notEmpty().getValue();
65 for (String expectedLib : new ArrayList<>(expectedLibs)) {
66 if (lib.contains(expectedLib)) {
67 expectedLibs.remove(expectedLib);
68 }
69 }
70 }
71 assertTrue(expectedLibs.isEmpty(), "Missing libraries:" + expectedLibs.stream().collect(Collectors.joining(", ")));
72 }
73
74 private static List<String> getExpectedLibs() throws Throwable {
75 String libTemplate = null;
76 if (Platform.isSolaris()) {
77 libTemplate = "lib%s.so";
78 } else if (Platform.isWindows()) {
79 libTemplate = "%s.dll";
80 } else if (Platform.isOSX()) {
81 libTemplate = "lib%s.dylib";
82 } else if (Platform.isLinux()) {
83 libTemplate = "lib%s.so";
84 }
85 if (libTemplate == null) {
86 throw new Exception("Unsupported OS");
87 }
88
89 List<String> libs = new ArrayList<String>();
90 String[] names = { "jvm", "java", "zip" };
91 for (String name : names) {
92 libs.add(String.format(libTemplate, name));
93 }
94 return libs;
95 }
96
97 private static void assertValidAddresses(long unsignedBaseAddress, long unsignedTopAddress) throws Exception {
98 if (unsignedTopAddress != 0) { // guard against missing value (0)
|
56 recording.stop();
57
58 List<String> expectedLibs = getExpectedLibs();
59 for (RecordedEvent event : Events.fromRecording(recording)) {
60 System.out.println("Event:" + event);
61 long unsignedTopAddress = event.getValue("topAddress");
62 long unsignedBaseAddress = event.getValue("baseAddress");
63 assertValidAddresses(unsignedBaseAddress, unsignedTopAddress);
64 String lib = Events.assertField(event, "name").notEmpty().getValue();
65 for (String expectedLib : new ArrayList<>(expectedLibs)) {
66 if (lib.contains(expectedLib)) {
67 expectedLibs.remove(expectedLib);
68 }
69 }
70 }
71 assertTrue(expectedLibs.isEmpty(), "Missing libraries:" + expectedLibs.stream().collect(Collectors.joining(", ")));
72 }
73
74 private static List<String> getExpectedLibs() throws Throwable {
75 String libTemplate = null;
76 if (Platform.isWindows()) {
77 libTemplate = "%s.dll";
78 } else if (Platform.isOSX()) {
79 libTemplate = "lib%s.dylib";
80 } else if (Platform.isLinux()) {
81 libTemplate = "lib%s.so";
82 }
83 if (libTemplate == null) {
84 throw new Exception("Unsupported OS");
85 }
86
87 List<String> libs = new ArrayList<String>();
88 String[] names = { "jvm", "java", "zip" };
89 for (String name : names) {
90 libs.add(String.format(libTemplate, name));
91 }
92 return libs;
93 }
94
95 private static void assertValidAddresses(long unsignedBaseAddress, long unsignedTopAddress) throws Exception {
96 if (unsignedTopAddress != 0) { // guard against missing value (0)
|