Skip to content

Commit

Permalink
testsuite: add test for xorg_crash_info_save_in_dump_dir()
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
  • Loading branch information
Matej Habrnal committed Nov 6, 2015
1 parent 3f76b51 commit 63a5685
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/xorg-utils.at
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,69 @@ int main(void)
return 0;
}
]])

AT_TESTCFUN([xorg_crash_info_save_in_dump_dir],
[$XORG_UTILS_CFLAGS],
[$XORG_UTILS_LDFLAGS],
[[
#include "libabrt.h"
#include "xorg-utils.h"

int main(void)
{
g_verbose = 3;

char template[] = "/tmp/XXXXXX/dump_dir";

char *last_slash = strrchr(template, '/');
*last_slash = '\0';

if (mkdtemp(template) == NULL) {
perror("mkdtemp()");
return EXIT_FAILURE;
}

*last_slash = '/';

struct dump_dir *dd = dd_create(template, (uid_t)-1, 0640);
assert(strcmp(dd->dd_dirname, template) == 0);
assert(dd->dd_fd >= 0);
assert(dd->dd_md_fd >= 0);

dd_create_basic_files(dd, (uid_t)-1, NULL);

struct xorg_crash_info crash_info = { .backtrace = (char *)"I am a backtrace",
.reason = (char *)"Reason here!",
.exe = (char *)"Executable here!" };

xorg_crash_info_save_in_dump_dir(&crash_info, dd);

dd_close(dd);
dd = NULL;

dd = dd_opendir(template, 0);
assert(dd != NULL);
assert(strcmp(dd->dd_dirname, template) == 0);

problem_data_t *pd = create_problem_data_from_dump_dir(dd);

assert(strcmp(problem_data_get_content_or_NULL(pd, FILENAME_ANALYZER), "abrt-xorg") == 0);
assert(strcmp(problem_data_get_content_or_NULL(pd, FILENAME_TYPE), "xorg") == 0);
assert(strcmp(problem_data_get_content_or_NULL(pd, FILENAME_REASON), crash_info.reason) == 0);
assert(strcmp(problem_data_get_content_or_NULL(pd, FILENAME_BACKTRACE), crash_info.backtrace) == 0);
assert(strcmp(problem_data_get_content_or_NULL(pd, FILENAME_EXECUTABLE), crash_info.exe) == 0);

problem_data_free(pd);

dd_delete(dd);

struct stat dd_st;
assert(stat(template, &dd_st) != 0);

*last_slash = '\0';
assert(rmdir(template) == 0);

return EXIT_SUCCESS;
}
]])

0 comments on commit 63a5685

Please sign in to comment.