-
-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is just a sanity check on whether the library correctly wraps the syscalls and it's using the "true" executable for posix_spawn() and execv(). The installCheckPhase is not executed if we are cross-compiling, so this shouldn't break cross-compilation. One thing I'm not actually sure is whether ${coreutils}/bin/true is universally available on all the platforms, nor whether all the functions we use in the test are available, but we can still fix that after we've found out about that. Signed-off-by: aszlig <aszlig@nix.build>
- Loading branch information
Showing
2 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <assert.h> | ||
#include <fcntl.h> | ||
#include <spawn.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
|
||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
|
||
#define TESTPATH "/foo/bar/test" | ||
|
||
extern char **environ; | ||
|
||
void test_spawn(void) { | ||
pid_t pid; | ||
int ret; | ||
posix_spawn_file_actions_t file_actions; | ||
char *argv[] = {"true", NULL}; | ||
|
||
assert(posix_spawn_file_actions_init(&file_actions) == 0); | ||
|
||
ret = posix_spawn(&pid, TESTPATH, &file_actions, NULL, argv, environ); | ||
|
||
assert(ret == 0); | ||
assert(waitpid(pid, NULL, 0) != -1); | ||
} | ||
|
||
void test_execv(void) { | ||
char *argv[] = {"true", NULL}; | ||
assert(execv(TESTPATH, argv) == 0); | ||
} | ||
|
||
int main(void) | ||
{ | ||
FILE *testfp; | ||
int testfd; | ||
struct stat testsb; | ||
|
||
testfp = fopen(TESTPATH, "r"); | ||
assert(testfp != NULL); | ||
fclose(testfp); | ||
|
||
testfd = open(TESTPATH, O_RDONLY); | ||
assert(testfd != -1); | ||
close(testfd); | ||
|
||
assert(access(TESTPATH, X_OK) == 0); | ||
|
||
assert(stat(TESTPATH, &testsb) != -1); | ||
|
||
test_spawn(); | ||
test_execv(); | ||
|
||
/* If all goes well, this is never reached because test_execv() replaces | ||
* the current process. | ||
*/ | ||
return 0; | ||
} |