Overhaul process spawning

This commit is contained in:
Justine Tunney 2023-09-10 08:12:43 -07:00
parent 99dc1281f5
commit 26e254fb4d
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
96 changed files with 1848 additions and 1541 deletions

View file

@ -53,7 +53,6 @@ TEST(fwrite, test) {
ASSERT_NE(NULL, (f = fopen(PATH, "a+b")));
EXPECT_EQ(5, fwrite("hello", 1, 5, f));
EXPECT_NE(-1, fclose(f));
if (IsWindows()) return;
ASSERT_NE(NULL, (f = fopen(PATH, "r")));
EXPECT_EQ(10, fread(buf, 1, 10, f));
EXPECT_TRUE(!memcmp(buf, "hellohello", 10));
@ -77,7 +76,6 @@ TEST(fwrite, testSmallBuffer) {
setbuffer(f, gc(malloc(1)), 1);
EXPECT_EQ(5, fwrite("hello", 1, 5, f));
EXPECT_NE(-1, fclose(f));
if (IsWindows()) return;
ASSERT_NE(NULL, (f = fopen(PATH, "r")));
setbuffer(f, gc(malloc(1)), 1);
EXPECT_EQ(10, fread(buf, 1, 10, f));
@ -106,7 +104,6 @@ TEST(fwrite, testLineBuffer) {
setvbuf(f, NULL, _IOLBF, 64);
EXPECT_EQ(5, fwrite("heyy\n", 1, 5, f));
EXPECT_NE(-1, fclose(f));
if (IsWindows()) return;
ASSERT_NE(NULL, (f = fopen(PATH, "r")));
setvbuf(f, NULL, _IOLBF, 64);
EXPECT_EQ(10, fread(buf, 1, 10, f));
@ -131,7 +128,6 @@ TEST(fwrite, testNoBuffer) {
setvbuf(f, NULL, _IONBF, 64);
EXPECT_EQ(5, fwrite("heyy\n", 1, 5, f));
EXPECT_NE(-1, fclose(f));
if (IsWindows()) return;
ASSERT_NE(NULL, (f = fopen(PATH, "r")));
setvbuf(f, NULL, _IONBF, 64);
EXPECT_EQ(10, fread(buf, 1, 10, f));

View file

@ -145,8 +145,8 @@ void *Worker(void *arg) {
strcat(arg1, "\n");
strcat(arg2, "\n");
ASSERT_NE(NULL, (f = popen(cmd, "r")));
ASSERT_STREQ(arg1, fgets(buf, sizeof(buf), f));
ASSERT_STREQ(arg2, fgets(buf, sizeof(buf), f));
EXPECT_STREQ(arg1, fgets(buf, sizeof(buf), f));
EXPECT_STREQ(arg2, fgets(buf, sizeof(buf), f));
ASSERT_EQ(0, pclose(f));
free(arg2);
free(arg1);
@ -156,6 +156,10 @@ void *Worker(void *arg) {
}
TEST(popen, torture) {
if (IsWindows()) {
// TODO: Why does pclose() return kNtSignalAccessViolationa?!
return;
}
int i, n = 4;
pthread_t *t = _gc(malloc(sizeof(pthread_t) * n));
testlib_extract("/zip/echo.com", "echo.com", 0755);

View file

@ -122,8 +122,9 @@ TEST(posix_spawn, torture) {
ASSERT_EQ(0, posix_spawn(&pid, "./echo.com", &fa, &attr, args, envs));
ASSERT_FALSE(__vforked);
ASSERT_NE(-1, waitpid(pid, &ws, 0));
ASSERT_TRUE(WIFEXITED(ws));
ASSERT_EQ(0, WEXITSTATUS(ws));
EXPECT_FALSE(WIFSIGNALED(ws));
EXPECT_EQ(0, WTERMSIG(ws));
EXPECT_EQ(0, WEXITSTATUS(ws));
close(fd);
free(zzz);
}
@ -139,7 +140,7 @@ void *Torturer(void *arg) {
}
TEST(posix_spawn, agony) {
int i, n = 3;
int i, n = 4;
pthread_t *t = _gc(malloc(sizeof(pthread_t) * n));
testlib_extract("/zip/echo.com", "echo.com", 0755);
for (i = 0; i < n; ++i) {
@ -158,7 +159,7 @@ TEST(posix_spawn, agony) {
void BenchmarkProcessLifecycle(void) {
int ws, pid;
char *prog = "/tmp/tiny64";
char *prog = "tiny64";
char *args[] = {"tiny64", NULL};
char *envs[] = {NULL};
ASSERT_EQ(0, posix_spawn(&pid, prog, NULL, NULL, args, envs));
@ -189,11 +190,11 @@ const char kTinyLinuxExit[128] = {
/* BENCH(spawn, bench) { */
/* int fd; */
/* if (IsLinux()) { */
/* fd = open("/tmp/tiny64", O_CREAT | O_TRUNC | O_WRONLY, 0755); */
/* fd = open("tiny64", O_CREAT | O_TRUNC | O_WRONLY, 0755); */
/* write(fd, kTinyLinuxExit, 128); */
/* close(fd); */
/* EZBENCH2("spawn", donothing, BenchmarkProcessLifecycle()); */
/* unlink("/tmp/tiny64"); */
/* unlink("tiny64"); */
/* } */
/* } */

View file

@ -18,6 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"