[SATYR PATCHv2 6/9] Tests for the type-agnostic functions

Martin Milata mmilata at redhat.com
Tue May 28 17:33:43 UTC 2013


Signed-off-by: Martin Milata <mmilata at redhat.com>
---
 tests/core_frame.at       | 36 ++++++++++++++++++++++++++++++++++++
 tests/core_stacktrace.at  | 39 +++++++++++++++++++++++++++++----------
 tests/core_thread.at      | 42 ++++++++++++++++++++++++++++++++++++++++++
 tests/gdb_stacktrace.at   |  5 +++++
 tests/java_frame.at       |  6 ++++++
 tests/java_thread.at      |  3 +++
 tests/koops_stacktrace.at |  8 ++++++++
 7 files changed, 129 insertions(+), 10 deletions(-)

diff --git a/tests/core_frame.at b/tests/core_frame.at
index cdd0c6e..09c3e31 100644
--- a/tests/core_frame.at
+++ b/tests/core_frame.at
@@ -93,3 +93,39 @@ main(void)
   return 0;
 }
 ]])
+
+## -------------------------------- ##
+## sr_core_frame_abstract_functions ##
+## -------------------------------- ##
+
+AT_TESTFUN([sr_core_frame_abstract_functions],
+[[
+#include <lib/core_frame.h>
+#include <lib/strbuf.h>
+#include <lib/frame.h>
+#include <assert.h>
+
+int
+main(void)
+{
+  struct sr_core_frame *frame = sr_core_frame_new();;
+  frame->address = 0xffffffff1;
+  frame->build_id = sr_strdup("aabbccddeeff1");
+  frame->build_id_offset = 2561;
+  frame->function_name = sr_strdup("test1");
+  frame->file_name = sr_strdup("executable1");
+  frame->fingerprint = sr_strdup("ab");
+  frame->next = 0xdeadbeef;
+
+  assert(sr_frame_next((struct sr_frame*)frame) == (void*)0xdeadbeef);
+
+  struct sr_strbuf *strbuf = sr_strbuf_new();
+  sr_frame_append_to_str((struct sr_frame*)frame, strbuf);
+  char *res = sr_strbuf_free_nobuf(strbuf);
+
+  assert(0 == strcmp(res, "test1 in executable1"));
+  free(res);
+
+  return 0;
+}
+]])
diff --git a/tests/core_stacktrace.at b/tests/core_stacktrace.at
index a0a7030..f1716a0 100644
--- a/tests/core_stacktrace.at
+++ b/tests/core_stacktrace.at
@@ -66,6 +66,10 @@ main(void)
   assert(reason);
   free(reason);
 
+  reason = sr_stacktrace_get_reason((struct sr_stacktrace*) stacktrace);
+  assert(reason);
+  free(reason);
+
   char *json = sr_core_stacktrace_to_json(stacktrace);
   puts(json);
   assert(0 == strcmp(json,
@@ -104,6 +108,9 @@ main(void)
             "        } ]\n"
             "}"));
 
+  char *json2 = sr_stacktrace_to_json((struct sr_stacktrace*) stacktrace);
+  assert(0 == strcmp(json, json2));
+
   sr_core_stacktrace_free(stacktrace);
   return 0;
 }
@@ -113,25 +120,19 @@ main(void)
 ## sr_core_stacktrace_from_json ##
 ## ---------------------------- ##
 
-AT_TESTFUN([sr_core_stacktrace_to_json],
+AT_TESTFUN([sr_core_stacktrace_from_json],
 [[
 #include <lib/core_stacktrace.h>
 #include <lib/core_thread.h>
 #include <lib/core_frame.h>
 #include <lib/utils.h>
+#include <lib/report_type.h>
 #include <assert.h>
 #include <signal.h>
 
-int
-main(void)
+void
+check(struct sr_core_stacktrace *stacktrace)
 {
-  char *error_message;
-  char *full_input = sr_file_to_string("../../json_files/core-01", &error_message);
-  assert(full_input);
-
-  struct sr_core_stacktrace *stacktrace = sr_core_stacktrace_from_json_text(full_input,
-     &error_message);
-
   assert(stacktrace);
   assert(stacktrace->signal == SIGABRT);
   assert(stacktrace->executable);
@@ -172,6 +173,24 @@ main(void)
   assert(0 == strcmp(f->function_name, "__libc_start_main"));
   assert(0 == strcmp(f->file_name, "/usr/lib64/libc-2.15.so"));
   assert(0 == strcmp(f->fingerprint, "5ff4a3d3743fdde711c49033d1e01784477e57fb"));
+}
+
+int
+main(void)
+{
+  char *error_message;
+  char *full_input = sr_file_to_string("../../json_files/core-01", &error_message);
+  assert(full_input);
+
+  struct sr_core_stacktrace *stacktrace = sr_core_stacktrace_from_json_text(full_input,
+     &error_message);
+  check(stacktrace);
+  sr_core_stacktrace_free(stacktrace);
+
+  stacktrace = (struct sr_core_stacktrace*) sr_stacktrace_parse(SR_REPORT_CORE,
+     full_input, &error_message);
+  check(stacktrace);
+  sr_stacktrace_free((struct sr_stacktrace*) stacktrace);
 
   return 0;
 }
diff --git a/tests/core_thread.at b/tests/core_thread.at
index 4ccb85c..65cf670 100644
--- a/tests/core_thread.at
+++ b/tests/core_thread.at
@@ -59,3 +59,45 @@ main(void)
   return 0;
 }
 ]])
