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.

rspamd_rrd_test.c 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Copyright (c) 2012, Vsevolod Stakhov
  2. * All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. *
  12. * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
  13. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  15. * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
  16. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  17. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  18. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  19. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #include "config.h"
  24. #include "tests.h"
  25. #include "rrd.h"
  26. #include "main.h"
  27. void
  28. rspamd_rrd_test_func ()
  29. {
  30. gchar tmpfile[PATH_MAX];
  31. struct rrd_rra_def rra;
  32. struct rrd_ds_def ds;
  33. GArray ar;
  34. GError *err = NULL;
  35. struct rspamd_rrd_file *rrd;
  36. gint i;
  37. gdouble t;
  38. rspamd_snprintf (tmpfile, sizeof (tmpfile), "/tmp/rspamd_rrd.rrd");
  39. /* Create sample rrd */
  40. g_assert ((rrd = rspamd_rrd_create (tmpfile, 1, 1, 1, &err)) != NULL);
  41. /* Add RRA */
  42. rrd_make_default_rra ("AVERAGE", 2, 4, &rra);
  43. ar.data = &rra;
  44. ar.len = sizeof (rra);
  45. g_assert (rspamd_rrd_add_rra (rrd, &ar, &err));
  46. /* Add DS */
  47. rrd_make_default_ds ("test", 1, &ds);
  48. ar.data = &ds;
  49. ar.len = sizeof (ds);
  50. g_assert (rspamd_rrd_add_ds (rrd, &ar, &err));
  51. /* Finalize */
  52. g_assert (rspamd_rrd_finalize (rrd, &err));
  53. /* Close */
  54. rspamd_rrd_close (rrd);
  55. /* Reopen */
  56. g_assert ((rrd = rspamd_rrd_open (tmpfile, &err)) != NULL);
  57. /* Add some points */
  58. for (i = 0; i < 20; i += 10) {
  59. sleep (1);
  60. t = i;
  61. ar.data = &t;
  62. ar.len = sizeof (gdouble);
  63. g_assert (rspamd_rrd_add_record (rrd, &ar, &err));
  64. }
  65. /* Finish */
  66. rspamd_rrd_close (rrd);
  67. /* unlink (tmpfile); */
  68. }