annotate graal/com.oracle.graal.debug.test/src/com/oracle/graal/debug/test/DebugHistogramTest.java @ 11551:63b4694d3627

split DebugHistogram printing out into separate service
author Doug Simon <doug.simon@oracle.com>
date Mon, 09 Sep 2013 13:57:53 +0200
parents 3495149b9531
children a771cc1f10f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9103
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2013, 2013, Oracle and/or its affiliates. All rights reserved.
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.debug.test;
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import java.io.*;
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27 import org.junit.*;
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 import com.oracle.graal.debug.*;
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents: 9104
diff changeset
30 import com.oracle.graal.debug.internal.*;
9103
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 public class DebugHistogramTest {
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 @Test
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 public void testEmptyHistogram() {
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36 DebugHistogram histogram = Debug.createHistogram("TestHistogram");
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents: 9104
diff changeset
38 new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram);
9103
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 Assert.assertEquals("TestHistogram is empty.\n", outputStream.toString());
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40 }
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
41
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 @Test
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 public void testSingleEntryHistogram() {
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 DebugHistogram histogram = Debug.createHistogram("TestHistogram");
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 histogram.add(new Integer(1));
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 histogram.add(new Integer(1));
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents: 9104
diff changeset
48 new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram);
9103
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 String[] lines = outputStream.toString().split("\n");
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
50 Assert.assertEquals(4, lines.length);
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51 Assert.assertEquals("TestHistogram has 1 unique elements and 2 total elements:", lines[0]);
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 Assert.assertEquals(
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 lines[1]);
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 Assert.assertEquals(
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 "| 1 | 2 | ==================================================================================================== |",
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 lines[2]);
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 Assert.assertEquals(
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 lines[3]);
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61 }
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
63 @Test
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64 public void testMultipleEntryHistogram() {
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 DebugHistogram histogram = Debug.createHistogram("TestHistogram");
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 histogram.add(new Integer(1));
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 histogram.add(new Integer(2));
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69 histogram.add(new Integer(2));
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents: 9104
diff changeset
70 new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram);
9103
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
71 String[] lines = outputStream.toString().split("\n");
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
72 Assert.assertEquals(5, lines.length);
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
73 Assert.assertEquals("TestHistogram has 2 unique elements and 3 total elements:", lines[0]);
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
74 Assert.assertEquals(
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
76 lines[1]);
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
77 Assert.assertEquals(
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
78 "| 2 | 2 | ==================================================================================================== |",
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
79 lines[2]);
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
80 Assert.assertEquals(
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
81 "| 1 | 1 | ================================================== |",
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
82 lines[3]);
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
83 Assert.assertEquals(
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
84 "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
85 lines[4]);
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
86 }
9104
3495149b9531 Added support for trimming the name of objects in the histogram and a corresponding test case.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9103
diff changeset
87
3495149b9531 Added support for trimming the name of objects in the histogram and a corresponding test case.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9103
diff changeset
88 @Test
3495149b9531 Added support for trimming the name of objects in the histogram and a corresponding test case.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9103
diff changeset
89 public void testTooLongValueString() {
3495149b9531 Added support for trimming the name of objects in the histogram and a corresponding test case.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9103
diff changeset
90 DebugHistogram histogram = Debug.createHistogram("TestHistogram");
3495149b9531 Added support for trimming the name of objects in the histogram and a corresponding test case.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9103
diff changeset
91 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
3495149b9531 Added support for trimming the name of objects in the histogram and a corresponding test case.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9103
diff changeset
92 histogram.add("MyCustomValue");
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents: 9104
diff changeset
93 new DebugHistogramAsciiPrinter(new PrintStream(outputStream), Integer.MAX_VALUE, 10, 10).print(histogram);
9104
3495149b9531 Added support for trimming the name of objects in the histogram and a corresponding test case.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9103
diff changeset
94 String[] lines = outputStream.toString().split("\n");
3495149b9531 Added support for trimming the name of objects in the histogram and a corresponding test case.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9103
diff changeset
95 Assert.assertEquals(4, lines.length);
3495149b9531 Added support for trimming the name of objects in the histogram and a corresponding test case.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9103
diff changeset
96 Assert.assertEquals("TestHistogram has 1 unique elements and 1 total elements:", lines[0]);
3495149b9531 Added support for trimming the name of objects in the histogram and a corresponding test case.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9103
diff changeset
97 Assert.assertEquals("----------------------------------------", lines[1]);
3495149b9531 Added support for trimming the name of objects in the histogram and a corresponding test case.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9103
diff changeset
98 Assert.assertEquals("| MyCusto... | 1 | ========== |", lines[2]);
3495149b9531 Added support for trimming the name of objects in the histogram and a corresponding test case.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9103
diff changeset
99 Assert.assertEquals("----------------------------------------", lines[3]);
3495149b9531 Added support for trimming the name of objects in the histogram and a corresponding test case.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9103
diff changeset
100 }
9103
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
101 }