aboutsummaryrefslogtreecommitdiffstats
path: root/vespamalloc/src/tests/test2
diff options
context:
space:
mode:
Diffstat (limited to 'vespamalloc/src/tests/test2')
-rw-r--r--vespamalloc/src/tests/test2/.gitignore4
-rw-r--r--vespamalloc/src/tests/test2/CMakeLists.txt10
-rw-r--r--vespamalloc/src/tests/test2/DESC1
-rw-r--r--vespamalloc/src/tests/test2/FILES1
-rw-r--r--vespamalloc/src/tests/test2/testgraph.cpp91
5 files changed, 107 insertions, 0 deletions
diff --git a/vespamalloc/src/tests/test2/.gitignore b/vespamalloc/src/tests/test2/.gitignore
new file mode 100644
index 00000000000..1c719511e5b
--- /dev/null
+++ b/vespamalloc/src/tests/test2/.gitignore
@@ -0,0 +1,4 @@
+.depend
+Makefile
+testgraph
+vespamalloc_testgraph_app
diff --git a/vespamalloc/src/tests/test2/CMakeLists.txt b/vespamalloc/src/tests/test2/CMakeLists.txt
new file mode 100644
index 00000000000..668c09feb03
--- /dev/null
+++ b/vespamalloc/src/tests/test2/CMakeLists.txt
@@ -0,0 +1,10 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(vespamalloc_testgraph_app
+ SOURCES
+ testgraph.cpp
+ ../../vespamalloc/util/stream.cpp
+ ../../vespamalloc/util/traceutil.cpp
+ ../../vespamalloc/util/callstack.cpp
+ DEPENDS
+)
+vespa_add_test(NAME vespamalloc_testgraph_app NO_VALGRIND COMMAND vespamalloc_testgraph_app)
diff --git a/vespamalloc/src/tests/test2/DESC b/vespamalloc/src/tests/test2/DESC
new file mode 100644
index 00000000000..4f3ca4d4d97
--- /dev/null
+++ b/vespamalloc/src/tests/test2/DESC
@@ -0,0 +1 @@
+This is a unittest of vespamalloc.
diff --git a/vespamalloc/src/tests/test2/FILES b/vespamalloc/src/tests/test2/FILES
new file mode 100644
index 00000000000..44b3d9f7c51
--- /dev/null
+++ b/vespamalloc/src/tests/test2/FILES
@@ -0,0 +1 @@
+testgraph.cpp
diff --git a/vespamalloc/src/tests/test2/testgraph.cpp b/vespamalloc/src/tests/test2/testgraph.cpp
new file mode 100644
index 00000000000..a9cf2c07b61
--- /dev/null
+++ b/vespamalloc/src/tests/test2/testgraph.cpp
@@ -0,0 +1,91 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespamalloc/util/index.h>
+#include <vespamalloc/util/callgraph.h>
+#include <vespamalloc/util/callstack.h>
+#include <vespamalloc/util/traceutil.h>
+
+using namespace vespamalloc;
+
+//typedef StackEntry<StackFrameReturnEntry> StackElem;
+typedef CallGraph<int, 0x1000, Index> CallGraphIntT;
+typedef CallGraph<StackElem, 0x1000, Index> CallGraphStackEntryT;
+
+namespace vespalibtest {
+
+template <typename T>
+class DumpGraph
+{
+public:
+ DumpGraph(const char * s="") : _string(s) { }
+ void handle(const T & node)
+ {
+ asciistream os;
+ os << ' ' << node;
+ _string += os.c_str();
+ if (node.callers() == NULL) {
+ printf("%s\n", _string.c_str());
+ }
+ }
+ const std::string & str() const { return _string; }
+private:
+ std::string _string;
+};
+
+}
+void testint() {
+ CallGraphIntT callGraph;
+ vespalibtest::DumpGraph<CallGraphIntT::Node> dump("int: ");
+ int s1[3] = { 1, 2, 3 };
+ int s2[3] = { 1, 2, 4 };
+ int s3[1] = { 1 };
+ int s4[3] = { 1, 3, 4 };
+ callGraph.addStack(s1, 3);
+ callGraph.addStack(s2, 3);
+ callGraph.addStack(s3, 1);
+ callGraph.addStack(s4, 3);
+ callGraph.traverseDepth(dump);
+ printf("%s\n", dump.str().c_str());
+}
+
+void teststackentry() {
+ CallGraphStackEntryT callGraph;
+ vespalibtest::DumpGraph<CallGraphStackEntryT::Node> dump("callstack: ");
+ StackElem s1[3] = { StackElem((void *)1), StackElem((void *)2), StackElem((void *)3) };
+ StackElem s2[3] = { StackElem((void *)1), StackElem((void *)2), StackElem((void *)4) };
+ StackElem s3[1] = { StackElem((void *)1) };
+ StackElem s4[3] = { StackElem((void *)1), StackElem((void *)3), StackElem((void *)4) };
+ callGraph.addStack(s1, 3);
+ callGraph.addStack(s2, 3);
+ callGraph.addStack(s3, 1);
+ callGraph.addStack(s4, 3);
+ callGraph.traverseDepth(dump);
+ printf("%s\n", dump.str().c_str());
+}
+
+void testaggregator() {
+ CallGraphStackEntryT callGraph;
+ StackElem s1[3] = { StackElem((void *)1), StackElem((void *)2), StackElem((void *)3) };
+ StackElem s2[3] = { StackElem((void *)1), StackElem((void *)2), StackElem((void *)4) };
+ StackElem s3[1] = { StackElem((void *)1) };
+ StackElem s4[3] = { StackElem((void *)1), StackElem((void *)3), StackElem((void *)4) };
+ callGraph.addStack(s1, 3);
+ callGraph.addStack(s2, 3);
+ callGraph.addStack(s3, 1);
+ callGraph.addStack(s4, 3);
+ Aggregator agg;
+ DumpGraph<CallGraphT::Node> dump(&agg, "{ ", " }");
+ callGraph.traverseDepth(dump);;
+ asciistream ost;
+ ost << agg;
+ printf("%s\n", ost.c_str());
+}
+int main (int argc, char *argv[])
+{
+ (void) argc;
+ (void) argv;
+ testint();
+ teststackentry();
+ testaggregator();
+ return 0;
+}
+