mirror of
https://gitlab.freedesktop.org/pipewire/pipewire
synced 2024-10-14 20:02:38 +00:00
pwtest: add pwtest_spawn for running external programs
This commit is contained in:
parent
df4f844daa
commit
581f6c7f1d
|
@ -407,6 +407,34 @@ pwtest_mkstemp(char path[PATH_MAX])
|
|||
pwtest_error_with_msg("Unable to create temporary file: %s", strerror(errno));
|
||||
}
|
||||
|
||||
int
|
||||
pwtest_spawn(const char *file, char *const argv[])
|
||||
{
|
||||
int r;
|
||||
int status = -1;
|
||||
pid_t pid;
|
||||
const int fail_code = 121;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
/* child process */
|
||||
setlinebuf(stderr);
|
||||
setlinebuf(stdout);
|
||||
execvp(file, (char **)argv);
|
||||
exit(fail_code);
|
||||
} else if (pid < 0)
|
||||
pwtest_error_with_msg("Unable to fork: %s", strerror(errno));
|
||||
|
||||
r = waitpid(pid, &status, 0);
|
||||
if (r <= 0)
|
||||
pwtest_error_with_msg("waitpid failed: %s", strerror(errno));
|
||||
|
||||
if (WEXITSTATUS(status) == fail_code)
|
||||
pwtest_error_with_msg("exec %s failed", file);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void _pwtest_add(struct pwtest_context *ctx, struct pwtest_suite *suite,
|
||||
const char *funcname, const void *func, ...)
|
||||
{
|
||||
|
|
|
@ -558,6 +558,11 @@ pwtest_spa_plugin_try_load_interface(struct pwtest_spa_plugin *plugin,
|
|||
*/
|
||||
void pwtest_mkstemp(char path[PATH_MAX]);
|
||||
|
||||
/**
|
||||
* Run a command and wait for it to return.
|
||||
*/
|
||||
int pwtest_spawn(const char *file, char *const argv[]);
|
||||
|
||||
|
||||
/**
|
||||
* \}
|
||||
|
|
Loading…
Reference in a new issue