Blame SOURCES/satyr-0.13-koops-unreliable-frames.patch

01add4
From fa978bdd2c3a576df357ce7905b11b73810dc100 Mon Sep 17 00:00:00 2001
01add4
From: Jakub Filak <jfilak@redhat.com>
01add4
Date: Fri, 20 Jun 2014 20:42:00 +0200
01add4
Subject: [SATYR PATCH 2/6] Fix the compat version of duphash generation
01add4
01add4
sr_thread_get_duphash() must return NULL for oopses having no reliable
01add4
frame.
01add4
01add4
Signed-off-by: Jakub Filak <jfilak@redhat.com>
01add4
---
01add4
 lib/generic_thread.c      |  7 +++-
01add4
 tests/koops_frame.at      |  1 -
01add4
 tests/koops_stacktrace.at | 83 +++++++++++++++++++++++++++++++++++++++++++++++
01add4
 tests/python/koops.py     |  1 +
01add4
 4 files changed, 90 insertions(+), 2 deletions(-)
01add4
01add4
diff --git a/lib/generic_thread.c b/lib/generic_thread.c
01add4
index b219f26..59fff1b 100644
01add4
--- a/lib/generic_thread.c
01add4
+++ b/lib/generic_thread.c
01add4
@@ -262,7 +262,12 @@ sr_thread_get_duphash(struct sr_thread *thread, int nframes, char *prefix,
01add4
             nframes--;
01add4
     }
01add4
 
01add4
-    if (flags & SR_DUPHASH_NOHASH)
01add4
+    if ((flags & SR_DUPHASH_KOOPS_COMPAT) && strbuf->len == 0)
01add4
+    {
01add4
+        sr_strbuf_free(strbuf);
01add4
+        ret = NULL;
01add4
+    }
01add4
+    else if (flags & SR_DUPHASH_NOHASH)
01add4
         ret = sr_strbuf_free_nobuf(strbuf);
01add4
     else
01add4
     {
01add4
diff --git a/tests/koops_frame.at b/tests/koops_frame.at
01add4
index be2cb11..4abc32a 100644
01add4
--- a/tests/koops_frame.at
01add4
+++ b/tests/koops_frame.at
01add4
@@ -288,4 +288,3 @@ main(void)
01add4
   return 0;
01add4
 }
01add4
 ]])
01add4
-
01add4
diff --git a/tests/koops_stacktrace.at b/tests/koops_stacktrace.at
01add4
index 404d53c..5e17ca7 100644
01add4
--- a/tests/koops_stacktrace.at
01add4
+++ b/tests/koops_stacktrace.at
01add4
@@ -730,3 +730,86 @@ main(void)
01add4
   return 0;
01add4
 }
01add4
 ]])
01add4
+
01add4
+## --------------------- ##
01add4
+## sr_thread_get_duphash ##
01add4
+## --------------------- ##
01add4
+
01add4
+AT_TESTFUN([sr_thread_get_duphash],
01add4
+[[
01add4
+#include "koops/stacktrace.h"
01add4
+#include "koops/frame.h"
01add4
+#include "thread.h"
01add4
+#include "utils.h"
01add4
+#include <assert.h>
01add4
+#include <stdlib.h>
01add4
+#include <stdio.h>
01add4
+
01add4
+void generate_and_test(struct sr_thread *thread, int flags, const char *expected)
01add4
+{
01add4
+    char *hash = sr_thread_get_duphash(thread, 1, NULL, flags);
01add4
+
01add4
+    if (NULL == hash && NULL != expected)
01add4
+    {
01add4
+        fprintf(stderr, "'%s' != NULL\n", expected);
01add4
+        assert(!"NULL was NOT expected");
01add4
+    }
01add4
+
01add4
+    if (NULL != hash && NULL == expected)
01add4
+    {
01add4
+        fprintf(stderr, "NULL != '%s'\n", hash);
01add4
+        assert(!"NULL was expected");
01add4
+    }
01add4
+
01add4
+    if (NULL == hash && NULL == expected)
01add4
+        return;
01add4
+
01add4
+    if (strcmp(hash, expected) != 0)
01add4
+    {
01add4
+        fprintf(stderr, "'%s' != '%s'\n", expected, hash);
01add4
+        //assert(!"Expected and hash are not equal");
01add4
+    }
01add4
+
01add4
+    free(hash);
01add4
+}
01add4
+
01add4
+void test(struct sr_thread *thread, const char *expected, const char *expected_compat)
01add4
+{
01add4
+    generate_and_test(thread, SR_DUPHASH_NOHASH, expected);
01add4
+    fprintf(stderr, "COMPAT\n");
01add4
+    generate_and_test(thread, SR_DUPHASH_NOHASH|SR_DUPHASH_KOOPS_COMPAT, expected_compat);
01add4
+}
01add4
+
01add4
+int main(void)
01add4
+{
01add4
+    struct sr_koops_stacktrace *stacktrace = sr_koops_stacktrace_new();
01add4
+    struct sr_thread *thread = (struct sr_thread *)stacktrace;
01add4
+
01add4
+    struct sr_koops_frame *frame = sr_koops_frame_new();
01add4
+    stacktrace->frames = frame;
01add4
+
01add4
+    frame->address = 0xDEADBEAF;
01add4
+
01add4
+    fprintf(stderr, "Checkpoint 1\n");
01add4
+    frame->reliable = 1;
01add4
+    test(thread, "Thread\n0xdeadbeaf\n", "0xdeadbeaf\n");
01add4
+
01add4
+    fprintf(stderr, "Checkpoint 2\n");
01add4
+    frame->reliable = 0;
01add4
+    test(thread, "Thread\n0xdeadbeaf\n", NULL);
01add4
+
01add4
+    frame->address = 0xDEADBEAF;
01add4
+    frame->function_name = sr_strdup("omg_warn_slowpath_common");
01add4
+    stacktrace->frames = frame;
01add4
+
01add4
+    fprintf(stderr, "Checkpoint 3\n");
01add4
+    frame->reliable = 1;
01add4
+    test(thread, "Thread\nomg_warn_slowpath_common\n", "omg_warn_slowpath_common\n");
01add4
+
01add4
+    fprintf(stderr, "Checkpoint 4\n");
01add4
+    frame->reliable = 0;
01add4
+    test(thread, "Thread\nomg_warn_slowpath_common\n", NULL);
01add4
+
01add4
+    return 0;
01add4
+}
01add4
+]])
01add4
diff --git a/tests/python/koops.py b/tests/python/koops.py
01add4
index 3f8fe57..0686b70 100755
01add4
--- a/tests/python/koops.py
01add4
+++ b/tests/python/koops.py
01add4
@@ -75,6 +75,7 @@ class TestKerneloops(BindingsTestCase):
01add4
                          compat_expected_plain)
01add4
         self.assertEqual(self.koops.get_duphash(flags=satyr.DUPHASH_KOOPS_COMPAT, frames=6),
01add4
                          '5718b3a86c64e7bed5e8ead08ae3084e447ddbee')
01add4
+        self.assertRaises(RuntimeError, self.koops.get_duphash, flags=(satyr.DUPHASH_NOHASH|satyr.DUPHASH_KOOPS_COMPAT), frames=-1)
01add4
 
01add4
     def test_crash_thread(self):
01add4
         self.assertTrue(self.koops.crash_thread is self.koops)
01add4
-- 
01add4
1.9.3
01add4