From 008035746541ad19669cc560da22858823fd2f07 Mon Sep 17 00:00:00 2001 From: Yann Weber Date: Mon, 6 Mar 2017 12:56:45 +0100 Subject: [PATCH] Updated tests --- tests/samples/1.log | 8 ++++ tests/samples/2.log | 0 tests/samples/3.log | 11 ++++++ tests/samples/4.log | 15 ++++++++ tests/samples/5.log | 29 +++++++++++++++ tests/ttail_search_check.c | 76 ++++++++++++++++++++++++++++++-------- 6 files changed, 124 insertions(+), 15 deletions(-) create mode 100644 tests/samples/1.log create mode 100644 tests/samples/2.log create mode 100644 tests/samples/3.log create mode 100644 tests/samples/4.log create mode 100644 tests/samples/5.log diff --git a/tests/samples/1.log b/tests/samples/1.log new file mode 100644 index 0000000..b51393c --- /dev/null +++ b/tests/samples/1.log @@ -0,0 +1,8 @@ +Mar 6 00:01:39 pilgrim dhclient: DHCPREQUEST on eth0 to 192.168.0.1 port 67 +Mar 6 00:01:40 pilgrim dhclient: DHCPACK from 192.168.0.1 +Mar 6 00:01:40 pilgrim dhclient: bound to 192.168.0.42 -- renewal in 1693 seconds. + +Mar 6 00:29:53 pilgrim dhclient: DHCPREQUEST on eth0 to 192.168.0.1 port 67 +Mar 6 00:29:54 pilgrim dhclient: DHCPACK from 192.168.0.1 +Mar 6 00:29:54 pilgrim dhclient: bound to 192.168.0.42 -- renewal in 1505 seconds. + diff --git a/tests/samples/2.log b/tests/samples/2.log new file mode 100644 index 0000000..e69de29 diff --git a/tests/samples/3.log b/tests/samples/3.log new file mode 100644 index 0000000..ff71cd9 --- /dev/null +++ b/tests/samples/3.log @@ -0,0 +1,11 @@ +2017-03-01 20:01:53,926 fail2ban.server [1266]: INFO Stopping all jails +2017-03-01 20:01:54,082 fail2ban.jail [1266]: INFO Jail 'ssh' stopped +2017-03-01 20:01:54,087 fail2ban.server [1266]: INFO Exiting Fail2ban +2017-03-01 20:02:55,937 fail2ban.server [1431]: INFO Changed logging target to /var/log/fail2ban.log for Fail2ban v0.8.13 +2017-03-01 20:02:55,938 fail2ban.jail [1431]: INFO Creating new jail 'ssh' +2017-03-01 20:02:55,997 fail2ban.jail [1431]: INFO Jail 'ssh' uses pyinotify +2017-03-01 20:02:56,032 fail2ban.jail [1431]: INFO Initiated 'pyinotify' backend +2017-03-01 20:02:56,036 fail2ban.filter [1431]: INFO Set maxRetry = 6 +2017-03-01 20:02:56,038 fail2ban.filter [1431]: INFO Set findtime = 600 +2017-03-01 20:02:56,039 fail2ban.actions[1431]: INFO Set banTime = 600 +2017-03-01 20:02:56,089 fail2ban.jail [1431]: INFO Jail 'ssh' started diff --git a/tests/samples/4.log b/tests/samples/4.log new file mode 100644 index 0000000..c25ab71 --- /dev/null +++ b/tests/samples/4.log @@ -0,0 +1,15 @@ +Mar 5 19:24:12 foobar kernel: [343648.872840] ttail_init_chec[16192]: segfault at 0 ip 00007fa0d8869c3a sp 00007ffed359ca08 error 4 in libc-2.19.so[7fa0d87e8000+1a1000] +Mar 5 20:29:09 foobar kernel: [347550.597495] ttail_init_chec[7461]: segfault at ffffffffffffff90 ip 00007f84401186de sp 00007ffc9d722f68 error 7 in libc-2.19.so[7f8440097000+1a1000] +Mar 5 20:29:24 foobar kernel: [347565.053550] ttail_init_chec[8046]: segfault at ffffffffffffff90 ip 00007fe9112b46de sp 00007ffea3fedeb8 error 7 in libc-2.19.so[7fe911233000+1a1000] +Mar 5 20:29:35 foobar kernel: [347576.031156] ttail_init_chec[8533]: segfault at ffffffffffffff90 ip 00007f545b5296de sp 00007ffeaa280ae8 error 7 in libc-2.19.so[7f545b4a8000+1a1000] +Mar 5 20:29:46 foobar kernel: [347587.318358] ttail_init_chec[9013]: segfault at ffffffffffffff90 ip 00007f8fb4fcf6de sp 00007ffec5e78888 error 7 in libc-2.19.so[7f8fb4f4e000+1a1000] +Mar 5 20:44:50 foobar kernel: [348492.502146] ttail_argparse_[3582]: segfault at 0 ip 00000000004019cd sp 00007fff7bc8dfb0 error 4 in ttail_argparse_check[400000+b000] +Mar 5 20:44:50 foobar kernel: [348492.503071] ttail_argparse_[3583]: segfault at 8 ip 0000000000401a28 sp 00007fff7bc8dfb0 error 4 in ttail_argparse_check[400000+b000] +Mar 5 20:44:50 foobar kernel: [348492.503778] ttail_argparse_[3584]: segfault at 10 ip 0000000000401a84 sp 00007fff7bc8dfb0 error 4 in ttail_argparse_check[400000+b000] +Mar 5 20:44:50 foobar kernel: [348492.504501] ttail_argparse_[3585]: segfault at d4 ip 0000000000401ae0 sp 00007fff7bc8dfb0 error 4 in ttail_argparse_check[400000+b000] +Mar 5 20:44:50 foobar kernel: [348492.505228] ttail_argparse_[3586]: segfault at 58 ip 0000000000401b3d sp 00007fff7bc8dfb0 error 4 in ttail_argparse_check[400000+b000] +Mar 5 20:44:50 foobar kernel: [348492.506038] ttail_argparse_[3587]: segfault at d0 ip 0000000000401b99 sp 00007fff7bc8dfb0 error 4 in ttail_argparse_check[400000+b000] +Mar 5 20:44:50 foobar kernel: [348492.531953] ttail_init_chec[3610]: segfault at 0 ip 00000000004019cd sp 00007ffd1a215bf0 error 4 in ttail_init_check[400000+e000] +Mar 5 20:44:50 foobar kernel: [348492.532638] ttail_init_chec[3611]: segfault at 10 ip 0000000000405511 sp 00007ffd1a215b80 error 4 in ttail_init_check[400000+e000] +Mar 5 20:44:50 foobar kernel: [348492.533500] ttail_init_chec[3612]: segfault at 10 ip 0000000000405511 sp 00007ffd1a215b70 error 4 in ttail_init_check[400000+e000] +Mar 5 20:44:50 foobar kernel: [348492.534337] ttail_init_chec[3613]: segfault at 10 ip 0000000000405511 sp 00007ffd1a215b50 error 4 in ttail_init_check[400000+e000] diff --git a/tests/samples/5.log b/tests/samples/5.log new file mode 100644 index 0000000..d565cbb --- /dev/null +++ b/tests/samples/5.log @@ -0,0 +1,29 @@ +[30167] 06 Nov 01:59:24.520 # You requested maxclients of 10000 requiring at least 10032 max file descriptors. +[30167] 06 Nov 01:59:24.520 # Redis can't set maximum open files to 10032 because of OS error: Operation not permitted. +[30167] 06 Nov 01:59:24.520 # Current maximum open files is 1024. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'. + _._ + _.-``__ ''-._ + _.-`` `. `_. ''-._ Redis 2.8.17 (00000000/0) 64 bit + .-`` .-```. ```\/ _.,_ ''-._ + ( ' , .-` | `, ) Running in stand alone mode + |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 + | `-._ `._ / _.-' | PID: 30167 + `-._ `-._ `-./ _.-' _.-' + |`-._`-._ `-.__.-' _.-'_.-'| + | `-._`-._ _.-'_.-' | http://redis.io + `-._ `-._`-.__.-'_.-' _.-' + |`-._`-._ `-.__.-' _.-'_.-'| + | `-._`-._ _.-'_.-' | + `-._ `-._`-.__.-'_.-' _.-' + `-._ `-.__.-' _.-' + `-._ _.-' + `-.__.-' + +[30167] 06 Nov 01:59:24.520 # Server started, Redis version 2.8.17 +[30167] 06 Nov 01:59:24.520 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. +[30167] 06 Nov 01:59:24.520 * The server is now ready to accept connections on port 6379 +[30167] 06 Nov 02:01:32.522 # User requested shutdown... +[30167] 06 Nov 02:01:32.522 * Saving the final RDB snapshot before exiting. +[30167] 06 Nov 02:01:32.528 * DB saved on disk +[30167] 06 Nov 02:01:32.528 * Removing the pid file. +[30167] 06 Nov 02:01:32.528 # Redis is now ready to exit, bye bye... diff --git a/tests/ttail_search_check.c b/tests/ttail_search_check.c index 1ff1011..9616a02 100644 --- a/tests/ttail_search_check.c +++ b/tests/ttail_search_check.c @@ -2,43 +2,89 @@ #include #include "ttail.h" +#include "ttail_init.h" #include "ttail_search.h" ttail_t *ttail; char *samples[5] = { "./samples/1.log", "./samples/2.log", "./samples/3.log",\ "./samples/4.log", "./samples/5.log"}; -off_t samples_sz[5] = { 442, 141, 893, 2587, 2310 }; - - -void setup_closest(void) -{ - -} +off_t samples_sz[5] = { 442, 0, 893, 2587, 2310 }; void teardown_closest(void) { + ttail_free(ttail); } -START_TEST (test_search_closest) +void setup_closest_fileinit(void) { - ttail_logline_subst(ttail, "Hello world !"); + ttail = ttail_init(1, (char**)&"foo"); + size_t i; + for(i=0; i<5; i++) + { + ttail_add_logfile(ttail, samples[i]); + } +} + +START_TEST (test_search_closest_init) +{ + int ret; + + ret = ttail_search_closest(ttail); + ck_assert_int_eq(ret,0); + #ifdef HUGEFILE + ck_assert_int_eq(ttail->session->file.sz_div,0); + #endif +} +END_TEST + +START_TEST (test_search_closest_init_filesz) +{ + size_t i; + ttail_search_closest(ttail); + for(i=0;i<5;i++) + { + ck_assert(samples_sz[i] == ttail->session->file.file_sz[i]); + } + +} +END_TEST + +START_TEST (test_search_closest_init_vfile) +{ + size_t i; + off_t full_sz; + + ttail_search_closest(ttail); + + full_sz = 0; + for(i=0;i<5;i++) + { + ck_assert(full_sz == ttail->session->file.vfile[i]); + full_sz += samples_sz[i]; + } + ck_assert(full_sz == ttail->session->file.vsz); } END_TEST Suite * ttail_search_suite(void) { Suite *s; - TCase *tc_search_closest; + TCase *tc_search_closest_fileinit; s = suite_create("ttail search checks"); - tc_search_closest = tcase_create("ttail_logline_closest checks"); - tcase_add_checked_fixture(tc_search_closest, - setup_closest, teardown_closest); - tcase_add_test(tc_search_closest, test_search_closest); + tc_search_closest_fileinit = tcase_create("\ +ttail_logline_closest_files_init() checks"); + tcase_add_checked_fixture(tc_search_closest_fileinit, + setup_closest_fileinit, teardown_closest); + tcase_add_test(tc_search_closest_fileinit, test_search_closest_init); + tcase_add_test(tc_search_closest_fileinit, + test_search_closest_init_filesz); + tcase_add_test(tc_search_closest_fileinit, + test_search_closest_init_vfile); - suite_add_tcase(s, tc_search_closest); + suite_add_tcase(s, tc_search_closest_fileinit); return s; }