traffic.o: traffic.c traffic.h common.h ifinfo.h misc.h
dbxml.o: dbxml.c dbxml.h common.h
dbshow.o: dbshow.c dbshow.h misc.h common.h
-dbaccess.o: dbaccess.c dbaccess.h misc.h common.h
+dbaccess.o: dbaccess.c dbaccess.h common.h
dbmerge.o: dbmerge.c dbmerge.h dbaccess.h common.h
dbcache.o: dbcache.c dbcache.h dbaccess.h common.h ifinfo.h
common.o: common.c common.h
return 0;
}
}
+
+uint64_t countercalc(uint64_t a, uint64_t b)
+{
+ /* no flip */
+ if (b>=a) {
+ if (debug)
+ printf("cc: %"PRIu64" - %"PRIu64" = %"PRIu64"\n", b, a, b-a);
+ return b-a;
+
+ /* flip exists */
+ } else {
+ /* original counter is 64bit */
+ if (a>FP32) {
+ if (debug)
+ printf("cc64: uint64 - %"PRIu64" + %"PRIu64" = %"PRIu64"\n", a, b, (uint64_t)FP64-a+b);
+ return FP64-a+b;
+
+ /* original counter is 32bit */
+ } else {
+ if (debug)
+ printf("cc32: uint32 - %"PRIu64" + %"PRIu64" = %"PRIu64"\n", a, b, (uint64_t)FP32-a+b);
+ return FP32-a+b;
+ }
+ }
+}
+
+void addtraffic(uint64_t *destmb, int *destkb, uint64_t srcmb, int srckb)
+{
+ *destmb+=srcmb;
+ *destkb+=srckb;
+
+ if (*destkb>=1024) {
+ *destmb+=*destkb/1024;
+ *destkb-=(*destkb/1024)*1024;
+ }
+}
+
+uint64_t mbkbtokb(uint64_t mb, uint64_t kb)
+{
+ if (kb>=1024) {
+ mb+=kb/1024;
+ kb-=(kb/1024)*1024;
+ }
+ return (mb*1024)+kb;
+}
int logprint(PrintType type);
int dmonth(int month);
uint32_t mosecs(void);
+uint64_t countercalc(uint64_t a, uint64_t b);
+void addtraffic(uint64_t *destmb, int *destkb, uint64_t srcmb, int srckb);
+uint64_t mbkbtokb(uint64_t mb, uint64_t kb);
/* global variables */
DATA data;
#include "common.h"
#include "dbaccess.h"
-#include "misc.h"
int readdb(const char *iface, const char *dirname)
{
}
}
-uint64_t countercalc(uint64_t a, uint64_t b)
-{
- /* no flip */
- if (b>=a) {
- if (debug)
- printf("cc: %"PRIu64" - %"PRIu64" = %"PRIu64"\n", b, a, b-a);
- return b-a;
-
- /* flip exists */
- } else {
- /* original counter is 64bit */
- if (a>FP32) {
- if (debug)
- printf("cc64: uint64 - %"PRIu64" + %"PRIu64" = %"PRIu64"\n", a, b, (uint64_t)FP64-a+b);
- return FP64-a+b;
-
- /* original counter is 32bit */
- } else {
- if (debug)
- printf("cc32: uint32 - %"PRIu64" + %"PRIu64" = %"PRIu64"\n", a, b, (uint64_t)FP32-a+b);
- return FP32-a+b;
- }
- }
-}
-
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
int readifaddrs(const char *iface)
{
int readproc(const char *iface);
int readsysclassnet(const char *iface);
void parseifinfo(int newdb);
-uint64_t countercalc(uint64_t a, uint64_t b);
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
int readifaddrs(const char *iface);
#endif
{
int l;
- if (rxk>=1024) {
- rx+=rxk/1024;
- rxk-=(rxk/1024)*1024;
- }
-
- if (txk>=1024) {
- tx+=txk/1024;
- txk-=(txk/1024)*1024;
- }
-
- rx=(rx*1024)+rxk;
- tx=(tx*1024)+txk;
+ rx=mbkbtokb(rx, rxk);
+ tx=mbkbtokb(tx, txk);
if ((rx+tx)!=max) {
len=((rx+tx)/(float)max)*len;
t=data.day[i].rx+data.day[i].tx;
tk=data.day[i].rxk+data.day[i].txk;
- if (tk>=1024) {
- t+=tk/1024;
- tk-=(tk/1024)*1024;
- }
-
- t=(t*1024)+tk;
+ t=mbkbtokb(t, tk);
if (t>max) {
max=t;
void drawdaily(int showheader, int showedge);
void drawmonthly(int showheader, int showedge);
void drawtop(int showheader, int showedge);
-void addtraffic(uint64_t *destmb, int *destkb, uint64_t srcmb, int srckb);
void hextorgb(char *input, int *rgb);
void modcolor(int *rgb, int offset, int force);
char *getimagevalue(uint64_t kb, int len, int rate);
return result;
}
-void addtraffic(uint64_t *destmb, int *destkb, uint64_t srcmb, int srckb)
-{
- *destmb=*destmb+srcmb;
- *destkb=*destkb+srckb;
-
- if (*destkb>=1024) {
- *destmb+=*destkb/1024;
- *destkb-=(*destkb/1024)*1024;
- }
-}
-
char *getvalue(uint64_t mb, uint64_t kb, int len, int type)
{
static char buffer[64];
}
if (mb!=0) {
- if (kb>=1024) {
- mb+=kb/1024;
- kb-=(kb/1024)*1024;
- }
- kB=(mb*1024)+kb;
+ kB=mbkbtokb(mb, kb);
} else {
kB=kb;
}
}
if (mb!=0) {
- if (kb>=1024) {
- mb+=kb/1024;
- kb-=(kb/1024)*1024;
- }
- kB=(mb*1024)+kb;
+ kB=mbkbtokb(mb, kb);
} else {
kB=kb;
}
int spacecheck(char *path);
void sighandler(int);
int getbtime(void);
-void addtraffic(uint64_t *destmb, int *destkb, uint64_t srcmb, int srckb);
char *getvalue(uint64_t mb, uint64_t kb, int len, int type);
char *getrate(uint64_t mb, uint64_t kb, uint32_t interval, int len);
char *gettrafficrate(uint64_t bytes, uint32_t interval, int len);
common.o: common.c common.h
ifinfo.o: ifinfo.c ifinfo.h common.h dbaccess.h misc.h cfg.h
-dbaccess.o: dbaccess.c dbaccess.h misc.h common.h
+dbaccess.o: dbaccess.c dbaccess.h common.h
dbcache.o: dbcache.c dbcache.h dbaccess.h common.h ifinfo.h
cfg.o: cfg.c cfg.h common.h
misc.o: misc.c misc.h common.h
}
END_TEST
+START_TEST(countercalc_no_change)
+{
+ ck_assert_int_eq(countercalc(0, 0), 0);
+ ck_assert_int_eq(countercalc(1, 1), 0);
+}
+END_TEST
+
+START_TEST(countercalc_small_change)
+{
+ ck_assert_int_eq(countercalc(0, 1), 1);
+ ck_assert_int_eq(countercalc(1, 2), 1);
+ ck_assert_int_eq(countercalc(1, 3), 2);
+}
+END_TEST
+
+START_TEST(countercalc_32bit)
+{
+ ck_assert(countercalc(1, 0)==(FP32-1));
+}
+END_TEST
+
+START_TEST(countercalc_64bit)
+{
+ ck_assert(countercalc(FP32+1, 0)==(FP64-FP32-1));
+}
+END_TEST
+
+START_TEST(addtraffic_does_not_add_zero_traffic)
+{
+ uint64_t srcmb, destmb;
+ int srckb, destkb;
+
+ srcmb=srckb=destmb=destkb=0;
+ addtraffic(&destmb, &destkb, srcmb, srckb);
+
+ ck_assert_int_eq(srcmb, 0);
+ ck_assert_int_eq(srckb, 0);
+ ck_assert_int_eq(destmb, 0);
+ ck_assert_int_eq(destkb, 0);
+}
+END_TEST
+
+START_TEST(addtraffic_with_simple_mb_addition)
+{
+ uint64_t srcmb, destmb;
+ int srckb, destkb;
+
+ destmb=destkb=0;
+ srcmb=1;
+ srckb=0;
+ addtraffic(&destmb, &destkb, srcmb, srckb);
+
+ ck_assert_int_eq(srcmb, 1);
+ ck_assert_int_eq(srckb, 0);
+ ck_assert_int_eq(destmb, 1);
+ ck_assert_int_eq(destkb, 0);
+}
+END_TEST
+
+START_TEST(addtraffic_with_simple_kb_addition)
+{
+ uint64_t srcmb, destmb;
+ int srckb, destkb;
+
+ destmb=destkb=0;
+ srcmb=0;
+ srckb=1;
+ addtraffic(&destmb, &destkb, srcmb, srckb);
+
+ ck_assert_int_eq(srcmb, 0);
+ ck_assert_int_eq(srckb, 1);
+ ck_assert_int_eq(destmb, 0);
+ ck_assert_int_eq(destkb, 1);
+}
+END_TEST
+
+START_TEST(addtraffic_with_simple_mixed_addition)
+{
+ uint64_t srcmb, destmb;
+ int srckb, destkb;
+
+ destmb=destkb=0;
+ srcmb=1;
+ srckb=1;
+ addtraffic(&destmb, &destkb, srcmb, srckb);
+
+ ck_assert_int_eq(srcmb, 1);
+ ck_assert_int_eq(srckb, 1);
+ ck_assert_int_eq(destmb, 1);
+ ck_assert_int_eq(destkb, 1);
+}
+END_TEST
+
+START_TEST(addtraffic_with_multiple_mixed_additions)
+{
+ uint64_t srcmb, destmb;
+ int srckb, destkb, i;
+
+ destmb=destkb=0;
+ srcmb=1;
+ srckb=1;
+
+ for (i=1; i<=10; i++) {
+ addtraffic(&destmb, &destkb, srcmb, srckb);
+
+ ck_assert_int_eq(srcmb, 1);
+ ck_assert_int_eq(srckb, 1);
+ ck_assert_int_eq(destmb, (uint64_t)i);
+ ck_assert_int_eq(destkb, i);
+ }
+}
+END_TEST
+
+START_TEST(addtraffic_with_exact_kb_to_mb_conversion)
+{
+ uint64_t srcmb, destmb;
+ int srckb, destkb;
+
+ destmb=destkb=0;
+ srcmb=0;
+ srckb=1024;
+ addtraffic(&destmb, &destkb, srcmb, srckb);
+
+ ck_assert_int_eq(srcmb, 0);
+ ck_assert_int_eq(srckb, 1024);
+ ck_assert_int_eq(destmb, 1);
+ ck_assert_int_eq(destkb, 0);
+}
+END_TEST
+
+START_TEST(addtraffic_with_inexact_kb_to_mb_conversion)
+{
+ uint64_t srcmb, destmb;
+ int srckb, destkb;
+
+ destmb=destkb=0;
+ srcmb=0;
+ srckb=1025;
+ addtraffic(&destmb, &destkb, srcmb, srckb);
+
+ ck_assert_int_eq(srcmb, 0);
+ ck_assert_int_eq(srckb, 1025);
+ ck_assert_int_eq(destmb, 1);
+ ck_assert_int_eq(destkb, 1);
+}
+END_TEST
+
+START_TEST(addtraffic_with_multiple_kb_to_mb_conversions)
+{
+ uint64_t destmb;
+ int destkb;
+
+ destmb=destkb=0;
+
+ addtraffic(&destmb, &destkb, 0, 1023);
+ ck_assert_int_eq(destmb, 0);
+ ck_assert_int_eq(destkb, 1023);
+
+ addtraffic(&destmb, &destkb, 0, 1);
+ ck_assert_int_eq(destmb, 1);
+ ck_assert_int_eq(destkb, 0);
+
+ addtraffic(&destmb, &destkb, 0, 1);
+ ck_assert_int_eq(destmb, 1);
+ ck_assert_int_eq(destkb, 1);
+
+ addtraffic(&destmb, &destkb, 0, 1023);
+ ck_assert_int_eq(destmb, 2);
+ ck_assert_int_eq(destkb, 0);
+
+ addtraffic(&destmb, &destkb, 0, 1024);
+ ck_assert_int_eq(destmb, 3);
+ ck_assert_int_eq(destkb, 0);
+
+ addtraffic(&destmb, &destkb, 0, 1025);
+ ck_assert_int_eq(destmb, 4);
+ ck_assert_int_eq(destkb, 1);
+
+ addtraffic(&destmb, &destkb, 0, 512);
+ ck_assert_int_eq(destmb, 4);
+ ck_assert_int_eq(destkb, 513);
+
+ addtraffic(&destmb, &destkb, 0, 512);
+ ck_assert_int_eq(destmb, 5);
+ ck_assert_int_eq(destkb, 1);
+
+ addtraffic(&destmb, &destkb, 0, 2048);
+ ck_assert_int_eq(destmb, 7);
+ ck_assert_int_eq(destkb, 1);
+}
+END_TEST
+
void add_common_tests(Suite *s)
{
/* Common test cases */
tcase_add_test(tc_common, logprint_options);
tcase_add_loop_test(tc_common, dmonth_return_within_range, 0, 12);
tcase_add_test(tc_common, mosecs_return_values);
+ tcase_add_test(tc_common, countercalc_no_change);
+ tcase_add_test(tc_common, countercalc_small_change);
+ tcase_add_test(tc_common, countercalc_32bit);
+ tcase_add_test(tc_common, countercalc_64bit);
+ tcase_add_test(tc_common, addtraffic_does_not_add_zero_traffic);
+ tcase_add_test(tc_common, addtraffic_with_simple_mb_addition);
+ tcase_add_test(tc_common, addtraffic_with_simple_kb_addition);
+ tcase_add_test(tc_common, addtraffic_with_simple_mixed_addition);
+ tcase_add_test(tc_common, addtraffic_with_multiple_mixed_additions);
+ tcase_add_test(tc_common, addtraffic_with_exact_kb_to_mb_conversion);
+ tcase_add_test(tc_common, addtraffic_with_inexact_kb_to_mb_conversion);
+ tcase_add_test(tc_common, addtraffic_with_multiple_kb_to_mb_conversions);
suite_add_tcase(s, tc_common);
}
#include "common.h"
#include "ifinfo.h"
-
-START_TEST(countercalc_no_change)
-{
- ck_assert_int_eq(countercalc(0, 0), 0);
- ck_assert_int_eq(countercalc(1, 1), 0);
-}
-END_TEST
-
-START_TEST(countercalc_small_change)
-{
- ck_assert_int_eq(countercalc(0, 1), 1);
- ck_assert_int_eq(countercalc(1, 2), 1);
- ck_assert_int_eq(countercalc(1, 3), 2);
-}
-END_TEST
-
-START_TEST(countercalc_32bit)
-{
- ck_assert(countercalc(1, 0)==(FP32-1));
-}
-END_TEST
-
-START_TEST(countercalc_64bit)
-{
- ck_assert(countercalc(FP32+1, 0)==(FP64-FP32-1));
-}
-END_TEST
-
void add_ifinfo_tests(Suite *s)
{
/* Ifinfo test cases */
TCase *tc_ifinfo = tcase_create("Ifinfo");
- tcase_add_test(tc_ifinfo, countercalc_no_change);
- tcase_add_test(tc_ifinfo, countercalc_small_change);
- tcase_add_test(tc_ifinfo, countercalc_32bit);
- tcase_add_test(tc_ifinfo, countercalc_64bit);
suite_add_tcase(s, tc_ifinfo);
}
}
END_TEST
-START_TEST(addtraffic_does_not_add_zero_traffic)
-{
- uint64_t srcmb, destmb;
- int srckb, destkb;
-
- srcmb=srckb=destmb=destkb=0;
- addtraffic(&destmb, &destkb, srcmb, srckb);
-
- ck_assert_int_eq(srcmb, 0);
- ck_assert_int_eq(srckb, 0);
- ck_assert_int_eq(destmb, 0);
- ck_assert_int_eq(destkb, 0);
-}
-END_TEST
-
-START_TEST(addtraffic_with_simple_mb_addition)
-{
- uint64_t srcmb, destmb;
- int srckb, destkb;
-
- destmb=destkb=0;
- srcmb=1;
- srckb=0;
- addtraffic(&destmb, &destkb, srcmb, srckb);
-
- ck_assert_int_eq(srcmb, 1);
- ck_assert_int_eq(srckb, 0);
- ck_assert_int_eq(destmb, 1);
- ck_assert_int_eq(destkb, 0);
-}
-END_TEST
-
-START_TEST(addtraffic_with_simple_kb_addition)
-{
- uint64_t srcmb, destmb;
- int srckb, destkb;
-
- destmb=destkb=0;
- srcmb=0;
- srckb=1;
- addtraffic(&destmb, &destkb, srcmb, srckb);
-
- ck_assert_int_eq(srcmb, 0);
- ck_assert_int_eq(srckb, 1);
- ck_assert_int_eq(destmb, 0);
- ck_assert_int_eq(destkb, 1);
-}
-END_TEST
-
-START_TEST(addtraffic_with_simple_mixed_addition)
-{
- uint64_t srcmb, destmb;
- int srckb, destkb;
-
- destmb=destkb=0;
- srcmb=1;
- srckb=1;
- addtraffic(&destmb, &destkb, srcmb, srckb);
-
- ck_assert_int_eq(srcmb, 1);
- ck_assert_int_eq(srckb, 1);
- ck_assert_int_eq(destmb, 1);
- ck_assert_int_eq(destkb, 1);
-}
-END_TEST
-
-START_TEST(addtraffic_with_multiple_mixed_additions)
-{
- uint64_t srcmb, destmb;
- int srckb, destkb, i;
-
- destmb=destkb=0;
- srcmb=1;
- srckb=1;
-
- for (i=1; i<=10; i++) {
- addtraffic(&destmb, &destkb, srcmb, srckb);
-
- ck_assert_int_eq(srcmb, 1);
- ck_assert_int_eq(srckb, 1);
- ck_assert_int_eq(destmb, (uint64_t)i);
- ck_assert_int_eq(destkb, i);
- }
-}
-END_TEST
-
-START_TEST(addtraffic_with_exact_kb_to_mb_conversion)
-{
- uint64_t srcmb, destmb;
- int srckb, destkb;
-
- destmb=destkb=0;
- srcmb=0;
- srckb=1024;
- addtraffic(&destmb, &destkb, srcmb, srckb);
-
- ck_assert_int_eq(srcmb, 0);
- ck_assert_int_eq(srckb, 1024);
- ck_assert_int_eq(destmb, 1);
- ck_assert_int_eq(destkb, 0);
-}
-END_TEST
-
-START_TEST(addtraffic_with_inexact_kb_to_mb_conversion)
-{
- uint64_t srcmb, destmb;
- int srckb, destkb;
-
- destmb=destkb=0;
- srcmb=0;
- srckb=1025;
- addtraffic(&destmb, &destkb, srcmb, srckb);
-
- ck_assert_int_eq(srcmb, 0);
- ck_assert_int_eq(srckb, 1025);
- ck_assert_int_eq(destmb, 1);
- ck_assert_int_eq(destkb, 1);
-}
-END_TEST
-
-START_TEST(addtraffic_with_multiple_kb_to_mb_conversions)
-{
- uint64_t destmb;
- int destkb;
-
- destmb=destkb=0;
-
- addtraffic(&destmb, &destkb, 0, 1023);
- ck_assert_int_eq(destmb, 0);
- ck_assert_int_eq(destkb, 1023);
-
- addtraffic(&destmb, &destkb, 0, 1);
- ck_assert_int_eq(destmb, 1);
- ck_assert_int_eq(destkb, 0);
-
- addtraffic(&destmb, &destkb, 0, 1);
- ck_assert_int_eq(destmb, 1);
- ck_assert_int_eq(destkb, 1);
-
- addtraffic(&destmb, &destkb, 0, 1023);
- ck_assert_int_eq(destmb, 2);
- ck_assert_int_eq(destkb, 0);
-
- addtraffic(&destmb, &destkb, 0, 1024);
- ck_assert_int_eq(destmb, 3);
- ck_assert_int_eq(destkb, 0);
-
- addtraffic(&destmb, &destkb, 0, 1025);
- ck_assert_int_eq(destmb, 4);
- ck_assert_int_eq(destkb, 1);
-
- addtraffic(&destmb, &destkb, 0, 512);
- ck_assert_int_eq(destmb, 4);
- ck_assert_int_eq(destkb, 513);
-
- addtraffic(&destmb, &destkb, 0, 512);
- ck_assert_int_eq(destmb, 5);
- ck_assert_int_eq(destkb, 1);
-
- addtraffic(&destmb, &destkb, 0, 2048);
- ck_assert_int_eq(destmb, 7);
- ck_assert_int_eq(destkb, 1);
-}
-END_TEST
-
START_TEST(getunit_returns_something_with_all_cfg_combinations)
{
char *string;
/* Misc test cases */
TCase *tc_misc = tcase_create("Misc");
tcase_add_test(tc_misc, getbtime_does_not_return_zero);
- tcase_add_test(tc_misc, addtraffic_does_not_add_zero_traffic);
- tcase_add_test(tc_misc, addtraffic_with_simple_mb_addition);
- tcase_add_test(tc_misc, addtraffic_with_simple_kb_addition);
- tcase_add_test(tc_misc, addtraffic_with_simple_mixed_addition);
- tcase_add_test(tc_misc, addtraffic_with_multiple_mixed_additions);
- tcase_add_test(tc_misc, addtraffic_with_exact_kb_to_mb_conversion);
- tcase_add_test(tc_misc, addtraffic_with_inexact_kb_to_mb_conversion);
- tcase_add_test(tc_misc, addtraffic_with_multiple_kb_to_mb_conversions);
tcase_add_loop_test(tc_misc, getunit_returns_something_with_all_cfg_combinations, 0, 2);
tcase_add_loop_test(tc_misc, getrateunit_returns_something_with_all_cfg_combinations, 0, 3);
tcase_add_loop_test(tc_misc, getunitdivider_returns_something_with_all_cfg_combinations, 0, 3);