|
Packit |
8ea169 |
# -*- Autotest -*-
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
AT_BANNER([kernel oops parser])
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
AT_TESTFUN([koops_extract_version],
|
|
Packit |
8ea169 |
[[
|
|
Packit |
8ea169 |
#include "libabrt.h"
|
|
Packit |
8ea169 |
#include "koops-test.h"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int run_test(const struct test_struct *test)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
FILE *fp = xfopen_ro(test->filename);
|
|
Packit |
8ea169 |
fprintf(stderr, "%s\t", test->filename);
|
|
Packit |
8ea169 |
char *line;
|
|
Packit |
8ea169 |
char *version;
|
|
Packit |
8ea169 |
while ((line = xmalloc_fgetline(fp)) != NULL)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
version = koops_extract_version(line);
|
|
Packit |
8ea169 |
free(line);
|
|
Packit |
8ea169 |
if (version && !strcmp(version, test->expected_results))
|
|
Packit |
8ea169 |
break;
|
|
Packit |
8ea169 |
free(version);
|
|
Packit |
8ea169 |
version = NULL;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
if (version)
|
|
Packit |
8ea169 |
log_warning("version %s", version);
|
|
Packit |
8ea169 |
else
|
|
Packit |
8ea169 |
log_warning("version was not found");
|
|
Packit |
8ea169 |
free(version);
|
|
Packit |
8ea169 |
fclose(fp);
|
|
Packit |
8ea169 |
return version == NULL;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int main(void)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
/* tests run in abrt/tests/testsuite.dir/X, where X is test number */
|
|
Packit |
8ea169 |
struct test_struct test[] = {
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/cut_here.right", "2.6.32-19.el6.x86_64" },
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/oops-kernel-3.x.x", "3.0.0-3.fc16.i686.PAE" },
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/koops-tainted-g", "3.1.0-0.rc9.git0.0.fc16.x86_64"},
|
|
Packit |
8ea169 |
};
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int ret = 0;
|
|
Packit |
8ea169 |
for (int i = 0 ; i < ARRAY_SIZE(test); ++i)
|
|
Packit |
8ea169 |
ret |= run_test(&test[i]);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
return ret;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
]])
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
AT_TESTFUN([koops_tainted_short],
|
|
Packit |
8ea169 |
[[
|
|
Packit |
8ea169 |
#include "libabrt.h"
|
|
Packit |
8ea169 |
#include "koops-test.h"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
enum {
|
|
Packit |
8ea169 |
TEST_TAINTED,
|
|
Packit |
8ea169 |
TEST_NOT_TAINTED
|
|
Packit |
8ea169 |
};
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int run_test(const struct test_struct *test, int flags)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
char *koops_bt = fread_full(test->filename);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
char *tnt = kernel_tainted_short(koops_bt);
|
|
Packit |
8ea169 |
free(koops_bt);
|
|
Packit |
8ea169 |
int ret = 0;
|
|
Packit |
8ea169 |
switch (flags) {
|
|
Packit |
8ea169 |
case TEST_NOT_TAINTED:
|
|
Packit |
8ea169 |
if (tnt)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
log_warning("%s '%s'", test->filename, tnt);
|
|
Packit |
8ea169 |
ret = 1;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
break;
|
|
Packit |
8ea169 |
case TEST_TAINTED:
|
|
Packit |
8ea169 |
if (!tnt)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
log_warning("%s", test->filename);
|
|
Packit |
8ea169 |
ret = 1;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
else if (strcmp(tnt, test->expected_results) != 0)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
log_warning("%s '%s'", test->filename, tnt);
|
|
Packit |
8ea169 |
ret = 1;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
};
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
free(tnt);
|
|
Packit |
8ea169 |
return ret;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int main(void)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
/* tests run in abrt/tests/testsuite.dir/X, where X is test number */
|
|
Packit |
8ea169 |
struct test_struct not_tainted[] = {
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/oops1.right", NULL},
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/koops-tainted-spaces", NULL},
|
|
Packit |
8ea169 |
};
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
struct test_struct tainted[] = {
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/koops-tainted-g", "G"},
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/koops-tainted-bg1", "GB" },
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/oops-same-as-oops4.right", "P" },
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/koops-tainted-insane", "ABCDEFGHIJKLMNOPQRSTUVWXYZ" },
|
|
Packit |
8ea169 |
};
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
log_warning("test not tainted");
|
|
Packit |
8ea169 |
int ret = 0;
|
|
Packit |
8ea169 |
for (int i = 0; i < ARRAY_SIZE(not_tainted); ++i)
|
|
Packit |
8ea169 |
ret |= run_test(¬_tainted[i], TEST_NOT_TAINTED);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
log_warning("test tainted");
|
|
Packit |
8ea169 |
for (int i = 0; i < ARRAY_SIZE(tainted); ++i)
|
|
Packit |
8ea169 |
ret |= run_test(&tainted[i], TEST_TAINTED);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
return ret;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
]])
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
AT_TESTFUN([koops_hash_improve],
|
|
Packit |
8ea169 |
[[
|
|
Packit |
8ea169 |
#include "libabrt.h"
|
|
Packit |
8ea169 |
#include "koops-test.h"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int run_test(const struct test_struct *test)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
char *oops1 = fread_full(test->filename);
|
|
Packit |
8ea169 |
char *oops2 = fread_full(test->expected_results);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
char hash_oops1[SHA1_RESULT_LEN*2 + 1];
|
|
Packit |
8ea169 |
koops_hash_str(hash_oops1, oops1);
|
|
Packit |
8ea169 |
free(oops1);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
char hash_oops2[SHA1_RESULT_LEN*2 + 1];
|
|
Packit |
8ea169 |
koops_hash_str(hash_oops2, oops2);
|
|
Packit |
8ea169 |
free(oops2);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
if (!strcmp(hash_oops1, hash_oops2))
|
|
Packit |
8ea169 |
return 0;
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
log_warning("'%s' != '%s'", hash_oops1, hash_oops2);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
return 1;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int main(void)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
struct test_struct all_same_hashes[] = {
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/oops4.right", EXAMPLE_PFX"/oops-same-as-oops4.right" },
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/hash-gen-oops6.right", EXAMPLE_PFX"/hash-gen-same-as-oops6.right" },
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/hash-gen-short-oops.right", EXAMPLE_PFX"/hash-gen-short-oops.right" },
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/nmi_oops_hash.test", EXAMPLE_PFX"/nmi_oops_hash.right" },
|
|
Packit |
8ea169 |
};
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
g_verbose = 4;
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int ret = 0;
|
|
Packit |
8ea169 |
for (int i = 0; i < ARRAY_SIZE(all_same_hashes); ++i)
|
|
Packit |
8ea169 |
ret |= run_test(&all_same_hashes[i]);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
return ret;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
]])
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
AT_TESTFUN([koops_parser_sanity],
|
|
Packit |
8ea169 |
[[
|
|
Packit |
8ea169 |
#include "libabrt.h"
|
|
Packit |
8ea169 |
#include "koops-test.h"
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int run_test(const struct test_struct *test)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
char *oops_test = fread_full(test->filename);
|
|
Packit |
8ea169 |
char *oops_test_bck = oops_test;
|
|
Packit |
8ea169 |
char *oops_expected = fread_full(test->expected_results);
|
|
Packit |
8ea169 |
char *oops_expected_bck = oops_expected;
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
if (strncmp(oops_expected, "abrt-dump-oops: Found oopses:",
|
|
Packit |
8ea169 |
strlen("abrt-dump-oops: Found oopses:")) == 0) {
|
|
Packit |
8ea169 |
/* Skip "abrt-dump-oops: Found oopses: N"
|
|
Packit |
8ea169 |
* and next line (which should be empty)
|
|
Packit |
8ea169 |
*/
|
|
Packit |
8ea169 |
oops_expected = strchr(oops_expected, '\n') + 1;
|
|
Packit |
8ea169 |
oops_expected = strchr(oops_expected, '\n') + 1;
|
|
Packit |
8ea169 |
if (strncmp(oops_expected, "Version: ",
|
|
Packit |
8ea169 |
strlen("Version: ")) == 0)
|
|
Packit |
8ea169 |
oops_expected += strlen("Version: ");
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
/* for testing purpose, I will record only one koops */
|
|
Packit |
8ea169 |
GList *oops_list = NULL;
|
|
Packit |
8ea169 |
koops_extract_oopses(&oops_list, oops_test, strlen(oops_test));
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int result = !(oops_list && !strcmp((char *)oops_list->data, oops_expected));
|
|
Packit |
8ea169 |
if (result)
|
|
Packit |
8ea169 |
log_warning("Obtained:\n'%s'\nExpected:\n'%s'", (char *)oops_list->data, oops_expected);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
g_list_free_full(oops_list, free);
|
|
Packit |
8ea169 |
free(oops_expected_bck);
|
|
Packit |
8ea169 |
free(oops_test_bck);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
return result;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int main(void)
|
|
Packit |
8ea169 |
{
|
|
Packit |
8ea169 |
struct test_struct all_same_hashes[] = {
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/oops-with-jiffies.test", EXAMPLE_PFX"/oops-with-jiffies.right" },
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/oops_recursive_locking1.test", EXAMPLE_PFX"/oops_recursive_locking1.right"},
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/nmi_oops.test", EXAMPLE_PFX"/nmi_oops.right"},
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/oops10_s390x.test", EXAMPLE_PFX"/oops10_s390x.right"},
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/kernel_panic_oom.test", EXAMPLE_PFX"/kernel_panic_oom.right"},
|
|
Packit |
8ea169 |
{ EXAMPLE_PFX"/debug_messages.test", EXAMPLE_PFX"/debug_messages.right"},
|
|
Packit |
8ea169 |
};
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
int ret = 0;
|
|
Packit |
8ea169 |
for (int i = 0; i < ARRAY_SIZE(all_same_hashes); ++i)
|
|
Packit |
8ea169 |
ret |= run_test(&all_same_hashes[i]);
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
return ret;
|
|
Packit |
8ea169 |
}
|
|
Packit |
8ea169 |
|
|
Packit |
8ea169 |
]])
|