mirror of
https://github.com/apple/swift-nio
synced 2026-11-26 04:57:49 +00:00
* Extend the integration test harness to track FDs Motivation This patch extends the NIO integration test harness to track file descriptors, in particular to search for leaks. This change has been validated on Linux and Darwin, and in both cases correctly diagnoses FD leaks. The goal is to enable us to regression test for things like Modifications - Add support for hooking socket and close calls. - Wire up this support into the test harness. - Extend the test harness to handle the logging. - Add new regression test for #2047. Results We can write regression tests for FD leaks. * Disable FD checking in most builds. I'm doing this for speed reasons * Always print the leaked fds number
63 lines
1.7 KiB
C
63 lines
1.7 KiB
C
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#define _GNU_SOURCE
|
|
#include <stdio.h>
|
|
#include <dlfcn.h>
|
|
#include <atomic-counter.h>
|
|
#include <hooked-functions.h>
|
|
#include <stdlib.h>
|
|
|
|
#if !__APPLE__
|
|
void free(void *ptr) {
|
|
replacement_free(ptr);
|
|
}
|
|
void *malloc(size_t size) {
|
|
return replacement_malloc(size);
|
|
}
|
|
void *calloc(size_t nmemb, size_t size) {
|
|
return replacement_calloc(nmemb, size);
|
|
}
|
|
void *realloc(void *ptr, size_t size) {
|
|
return replacement_realloc(ptr, size);
|
|
}
|
|
void *reallocf(void *ptr, size_t size) {
|
|
return replacement_reallocf(ptr, size);
|
|
}
|
|
void *valloc(size_t size) {
|
|
return replacement_valloc(size);
|
|
}
|
|
int posix_memalign(void **memptr, size_t alignment, size_t size) {
|
|
return replacement_posix_memalign(memptr, alignment, size);
|
|
}
|
|
int socket(int domain, int type, int protocol) {
|
|
return replacement_socket(domain, type, protocol);
|
|
}
|
|
int accept(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len) {
|
|
return replacement_accept(socket, address, address_len);
|
|
}
|
|
int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) {
|
|
return replacement_accept4(sockfd, addr, addrlen, flags);
|
|
}
|
|
int close(int fildes) {
|
|
return replacement_close(fildes);
|
|
}
|
|
#endif
|
|
|
|
void swift_main(void);
|
|
|
|
int main() {
|
|
swift_main();
|
|
}
|