+
+## --------------------------------- ##
+## sr_core_thread_abstract_functions ##
+## --------------------------------- ##
+
+AT_TESTFUN([sr_core_thread_abstract_functions],
+[[
+#include <lib/core_thread.h>
+#include <lib/core_frame.h>
+#include <lib/utils.h>
+#include <lib/thread.h>
+#include <assert.h>
+
+int
+main(void)
+{
+  struct sr_core_frame *frame1 = sr_core_frame_new();
+  frame1->address = 0xffffffff0;
+  frame1->build_id = sr_strdup("aabbccddeeff0");
+  frame1->build_id_offset = 2560;
+  frame1->function_name = sr_strdup("test0");
+  frame1->file_name = sr_strdup("executable0");
+
+  struct sr_core_frame *frame0 = sr_core_frame_new();;
+  frame0->address = 0xffffffff1;
+  frame0->build_id = sr_strdup("aabbccddeeff1");
+  frame0->build_id_offset = 2561;
+  frame0->function_name = sr_strdup("test1");
+  frame0->file_name = sr_strdup("executable1");
+  frame0->fingerprint = sr_strdup("ab");
+  frame0->next = frame1;
+
+  struct sr_core_thread *thread = sr_core_thread_new();
+  thread->frames = frame0;
+
+  assert(sr_thread_frames((struct sr_thread*) thread) == thread->frames);
+  assert(sr_thread_next((struct sr_thread*) thread) == thread->next);
+  assert(sr_thread_frame_count((struct sr_thread*) thread) == 2);
+
+  return 0;
+}
+]])
diff --git a/tests/gdb_stacktrace.at b/tests/gdb_stacktrace.at
index d4033b9..15d2050 100644
--- a/tests/gdb_stacktrace.at
+++ b/tests/gdb_stacktrace.at
@@ -86,6 +86,11 @@ check(const char *path, const char *first_thread_function_name)
   struct sr_gdb_thread *crash_thread = sr_gdb_stacktrace_find_crash_thread(stacktrace);
   assert(crash_thread);
   assert(0 == strcmp(crash_thread->frames->function_name, first_thread_function_name));
+
+  struct sr_gdb_thread *crash_thread2 = sr_stacktrace_find_crash_thread(stacktrace);
+  assert(crash_thread2);
+  assert(crash_thread == crash_thread2);
+
   sr_gdb_stacktrace_free(stacktrace);
   free(full_input);
 }
diff --git a/tests/java_frame.at b/tests/java_frame.at
index 8384436..041d011 100644
--- a/tests/java_frame.at
+++ b/tests/java_frame.at
@@ -188,6 +188,7 @@ AT_TESTFUN([sr_java_frame_append_to_str],
 #include <lib/java_frame.h>
 #include <lib/strbuf.h>
 #include <lib/utils.h>
+#include <lib/frame.h>
 #include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -206,7 +207,12 @@ check(struct sr_java_frame *frame, const char *expected)
 
   assert(strcmp(expected, buf->buf) == 0);
 
+  struct sr_strbuf *buf2 = sr_strbuf_new();
+  sr_frame_append_to_str((struct sr_frame*)frame, buf2);
+  assert(strcmp(expected, buf2->buf) == 0);
+
   sr_strbuf_free(buf);
+  sr_strbuf_free(buf2);
 }
 
 int
diff --git a/tests/java_thread.at b/tests/java_thread.at
index c7bed76..1d80b2c 100644
--- a/tests/java_thread.at
+++ b/tests/java_thread.at
@@ -23,11 +23,13 @@ main(void)
   struct sr_java_thread *thread1 = create_real_main_thread_objects();
 
   assert(0 == sr_java_thread_cmp(thread0, thread1));
+  assert(0 == sr_thread_cmp(thread0, thread1));
 
   sr_java_frame_free_full(thread1->frames);
   thread1->frames = NULL;
 
   assert(0 != sr_java_thread_cmp(thread0, thread1));
+  assert(0 != sr_thread_cmp(thread0, thread1));
 
   sr_java_thread_free(thread1);
 
@@ -36,6 +38,7 @@ main(void)
   thread1->name = sr_strdup("worker");
 
   assert(0 != sr_java_thread_cmp(thread0, thread1));
+  assert(0 != sr_thread_cmp(thread0, thread1));
 
   sr_java_thread_free(thread0);
   sr_java_thread_free(thread1);
diff --git a/tests/koops_stacktrace.at b/tests/koops_stacktrace.at
index 9026649..6b717e0 100644
--- a/tests/koops_stacktrace.at
+++ b/tests/koops_stacktrace.at
@@ -143,7 +143,11 @@ check(const char *path,
 
   char *reason = sr_koops_stacktrace_get_reason(stacktrace);
   assert(reason);
+  char *reason2 = sr_stacktrace_get_reason(stacktrace);
+  assert(reason2);
+  assert(0 == strcmp(reason, reason2));
   free(reason);
+  free(reason2);
 
   int actual_taint_count =
     stacktrace->taint_module_proprietary +
@@ -644,6 +648,10 @@ main(void)
     "        } ]\n"
     "}"));
 
+  char *json2 = sr_stacktrace_to_json(stacktrace);
+  assert(0 == strcmp(json, json2));
+  free(json2);
+
   sr_koops_stacktrace_free(stacktrace);
   free(json);
   return 0;
-- 
1.7.11.7



More information about the Crash-catcher mailing list