|
|
01add4 |
From b0c2427cdc59be0bb1fa76e928b17d9aa1a0d4eb Mon Sep 17 00:00:00 2001
|
|
|
01add4 |
From: Martin Milata <mmilata@redhat.com>
|
|
|
01add4 |
Date: Wed, 28 Jan 2015 17:31:41 +0100
|
|
|
01add4 |
Subject: [PATCH] python: add Ruby support
|
|
|
01add4 |
|
|
|
01add4 |
Related: #1334604
|
|
|
01add4 |
|
|
|
01add4 |
Signed-off-by: Martin Milata <mmilata@redhat.com>
|
|
|
01add4 |
|
|
|
01add4 |
Conflicts:
|
|
|
01add4 |
tests/Makefile.am
|
|
|
01add4 |
---
|
|
|
01add4 |
python/Makefile.am | 4 +
|
|
|
01add4 |
python/py_module.c | 22 +++++
|
|
|
01add4 |
python/py_report.c | 9 ++
|
|
|
01add4 |
python/py_ruby_frame.c | 227 ++++++++++++++++++++++++++++++++++++++++++++
|
|
|
01add4 |
python/py_ruby_frame.h | 69 ++++++++++++++
|
|
|
01add4 |
python/py_ruby_stacktrace.c | 182 +++++++++++++++++++++++++++++++++++
|
|
|
01add4 |
python/py_ruby_stacktrace.h | 71 ++++++++++++++
|
|
|
01add4 |
tests/Makefile.am | 11 ++-
|
|
|
01add4 |
tests/python/ruby.py | 174 +++++++++++++++++++++++++++++++++
|
|
|
01add4 |
tests/python_bindings.at | 1 +
|
|
|
01add4 |
10 files changed, 769 insertions(+), 1 deletion(-)
|
|
|
01add4 |
create mode 100644 python/py_ruby_frame.c
|
|
|
01add4 |
create mode 100644 python/py_ruby_frame.h
|
|
|
01add4 |
create mode 100644 python/py_ruby_stacktrace.c
|
|
|
01add4 |
create mode 100644 python/py_ruby_stacktrace.h
|
|
|
01add4 |
create mode 100755 tests/python/ruby.py
|
|
|
01add4 |
|
|
|
01add4 |
diff --git a/python/Makefile.am b/python/Makefile.am
|
|
|
01add4 |
index 83273a2..9380c12 100644
|
|
|
01add4 |
--- a/python/Makefile.am
|
|
|
01add4 |
+++ b/python/Makefile.am
|
|
|
01add4 |
@@ -44,6 +44,10 @@ _satyr_la_SOURCES = \
|
|
|
01add4 |
py_java_thread.c \
|
|
|
01add4 |
py_java_stacktrace.h \
|
|
|
01add4 |
py_java_stacktrace.c \
|
|
|
01add4 |
+ py_ruby_frame.h \
|
|
|
01add4 |
+ py_ruby_frame.c \
|
|
|
01add4 |
+ py_ruby_stacktrace.h \
|
|
|
01add4 |
+ py_ruby_stacktrace.c \
|
|
|
01add4 |
py_rpm_package.h \
|
|
|
01add4 |
py_rpm_package.c \
|
|
|
01add4 |
py_metrics.h \
|
|
|
01add4 |
diff --git a/python/py_module.c b/python/py_module.c
|
|
|
01add4 |
index 83697ef..144465b 100644
|
|
|
01add4 |
--- a/python/py_module.c
|
|
|
01add4 |
+++ b/python/py_module.c
|
|
|
01add4 |
@@ -17,6 +17,8 @@
|
|
|
01add4 |
#include "py_core_frame.h"
|
|
|
01add4 |
#include "py_core_thread.h"
|
|
|
01add4 |
#include "py_core_stacktrace.h"
|
|
|
01add4 |
+#include "py_ruby_frame.h"
|
|
|
01add4 |
+#include "py_ruby_stacktrace.h"
|
|
|
01add4 |
#include "py_rpm_package.h"
|
|
|
01add4 |
#include "py_metrics.h"
|
|
|
01add4 |
#include "py_operating_system.h"
|
|
|
01add4 |
@@ -187,6 +189,18 @@ init_satyr()
|
|
|
01add4 |
return;
|
|
|
01add4 |
}
|
|
|
01add4 |
|
|
|
01add4 |
+ if (PyType_Ready(&sr_py_ruby_frame_type) < 0)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ puts("PyType_Ready(&sr_py_ruby_frame_type) < 0");
|
|
|
01add4 |
+ return;
|
|
|
01add4 |
+ }
|
|
|
01add4 |
+
|
|
|
01add4 |
+ if (PyType_Ready(&sr_py_ruby_stacktrace_type) < 0)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ puts("PyType_Ready(&sr_py_ruby_stacktrace_type) < 0");
|
|
|
01add4 |
+ return;
|
|
|
01add4 |
+ }
|
|
|
01add4 |
+
|
|
|
01add4 |
if (PyType_Ready(&sr_py_operating_system_type) < 0)
|
|
|
01add4 |
{
|
|
|
01add4 |
puts("PyType_Ready(&sr_py_operating_system_type) < 0");
|
|
|
01add4 |
@@ -301,6 +315,14 @@ init_satyr()
|
|
|
01add4 |
PyModule_AddObject(module, "JavaStacktrace",
|
|
|
01add4 |
(PyObject *)&sr_py_java_stacktrace_type);
|
|
|
01add4 |
|
|
|
01add4 |
+ Py_INCREF(&sr_py_ruby_frame_type);
|
|
|
01add4 |
+ PyModule_AddObject(module, "RubyFrame",
|
|
|
01add4 |
+ (PyObject *)&sr_py_ruby_frame_type);
|
|
|
01add4 |
+
|
|
|
01add4 |
+ Py_INCREF(&sr_py_ruby_stacktrace_type);
|
|
|
01add4 |
+ PyModule_AddObject(module, "RubyStacktrace",
|
|
|
01add4 |
+ (PyObject *)&sr_py_ruby_stacktrace_type);
|
|
|
01add4 |
+
|
|
|
01add4 |
Py_INCREF(&sr_py_core_frame_type);
|
|
|
01add4 |
PyModule_AddObject(module, "CoreFrame",
|
|
|
01add4 |
(PyObject *)&sr_py_core_frame_type);
|
|
|
01add4 |
diff --git a/python/py_report.c b/python/py_report.c
|
|
|
01add4 |
index 8aa35dd..74cd9dd 100644
|
|
|
01add4 |
--- a/python/py_report.c
|
|
|
01add4 |
+++ b/python/py_report.c
|
|
|
01add4 |
@@ -28,6 +28,7 @@
|
|
|
01add4 |
#include "py_python_stacktrace.h"
|
|
|
01add4 |
#include "py_koops_stacktrace.h"
|
|
|
01add4 |
#include "py_java_stacktrace.h"
|
|
|
01add4 |
+#include "py_ruby_stacktrace.h"
|
|
|
01add4 |
|
|
|
01add4 |
#include "report.h"
|
|
|
01add4 |
#include "operating_system.h"
|
|
|
01add4 |
@@ -284,6 +285,10 @@ report_prepare_subobjects(struct sr_py_report *report)
|
|
|
01add4 |
if (stacktrace_prepare(report, &sr_py_koops_stacktrace_type, false) < 0)
|
|
|
01add4 |
return -1;
|
|
|
01add4 |
break;
|
|
|
01add4 |
+ case SR_REPORT_RUBY:
|
|
|
01add4 |
+ if (stacktrace_prepare(report, &sr_py_ruby_stacktrace_type, false) < 0)
|
|
|
01add4 |
+ return -1;
|
|
|
01add4 |
+ break;
|
|
|
01add4 |
default:
|
|
|
01add4 |
report->report->stacktrace = NULL;
|
|
|
01add4 |
break;
|
|
|
01add4 |
@@ -347,6 +352,10 @@ report_to_python_obj(struct sr_report *report)
|
|
|
01add4 |
ro->stacktrace = koops_stacktrace_to_python_obj(
|
|
|
01add4 |
(struct sr_koops_stacktrace *)report->stacktrace);
|
|
|
01add4 |
break;
|
|
|
01add4 |
+ case SR_REPORT_RUBY:
|
|
|
01add4 |
+ ro->stacktrace = ruby_stacktrace_to_python_obj(
|
|
|
01add4 |
+ (struct sr_ruby_stacktrace *)report->stacktrace);
|
|
|
01add4 |
+ break;
|
|
|
01add4 |
default:
|
|
|
01add4 |
Py_INCREF(Py_None);
|
|
|
01add4 |
ro->stacktrace = Py_None;
|
|
|
01add4 |
diff --git a/python/py_ruby_frame.c b/python/py_ruby_frame.c
|
|
|
01add4 |
new file mode 100644
|
|
|
01add4 |
index 0000000..9ed45ad
|
|
|
01add4 |
--- /dev/null
|
|
|
01add4 |
+++ b/python/py_ruby_frame.c
|
|
|
01add4 |
@@ -0,0 +1,227 @@
|
|
|
01add4 |
+/*
|
|
|
01add4 |
+ py_ruby_frame.c
|
|
|
01add4 |
+
|
|
|
01add4 |
+ Copyright (C) 2015 Red Hat, Inc.
|
|
|
01add4 |
+
|
|
|
01add4 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
01add4 |
+ it under the terms of the GNU General Public License as published by
|
|
|
01add4 |
+ the Free Software Foundation; either version 2 of the License, or
|
|
|
01add4 |
+ (at your option) any later version.
|
|
|
01add4 |
+
|
|
|
01add4 |
+ This program is distributed in the hope that it will be useful,
|
|
|
01add4 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
01add4 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
01add4 |
+ GNU General Public License for more details.
|
|
|
01add4 |
+
|
|
|
01add4 |
+ You should have received a copy of the GNU General Public License along
|
|
|
01add4 |
+ with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
01add4 |
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
01add4 |
+*/
|
|
|
01add4 |
+#include "py_common.h"
|
|
|
01add4 |
+#include "py_base_frame.h"
|
|
|
01add4 |
+#include "py_ruby_frame.h"
|
|
|
01add4 |
+#include "location.h"
|
|
|
01add4 |
+#include "strbuf.h"
|
|
|
01add4 |
+#include "utils.h"
|
|
|
01add4 |
+#include "ruby/frame.h"
|
|
|
01add4 |
+
|
|
|
01add4 |
+#define frame_doc "satyr.RubyFrame - class representing a ruby frame\n\n" \
|
|
|
01add4 |
+ "Usage:\n\n" \
|
|
|
01add4 |
+ "satyr.RubyFrame() - creates an empty frame\n\n" \
|
|
|
01add4 |
+ "satyr.RubyFrame(str) - parses str and fills the frame object"
|
|
|
01add4 |
+
|
|
|
01add4 |
+#define f_dup_doc "Usage: frame.dup()\n\n" \
|
|
|
01add4 |
+ "Returns: satyr.RubyFrame - a new clone of frame\n\n" \
|
|
|
01add4 |
+ "Clones the frame object. All new structures are independent " \
|
|
|
01add4 |
+ "of the original object."
|
|
|
01add4 |
+
|
|
|
01add4 |
+
|
|
|
01add4 |
+static PyMethodDef
|
|
|
01add4 |
+frame_methods[] =
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ /* methods */
|
|
|
01add4 |
+ { "dup", sr_py_ruby_frame_dup, METH_NOARGS, f_dup_doc },
|
|
|
01add4 |
+ { NULL },
|
|
|
01add4 |
+};
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* See python/py_common.h and python/py_gdb_frame.c for generic getters/setters documentation. */
|
|
|
01add4 |
+#define GSOFF_PY_STRUCT sr_py_ruby_frame
|
|
|
01add4 |
+#define GSOFF_PY_MEMBER frame
|
|
|
01add4 |
+#define GSOFF_C_STRUCT sr_ruby_frame
|
|
|
01add4 |
+GSOFF_START
|
|
|
01add4 |
+GSOFF_MEMBER(file_name),
|
|
|
01add4 |
+GSOFF_MEMBER(file_line),
|
|
|
01add4 |
+GSOFF_MEMBER(special_function),
|
|
|
01add4 |
+GSOFF_MEMBER(function_name),
|
|
|
01add4 |
+GSOFF_MEMBER(block_level),
|
|
|
01add4 |
+GSOFF_MEMBER(rescue_level)
|
|
|
01add4 |
+GSOFF_END
|
|
|
01add4 |
+
|
|
|
01add4 |
+static PyGetSetDef
|
|
|
01add4 |
+frame_getset[] =
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ SR_ATTRIBUTE_STRING(file_name, "Source file name (string)" ),
|
|
|
01add4 |
+ SR_ATTRIBUTE_UINT32(file_line, "Source line number (positive integer)" ),
|
|
|
01add4 |
+ SR_ATTRIBUTE_BOOL (special_function, "True if the frame doesn't belong to an actual function" ),
|
|
|
01add4 |
+ SR_ATTRIBUTE_STRING(function_name, "Function name (string)" ),
|
|
|
01add4 |
+ SR_ATTRIBUTE_UINT32(block_level, "Block nesting level (integer)" ),
|
|
|
01add4 |
+ SR_ATTRIBUTE_UINT32(rescue_level, "Rescue block nesting level (integer)" ),
|
|
|
01add4 |
+ { NULL },
|
|
|
01add4 |
+};
|
|
|
01add4 |
+
|
|
|
01add4 |
+PyTypeObject
|
|
|
01add4 |
+sr_py_ruby_frame_type =
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ PyObject_HEAD_INIT(NULL)
|
|
|
01add4 |
+ 0,
|
|
|
01add4 |
+ "satyr.RubyFrame", /* tp_name */
|
|
|
01add4 |
+ sizeof(struct sr_py_ruby_frame), /* tp_basicsize */
|
|
|
01add4 |
+ 0, /* tp_itemsize */
|
|
|
01add4 |
+ sr_py_ruby_frame_free, /* tp_dealloc */
|
|
|
01add4 |
+ NULL, /* tp_print */
|
|
|
01add4 |
+ NULL, /* tp_getattr */
|
|
|
01add4 |
+ NULL, /* tp_setattr */
|
|
|
01add4 |
+ NULL, /* tp_compare */
|
|
|
01add4 |
+ NULL, /* tp_repr */
|
|
|
01add4 |
+ NULL, /* tp_as_number */
|
|
|
01add4 |
+ NULL, /* tp_as_sequence */
|
|
|
01add4 |
+ NULL, /* tp_as_mapping */
|
|
|
01add4 |
+ NULL, /* tp_hash */
|
|
|
01add4 |
+ NULL, /* tp_call */
|
|
|
01add4 |
+ sr_py_ruby_frame_str, /* tp_str */
|
|
|
01add4 |
+ NULL, /* tp_getattro */
|
|
|
01add4 |
+ NULL, /* tp_setattro */
|
|
|
01add4 |
+ NULL, /* tp_as_buffer */
|
|
|
01add4 |
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
|
|
|
01add4 |
+ frame_doc, /* tp_doc */
|
|
|
01add4 |
+ NULL, /* tp_traverse */
|
|
|
01add4 |
+ NULL, /* tp_clear */
|
|
|
01add4 |
+ NULL, /* tp_richcompare */
|
|
|
01add4 |
+ 0, /* tp_weaklistoffset */
|
|
|
01add4 |
+ NULL, /* tp_iter */
|
|
|
01add4 |
+ NULL, /* tp_iternext */
|
|
|
01add4 |
+ frame_methods, /* tp_methods */
|
|
|
01add4 |
+ NULL, /* tp_members */
|
|
|
01add4 |
+ frame_getset, /* tp_getset */
|
|
|
01add4 |
+ &sr_py_base_frame_type, /* tp_base */
|
|
|
01add4 |
+ NULL, /* tp_dict */
|
|
|
01add4 |
+ NULL, /* tp_descr_get */
|
|
|
01add4 |
+ NULL, /* tp_descr_set */
|
|
|
01add4 |
+ 0, /* tp_dictoffset */
|
|
|
01add4 |
+ NULL, /* tp_init */
|
|
|
01add4 |
+ NULL, /* tp_alloc */
|
|
|
01add4 |
+ sr_py_ruby_frame_new, /* tp_new */
|
|
|
01add4 |
+ NULL, /* tp_free */
|
|
|
01add4 |
+ NULL, /* tp_is_gc */
|
|
|
01add4 |
+ NULL, /* tp_bases */
|
|
|
01add4 |
+ NULL, /* tp_mro */
|
|
|
01add4 |
+ NULL, /* tp_cache */
|
|
|
01add4 |
+ NULL, /* tp_subclasses */
|
|
|
01add4 |
+ NULL, /* tp_weaklist */
|
|
|
01add4 |
+};
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* constructor */
|
|
|
01add4 |
+PyObject *
|
|
|
01add4 |
+sr_py_ruby_frame_new(PyTypeObject *object, PyObject *args, PyObject *kwds)
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ struct sr_py_ruby_frame *fo = (struct sr_py_ruby_frame*)
|
|
|
01add4 |
+ PyObject_New(struct sr_py_ruby_frame, &sr_py_ruby_frame_type);
|
|
|
01add4 |
+
|
|
|
01add4 |
+ if (!fo)
|
|
|
01add4 |
+ return PyErr_NoMemory();
|
|
|
01add4 |
+
|
|
|
01add4 |
+ const char *str = NULL;
|
|
|
01add4 |
+ if (!PyArg_ParseTuple(args, "|s", &str))
|
|
|
01add4 |
+ return NULL;
|
|
|
01add4 |
+
|
|
|
01add4 |
+ if (str)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ struct sr_location location;
|
|
|
01add4 |
+ sr_location_init(&location);
|
|
|
01add4 |
+ fo->frame = sr_ruby_frame_parse(&str, &location);
|
|
|
01add4 |
+
|
|
|
01add4 |
+ if (!fo->frame)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ PyErr_SetString(PyExc_ValueError, location.message);
|
|
|
01add4 |
+ return NULL;
|
|
|
01add4 |
+ }
|
|
|
01add4 |
+ }
|
|
|
01add4 |
+ else
|
|
|
01add4 |
+ fo->frame = sr_ruby_frame_new();
|
|
|
01add4 |
+
|
|
|
01add4 |
+ return (PyObject*)fo;
|
|
|
01add4 |
+}
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* destructor */
|
|
|
01add4 |
+void
|
|
|
01add4 |
+sr_py_ruby_frame_free(PyObject *object)
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ struct sr_py_ruby_frame *this = (struct sr_py_ruby_frame*)object;
|
|
|
01add4 |
+ sr_ruby_frame_free(this->frame);
|
|
|
01add4 |
+ PyObject_Del(object);
|
|
|
01add4 |
+}
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* str */
|
|
|
01add4 |
+PyObject *
|
|
|
01add4 |
+sr_py_ruby_frame_str(PyObject *self)
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ struct sr_py_ruby_frame *this = (struct sr_py_ruby_frame*)self;
|
|
|
01add4 |
+ struct sr_strbuf *buf = sr_strbuf_new();
|
|
|
01add4 |
+
|
|
|
01add4 |
+
|
|
|
01add4 |
+ if (this->frame->file_name)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ sr_strbuf_append_str(buf, this->frame->file_name);
|
|
|
01add4 |
+ }
|
|
|
01add4 |
+
|
|
|
01add4 |
+ if (this->frame->file_line)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ sr_strbuf_append_strf(buf, ":%d", this->frame->file_line);
|
|
|
01add4 |
+ }
|
|
|
01add4 |
+
|
|
|
01add4 |
+ if (this->frame->function_name)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ sr_strbuf_append_str(buf, ":in `");
|
|
|
01add4 |
+
|
|
|
01add4 |
+ int i;
|
|
|
01add4 |
+ for (i = 0; i < this->frame->rescue_level; i++)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ sr_strbuf_append_str(buf, "rescue in ");
|
|
|
01add4 |
+ }
|
|
|
01add4 |
+
|
|
|
01add4 |
+ if (this->frame->block_level == 1)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ sr_strbuf_append_str(buf, "block in ");
|
|
|
01add4 |
+ }
|
|
|
01add4 |
+ else if (this->frame->block_level > 1)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ sr_strbuf_append_strf(buf, "block (%d levels) in ", this->frame->block_level);
|
|
|
01add4 |
+ }
|
|
|
01add4 |
+
|
|
|
01add4 |
+ sr_strbuf_append_strf(buf, "%s%s%s'",
|
|
|
01add4 |
+ (this->frame->special_function ? "<" : ""),
|
|
|
01add4 |
+ this->frame->function_name,
|
|
|
01add4 |
+ (this->frame->special_function ? ">" : ""));
|
|
|
01add4 |
+ }
|
|
|
01add4 |
+
|
|
|
01add4 |
+ char *str = sr_strbuf_free_nobuf(buf);
|
|
|
01add4 |
+ PyObject *result = Py_BuildValue("s", str);
|
|
|
01add4 |
+ free(str);
|
|
|
01add4 |
+ return result;
|
|
|
01add4 |
+}
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* methods */
|
|
|
01add4 |
+PyObject *
|
|
|
01add4 |
+sr_py_ruby_frame_dup(PyObject *self, PyObject *args)
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ struct sr_py_ruby_frame *this = (struct sr_py_ruby_frame*)self;
|
|
|
01add4 |
+ struct sr_py_ruby_frame *fo = (struct sr_py_ruby_frame*)
|
|
|
01add4 |
+ PyObject_New(struct sr_py_ruby_frame, &sr_py_ruby_frame_type);
|
|
|
01add4 |
+
|
|
|
01add4 |
+ if (!fo)
|
|
|
01add4 |
+ return PyErr_NoMemory();
|
|
|
01add4 |
+
|
|
|
01add4 |
+ fo->frame = sr_ruby_frame_dup(this->frame, false);
|
|
|
01add4 |
+
|
|
|
01add4 |
+ return (PyObject*)fo;
|
|
|
01add4 |
+}
|
|
|
01add4 |
diff --git a/python/py_ruby_frame.h b/python/py_ruby_frame.h
|
|
|
01add4 |
new file mode 100644
|
|
|
01add4 |
index 0000000..7f460ff
|
|
|
01add4 |
--- /dev/null
|
|
|
01add4 |
+++ b/python/py_ruby_frame.h
|
|
|
01add4 |
@@ -0,0 +1,69 @@
|
|
|
01add4 |
+/*
|
|
|
01add4 |
+ py_ruby_frame.h
|
|
|
01add4 |
+
|
|
|
01add4 |
+ Copyright (C) 2015 Red Hat, Inc.
|
|
|
01add4 |
+
|
|
|
01add4 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
01add4 |
+ it under the terms of the GNU General Public License as published by
|
|
|
01add4 |
+ the Free Software Foundation; either version 2 of the License, or
|
|
|
01add4 |
+ (at your option) any later version.
|
|
|
01add4 |
+
|
|
|
01add4 |
+ This program is distributed in the hope that it will be useful,
|
|
|
01add4 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
01add4 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
01add4 |
+ GNU General Public License for more details.
|
|
|
01add4 |
+
|
|
|
01add4 |
+ You should have received a copy of the GNU General Public License along
|
|
|
01add4 |
+ with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
01add4 |
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
01add4 |
+*/
|
|
|
01add4 |
+#ifndef SATYR_PY_RUBY_FRAME_H
|
|
|
01add4 |
+#define SATYR_PY_RUBY_FRAME_H
|
|
|
01add4 |
+
|
|
|
01add4 |
+/**
|
|
|
01add4 |
+ * @file
|
|
|
01add4 |
+ * @brief Python bindings for RUBY frame.
|
|
|
01add4 |
+ */
|
|
|
01add4 |
+
|
|
|
01add4 |
+#ifdef __cplusplus
|
|
|
01add4 |
+extern "C" {
|
|
|
01add4 |
+#endif
|
|
|
01add4 |
+
|
|
|
01add4 |
+#include <Python.h>
|
|
|
01add4 |
+#include <structmember.h>
|
|
|
01add4 |
+
|
|
|
01add4 |
+PyTypeObject sr_py_ruby_frame_type;
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* The beginning of this structure has to have the same layout as
|
|
|
01add4 |
+ * sr_py_base_frame.
|
|
|
01add4 |
+ */
|
|
|
01add4 |
+struct sr_py_ruby_frame
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ PyObject_HEAD
|
|
|
01add4 |
+ struct sr_ruby_frame *frame;
|
|
|
01add4 |
+};
|
|
|
01add4 |
+
|
|
|
01add4 |
+/**
|
|
|
01add4 |
+ * Constructor.
|
|
|
01add4 |
+ */
|
|
|
01add4 |
+PyObject *sr_py_ruby_frame_new(PyTypeObject *object,
|
|
|
01add4 |
+ PyObject *args, PyObject *kwds);
|
|
|
01add4 |
+
|
|
|
01add4 |
+/**
|
|
|
01add4 |
+ * Destructor.
|
|
|
01add4 |
+ */
|
|
|
01add4 |
+void sr_py_ruby_frame_free(PyObject *object);
|
|
|
01add4 |
+
|
|
|
01add4 |
+/**
|
|
|
01add4 |
+ * str
|
|
|
01add4 |
+ */
|
|
|
01add4 |
+PyObject *sr_py_ruby_frame_str(PyObject *self);
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* methods */
|
|
|
01add4 |
+PyObject *sr_py_ruby_frame_dup(PyObject *self, PyObject *args);
|
|
|
01add4 |
+
|
|
|
01add4 |
+#ifdef __cplusplus
|
|
|
01add4 |
+}
|
|
|
01add4 |
+#endif
|
|
|
01add4 |
+
|
|
|
01add4 |
+#endif
|
|
|
01add4 |
diff --git a/python/py_ruby_stacktrace.c b/python/py_ruby_stacktrace.c
|
|
|
01add4 |
new file mode 100644
|
|
|
01add4 |
index 0000000..97fbb44
|
|
|
01add4 |
--- /dev/null
|
|
|
01add4 |
+++ b/python/py_ruby_stacktrace.c
|
|
|
01add4 |
@@ -0,0 +1,182 @@
|
|
|
01add4 |
+#include "py_common.h"
|
|
|
01add4 |
+#include "py_ruby_frame.h"
|
|
|
01add4 |
+#include "py_ruby_stacktrace.h"
|
|
|
01add4 |
+#include "py_base_stacktrace.h"
|
|
|
01add4 |
+#include "utils.h"
|
|
|
01add4 |
+#include "strbuf.h"
|
|
|
01add4 |
+#include "ruby/frame.h"
|
|
|
01add4 |
+#include "ruby/stacktrace.h"
|
|
|
01add4 |
+#include "location.h"
|
|
|
01add4 |
+#include "stacktrace.h"
|
|
|
01add4 |
+
|
|
|
01add4 |
+#define stacktrace_doc "satyr.RubyStacktrace - class representing a ruby stacktrace\n\n" \
|
|
|
01add4 |
+ "Usage:\n\n" \
|
|
|
01add4 |
+ "satyr.RubyStacktrace() - creates an empty ruby stacktrace\n\n" \
|
|
|
01add4 |
+ "satyr.RubyStacktrace(str) - parses str and fills the ruby stacktrace object"
|
|
|
01add4 |
+
|
|
|
01add4 |
+#define f_dup_doc "Usage: stacktrace.dup()\n\n" \
|
|
|
01add4 |
+ "Returns: satyr.RubyStacktrace - a new clone of ruby stacktrace\n\n" \
|
|
|
01add4 |
+ "Clones the RubyStacktrace object. All new structures are independent " \
|
|
|
01add4 |
+ "of the original object."
|
|
|
01add4 |
+
|
|
|
01add4 |
+
|
|
|
01add4 |
+static PyMethodDef
|
|
|
01add4 |
+ruby_stacktrace_methods[] =
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ /* methods */
|
|
|
01add4 |
+ { "dup", sr_py_ruby_stacktrace_dup, METH_NOARGS, f_dup_doc },
|
|
|
01add4 |
+ { NULL },
|
|
|
01add4 |
+};
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* See python/py_common.h and python/py_gdb_frame.c for generic getters/setters documentation. */
|
|
|
01add4 |
+#define GSOFF_PY_STRUCT sr_py_ruby_stacktrace
|
|
|
01add4 |
+#define GSOFF_PY_MEMBER stacktrace
|
|
|
01add4 |
+#define GSOFF_C_STRUCT sr_ruby_stacktrace
|
|
|
01add4 |
+GSOFF_START
|
|
|
01add4 |
+GSOFF_MEMBER(exception_name)
|
|
|
01add4 |
+GSOFF_END
|
|
|
01add4 |
+
|
|
|
01add4 |
+static PyGetSetDef
|
|
|
01add4 |
+ruby_stacktrace_getset[] =
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ SR_ATTRIBUTE_STRING(exception_name, "Exception type (string)" ),
|
|
|
01add4 |
+ { NULL },
|
|
|
01add4 |
+};
|
|
|
01add4 |
+
|
|
|
01add4 |
+PyTypeObject sr_py_ruby_stacktrace_type = {
|
|
|
01add4 |
+ PyObject_HEAD_INIT(NULL)
|
|
|
01add4 |
+ 0,
|
|
|
01add4 |
+ "satyr.RubyStacktrace", /* tp_name */
|
|
|
01add4 |
+ sizeof(struct sr_py_ruby_stacktrace), /* tp_basicsize */
|
|
|
01add4 |
+ 0, /* tp_itemsize */
|
|
|
01add4 |
+ sr_py_ruby_stacktrace_free, /* tp_dealloc */
|
|
|
01add4 |
+ NULL, /* tp_print */
|
|
|
01add4 |
+ NULL, /* tp_getattr */
|
|
|
01add4 |
+ NULL, /* tp_setattr */
|
|
|
01add4 |
+ NULL, /* tp_compare */
|
|
|
01add4 |
+ NULL, /* tp_repr */
|
|
|
01add4 |
+ NULL, /* tp_as_number */
|
|
|
01add4 |
+ NULL, /* tp_as_sequence */
|
|
|
01add4 |
+ NULL, /* tp_as_mapping */
|
|
|
01add4 |
+ NULL, /* tp_hash */
|
|
|
01add4 |
+ NULL, /* tp_call */
|
|
|
01add4 |
+ sr_py_ruby_stacktrace_str, /* tp_str */
|
|
|
01add4 |
+ NULL, /* tp_getattro */
|
|
|
01add4 |
+ NULL, /* tp_setattro */
|
|
|
01add4 |
+ NULL, /* tp_as_buffer */
|
|
|
01add4 |
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
|
|
|
01add4 |
+ stacktrace_doc, /* tp_doc */
|
|
|
01add4 |
+ NULL, /* tp_traverse */
|
|
|
01add4 |
+ NULL, /* tp_clear */
|
|
|
01add4 |
+ NULL, /* tp_richcompare */
|
|
|
01add4 |
+ 0, /* tp_weaklistoffset */
|
|
|
01add4 |
+ NULL, /* tp_iter */
|
|
|
01add4 |
+ NULL, /* tp_iternext */
|
|
|
01add4 |
+ ruby_stacktrace_methods, /* tp_methods */
|
|
|
01add4 |
+ NULL, /* tp_members */
|
|
|
01add4 |
+ ruby_stacktrace_getset, /* tp_getset */
|
|
|
01add4 |
+ &sr_py_single_stacktrace_type, /* tp_base */
|
|
|
01add4 |
+ NULL, /* tp_dict */
|
|
|
01add4 |
+ NULL, /* tp_descr_get */
|
|
|
01add4 |
+ NULL, /* tp_descr_set */
|
|
|
01add4 |
+ 0, /* tp_dictoffset */
|
|
|
01add4 |
+ NULL, /* tp_init */
|
|
|
01add4 |
+ NULL, /* tp_alloc */
|
|
|
01add4 |
+ sr_py_ruby_stacktrace_new, /* tp_new */
|
|
|
01add4 |
+ NULL, /* tp_free */
|
|
|
01add4 |
+ NULL, /* tp_is_gc */
|
|
|
01add4 |
+ NULL, /* tp_bases */
|
|
|
01add4 |
+ NULL, /* tp_mro */
|
|
|
01add4 |
+ NULL, /* tp_cache */
|
|
|
01add4 |
+ NULL, /* tp_subclasses */
|
|
|
01add4 |
+ NULL, /* tp_weaklist */
|
|
|
01add4 |
+};
|
|
|
01add4 |
+
|
|
|
01add4 |
+PyObject *
|
|
|
01add4 |
+ruby_stacktrace_to_python_obj(struct sr_ruby_stacktrace *stacktrace)
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ struct sr_py_ruby_stacktrace *bo = PyObject_New(struct sr_py_ruby_stacktrace,
|
|
|
01add4 |
+ &sr_py_ruby_stacktrace_type);
|
|
|
01add4 |
+ if (!bo)
|
|
|
01add4 |
+ return PyErr_NoMemory();
|
|
|
01add4 |
+
|
|
|
01add4 |
+ bo->frame_type = &sr_py_ruby_frame_type;
|
|
|
01add4 |
+
|
|
|
01add4 |
+ bo->stacktrace = stacktrace;
|
|
|
01add4 |
+ bo->frames = frames_to_python_list((struct sr_thread *)bo->stacktrace,
|
|
|
01add4 |
+ bo->frame_type);
|
|
|
01add4 |
+ if (!bo->frames)
|
|
|
01add4 |
+ return NULL;
|
|
|
01add4 |
+
|
|
|
01add4 |
+ return (PyObject *)bo;
|
|
|
01add4 |
+}
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* constructor */
|
|
|
01add4 |
+PyObject *
|
|
|
01add4 |
+sr_py_ruby_stacktrace_new(PyTypeObject *object,
|
|
|
01add4 |
+ PyObject *args,
|
|
|
01add4 |
+ PyObject *kwds)
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ const char *str = NULL;
|
|
|
01add4 |
+ if (!PyArg_ParseTuple(args, "|s", &str))
|
|
|
01add4 |
+ return NULL;
|
|
|
01add4 |
+
|
|
|
01add4 |
+ struct sr_ruby_stacktrace *stacktrace;
|
|
|
01add4 |
+
|
|
|
01add4 |
+ if (str)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ struct sr_location location;
|
|
|
01add4 |
+ sr_location_init(&location);
|
|
|
01add4 |
+ stacktrace = sr_ruby_stacktrace_parse(&str, &location);
|
|
|
01add4 |
+ if (!stacktrace)
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ PyErr_SetString(PyExc_ValueError, location.message);
|
|
|
01add4 |
+ return NULL;
|
|
|
01add4 |
+ }
|
|
|
01add4 |
+ }
|
|
|
01add4 |
+ else
|
|
|
01add4 |
+ stacktrace = sr_ruby_stacktrace_new();
|
|
|
01add4 |
+
|
|
|
01add4 |
+ return ruby_stacktrace_to_python_obj(stacktrace);
|
|
|
01add4 |
+}
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* destructor */
|
|
|
01add4 |
+void
|
|
|
01add4 |
+sr_py_ruby_stacktrace_free(PyObject *object)
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ struct sr_py_ruby_stacktrace *this = (struct sr_py_ruby_stacktrace*)object;
|
|
|
01add4 |
+ /* the list will decref all of its elements */
|
|
|
01add4 |
+ Py_DECREF(this->frames);
|
|
|
01add4 |
+ this->stacktrace->frames = NULL;
|
|
|
01add4 |
+ sr_ruby_stacktrace_free(this->stacktrace);
|
|
|
01add4 |
+ PyObject_Del(object);
|
|
|
01add4 |
+}
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* str */
|
|
|
01add4 |
+PyObject *
|
|
|
01add4 |
+sr_py_ruby_stacktrace_str(PyObject *self)
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ struct sr_py_ruby_stacktrace *this = (struct sr_py_ruby_stacktrace *)self;
|
|
|
01add4 |
+ struct sr_strbuf *buf = sr_strbuf_new();
|
|
|
01add4 |
+ sr_strbuf_append_strf(buf, "Ruby stacktrace with %zd frames",
|
|
|
01add4 |
+ (ssize_t)(PyList_Size(this->frames)));
|
|
|
01add4 |
+ char *str = sr_strbuf_free_nobuf(buf);
|
|
|
01add4 |
+ PyObject *result = Py_BuildValue("s", str);
|
|
|
01add4 |
+ free(str);
|
|
|
01add4 |
+ return result;
|
|
|
01add4 |
+}
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* methods */
|
|
|
01add4 |
+PyObject *
|
|
|
01add4 |
+sr_py_ruby_stacktrace_dup(PyObject *self, PyObject *args)
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ struct sr_py_ruby_stacktrace *this = (struct sr_py_ruby_stacktrace*)self;
|
|
|
01add4 |
+ if (frames_prepare_linked_list((struct sr_py_base_thread *)this) < 0)
|
|
|
01add4 |
+ return NULL;
|
|
|
01add4 |
+
|
|
|
01add4 |
+ struct sr_ruby_stacktrace *stacktrace = sr_ruby_stacktrace_dup(this->stacktrace);
|
|
|
01add4 |
+ if (!stacktrace)
|
|
|
01add4 |
+ return NULL;
|
|
|
01add4 |
+
|
|
|
01add4 |
+ return ruby_stacktrace_to_python_obj(stacktrace);
|
|
|
01add4 |
+}
|
|
|
01add4 |
diff --git a/python/py_ruby_stacktrace.h b/python/py_ruby_stacktrace.h
|
|
|
01add4 |
new file mode 100644
|
|
|
01add4 |
index 0000000..f4eebce
|
|
|
01add4 |
--- /dev/null
|
|
|
01add4 |
+++ b/python/py_ruby_stacktrace.h
|
|
|
01add4 |
@@ -0,0 +1,71 @@
|
|
|
01add4 |
+/*
|
|
|
01add4 |
+ py_ruby_stacktrace.h
|
|
|
01add4 |
+
|
|
|
01add4 |
+ Copyright (C) 2015 Red Hat, Inc.
|
|
|
01add4 |
+
|
|
|
01add4 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
01add4 |
+ it under the terms of the GNU General Public License as published by
|
|
|
01add4 |
+ the Free Software Foundation; either version 2 of the License, or
|
|
|
01add4 |
+ (at your option) any later version.
|
|
|
01add4 |
+
|
|
|
01add4 |
+ This program is distributed in the hope that it will be useful,
|
|
|
01add4 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
01add4 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
01add4 |
+ GNU General Public License for more details.
|
|
|
01add4 |
+
|
|
|
01add4 |
+ You should have received a copy of the GNU General Public License along
|
|
|
01add4 |
+ with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
01add4 |
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
01add4 |
+*/
|
|
|
01add4 |
+#ifndef SATYR_PY_RUBY_STACKTRACE_H
|
|
|
01add4 |
+#define SATYR_PY_RUBY_STACKTRACE_H
|
|
|
01add4 |
+
|
|
|
01add4 |
+/**
|
|
|
01add4 |
+ * @file
|
|
|
01add4 |
+ * @brief Python bindings for Ruby stack trace.
|
|
|
01add4 |
+ */
|
|
|
01add4 |
+
|
|
|
01add4 |
+#ifdef __cplusplus
|
|
|
01add4 |
+extern "C" {
|
|
|
01add4 |
+#endif
|
|
|
01add4 |
+
|
|
|
01add4 |
+#include <Python.h>
|
|
|
01add4 |
+#include <structmember.h>
|
|
|
01add4 |
+
|
|
|
01add4 |
+PyTypeObject sr_py_ruby_stacktrace_type;
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* The beginning of this structure has to have the same layout as
|
|
|
01add4 |
+ * sr_py_base_thread.
|
|
|
01add4 |
+ */
|
|
|
01add4 |
+struct sr_py_ruby_stacktrace
|
|
|
01add4 |
+{
|
|
|
01add4 |
+ PyObject_HEAD
|
|
|
01add4 |
+ struct sr_ruby_stacktrace *stacktrace;
|
|
|
01add4 |
+ PyObject *frames;
|
|
|
01add4 |
+ PyTypeObject *frame_type;
|
|
|
01add4 |
+};
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* helpers */
|
|
|
01add4 |
+PyObject *ruby_stacktrace_to_python_obj(struct sr_ruby_stacktrace *stacktrace);
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* constructor */
|
|
|
01add4 |
+PyObject *sr_py_ruby_stacktrace_new(PyTypeObject *object,
|
|
|
01add4 |
+ PyObject *args,
|
|
|
01add4 |
+ PyObject *kwds);
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* destructor */
|
|
|
01add4 |
+void sr_py_ruby_stacktrace_free(PyObject *object);
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* str */
|
|
|
01add4 |
+PyObject *sr_py_ruby_stacktrace_str(PyObject *self);
|
|
|
01add4 |
+
|
|
|
01add4 |
+/* methods */
|
|
|
01add4 |
+PyObject *sr_py_ruby_stacktrace_dup(PyObject *self, PyObject *args);
|
|
|
01add4 |
+PyObject *sr_py_ruby_stacktrace_normalize(PyObject *self, PyObject *args);
|
|
|
01add4 |
+
|
|
|
01add4 |
+
|
|
|
01add4 |
+#ifdef __cplusplus
|
|
|
01add4 |
+}
|
|
|
01add4 |
+#endif
|
|
|
01add4 |
+
|
|
|
01add4 |
+#endif
|
|
|
01add4 |
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
|
|
01add4 |
index 0eb33a5..b261880 100644
|
|
|
01add4 |
--- a/tests/Makefile.am
|
|
|
01add4 |
+++ b/tests/Makefile.am
|
|
|
01add4 |
@@ -4,7 +4,16 @@ EXTRA_DIST = gdb_stacktraces \
|
|
|
01add4 |
json_files \
|
|
|
01add4 |
kerneloopses \
|
|
|
01add4 |
programs \
|
|
|
01add4 |
- python \
|
|
|
01add4 |
+ python/core.py \
|
|
|
01add4 |
+ python/gdb.py \
|
|
|
01add4 |
+ python/java.py \
|
|
|
01add4 |
+ python/koops.py \
|
|
|
01add4 |
+ python/metrics.py \
|
|
|
01add4 |
+ python/misc.py \
|
|
|
01add4 |
+ python/python.py \
|
|
|
01add4 |
+ python/report.py \
|
|
|
01add4 |
+ python/ruby.py \
|
|
|
01add4 |
+ python/test_helpers.py \
|
|
|
01add4 |
python_stacktraces
|
|
|
01add4 |
|
|
|
01add4 |
## ------------ ##
|
|
|
01add4 |
diff --git a/tests/python/ruby.py b/tests/python/ruby.py
|
|
|
01add4 |
new file mode 100755
|
|
|
01add4 |
index 0000000..8a20593
|
|
|
01add4 |
--- /dev/null
|
|
|
01add4 |
+++ b/tests/python/ruby.py
|
|
|
01add4 |
@@ -0,0 +1,174 @@
|
|
|
01add4 |
+#!/usr/bin/env python
|
|
|
01add4 |
+
|
|
|
01add4 |
+import unittest
|
|
|
01add4 |
+from test_helpers import *
|
|
|
01add4 |
+
|
|
|
01add4 |
+path = '../ruby_stacktraces/ruby-01'
|
|
|
01add4 |
+contents = load_input_contents(path)
|
|
|
01add4 |
+frames_expected = 21
|
|
|
01add4 |
+expected_short_text = '''#1 rescue in block (2 levels) in func in /usr/share/ruby/vendor_ruby/will_crash.rb:13
|
|
|
01add4 |
+#2 block (2 levels) in func in /usr/share/ruby/vendor_ruby/will_crash.rb:10
|
|
|
01add4 |
+#3 times in /usr/share/ruby/vendor_ruby/will_crash.rb:9
|
|
|
01add4 |
+#4 block in func in /usr/share/ruby/vendor_ruby/will_crash.rb:9
|
|
|
01add4 |
+#5 times in /usr/share/ruby/vendor_ruby/will_crash.rb:8
|
|
|
01add4 |
+#6 func in /usr/share/ruby/vendor_ruby/will_crash.rb:8
|
|
|
01add4 |
+'''
|
|
|
01add4 |
+
|
|
|
01add4 |
+class TestRubyStacktrace(BindingsTestCase):
|
|
|
01add4 |
+ def setUp(self):
|
|
|
01add4 |
+ self.trace = satyr.RubyStacktrace(contents)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_correct_frame_count(self):
|
|
|
01add4 |
+ self.assertEqual(frame_count(self.trace), frames_expected)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_dup(self):
|
|
|
01add4 |
+ dup = self.trace.dup()
|
|
|
01add4 |
+ self.assertNotEqual(id(dup.frames), id(self.trace.frames))
|
|
|
01add4 |
+ self.assertTrue(all(map(lambda t1, t2: t1.equals(t2), dup.frames, self.trace.frames)))
|
|
|
01add4 |
+
|
|
|
01add4 |
+ dup.frames = dup.frames[:5]
|
|
|
01add4 |
+ dup2 = dup.dup()
|
|
|
01add4 |
+ self.assertEqual(len(dup.frames), len(dup2.frames))
|
|
|
01add4 |
+ self.assertNotEqual(id(dup.frames), id(dup2.frames))
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_prepare_linked_list(self):
|
|
|
01add4 |
+ dup = self.trace.dup()
|
|
|
01add4 |
+ dup.frames = dup.frames[:5]
|
|
|
01add4 |
+ dup2 = dup.dup()
|
|
|
01add4 |
+ self.assertTrue(len(dup2.frames) <= 5)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_str(self):
|
|
|
01add4 |
+ out = str(self.trace)
|
|
|
01add4 |
+ self.assertTrue(('Ruby stacktrace with %d frames' % frames_expected) in out)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_getset(self):
|
|
|
01add4 |
+ self.assertGetSetCorrect(self.trace, 'exception_name', 'Wrap::MyException', 'WhateverException')
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_special_functions(self):
|
|
|
01add4 |
+ trace = load_input_contents('../ruby_stacktraces/ruby-01')
|
|
|
01add4 |
+ trace = satyr.RubyStacktrace(trace)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ f = trace.frames[0]
|
|
|
01add4 |
+ self.assertEqual(f.file_name, '/usr/share/ruby/vendor_ruby/will_crash.rb')
|
|
|
01add4 |
+ self.assertEqual(f.function_name, 'func')
|
|
|
01add4 |
+ self.assertFalse(f.special_function)
|
|
|
01add4 |
+ self.assertEqual(f.block_level, 2)
|
|
|
01add4 |
+ self.assertEqual(f.rescue_level, 1)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ f = trace.frames[-1]
|
|
|
01add4 |
+ self.assertEqual(f.file_name, '/usr/bin/will_ruby_raise')
|
|
|
01add4 |
+ self.assertEqual(f.function_name, 'main')
|
|
|
01add4 |
+ self.assertTrue(f.special_function)
|
|
|
01add4 |
+ self.assertEqual(f.block_level, 0)
|
|
|
01add4 |
+ self.assertEqual(f.rescue_level, 0)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_to_short_text(self):
|
|
|
01add4 |
+ self.assertEqual(self.trace.to_short_text(6), expected_short_text)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_bthash(self):
|
|
|
01add4 |
+ self.assertEqual(self.trace.get_bthash(), '6124e03542a0381b14ebaf2c5b5e9f467ebba33b')
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_duphash(self):
|
|
|
01add4 |
+ expected_plain = '''Thread
|
|
|
01add4 |
+/usr/share/ruby/vendor_ruby/will_crash.rb:13
|
|
|
01add4 |
+/usr/share/ruby/vendor_ruby/will_crash.rb:10
|
|
|
01add4 |
+/usr/share/ruby/vendor_ruby/will_crash.rb:9
|
|
|
01add4 |
+'''
|
|
|
01add4 |
+ self.assertEqual(self.trace.get_duphash(flags=satyr.DUPHASH_NOHASH, frames=3), expected_plain)
|
|
|
01add4 |
+ self.assertEqual(self.trace.get_duphash(), 'c877cda04fbce8d51c4d9b1d628b0f618677607e')
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_crash_thread(self):
|
|
|
01add4 |
+ self.assertTrue(self.trace.crash_thread is self.trace)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_from_json(self):
|
|
|
01add4 |
+ trace = satyr.RubyStacktrace.from_json('{}')
|
|
|
01add4 |
+ self.assertEqual(trace.frames, [])
|
|
|
01add4 |
+
|
|
|
01add4 |
+ json_text = '''
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ "exception_name": "NotImplementedError",
|
|
|
01add4 |
+ "stacktrace": [
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ "file_name": "/usr/share/foobar/mod/file.rb",
|
|
|
01add4 |
+ "function_name": "do_nothing",
|
|
|
01add4 |
+ "file_line": 42,
|
|
|
01add4 |
+ },
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ "special_function": "top (required)",
|
|
|
01add4 |
+ "file_line": 451
|
|
|
01add4 |
+ },
|
|
|
01add4 |
+ {
|
|
|
01add4 |
+ "unknown_key": 19876543,
|
|
|
01add4 |
+ "block_level": 42,
|
|
|
01add4 |
+ "rescue_level": 6
|
|
|
01add4 |
+ }
|
|
|
01add4 |
+ ]
|
|
|
01add4 |
+ }
|
|
|
01add4 |
+'''
|
|
|
01add4 |
+ trace = satyr.RubyStacktrace.from_json(json_text)
|
|
|
01add4 |
+ self.assertEqual(trace.exception_name, 'NotImplementedError')
|
|
|
01add4 |
+ self.assertEqual(len(trace.frames), 3)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ self.assertEqual(trace.frames[0].file_name, '/usr/share/foobar/mod/file.rb')
|
|
|
01add4 |
+ self.assertEqual(trace.frames[0].function_name, 'do_nothing')
|
|
|
01add4 |
+ self.assertEqual(trace.frames[0].file_line, 42)
|
|
|
01add4 |
+ self.assertFalse(trace.frames[0].special_function)
|
|
|
01add4 |
+ self.assertEqual(trace.frames[0].block_level, 0)
|
|
|
01add4 |
+ self.assertEqual(trace.frames[0].rescue_level, 0)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ self.assertEqual(trace.frames[1].file_name, None)
|
|
|
01add4 |
+ self.assertEqual(trace.frames[1].function_name, 'top (required)')
|
|
|
01add4 |
+ self.assertEqual(trace.frames[1].file_line, 451)
|
|
|
01add4 |
+ self.assertTrue(trace.frames[1].special_function)
|
|
|
01add4 |
+ self.assertEqual(trace.frames[1].block_level, 0)
|
|
|
01add4 |
+ self.assertEqual(trace.frames[1].rescue_level, 0)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ self.assertEqual(trace.frames[2].file_name, None)
|
|
|
01add4 |
+ self.assertEqual(trace.frames[2].function_name, None)
|
|
|
01add4 |
+ self.assertEqual(trace.frames[2].file_line, 0)
|
|
|
01add4 |
+ self.assertFalse(trace.frames[2].special_function)
|
|
|
01add4 |
+ self.assertEqual(trace.frames[2].block_level, 42)
|
|
|
01add4 |
+ self.assertEqual(trace.frames[2].rescue_level, 6)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_hash(self):
|
|
|
01add4 |
+ self.assertHashable(self.trace)
|
|
|
01add4 |
+
|
|
|
01add4 |
+
|
|
|
01add4 |
+class TestRubyFrame(BindingsTestCase):
|
|
|
01add4 |
+ def setUp(self):
|
|
|
01add4 |
+ self.frame = satyr.RubyStacktrace(contents).frames[1]
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_str(self):
|
|
|
01add4 |
+ out = str(self.frame)
|
|
|
01add4 |
+ self.assertEqual(out, "/usr/share/ruby/vendor_ruby/will_crash.rb:10:in `block (2 levels) in func'")
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_dup(self):
|
|
|
01add4 |
+ dup = self.frame.dup()
|
|
|
01add4 |
+ self.assertEqual(dup.function_name,
|
|
|
01add4 |
+ self.frame.function_name)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ dup.function_name = 'other'
|
|
|
01add4 |
+ self.assertNotEqual(dup.function_name,
|
|
|
01add4 |
+ self.frame.function_name)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_cmp(self):
|
|
|
01add4 |
+ dup = self.frame.dup()
|
|
|
01add4 |
+ self.assertTrue(dup.equals(dup))
|
|
|
01add4 |
+ self.assertTrue(dup.equals(self.frame))
|
|
|
01add4 |
+ self.assertNotEqual(id(dup), id(self.frame))
|
|
|
01add4 |
+ dup.function_name = 'another'
|
|
|
01add4 |
+ self.assertFalse(dup.equals(self.frame))
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_getset(self):
|
|
|
01add4 |
+ self.assertGetSetCorrect(self.frame, 'file_name', '/usr/share/ruby/vendor_ruby/will_crash.rb', 'java.rs')
|
|
|
01add4 |
+ self.assertGetSetCorrect(self.frame, 'file_line', 10, 6667)
|
|
|
01add4 |
+ self.assertGetSetCorrect(self.frame, 'special_function', False, True)
|
|
|
01add4 |
+ self.assertGetSetCorrect(self.frame, 'function_name', 'func', 'iiiiii')
|
|
|
01add4 |
+ self.assertGetSetCorrect(self.frame, 'block_level', 2, 666)
|
|
|
01add4 |
+ self.assertGetSetCorrect(self.frame, 'rescue_level', 0, 9000)
|
|
|
01add4 |
+
|
|
|
01add4 |
+ def test_hash(self):
|
|
|
01add4 |
+ self.assertHashable(self.frame)
|
|
|
01add4 |
+
|
|
|
01add4 |
+if __name__ == '__main__':
|
|
|
01add4 |
+ unittest.main()
|
|
|
01add4 |
diff --git a/tests/python_bindings.at b/tests/python_bindings.at
|
|
|
01add4 |
index a5e19c3..906f561 100644
|
|
|
01add4 |
--- a/tests/python_bindings.at
|
|
|
01add4 |
+++ b/tests/python_bindings.at
|
|
|
01add4 |
@@ -12,5 +12,6 @@ AT_TEST_PYTHON([koops])
|
|
|
01add4 |
AT_TEST_PYTHON([python])
|
|
|
01add4 |
AT_TEST_PYTHON([java])
|
|
|
01add4 |
AT_TEST_PYTHON([core])
|
|
|
01add4 |
+AT_TEST_PYTHON([ruby])
|
|
|
01add4 |
AT_TEST_PYTHON([metrics])
|
|
|
01add4 |
AT_TEST_PYTHON([report])
|
|
|
01add4 |
--
|
|
|
01add4 |
1.8.3.1
|
|
|
01add4 |
|