Introduce 'test' target, add /proc/net/tcp parsing to it
The test itself doesn't do much yet, but might shed some light on what's going on in https://github.com/raboof/nethogs/issues/22
This commit is contained in:
13
MakeApp.mk
13
MakeApp.mk
@@ -6,9 +6,6 @@ man8 := $(prefix)/share/man/man8
|
|||||||
|
|
||||||
all: nethogs decpcap_test
|
all: nethogs decpcap_test
|
||||||
|
|
||||||
runtests: test
|
|
||||||
./test
|
|
||||||
|
|
||||||
# nethogs_testsum
|
# nethogs_testsum
|
||||||
|
|
||||||
CFLAGS?=-Wall -Wextra
|
CFLAGS?=-Wall -Wextra
|
||||||
@@ -38,9 +35,6 @@ uninstall:
|
|||||||
rm $(DESTDIR)$(sbin)/nethogs
|
rm $(DESTDIR)$(sbin)/nethogs
|
||||||
rm $(DESTDIR)$(man8)/nethogs.8
|
rm $(DESTDIR)$(man8)/nethogs.8
|
||||||
|
|
||||||
test: test.cpp
|
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) test.cpp -o test -lpcap -lm ${NCURSES_LIBS} -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"
|
|
||||||
|
|
||||||
nethogs: main.cpp nethogs.cpp $(OBJS)
|
nethogs: main.cpp nethogs.cpp $(OBJS)
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) main.cpp $(OBJS) -o nethogs -lpcap -lm ${NCURSES_LIBS} -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) main.cpp $(OBJS) -o nethogs -lpcap -lm ${NCURSES_LIBS} -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"
|
||||||
nethogs_testsum: nethogs_testsum.cpp $(OBJS)
|
nethogs_testsum: nethogs_testsum.cpp $(OBJS)
|
||||||
@@ -68,9 +62,16 @@ conninode.o: conninode.cpp nethogs.h conninode.h
|
|||||||
cui.o: cui.cpp cui.h nethogs.h
|
cui.o: cui.cpp cui.h nethogs.h
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c cui.cpp -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c cui.cpp -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"
|
||||||
|
|
||||||
|
TESTS=conninode_test
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test: $(TESTS)
|
||||||
|
for test in $(TESTS); do echo $$test ; ./$$test ; done
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS)
|
rm -f $(OBJS)
|
||||||
|
rm -f $(TESTS)
|
||||||
rm -f nethogs
|
rm -f nethogs
|
||||||
rm -f test
|
rm -f test
|
||||||
rm -f decpcap_test
|
rm -f decpcap_test
|
||||||
|
|||||||
@@ -24,12 +24,12 @@ ifeq ($(DEBUG),1)
|
|||||||
$(info Bulding debug version)
|
$(info Bulding debug version)
|
||||||
ODIR:=$(ODIR_BASE)/lib/debug
|
ODIR:=$(ODIR_BASE)/lib/debug
|
||||||
CFLAGS?=-Wall -Wextra -O0 -g -fPIC $(VISIBILITY)
|
CFLAGS?=-Wall -Wextra -O0 -g -fPIC $(VISIBILITY)
|
||||||
CXXFLAGS?=-Wall -Wextra -O0 -g -fPIC $(VISIBILITY) $(CXXINCLUDES)
|
CXXFLAGS?=-Wall -Wextra --std=c++0x -O0 -g -fPIC $(VISIBILITY) $(CXXINCLUDES)
|
||||||
else
|
else
|
||||||
# Release mode options
|
# Release mode options
|
||||||
ODIR:=$(ODIR_BASE)/lib/release
|
ODIR:=$(ODIR_BASE)/lib/release
|
||||||
CFLAGS?=-Wall -Wextra -O3 -fPIC $(VISIBILITY)
|
CFLAGS?=-Wall -Wextra -O3 -fPIC $(VISIBILITY)
|
||||||
CXXFLAGS?=-Wall -Wextra -O3 -fPIC $(VISIBILITY) $(CXXINCLUDES)
|
CXXFLAGS?=-Wall -Wextra --std=c++0x -O3 -fPIC $(VISIBILITY) $(CXXINCLUDES)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
OBJ_NAMES= libnethogs.o packet.o connection.o process.o decpcap.o inode2prog.o conninode.o devices.o
|
OBJ_NAMES= libnethogs.o packet.o connection.o process.o decpcap.o inode2prog.o conninode.o devices.o
|
||||||
|
|||||||
8
Makefile
8
Makefile
@@ -2,13 +2,10 @@ export VERSION := 0
|
|||||||
export SUBVERSION := 8
|
export SUBVERSION := 8
|
||||||
export MINORVERSION := 2-SNAPSHOT
|
export MINORVERSION := 2-SNAPSHOT
|
||||||
|
|
||||||
all: nethogs decpcap_test
|
all: nethogs decpcap_test test
|
||||||
$(MAKE) -f MakeApp.mk $@
|
$(MAKE) -f MakeApp.mk $@
|
||||||
$(MAKE) -f MakeLib.mk $@
|
$(MAKE) -f MakeLib.mk $@
|
||||||
|
|
||||||
runtests: test
|
|
||||||
./test
|
|
||||||
|
|
||||||
.PHONY:
|
.PHONY:
|
||||||
tgz: clean
|
tgz: clean
|
||||||
cd .. ; tar czvf nethogs-$(VERSION).$(SUBVERSION).$(MINORVERSION).tar.gz --exclude-vcs nethogs/*
|
cd .. ; tar czvf nethogs-$(VERSION).$(SUBVERSION).$(MINORVERSION).tar.gz --exclude-vcs nethogs/*
|
||||||
@@ -33,6 +30,9 @@ nethogs:
|
|||||||
decpcap_test:
|
decpcap_test:
|
||||||
$(MAKE) -f MakeApp.mk $@
|
$(MAKE) -f MakeApp.mk $@
|
||||||
|
|
||||||
|
test:
|
||||||
|
$(MAKE) -f MakeApp.mk $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f MakeApp.mk $@
|
$(MAKE) -f MakeApp.mk $@
|
||||||
$(MAKE) -f MakeLib.mk $@
|
$(MAKE) -f MakeLib.mk $@
|
||||||
|
|||||||
28
conninode_test.cpp
Normal file
28
conninode_test.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#include "conninode.cpp"
|
||||||
|
|
||||||
|
local_addr *local_addrs = NULL;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
if (!addprocinfo("testfiles/proc_net_tcp")) {
|
||||||
|
std::cerr << "Failed to load testfiles/proc_net_tcp" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!addprocinfo("testfiles/proc_net_tcp_big")) {
|
||||||
|
std::cerr << "Failed to load testfiles/proc_net_tcp_big" << std::endl;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
if (!addprocinfo("net.inet.tcp.pcblist")) {
|
||||||
|
std::cerr << "Failed to load net.inet.tcp.pcblist" << std::endl;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (!addprocinfo("/proc/net/tcp")) {
|
||||||
|
std::cerr << "Failed to load /proc/net/tcp" << std::endl;
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
25
testfiles/proc_net_tcp
Normal file
25
testfiles/proc_net_tcp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
|
||||||
|
0: 00000000:0050 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 19316 1 ffff88041a179800 100 0 0 10 0
|
||||||
|
1: 0100007F:0277 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 4086615 1 ffff8800461b4800 100 0 0 10 0
|
||||||
|
2: 0100007F:1B58 00000000:0000 0A 00000000:00000000 00:00000000 00000000 115 0 26988 1 ffff8800c6263040 100 0 0 10 0
|
||||||
|
3: 0100007F:1538 00000000:0000 0A 00000000:00000000 00:00000000 00000000 131 0 13278 1 ffff880036a60800 100 0 0 10 0
|
||||||
|
4: 0100007F:0019 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 28687 1 ffff88041b65f800 100 0 0 10 0
|
||||||
|
5: 0100007F:9B7A 00000000:0000 0A 00000000:00000000 00:00000000 00000000 115 0 28750 1 ffff88041a6c9040 100 0 0 10 0
|
||||||
|
6: 00000000:01BB 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 19318 1 ffff88041a179040 100 0 0 10 0
|
||||||
|
7: 0100007F:1C1F 00000000:0000 0A 00000000:00000000 00:00000000 00000000 115 0 28749 1 ffff88041b65f040 100 0 0 10 0
|
||||||
|
8: 0100007F:14E1 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 24760 1 ffff880036a60040 100 0 0 10 0
|
||||||
|
9: 00000000:14E9 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 20847 1 ffff8800c6263800 100 0 0 10 0
|
||||||
|
10: 0100007F:0CEA 00000000:0000 0A 00000000:00000000 00:00000000 00000000 118 0 23055 1 ffff88041b566800 100 0 0 10 0
|
||||||
|
11: 16B2A8C0:EB00 7AA34D36:01BB 01 00000000:00000000 00:00000000 00000000 0 0 3625687 1 ffff8802f81f0800 23 4 28 10 -1
|
||||||
|
12: 16B2A8C0:C2FA 1A5097C2:01BB 06 00000000:00000000 03:00001184 00000000 0 0 0 3 ffff8801288f0ef0
|
||||||
|
13: 16B2A8C0:C2FC 1A5097C2:01BB 01 00000000:00000000 02:000001E6 00000000 1000 0 4391829 2 ffff88011f795800 22 4 26 10 7
|
||||||
|
14: 16B2A8C0:C162 E8675436:01BB 01 00000000:00000000 02:0000040D 00000000 1000 0 3730430 2 ffff8802debaa040 32 4 30 10 7
|
||||||
|
15: 16B2A8C0:BB92 5AFC1EC0:01BB 01 00000000:00000000 02:00001040 00000000 1000 0 4362368 2 ffff8801cff91040 29 4 29 10 -1
|
||||||
|
16: 16B2A8C0:D916 463A4834:01BB 01 00000000:00000000 02:0000085A 00000000 1000 0 4258238 2 ffff88025ccf5040 32 4 30 10 -1
|
||||||
|
17: 16B2A8C0:C150 E8675436:01BB 01 00000000:00000000 02:0000078D 00000000 1000 0 3689096 2 ffff8804195f7800 32 4 30 10 7
|
||||||
|
18: 16B2A8C0:A9BA 58FC1EC0:01BB 01 00000000:00000000 02:00001040 00000000 1000 0 4372829 2 ffff8801e1715800 30 4 29 10 -1
|
||||||
|
19: 16B2A8C0:B600 5BFC1EC0:01BB 01 00000000:00000000 02:00001040 00000000 1000 0 4152135 2 ffff88007c33c040 30 4 29 10 -1
|
||||||
|
20: 16B2A8C0:BCC8 5AFC1EC0:01BB 01 00000000:00000000 02:00001040 00000000 1000 0 4396886 2 ffff88011f795040 30 4 25 10 -1
|
||||||
|
21: 16B2A8C0:8C86 2EB2A8C0:1F49 01 00000000:00000000 02:000006A6 00000000 1000 0 4271722 2 ffff8804195f7040 21 4 22 10 -1
|
||||||
|
22: 16B2A8C0:8106 19CEFCC6:01BB 01 00000000:00000000 02:0000048D 00000000 1000 0 4400836 2 ffff8802504c1040 30 4 21 10 -1
|
||||||
|
23: 16B2A8C0:C026 3C6D5A34:01BB 01 00000000:00000000 02:00000B73 00000000 1000 0 3411654 2 ffff880220c79800 29 4 30 10 -1
|
||||||
48025
testfiles/proc_net_tcp_big
Normal file
48025
testfiles/proc_net_tcp_big
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user