tests: Add posix_spawn test
Signed-off-by: Dennisbonke <admin@dennisbonke.com>
This commit is contained in:
parent
3e6bbfc281
commit
581d651fc1
|
@ -10,7 +10,8 @@ posix_test_cases = [
|
|||
'inet_pton',
|
||||
'pthread_rwlock',
|
||||
'getaddrinfo',
|
||||
'dprintf'
|
||||
'dprintf',
|
||||
'posix_spawn'
|
||||
]
|
||||
|
||||
glibc_test_cases = [
|
||||
|
|
39
tests/posix/posix_spawn.c
Normal file
39
tests/posix/posix_spawn.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <spawn.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
extern char **environ;
|
||||
|
||||
void run_cmd(char *cmd)
|
||||
{
|
||||
pid_t pid;
|
||||
char *argv[] = {"sh", "-c", cmd, NULL};
|
||||
int status;
|
||||
printf("Run command: %s\n", cmd);
|
||||
status = posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ);
|
||||
if(status == 0) {
|
||||
printf("Child pid: %i\n", pid);
|
||||
if(waitpid(pid, &status, 0) != -1) {
|
||||
printf("Child exited with status %i\n", status);
|
||||
printf("Child exit status: %i\n", WEXITSTATUS(status));
|
||||
assert(WEXITSTATUS(status) == 0);
|
||||
} else {
|
||||
perror("waitpid");
|
||||
assert(0 == 1);
|
||||
}
|
||||
} else {
|
||||
printf("posix_spawn: %s\n", strerror(status));
|
||||
assert(0 == 1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
run_cmd("/usr/bin/true");
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue