mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Add test to check if tox_new/tox_kill leaks.
We create and destroy 20k tox instances and run a single tox_iterate on it. This test is not comprehensive, but provides a simple check to see whether the destruction properly cleans up memory and perhaps other resources.
This commit is contained in:
parent
5237844877
commit
de623f9eb9
|
@ -420,6 +420,7 @@ auto_test(encryptsave)
|
|||
auto_test(messenger)
|
||||
auto_test(network)
|
||||
auto_test(onion)
|
||||
auto_test(resource_leak)
|
||||
auto_test(save_friend)
|
||||
auto_test(skeleton)
|
||||
auto_test(tox)
|
||||
|
|
50
auto_tests/resource_leak_test.c
Normal file
50
auto_tests/resource_leak_test.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "helpers.h"
|
||||
|
||||
// See man 2 sbrk.
|
||||
#if _BSD_SOURCE || _SVID_SOURCE || \
|
||||
(_XOPEN_SOURCE >= 500 || \
|
||||
_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && \
|
||||
!(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
|
||||
#define HAVE_SBRK 1
|
||||
#endif
|
||||
|
||||
#if HAVE_SBRK
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define ITERATIONS 20000
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
puts("Warming up: creating/deleting 10 tox instances");
|
||||
|
||||
// Warm-up.
|
||||
for (i = 0; i < 10; i++) {
|
||||
Tox *tox = tox_new(0, 0);
|
||||
tox_iterate(tox, NULL);
|
||||
tox_kill(tox);
|
||||
}
|
||||
|
||||
#if HAVE_SBRK
|
||||
// Low water mark.
|
||||
char *hwm = (char *)sbrk(0);
|
||||
#endif
|
||||
printf("Creating/deleting %d tox instances\n", ITERATIONS);
|
||||
|
||||
for (i = 0; i < ITERATIONS; i++) {
|
||||
Tox *tox = tox_new(0, 0);
|
||||
tox_iterate(tox, NULL);
|
||||
tox_kill(tox);
|
||||
#if HAVE_SBRK
|
||||
char *next_hwm = (char *)sbrk(0);
|
||||
assert(hwm == next_hwm);
|
||||
#endif
|
||||
}
|
||||
|
||||
puts("Success: no resource leaks detected");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user