Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized TEST #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion utils/gnl.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#ifndef GNL_HPP
# define GNL_HPP
# include "leaks.hpp"
#include <chrono>

using namespace std::chrono;

//Don't do that at home
#define TEST(x) {int status = 0; int test = fork(); if (test == 0) {x showLeaks(); exit(EXIT_SUCCESS);} else {usleep(TIMEOUT_US); if (waitpid(test, &status, WNOHANG) == 0) {kill(test, 9); cout << FG_RED << "TIMEOUT";}}}
#define USLEEP_TERM 100
#define TEST(x) {int status = 0; int test = fork(); if (test == 0) {x showLeaks(); exit(EXIT_SUCCESS);} else {auto a = high_resolution_clock::now(); auto b = high_resolution_clock::now(); while(duration_cast<microseconds>(b - a).count()<TIMEOUT_US){ usleep(USLEEP_TERM); if (waitpid(test, &status, WNOHANG) != 0) { break; } b = high_resolution_clock::now(); } if (waitpid(test, &status, WNOHANG) == 0) { kill(test, 9); cout << FG_RED << "TIMEOUT"; }}}

void gnl(int fd, char const * s);

Expand Down