-
Notifications
You must be signed in to change notification settings - Fork 184
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
Forking a child process during a test hangs and prints error message. #383
Comments
reduced example:
|
The issue is that criterion is receiving a message from your forked process via cr_log_info, but has no idea who it is, since it's a process outside of its watch list. I would expect that moving the fork after all of your argv preparation would cause the test to stop hanging. I'm not sure if this is something that we want so support. The runner certainly has no way to correlate a message from a random PID, so maybe the most "unsurprising" behaviour there would be to record somewhere the test PID and access it in these children. Not great though. |
Ok so moving the |
@CamJN Your example code contained some undefined behavior. After fixing those, it started to work correctly for me: #include <criterion/criterion.h>
#include <unistd.h>
pid_t spawn(const char *executable, ...);
Test(test,spawn){
int status;
waitpid(spawn("/bin/sleep", "sleep", "2", NULL), &status, 0);
}
pid_t spawn(const char *executable, ...) {
va_list val;
const char** args = NULL;
int argc = 1; //room for terminating NULL
va_start(val, executable);
while (va_arg(val, const char *) != NULL) argc++;
va_end(val);
cr_log_info("%d\n",argc);
args = (const char **) malloc(argc * sizeof(char*));
va_start(val, executable);
for (int i = 0; i < argc; i++) {
args[i] = va_arg(val, const char *);
cr_log_info("%s\n", args[i]);
}
va_end(val);
pid_t pid = fork();
if (pid != 0) return pid;
execv(executable, args);
_Exit(EXIT_FAILURE);
} Note: Criterion tests are executed in a sandboxed environment. These are called |
@MrAnno I understand that the parent process is |
In the above example, |
Ugh nevermind, looks like it was a race, the |
I am working on some code that deals with processes, In order to test one function, I need to know the PID of a running process that I own, with more than 1 argument. I tried to fork then exec a child process for this purpose, but the 3 processes then hang (criterion parent/runner process, test process, and my child process), and the following message gets printed:
[ERR ] Received message identified by a PID '21459' that is not a child process.
I think there's some kind of magic going around with how children of criterion's runner process are handled, but I need to know how to opt out of that, or perhaps it should disable itself after one fork.
The text was updated successfully, but these errors were encountered: