Comparison was previously implemented by means of cmp() methods. Now we
can do `f1 < f2` instead of `f1.cmp(f2) < 0`. Notably, "==" works as
expected. Related to #59.
Signed-off-by: Martin Milata <mmilata(a)redhat.com>
---
python/py_common.c | 11 +++++++++++
python/py_common.h | 6 ++++++
python/py_gdb_frame.c | 31 ++++++-------------------------
python/py_gdb_frame.h | 6 +++++-
python/py_gdb_thread.c | 33 ++++++++++-----------------------
python/py_gdb_thread.h | 4 +++-
python/py_java_frame.c | 28 ++++++----------------------
python/py_java_frame.h | 6 +++++-
python/py_java_thread.c | 33 ++++++++++-----------------------
python/py_java_thread.h | 4 +++-
python/py_koops_frame.c | 28 ++++++----------------------
python/py_koops_frame.h | 6 +++++-
python/py_python_frame.c | 28 ++++++----------------------
python/py_python_frame.h | 6 +++++-
tests/python/gdb.py | 20 ++++++++++++++------
tests/python/java.py | 22 +++++++++++++++++-----
tests/python/koops.py | 16 +++++++++++-----
tests/python/python.py | 14 +++++++++-----
18 files changed, 138 insertions(+), 164 deletions(-)
diff --git a/python/py_common.c b/python/py_common.c
index 15aa108..f441815 100644
--- a/python/py_common.c
+++ b/python/py_common.c
@@ -125,3 +125,14 @@ sr_py_setter_uint64(PyObject *self, PyObject *rhs, void *data)
MEMB_T(uint64_t, MEMB(self, gsoff->c_struct_offset), gsoff->member_offset) =
newvalue;
return 0;
}
+
+int
+normalize_cmp(int n)
+{
+ if (n > 0)
+ return 1;
+ else if (n < 0)
+ return -1;
+
+ return 0;
+}
diff --git a/python/py_common.h b/python/py_common.h
index 7b9dc82..9cc39e7 100644
--- a/python/py_common.h
+++ b/python/py_common.h
@@ -119,6 +119,12 @@ int sr_py_setter_bool(PyObject *self, PyObject *rhs, void *data);
PyObject *sr_py_getter_uint64(PyObject *self, void *data);
int sr_py_setter_uint64(PyObject *self, PyObject *rhs, void *data);
+/*
+ * Satyr's comparison functions return arbitrary numbers, while python
+ * requires the result to be in {-1, 0, 1}.
+ */
+int normalize_cmp(int n);
+
#ifdef __cplusplus
}
#endif
diff --git a/python/py_gdb_frame.c b/python/py_gdb_frame.c
index 6bfd700..48b027e 100644
--- a/python/py_gdb_frame.c
+++ b/python/py_gdb_frame.c
@@ -50,21 +50,12 @@
"Checks whether the frame represents a call to
" \
"a function with given name from a given
file."
-#define f_cmp_doc "Usage: frame.cmp(frame2, compare_number)\n" \
- "frame2: satyr.Frame - another frame to compare\n" \
- "compare_number: boolean - whether to compare also thread
numbers\n" \
- "Returns: integer - distance\n" \
- "Compares frame to frame2. Returns 0 if frame = frame2, " \
- "<0 if frame is 'less' than frame2, >0 if frame is
'more' " \
- "than frame2."
-
static PyMethodDef
frame_methods[] =
{
/* methods */
{ "dup", sr_py_gdb_frame_dup, METH_NOARGS,
f_dup_doc },
- { "cmp", sr_py_gdb_frame_cmp, METH_VARARGS,
f_cmp_doc },
{ "calls_func", sr_py_gdb_frame_calls_func, METH_VARARGS,
f_calls_func_doc },
{ "calls_func_in_file", sr_py_gdb_frame_calls_func_in_file, METH_VARARGS,
f_calls_func_in_file_doc },
{ NULL },
@@ -143,7 +134,7 @@ sr_py_gdb_frame_type =
NULL, /* tp_print */
NULL, /* tp_getattr */
NULL, /* tp_setattr */
- NULL, /* tp_compare */
+ sr_py_gdb_frame_cmp, /* tp_compare */
NULL, /* tp_repr */
NULL, /* tp_as_number */
NULL, /* tp_as_sequence */
@@ -262,23 +253,13 @@ sr_py_gdb_frame_dup(PyObject *self, PyObject *args)
return (PyObject*)fo;
}
-PyObject *
-sr_py_gdb_frame_cmp(PyObject *self, PyObject *args)
+int
+sr_py_gdb_frame_cmp(PyObject *self, PyObject *other)
{
- PyObject *compare_to;
- int compare_number;
- if (!PyArg_ParseTuple(args,
- "O!i",
- &sr_py_gdb_frame_type,
- &compare_to,
- &compare_number))
- {
- return NULL;
- }
-
struct sr_gdb_frame *f1 = ((struct sr_py_gdb_frame*)self)->frame;
- struct sr_gdb_frame *f2 = ((struct sr_py_gdb_frame*)compare_to)->frame;
- return Py_BuildValue("i", sr_gdb_frame_cmp(f1, f2, compare_number));
+ struct sr_gdb_frame *f2 = ((struct sr_py_gdb_frame*)other)->frame;
+
+ return normalize_cmp(sr_gdb_frame_cmp(f1, f2, true));
}
PyObject *
diff --git a/python/py_gdb_frame.h b/python/py_gdb_frame.h
index 4926014..e0ac90c 100644
--- a/python/py_gdb_frame.h
+++ b/python/py_gdb_frame.h
@@ -56,9 +56,13 @@ void sr_py_gdb_frame_free(PyObject *object);
*/
PyObject *sr_py_gdb_frame_str(PyObject *self);
+/**
+ * cmp
+ */
+int sr_py_gdb_frame_cmp(PyObject *self, PyObject *other);
+
/* methods */
PyObject *sr_py_gdb_frame_dup(PyObject *self, PyObject *args);
-PyObject *sr_py_gdb_frame_cmp(PyObject *self, PyObject *args);
PyObject *sr_py_gdb_frame_calls_func(PyObject *self, PyObject *args);
PyObject *sr_py_gdb_frame_calls_func_in_file(PyObject *self, PyObject *args);
diff --git a/python/py_gdb_thread.c b/python/py_gdb_thread.c
index 1af6108..3f47043 100644
--- a/python/py_gdb_thread.c
+++ b/python/py_gdb_thread.c
@@ -17,13 +17,6 @@
"Clones the thread object. All new structures are independent
" \
"on the original object."
-#define t_cmp_doc "Usage: thread.cmp(thread2)\n" \
- "thread2: satyr.Thread - another thread to compare" \
- "Returns: integer - distance" \
- "Compares thread to thread2. Returns 0 if thread = thread2, "
\
- "<0 if thread is 'less' than thread2, >0 if thread
is 'more' " \
- "than thread2."
-
#define t_quality_counts_doc "Usage: thread.quality_counts()\n" \
"Returns: tuple (ok, all) - ok representing number of
" \
"'good' frames, all representing total number
of frames\n" \
@@ -44,7 +37,6 @@ static PyMethodDef
gdb_thread_methods[] =
{
/* methods */
- { "cmp", sr_py_gdb_thread_cmp, METH_VARARGS,
t_cmp_doc },
{ "dup", sr_py_gdb_thread_dup, METH_NOARGS,
t_dup_doc },
{ "quality_counts", sr_py_gdb_thread_quality_counts, METH_NOARGS,
t_quality_counts_doc },
{ "quality", sr_py_gdb_thread_quality, METH_NOARGS,
t_quality_doc },
@@ -85,7 +77,7 @@ PyTypeObject sr_py_gdb_thread_type =
NULL, /* tp_print */
NULL, /* tp_getattr */
NULL, /* tp_setattr */
- NULL, /* tp_compare */
+ (cmpfunc)sr_py_gdb_thread_cmp, /* tp_compare */
NULL, /* tp_repr */
NULL, /* tp_as_number */
NULL, /* tp_as_sequence */
@@ -331,22 +323,17 @@ sr_py_gdb_thread_dup(PyObject *self, PyObject *args)
return (PyObject *)to;
}
-PyObject *
-sr_py_gdb_thread_cmp(PyObject *self, PyObject *args)
+int
+sr_py_gdb_thread_cmp(struct sr_py_gdb_thread *self, struct sr_py_gdb_thread *other)
{
- struct sr_py_gdb_thread *this = (struct sr_py_gdb_thread *)self;
- PyObject *compare_to;
- if (!PyArg_ParseTuple(args, "O!", &sr_py_gdb_thread_type,
&compare_to))
- return NULL;
-
- struct sr_py_gdb_thread *cmp_to = (struct sr_py_gdb_thread *)compare_to;
-
- if (thread_prepare_linked_list(this) < 0)
- return NULL;
- if (thread_prepare_linked_list(cmp_to) < 0)
- return NULL;
+ if (thread_prepare_linked_list(self) < 0
+ || thread_prepare_linked_list(other) < 0)
+ {
+ /* exception is already set */
+ return -1;
+ }
- return Py_BuildValue("i", sr_gdb_thread_cmp(this->thread,
cmp_to->thread));
+ return normalize_cmp(sr_gdb_thread_cmp(self->thread, other->thread));
}
PyObject *
diff --git a/python/py_gdb_thread.h b/python/py_gdb_thread.h
index c2c4611..00c32b9 100644
--- a/python/py_gdb_thread.h
+++ b/python/py_gdb_thread.h
@@ -57,9 +57,11 @@ void sr_py_gdb_thread_free(PyObject *object);
/* str */
PyObject *sr_py_gdb_thread_str(PyObject *self);
+/* cmp */
+int sr_py_gdb_thread_cmp(struct sr_py_gdb_thread *self, struct sr_py_gdb_thread *other);
+
/* methods */
PyObject *sr_py_gdb_thread_dup(PyObject *self, PyObject *args);
-PyObject *sr_py_gdb_thread_cmp(PyObject *self, PyObject *args);
PyObject *sr_py_gdb_thread_quality_counts(PyObject *self, PyObject *args);
PyObject *sr_py_gdb_thread_quality(PyObject *self, PyObject *args);
PyObject *sr_py_gdb_thread_format_funs(PyObject *self, PyObject *args);
diff --git a/python/py_java_frame.c b/python/py_java_frame.c
index 507f978..d923fb5 100644
--- a/python/py_java_frame.c
+++ b/python/py_java_frame.c
@@ -34,20 +34,12 @@
"Clones the frame object. All new structures are independent
" \
"on the original object."
-#define f_cmp_doc "Usage: frame.cmp(frame2)\n" \
- "frame2: satyr.Frame - another frame to compare\n" \
- "Returns: integer - distance\n" \
- "Compares frame to frame2. Returns 0 if frame = frame2, " \
- "<0 if frame is 'less' than frame2, >0 if frame is
'more' " \
- "than frame2."
-
static PyMethodDef
frame_methods[] =
{
/* methods */
{ "dup", sr_py_java_frame_dup, METH_NOARGS, f_dup_doc },
- { "cmp", sr_py_java_frame_cmp, METH_VARARGS, f_cmp_doc },
{ NULL },
};
@@ -90,7 +82,7 @@ sr_py_java_frame_type =
NULL, /* tp_print */
NULL, /* tp_getattr */
NULL, /* tp_setattr */
- NULL, /* tp_compare */
+ sr_py_java_frame_cmp, /* tp_compare */
NULL, /* tp_repr */
NULL, /* tp_as_number */
NULL, /* tp_as_sequence */
@@ -229,19 +221,11 @@ sr_py_java_frame_dup(PyObject *self, PyObject *args)
return (PyObject*)fo;
}
-PyObject *
-sr_py_java_frame_cmp(PyObject *self, PyObject *args)
+int
+sr_py_java_frame_cmp(PyObject *self, PyObject *other)
{
- PyObject *compare_to;
- if (!PyArg_ParseTuple(args,
- "O!",
- &sr_py_java_frame_type,
- &compare_to))
- {
- return NULL;
- }
-
struct sr_java_frame *f1 = ((struct sr_py_java_frame*)self)->frame;
- struct sr_java_frame *f2 = ((struct sr_py_java_frame*)compare_to)->frame;
- return Py_BuildValue("i", sr_java_frame_cmp(f1, f2));
+ struct sr_java_frame *f2 = ((struct sr_py_java_frame*)other)->frame;
+
+ return normalize_cmp(sr_java_frame_cmp(f1, f2));
}
diff --git a/python/py_java_frame.h b/python/py_java_frame.h
index fead53a..c71d655 100644
--- a/python/py_java_frame.h
+++ b/python/py_java_frame.h
@@ -56,9 +56,13 @@ void sr_py_java_frame_free(PyObject *object);
*/
PyObject *sr_py_java_frame_str(PyObject *self);
+/**
+ * cmp
+ */
+int sr_py_java_frame_cmp(PyObject *self, PyObject *other);
+
/* methods */
PyObject *sr_py_java_frame_dup(PyObject *self, PyObject *args);
-PyObject *sr_py_java_frame_cmp(PyObject *self, PyObject *args);
#ifdef __cplusplus
}
diff --git a/python/py_java_thread.c b/python/py_java_thread.c
index d70af6e..dc3bd5f 100644
--- a/python/py_java_thread.c
+++ b/python/py_java_thread.c
@@ -18,13 +18,6 @@
"Clones the thread object. All new structures are independent
" \
"on the original object."
-#define t_cmp_doc "Usage: thread.cmp(thread2)\n" \
- "thread2: satyr.JavaThread - another thread to compare" \
- "Returns: integer - distance" \
- "Compares thread to thread2. Returns 0 if thread = thread2, "
\
- "<0 if thread is 'less' than thread2, >0 if thread
is 'more' " \
- "than thread2."
-
#define t_quality_counts_doc "Usage: thread.quality_counts()\n" \
"Returns: tuple (ok, all) - ok representing number of
" \
"'good' frames, all representing total number
of frames\n" \
@@ -45,7 +38,6 @@ static PyMethodDef
java_thread_methods[] =
{
/* methods */
- { "cmp", sr_py_java_thread_cmp, METH_VARARGS,
t_cmp_doc },
{ "dup", sr_py_java_thread_dup, METH_NOARGS,
t_dup_doc },
{ "quality_counts", sr_py_java_thread_quality_counts, METH_NOARGS,
t_quality_counts_doc },
{ "quality", sr_py_java_thread_quality, METH_NOARGS,
t_quality_doc },
@@ -86,7 +78,7 @@ PyTypeObject sr_py_java_thread_type =
NULL, /* tp_print */
NULL, /* tp_getattr */
NULL, /* tp_setattr */
- NULL, /* tp_compare */
+ (cmpfunc)sr_py_java_thread_cmp, /* tp_compare */
NULL, /* tp_repr */
NULL, /* tp_as_number */
NULL, /* tp_as_sequence */
@@ -301,22 +293,17 @@ sr_py_java_thread_dup(PyObject *self, PyObject *args)
return (PyObject *)to;
}
-PyObject *
-sr_py_java_thread_cmp(PyObject *self, PyObject *args)
+int
+sr_py_java_thread_cmp(struct sr_py_java_thread *self, struct sr_py_java_thread *other)
{
- struct sr_py_java_thread *this = (struct sr_py_java_thread *)self;
- PyObject *compare_to;
- if (!PyArg_ParseTuple(args, "O!", &sr_py_java_thread_type,
&compare_to))
- return NULL;
-
- struct sr_py_java_thread *cmp_to = (struct sr_py_java_thread *)compare_to;
-
- if (java_thread_prepare_linked_list(this) < 0)
- return NULL;
- if (java_thread_prepare_linked_list(cmp_to) < 0)
- return NULL;
+ if (java_thread_prepare_linked_list(self) < 0
+ || java_thread_prepare_linked_list(other) < 0)
+ {
+ /* exception is already set */
+ return -1;
+ }
- return Py_BuildValue("i", sr_java_thread_cmp(this->thread,
cmp_to->thread));
+ return normalize_cmp(sr_java_thread_cmp(self->thread, other->thread));
}
PyObject *
diff --git a/python/py_java_thread.h b/python/py_java_thread.h
index a0754c5..f9958f6 100644
--- a/python/py_java_thread.h
+++ b/python/py_java_thread.h
@@ -57,9 +57,11 @@ void sr_py_java_thread_free(PyObject *object);
/* str */
PyObject *sr_py_java_thread_str(PyObject *self);
+/* cmp */
+int sr_py_java_thread_cmp(struct sr_py_java_thread *self, struct sr_py_java_thread
*other);
+
/* methods */
PyObject *sr_py_java_thread_dup(PyObject *self, PyObject *args);
-PyObject *sr_py_java_thread_cmp(PyObject *self, PyObject *args);
PyObject *sr_py_java_thread_quality_counts(PyObject *self, PyObject *args);
PyObject *sr_py_java_thread_quality(PyObject *self, PyObject *args);
PyObject *sr_py_java_thread_format_funs(PyObject *self, PyObject *args);
diff --git a/python/py_koops_frame.c b/python/py_koops_frame.c
index 778af3f..a7fc9b7 100644
--- a/python/py_koops_frame.c
+++ b/python/py_koops_frame.c
@@ -37,20 +37,12 @@
"Clones the frame object. All new structures are independent
" \
"on the original object."
-#define f_cmp_doc "Usage: frame.cmp(frame2)\n" \
- "frame2: satyr.KerneloopsFrame - another frame to compare\n"
\
- "Returns: integer - distance\n" \
- "Compares frame to frame2. Returns 0 if frame = frame2, " \
- "<0 if frame is 'less' than frame2, >0 if frame is
'more' " \
- "than frame2."
-
static PyMethodDef
frame_methods[] =
{
/* methods */
{ "dup", sr_py_koops_frame_dup,
METH_NOARGS, f_dup_doc },
- { "cmp", sr_py_koops_frame_cmp,
METH_VARARGS, f_cmp_doc },
{ NULL },
};
@@ -101,7 +93,7 @@ sr_py_koops_frame_type =
NULL, /* tp_print */
NULL, /* tp_getattr */
NULL, /* tp_setattr */
- NULL, /* tp_compare */
+ sr_py_koops_frame_cmp, /* tp_compare */
NULL, /* tp_repr */
NULL, /* tp_as_number */
NULL, /* tp_as_sequence */
@@ -237,19 +229,11 @@ sr_py_koops_frame_dup(PyObject *self, PyObject *args)
return (PyObject*)fo;
}
-PyObject *
-sr_py_koops_frame_cmp(PyObject *self, PyObject *args)
+int
+sr_py_koops_frame_cmp(PyObject *self, PyObject *other)
{
- PyObject *compare_to;
- if (!PyArg_ParseTuple(args,
- "O!",
- &sr_py_koops_frame_type,
- &compare_to))
- {
- return NULL;
- }
-
struct sr_koops_frame *f1 = ((struct sr_py_koops_frame*)self)->frame;
- struct sr_koops_frame *f2 = ((struct sr_py_koops_frame*)compare_to)->frame;
- return Py_BuildValue("i", sr_koops_frame_cmp(f1, f2));
+ struct sr_koops_frame *f2 = ((struct sr_py_koops_frame*)other)->frame;
+
+ return normalize_cmp(sr_koops_frame_cmp(f1, f2));
}
diff --git a/python/py_koops_frame.h b/python/py_koops_frame.h
index e9c13f5..ecbf874 100644
--- a/python/py_koops_frame.h
+++ b/python/py_koops_frame.h
@@ -56,9 +56,13 @@ void sr_py_koops_frame_free(PyObject *object);
*/
PyObject *sr_py_koops_frame_str(PyObject *self);
+/*
+ * cmp
+ */
+int sr_py_koops_frame_cmp(PyObject *self, PyObject *other);
+
/* methods */
PyObject *sr_py_koops_frame_dup(PyObject *self, PyObject *args);
-PyObject *sr_py_koops_frame_cmp(PyObject *self, PyObject *args);
#ifdef __cplusplus
}
diff --git a/python/py_python_frame.c b/python/py_python_frame.c
index 9e5e5c6..e654b64 100644
--- a/python/py_python_frame.c
+++ b/python/py_python_frame.c
@@ -34,20 +34,12 @@
"Clones the frame object. All new structures are independent
" \
"on the original object."
-#define f_cmp_doc "Usage: frame.cmp(frame2)\n" \
- "frame2: satyr.Frame - another frame to compare\n" \
- "Returns: integer - distance\n" \
- "Compares frame to frame2. Returns 0 if frame = frame2, " \
- "<0 if frame is 'less' than frame2, >0 if frame is
'more' " \
- "than frame2."
-
static PyMethodDef
frame_methods[] =
{
/* methods */
{ "dup", sr_py_python_frame_dup, METH_NOARGS, f_dup_doc },
- { "cmp", sr_py_python_frame_cmp, METH_VARARGS, f_cmp_doc },
{ NULL },
};
@@ -86,7 +78,7 @@ sr_py_python_frame_type =
NULL, /* tp_print */
NULL, /* tp_getattr */
NULL, /* tp_setattr */
- NULL, /* tp_compare */
+ sr_py_python_frame_cmp, /* tp_compare */
NULL, /* tp_repr */
NULL, /* tp_as_number */
NULL, /* tp_as_sequence */
@@ -211,19 +203,11 @@ sr_py_python_frame_dup(PyObject *self, PyObject *args)
return (PyObject*)fo;
}
-PyObject *
-sr_py_python_frame_cmp(PyObject *self, PyObject *args)
+int
+sr_py_python_frame_cmp(PyObject *self, PyObject *other)
{
- PyObject *compare_to;
- if (!PyArg_ParseTuple(args,
- "O!",
- &sr_py_python_frame_type,
- &compare_to))
- {
- return NULL;
- }
-
struct sr_python_frame *f1 = ((struct sr_py_python_frame*)self)->frame;
- struct sr_python_frame *f2 = ((struct sr_py_python_frame*)compare_to)->frame;
- return Py_BuildValue("i", sr_python_frame_cmp(f1, f2));
+ struct sr_python_frame *f2 = ((struct sr_py_python_frame*)other)->frame;
+
+ return normalize_cmp(sr_python_frame_cmp(f1, f2));
}
diff --git a/python/py_python_frame.h b/python/py_python_frame.h
index f0848c2..736056b 100644
--- a/python/py_python_frame.h
+++ b/python/py_python_frame.h
@@ -56,9 +56,13 @@ void sr_py_python_frame_free(PyObject *object);
*/
PyObject *sr_py_python_frame_str(PyObject *self);
+/**
+ * cmp
+ */
+int sr_py_python_frame_cmp(PyObject *self, PyObject *other);
+
/* methods */
PyObject *sr_py_python_frame_dup(PyObject *self, PyObject *args);
-PyObject *sr_py_python_frame_cmp(PyObject *self, PyObject *args);
#ifdef __cplusplus
}
diff --git a/tests/python/gdb.py b/tests/python/gdb.py
index 54f0fbf..ea04776 100755
--- a/tests/python/gdb.py
+++ b/tests/python/gdb.py
@@ -35,11 +35,13 @@ class TestGdbStacktrace(BindingsTestCase):
def test_dup(self):
dup = self.trace.dup()
- self.assertNotEqual(dup.threads, self.trace.threads)
+ self.assertNotEqual(id(dup.threads), id(self.trace.threads))
+ self.assertEqual(dup.threads, self.trace.threads)
dup.threads = dup.threads[:5]
dup2 = dup.dup()
- self.assertEqual(len(dup.threads), len(dup2.threads))
+ self.assertNotEqual(id(dup.threads), id(dup2.threads))
+ self.assertEqual(dup.threads, dup2.threads)
def test_prepare_linked_list(self):
dup = self.trace.dup()
@@ -63,6 +65,13 @@ class TestGdbThread(BindingsTestCase):
def test_getset(self):
self.assertGetSetCorrect(self.thread, 'number', 2, 9000)
+ def test_cmp(self):
+ self.assertEqual(self.thread, self.thread)
+ dup = self.thread.dup()
+ self.assertEqual(self.thread, dup)
+ dup.number = 9000
+ self.assertNotEqual(self.thread, dup)
+
class TestGdbSharedlib(BindingsTestCase):
def setUp(self):
self.shlib = satyr.GdbStacktrace(contents).libs[0]
@@ -94,11 +103,10 @@ class TestGdbFrame(BindingsTestCase):
def test_cmp(self):
dup = self.frame.dup()
- self.assertEqual(dup.cmp(dup, 0), 0)
- self.assertEqual(dup.cmp(self.frame, 0), 0)
- self.assertEqual(dup.cmp(self.frame, 0), 0)
+ self.assertEqual(dup, dup)
+ self.assertEqual(dup, self.frame)
dup.function_name = 'another'
- self.assertNotEqual(dup.cmp(self.frame, 0), 0)
+ self.assertNotEqual(dup, self.frame)
def test_getset(self):
self.assertGetSetCorrect(self.frame, 'function_name', 'write',
'foo bar')
diff --git a/tests/python/java.py b/tests/python/java.py
index 37bf286..ba0cb49 100755
--- a/tests/python/java.py
+++ b/tests/python/java.py
@@ -34,11 +34,13 @@ class TestJavaStacktrace(BindingsTestCase):
def test_dup(self):
dup = self.trace.dup()
- self.assertNotEqual(dup.threads, self.trace.threads)
+ self.assertNotEqual(id(dup.threads), id(self.trace.threads))
+ self.assertEqual(dup.threads, self.trace.threads)
dup.threads = dup.threads[:5]
dup2 = dup.dup()
self.assertEqual(len(dup.threads), len(dup2.threads))
+ self.assertNotEqual(id(dup.threads), id(dup2.threads))
def test_prepare_linked_list(self):
dup = self.trace.dup()
@@ -57,6 +59,13 @@ class TestJavaThread(BindingsTestCase):
def test_getset(self):
self.assertGetSetCorrect(self.thread, 'name', None, 'elvis')
+ def test_cmp(self):
+ self.assertEqual(self.thread, self.thread)
+ dup = self.thread.dup()
+ self.assertEqual(self.thread, dup)
+ dup.name = ' 45678987\n\n\n\n'
+ self.assertNotEqual(self.thread, dup)
+
class TestJavaSharedlib(BindingsTestCase):
def setUp(self):
self.shlib = satyr.JavaStacktrace(contents).libs[0]
@@ -82,11 +91,14 @@ class TestJavaFrame(BindingsTestCase):
def test_cmp(self):
dup = self.frame.dup()
- self.assertEqual(dup.cmp(dup), 0)
- self.assertEqual(dup.cmp(self.frame), 0)
- self.assertEqual(dup.cmp(self.frame), 0)
+ self.assertEqual(dup, dup)
+ self.assertEqual(dup, self.frame)
+ self.assertEqual(dup, self.frame)
+ self.assertNotEqual(id(dup), id(self.frame))
dup.name = 'another'
- self.assertNotEqual(dup.cmp(self.frame), 0)
+ self.assertNotEqual(dup, self.frame)
+ self.assertFalse(dup > self.frame)
+ self.assertTrue(dup < self.frame)
def test_getset(self):
self.assertGetSetCorrect(self.frame, 'name',
'org.hibernate.exception.ConstraintViolationException',
'long.name.is.Long')
diff --git a/tests/python/koops.py b/tests/python/koops.py
index fbeb8dd..df6462f 100755
--- a/tests/python/koops.py
+++ b/tests/python/koops.py
@@ -34,11 +34,13 @@ class TestKerneloops(BindingsTestCase):
def test_dup(self):
dup = self.koops.dup()
- self.assertNotEqual(dup.frames, self.koops.frames)
+ self.assertNotEqual(id(dup.frames), id(self.koops.frames))
+ self.assertEqual(dup.frames, self.koops.frames)
dup.frames = dup.frames[:5]
dup2 = dup.dup()
self.assertEqual(len(dup.frames), len(dup2.frames))
+ self.assertNotEqual(id(dup.frames), id(dup2.frames))
def test_normalize(self):
dup = self.koops.dup()
@@ -72,11 +74,15 @@ class TestKoopsFrame(BindingsTestCase):
def test_cmp(self):
dup = self.frame.dup()
- self.assertEqual(dup.cmp(dup), 0)
- self.assertEqual(dup.cmp(self.frame), 0)
- self.assertEqual(dup.cmp(self.frame), 0)
+ self.assertEqual(dup, dup)
+ self.assertEqual(dup, self.frame)
+ self.assertEqual(dup, self.frame)
+ self.assertNotEqual(id(dup), id(self.frame))
+
dup.reliable = False
- self.assertNotEqual(dup.cmp(self.frame), 0)
+ self.assertNotEqual(dup, self.frame)
+ self.assertTrue(dup > self.frame)
+ self.assertFalse(dup < self.frame)
def test_getset(self):
self.assertGetSetCorrect(self.frame, 'reliable', True, False)
diff --git a/tests/python/python.py b/tests/python/python.py
index 59d61ce..5b8b32f 100755
--- a/tests/python/python.py
+++ b/tests/python/python.py
@@ -31,11 +31,13 @@ class TestPythonStacktrace(BindingsTestCase):
def test_dup(self):
dup = self.trace.dup()
- self.assertNotEqual(dup.frames, self.trace.frames)
+ self.assertNotEqual(id(dup.frames), id(self.trace.frames))
+ self.assertEqual(dup.frames, self.trace.frames)
dup.frames = dup.frames[:5]
dup2 = dup.dup()
self.assertEqual(len(dup.frames), len(dup2.frames))
+ self.assertNotEqual(id(dup.frames), id(dup2.frames))
def test_prepare_linked_list(self):
dup = self.trace.dup()
@@ -73,11 +75,13 @@ class TestPythonFrame(BindingsTestCase):
def test_cmp(self):
dup = self.frame.dup()
- self.assertEqual(dup.cmp(dup), 0)
- self.assertEqual(dup.cmp(self.frame), 0)
- self.assertEqual(dup.cmp(self.frame), 0)
+ self.assertEqual(dup, dup)
+ self.assertEqual(dup, self.frame)
+ self.assertEqual(dup, self.frame)
+ self.assertNotEqual(id(dup), id(self.frame))
dup.function_name = 'another'
- self.assertNotEqual(dup.cmp(self.frame), 0)
+ self.assertNotEqual(dup, self.frame)
+ self.assertTrue(dup > self.frame)
def test_getset(self):
self.assertGetSetCorrect(self.frame, 'file_name',
'/usr/share/PackageKit/helpers/yum/yumBackend.py', 'java.py')
--
1.7.11.7