timed tail for logfiles. Display loglines given a minimum date and/or a maximum date.
c
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ttail_check.h 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef _ttail_check_h__
  2. #define _ttail_check_h__
  3. #include <check.h>
  4. #include <errno.h>
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #include <libgen.h>
  8. #include "ttail.h"
  9. #include "ttail_init.h"
  10. ttail_t *ttail;
  11. #define __Fname_sz 5
  12. #define FNAME_NO_EXIST 0
  13. #define FNAME_EXIST 1
  14. char *fname[__Fname_sz];
  15. /*date formats*/
  16. char *fmt[] = TTAIL_DEFAULT_FORMATS;
  17. /* logfiles samples */
  18. char *samples[6] = { "./samples/1.log", "./samples/2.log", "./samples/3.log",\
  19. "./samples/4.log", "./samples/5.log", "./samples/1.1.log"};
  20. off_t samples_sz[6] = { 442, 0, 893, 2587, 2310, 220 };
  21. FILE *fpl;
  22. void teardown_ttail(void)
  23. {
  24. ttail_free(ttail);
  25. }
  26. void setup_ttail_empty(void)
  27. {
  28. ttail = ttail_init(1, (char**)&"foo");
  29. }
  30. void setup_fname(void)
  31. {
  32. int i;
  33. FILE *fp;
  34. for(i=0;i<__Fname_sz;i++)
  35. {
  36. fname[i] = NULL;
  37. }
  38. for(i=0; i<__Fname_sz; i++)
  39. {
  40. fname[i] = tempnam(NULL, "ttail_check");
  41. if(i%2)
  42. {
  43. if((fp=fopen(fname[i], "w+")) == NULL)
  44. {
  45. perror("Unable to create file for testing");
  46. ck_abort_msg("Unable to create file for testing");
  47. }
  48. if(fclose(fp))
  49. {
  50. perror("Unable to close file for testing");
  51. ck_abort_msg("Unable to close file for testing");
  52. }
  53. }
  54. }
  55. }
  56. void teardown_fname(void)
  57. {
  58. int i;
  59. for(i=0; i<__Fname_sz; i++)
  60. {
  61. unlink(fname[i]);
  62. if(fname[i] != NULL)
  63. {
  64. free(fname[i]);
  65. }
  66. }
  67. }
  68. void setup_file_line(void)
  69. {
  70. fpl = fopen(samples[0], "r");
  71. if(!fpl)
  72. {
  73. perror("Unable to open file for testing :");
  74. ck_abort();
  75. }
  76. }
  77. void teardown_file_line(void)
  78. {
  79. fclose(fpl);
  80. }
  81. void teardown_closest(void)
  82. {
  83. ttail_free(ttail);
  84. }
  85. void setup_closest(void)
  86. {
  87. ttail = ttail_init(1, (char**)&"foo");
  88. }
  89. void setup_closest_fileinit(void)
  90. {
  91. size_t i;
  92. setup_closest();
  93. for(i=0; i<6; i++)
  94. {
  95. ttail_add_logfile(ttail, samples[i]);
  96. }
  97. }
  98. void teardown_closest_fileinit(void)
  99. {
  100. _ttail_search_file_free(ttail);
  101. teardown_closest();
  102. }
  103. #define TTAIL_CHECK_MAIN(suite) int main(int argc, char **argv) {\
  104. int n_fail;\
  105. SRunner *sr;\
  106. chdir(dirname(argv[0])); /* move in ./tests dir */ \
  107. sr = srunner_create(suite());\
  108. srunner_set_fork_status(sr, CK_FORK);\
  109. srunner_run_all(sr, CK_VERBOSE);\
  110. n_fail = srunner_ntests_failed(sr);\
  111. srunner_free(sr);\
  112. return (n_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;\
  113. }
  114. #endif