Created
June 11, 2018 19:10
-
-
Save artem-smotrakov/ada29fd193cf3805c484fe3359c88b97 to your computer and use it in GitHub Desktop.
A patch for t/cli.c which adds a signal handler for dumping code coverage data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/t/cli.c b/t/cli.c | |
index 8d9b68b..99cc4ab 100644 | |
--- a/t/cli.c | |
+++ b/t/cli.c | |
@@ -19,6 +19,11 @@ | |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
* IN THE SOFTWARE. | |
*/ | |
+ | |
+/* | |
+ * This is a modified version of t/cli.c | |
+ */ | |
+ | |
#ifndef _XOPEN_SOURCE | |
#define _XOPEN_SOURCE 700 /* required for glibc to use getaddrinfo, etc. */ | |
#endif | |
@@ -29,6 +34,7 @@ | |
#include <fcntl.h> | |
#include <getopt.h> | |
#include <inttypes.h> | |
+#include <signal.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <sys/select.h> | |
@@ -45,6 +51,17 @@ | |
#include "picotls/openssl.h" | |
#include "util.h" | |
+// forward declaration of __gcov_flush() | |
+void __gcov_flush(); | |
+ | |
+// signal handler definition which flushes coverage data | |
+void signal_handler(int signum) | |
+{ | |
+ fprintf(stderr, "received signal %d, dump code coverage data\n", signum); | |
+ __gcov_flush(); | |
+ exit(1); | |
+} | |
+ | |
static void shift_buffer(ptls_buffer_t *buf, size_t delta) | |
{ | |
if (delta != 0) { | |
@@ -318,6 +335,13 @@ int main(int argc, char **argv) | |
struct sockaddr_storage sa; | |
socklen_t salen; | |
int family = 0; | |
+ int signum; | |
+ | |
+ printf("set a signal handler\n"); | |
+ if (signal(SIGINT, signal_handler) == SIG_ERR) { | |
+ fprintf(stderr, "couldn't set a handler for signal: %d\n", signum); | |
+ exit(1); | |
+ } | |
while ((ch = getopt(argc, argv, "46aC:c:i:k:nes:Sl:vh")) != -1) { | |
switch (ch) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment