mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 00:02:28 +00:00
Apply clang-format update to repo (#1154)
Commit bc6c183
introduced a bunch of discrepancies between what files
look like in the repo and what clang-format says they should look like.
However, there were already a few discrepancies prior to that. Most of
these discrepancies seemed to be unintentional, but a few of them were
load-bearing (e.g., a #include that violated header ordering needing
something to have been #defined by a 'later' #include.)
I opted to take what I hope is a relatively smooth-brained approach: I
reverted the .clang-format change, ran clang-format on the whole repo,
reapplied the .clang-format change, reran clang-format again, and then
reverted the commit that contained the first run. Thus the full effect
of this PR should only be to apply the changed formatting rules to the
repo, and from skimming the results, this seems to be the case.
My work can be checked by applying the short, manual commits, and then
rerunning the command listed in the autogenerated commits (those whose
messages I have prefixed auto:) and seeing if your results agree.
It might be that the other diffs should be fixed at some point but I'm
leaving that aside for now.
fd '\.c(c|pp)?$' --print0| xargs -0 clang-format -i
This commit is contained in:
parent
342d0c81e5
commit
6e6fc38935
863 changed files with 9201 additions and 4627 deletions
|
@ -34,7 +34,8 @@ void SetUpOnce(void) {
|
|||
}
|
||||
|
||||
TEST(access, efault) {
|
||||
if (IsWindows() || !IsAsan()) return; // not possible
|
||||
if (IsWindows() || !IsAsan())
|
||||
return; // not possible
|
||||
ASSERT_SYS(EFAULT, -1, access((void *)77, F_OK));
|
||||
}
|
||||
|
||||
|
@ -61,7 +62,8 @@ TEST(access, test) {
|
|||
}
|
||||
|
||||
TEST(access, testRequestWriteOnReadOnly_returnsEaccess) {
|
||||
if (1) return; // TODO(jart): maybe we need root to help?
|
||||
if (1)
|
||||
return; // TODO(jart): maybe we need root to help?
|
||||
ASSERT_SYS(ENOENT, -1, access("file", F_OK));
|
||||
ASSERT_SYS(0, 0, close(creat("file", 0444)));
|
||||
ASSERT_SYS(0, 0, access("file", F_OK));
|
||||
|
|
|
@ -93,7 +93,8 @@ TEST(cachestat, testCachestatSyncNoDirty) {
|
|||
"total number of evicted pages is off.");
|
||||
struct statfs statfs;
|
||||
ASSERT_SYS(0, 0, fstatfs(3, &statfs));
|
||||
if (statfs.f_type == TMPFS_MAGIC) goto done;
|
||||
if (statfs.f_type == TMPFS_MAGIC)
|
||||
goto done;
|
||||
ASSERT_SYS(0, 0, fsync(3));
|
||||
ASSERT_SYS(0, 0, cachestat(3, &range, &cs, 0));
|
||||
EXPECT_EQ(0, cs.nr_dirty,
|
||||
|
|
|
@ -29,7 +29,8 @@ void SetUpOnce(void) {
|
|||
|
||||
TEST(chdir, efault) {
|
||||
ASSERT_SYS(EFAULT, -1, chdir(0));
|
||||
if (IsWindows() || !IsAsan()) return; // not possible
|
||||
if (IsWindows() || !IsAsan())
|
||||
return; // not possible
|
||||
ASSERT_SYS(EFAULT, -1, chdir((void *)77));
|
||||
}
|
||||
|
||||
|
|
|
@ -40,14 +40,16 @@ TEST(clock_getres, realtimeFastHasMillisecondPrecisionOrBetter) {
|
|||
}
|
||||
|
||||
TEST(clock_getres, realtimeCoarseHasMillisecondPrecisionOrBetter) {
|
||||
if (clock_getres(CLOCK_REALTIME_COARSE, &ts)) return;
|
||||
if (clock_getres(CLOCK_REALTIME_COARSE, &ts))
|
||||
return;
|
||||
EXPECT_EQ(0, ts.tv_sec);
|
||||
EXPECT_LT(ts.tv_nsec, 100000000);
|
||||
EXPECT_GT(ts.tv_nsec, 0);
|
||||
}
|
||||
|
||||
TEST(clock_getres, realtimePreciseHasMillisecondPrecisionOrBetter) {
|
||||
if (clock_getres(CLOCK_REALTIME_PRECISE, &ts)) return;
|
||||
if (clock_getres(CLOCK_REALTIME_PRECISE, &ts))
|
||||
return;
|
||||
EXPECT_EQ(0, ts.tv_sec);
|
||||
EXPECT_LT(ts.tv_nsec, 100000000);
|
||||
EXPECT_GT(ts.tv_nsec, 0);
|
||||
|
@ -68,14 +70,16 @@ TEST(clock_getres, monotonicFastHasMillisecondPrecisionOrBetter) {
|
|||
}
|
||||
|
||||
TEST(clock_getres, monotonicCoarseHasMillisecondPrecisionOrBetter) {
|
||||
if (clock_getres(CLOCK_MONOTONIC_COARSE, &ts)) return;
|
||||
if (clock_getres(CLOCK_MONOTONIC_COARSE, &ts))
|
||||
return;
|
||||
EXPECT_EQ(0, ts.tv_sec);
|
||||
EXPECT_LT(ts.tv_nsec, 100000000);
|
||||
EXPECT_GT(ts.tv_nsec, 0);
|
||||
}
|
||||
|
||||
TEST(clock_getres, monotonicPreciseHasMillisecondPrecisionOrBetter) {
|
||||
if (clock_getres(CLOCK_MONOTONIC_PRECISE, &ts)) return;
|
||||
if (clock_getres(CLOCK_MONOTONIC_PRECISE, &ts))
|
||||
return;
|
||||
EXPECT_EQ(0, ts.tv_sec);
|
||||
EXPECT_LT(ts.tv_nsec, 100000000);
|
||||
EXPECT_GT(ts.tv_nsec, 0);
|
||||
|
|
|
@ -70,6 +70,7 @@ TEST(close_range, test) {
|
|||
}
|
||||
|
||||
TEST(close_range, ignoresNonexistantRanges) {
|
||||
if (!IsLinux() && !IsFreebsd()) return;
|
||||
if (!IsLinux() && !IsFreebsd())
|
||||
return;
|
||||
EXPECT_SYS(0, 0, close_range(-2, -1, 0));
|
||||
}
|
||||
|
|
|
@ -100,7 +100,8 @@ TEST(commandv, test_DirPaths_wontConsiderDirectoriesExecutable2) {
|
|||
}
|
||||
|
||||
TEST(commandv, test_nonExecutableFile_willEacces) {
|
||||
if (IsWindows()) return; // TODO: fixme
|
||||
if (IsWindows())
|
||||
return; // TODO: fixme
|
||||
setenv("PATH", "foo", true);
|
||||
EXPECT_SYS(0, 0, mkdir("foo", 0755));
|
||||
EXPECT_SYS(0, 0, touch("foo/bar", 0400));
|
||||
|
|
|
@ -94,19 +94,23 @@ bool HasCopyFileRange(void) {
|
|||
}
|
||||
|
||||
TEST(copy_file_range, badFd) {
|
||||
if (!HasCopyFileRange()) return;
|
||||
if (!HasCopyFileRange())
|
||||
return;
|
||||
ASSERT_SYS(EBADF, -1, copy_file_range(-1, 0, -1, 0, -1u, 0));
|
||||
}
|
||||
|
||||
TEST(copy_file_range, badFlags) {
|
||||
if (!HasCopyFileRange()) return;
|
||||
if (!HasCopyFileRange())
|
||||
return;
|
||||
ASSERT_SYS(EINVAL, -1, copy_file_range(0, 0, 1, 0, -1u, -1));
|
||||
}
|
||||
|
||||
TEST(copy_file_range, differentFileSystems) {
|
||||
return; // TODO(jart): Why does this flake on GitHub Actions?
|
||||
if (!IsLinux()) return;
|
||||
if (!HasCopyFileRange()) return;
|
||||
if (!IsLinux())
|
||||
return;
|
||||
if (!HasCopyFileRange())
|
||||
return;
|
||||
ASSERT_SYS(0, 3, open("/proc/stat", 0));
|
||||
ASSERT_SYS(0, 4, creat("foo", 0644));
|
||||
ASSERT_SYS(EXDEV, -1, copy_file_range(3, 0, 4, 0, -1u, 0));
|
||||
|
@ -117,7 +121,8 @@ TEST(copy_file_range, differentFileSystems) {
|
|||
TEST(copy_file_range, twoDifferentFiles) {
|
||||
char buf[16] = {0};
|
||||
int64_t i = 1, o = 0;
|
||||
if (!HasCopyFileRange()) return;
|
||||
if (!HasCopyFileRange())
|
||||
return;
|
||||
ASSERT_SYS(0, 3, open("foo", O_RDWR | O_CREAT | O_TRUNC, 0644));
|
||||
ASSERT_SYS(0, 4, open("bar", O_RDWR | O_CREAT | O_TRUNC, 0644));
|
||||
ASSERT_SYS(0, 5, pwrite(3, "hello", 5, 0));
|
||||
|
@ -134,7 +139,8 @@ TEST(copy_file_range, twoDifferentFiles) {
|
|||
TEST(copy_file_range, sameFile_doesntChangeFilePointer) {
|
||||
char buf[16] = {0};
|
||||
int64_t i = 1, o = 5;
|
||||
if (!HasCopyFileRange()) return;
|
||||
if (!HasCopyFileRange())
|
||||
return;
|
||||
ASSERT_SYS(0, 3, open("foo", O_RDWR | O_CREAT | O_TRUNC, 0644));
|
||||
ASSERT_SYS(0, 5, pwrite(3, "hello", 5, 0));
|
||||
ASSERT_SYS(0, 4, copy_file_range(3, &i, 3, &o, 4, 0));
|
||||
|
@ -148,7 +154,8 @@ TEST(copy_file_range, sameFile_doesntChangeFilePointer) {
|
|||
TEST(copy_file_range, overlappingRange) {
|
||||
int rc;
|
||||
int64_t i = 1, o = 2;
|
||||
if (!HasCopyFileRange()) return;
|
||||
if (!HasCopyFileRange())
|
||||
return;
|
||||
ASSERT_SYS(0, 3, open("foo", O_RDWR | O_CREAT | O_TRUNC, 0644));
|
||||
ASSERT_SYS(0, 5, pwrite(3, "hello", 5, 0));
|
||||
rc = copy_file_range(3, &i, 3, &o, 4, 0);
|
||||
|
|
|
@ -32,7 +32,8 @@ void SetUpOnce(void) {
|
|||
TEST(devfd, test) {
|
||||
// TODO: What is up with this mysterious ENOENT error?
|
||||
// The code appears like it should support this.
|
||||
if (IsFreebsd()) return;
|
||||
if (IsFreebsd())
|
||||
return;
|
||||
char buf[8] = {0};
|
||||
struct stat st[2] = {0};
|
||||
ASSERT_SYS(0, 0, xbarf("hello.txt", "bone", -1));
|
||||
|
@ -50,7 +51,8 @@ TEST(devfd, test) {
|
|||
TEST(devfd, not_DEV_FD_STAT_BROKEN) {
|
||||
// fstat() and stat() are inconsistent on bsd systems
|
||||
// with xnu it only appears to be st_dev that differs
|
||||
if (IsBsd()) return;
|
||||
if (IsBsd())
|
||||
return;
|
||||
char buf[8] = {0};
|
||||
struct stat st[2] = {0};
|
||||
ASSERT_SYS(0, 0, xbarf("hello.txt", "bone", -1));
|
||||
|
|
|
@ -34,7 +34,8 @@ void SetUpOnce(void) {
|
|||
}
|
||||
|
||||
TEST(fchmodat, testFchmodat) {
|
||||
if (IsWindows()) return; // not advanced enough yet
|
||||
if (IsWindows())
|
||||
return; // not advanced enough yet
|
||||
struct stat st;
|
||||
umask(022);
|
||||
ASSERT_SYS(0, 3,
|
||||
|
|
|
@ -139,8 +139,10 @@ void OnSig(int sig) {
|
|||
}
|
||||
|
||||
TEST(posixAdvisoryLocks, twoProcesses) {
|
||||
if (IsWindows()) return; // due to signals
|
||||
if (IsNetbsd()) return; // TODO: why does sigusr1 kill runitd?
|
||||
if (IsWindows())
|
||||
return; // due to signals
|
||||
if (IsNetbsd())
|
||||
return; // TODO: why does sigusr1 kill runitd?
|
||||
|
||||
int ws, pid;
|
||||
struct flock lock;
|
||||
|
|
|
@ -70,7 +70,8 @@ TEST(ftruncate, pipeFd_einval) {
|
|||
|
||||
TEST(ftruncate, efbig) {
|
||||
// FreeBSD and RHEL7 return 0 (why??)
|
||||
if (IsLinux() || IsFreebsd()) return;
|
||||
if (IsLinux() || IsFreebsd())
|
||||
return;
|
||||
sighandler_t old = signal(SIGXFSZ, SIG_IGN);
|
||||
ASSERT_SYS(0, 3, creat("foo", 0755));
|
||||
ASSERT_SYS(IsWindows() ? EINVAL : EFBIG, -1, ftruncate(3, INT64_MAX));
|
||||
|
|
|
@ -33,7 +33,8 @@ void SetUpOnce(void) {
|
|||
}
|
||||
|
||||
TEST(__getcwd, zero) {
|
||||
if (IsQemuUser()) return;
|
||||
if (IsQemuUser())
|
||||
return;
|
||||
ASSERT_SYS(ERANGE, -1, __getcwd(0, 0));
|
||||
}
|
||||
|
||||
|
@ -83,7 +84,8 @@ TEST(getcwd, testNullBuf_allocatesResult) {
|
|||
}
|
||||
|
||||
TEST(getcwd, testWindows_addsFunnyPrefix) {
|
||||
if (!IsWindows()) return;
|
||||
if (!IsWindows())
|
||||
return;
|
||||
char path[PATH_MAX];
|
||||
ASSERT_NE(0, getcwd(path, sizeof(path)));
|
||||
path[1] = tolower(path[1]);
|
||||
|
|
|
@ -23,9 +23,11 @@
|
|||
|
||||
TEST(getgroups, test) {
|
||||
int n;
|
||||
if (IsWindows()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
uint32_t G[500];
|
||||
EXPECT_GT((n = getgroups(ARRAYLEN(G), G)), 0);
|
||||
if (getuid()) return; // this needs root
|
||||
if (getuid())
|
||||
return; // this needs root
|
||||
EXPECT_SYS(0, 0, setgroups(n, G));
|
||||
}
|
||||
|
|
|
@ -103,7 +103,8 @@ TEST(GetProgramExecutableName, ofThisFile) {
|
|||
}
|
||||
|
||||
TEST(GetProgramExecutableName, nullEnv) {
|
||||
if (skiptests) return;
|
||||
if (skiptests)
|
||||
return;
|
||||
SPAWN(fork);
|
||||
execve(self, (char *[]){self, "Child", self, skiparg0 ? 0 : self, 0},
|
||||
(char *[]){0});
|
||||
|
@ -112,7 +113,8 @@ TEST(GetProgramExecutableName, nullEnv) {
|
|||
}
|
||||
|
||||
TEST(GetProramExecutableName, weirdArgv0NullEnv) {
|
||||
if (skiptests) return;
|
||||
if (skiptests)
|
||||
return;
|
||||
SPAWN(fork);
|
||||
execve(self, (char *[]){"hello", "Child", self, skiparg0 ? 0 : "hello", 0},
|
||||
(char *[]){0});
|
||||
|
@ -121,7 +123,8 @@ TEST(GetProramExecutableName, weirdArgv0NullEnv) {
|
|||
}
|
||||
|
||||
TEST(GetProgramExecutableName, movedSelf) {
|
||||
if (skiptests) return;
|
||||
if (skiptests)
|
||||
return;
|
||||
if (IsAarch64() && IsQemuUser()) {
|
||||
// clang-format off
|
||||
// TODO(mrdomino): fix: make -j8 m=aarch64 o/aarch64/test/libc/calls/getprogramexecutablename_test.ok
|
||||
|
|
|
@ -59,9 +59,11 @@ void *TortureWorker(void *arg) {
|
|||
ASSERT_SYS(0, 0, sigprocmask(SIG_SETMASK, &ss, 0));
|
||||
ready = true;
|
||||
while (!done) {
|
||||
if (!IsWindows()) pthread_kill(parent, SIGUSR1);
|
||||
if (!IsWindows())
|
||||
pthread_kill(parent, SIGUSR1);
|
||||
usleep(1);
|
||||
if (!IsWindows()) pthread_kill(parent, SIGUSR2);
|
||||
if (!IsWindows())
|
||||
pthread_kill(parent, SIGUSR2);
|
||||
usleep(1);
|
||||
}
|
||||
return 0;
|
||||
|
@ -78,9 +80,11 @@ TEST(getrandom, test) {
|
|||
if ((e = MeasureEntropy(buf, n)) < w) {
|
||||
fprintf(stderr, "error: entropy is suspect! got %g but want >=%g\n", e, w);
|
||||
for (i = 0; i < n;) {
|
||||
if (!(i % 16)) fprintf(stderr, "%6x ", i);
|
||||
if (!(i % 16))
|
||||
fprintf(stderr, "%6x ", i);
|
||||
fprintf(stderr, "%lc", kCp437[buf[i] & 255]);
|
||||
if (!(++i % 16)) fprintf(stderr, "\n");
|
||||
if (!(++i % 16))
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
exit(1);
|
||||
|
@ -100,7 +104,8 @@ TEST(getrandom, test2) {
|
|||
ASSERT_SYS(0, 0, sigaction(SIGUSR2, &sa, 0));
|
||||
parent = pthread_self();
|
||||
ASSERT_EQ(0, pthread_create(&child, 0, TortureWorker, 0));
|
||||
while (!ready) pthread_yield();
|
||||
while (!ready)
|
||||
pthread_yield();
|
||||
for (k = 0; k < 10; ++k) {
|
||||
ASSERT_SYS(0, 0, getrandom(0, 0, 0));
|
||||
for (i = 0; i < n; i += m) {
|
||||
|
@ -111,9 +116,11 @@ TEST(getrandom, test2) {
|
|||
if ((e = MeasureEntropy(buf, n)) < w) {
|
||||
fprintf(stderr, "error: entropy suspect! got %g but want >=%g\n", e, w);
|
||||
for (i = 0; i < n;) {
|
||||
if (!(i % 16)) fprintf(stderr, "%6x ", i);
|
||||
if (!(i % 16))
|
||||
fprintf(stderr, "%6x ", i);
|
||||
fprintf(stderr, "%lc", kCp437[buf[i] & 255]);
|
||||
if (!(++i % 16)) fprintf(stderr, "\n");
|
||||
if (!(++i % 16))
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
done = true;
|
||||
|
@ -123,7 +130,8 @@ TEST(getrandom, test2) {
|
|||
}
|
||||
done = true;
|
||||
ASSERT_EQ(0, pthread_join(child, 0));
|
||||
if (!IsWindows()) ASSERT_GT(gotsome, 0);
|
||||
if (!IsWindows())
|
||||
ASSERT_GT(gotsome, 0);
|
||||
}
|
||||
|
||||
/* JustReturnZero */
|
||||
|
@ -237,13 +245,15 @@ uint64_t SixthEditionLowByte(void) {
|
|||
|
||||
uint64_t MobyDick(void) {
|
||||
static int i;
|
||||
if ((i += 8) > kMobySize) i = 8;
|
||||
if ((i += 8) > kMobySize)
|
||||
i = 8;
|
||||
return READ64LE(kMoby + i);
|
||||
}
|
||||
|
||||
uint64_t ExecutableImage(void) {
|
||||
static int i;
|
||||
if ((i += 8) > _end - __executable_start) i = 8;
|
||||
if ((i += 8) > _end - __executable_start)
|
||||
i = 8;
|
||||
return READ64LE(__executable_start + i);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,8 @@ TEST(siocgifconf, test) {
|
|||
conf.ifc_len = n;
|
||||
ASSERT_NE(-1, ioctl(socketfd, SIOCGIFCONF, &conf));
|
||||
for (ifr = (struct ifreq *)data; (char *)ifr < data + conf.ifc_len; ++ifr) {
|
||||
if (ifr->ifr_addr.sa_family != AF_INET) continue;
|
||||
if (ifr->ifr_addr.sa_family != AF_INET)
|
||||
continue;
|
||||
ip = ntohl(((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr);
|
||||
EXPECT_NE(-1, ioctl(socketfd, SIOCGIFNETMASK, ifr));
|
||||
netmask = ntohl(((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr);
|
||||
|
@ -72,7 +73,8 @@ TEST(siocgifconf, test) {
|
|||
}
|
||||
|
||||
TEST(siocgifconf, mkntenvblock_systemroot) {
|
||||
if (__argc != 1) return;
|
||||
if (__argc != 1)
|
||||
return;
|
||||
SPAWN(fork);
|
||||
execve(GetProgramExecutableName(),
|
||||
(char *[]){GetProgramExecutableName(), "hi", NULL}, (char *[]){NULL});
|
||||
|
|
|
@ -48,7 +48,8 @@ _Thread_local const char *kind;
|
|||
bool SupportsOfdLocks(void) {
|
||||
int e;
|
||||
bool r;
|
||||
if (!IsLinux()) return false;
|
||||
if (!IsLinux())
|
||||
return false;
|
||||
// F_OFD_* was introduced in linux 3.15
|
||||
// getrandom() was introduced in linux 3.17
|
||||
// testing for getrandom() should be a sure thing w/o creating an fd
|
||||
|
|
|
@ -72,8 +72,10 @@ TEST(madvise, subPages) {
|
|||
|
||||
TEST(madvise, misalign) {
|
||||
char *p;
|
||||
if (!IsLinux()) return; // most platforms don't care
|
||||
if (IsQemuUser()) return; // qemu claims to be linux but doesn't care
|
||||
if (!IsLinux())
|
||||
return; // most platforms don't care
|
||||
if (IsQemuUser())
|
||||
return; // qemu claims to be linux but doesn't care
|
||||
ASSERT_NE(MAP_FAILED, (p = mmap(0, FRAMESIZE, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)));
|
||||
ASSERT_SYS(EINVAL, -1, madvise(p + 1, FRAMESIZE - 1, MADV_WILLNEED));
|
||||
|
@ -82,7 +84,8 @@ TEST(madvise, misalign) {
|
|||
|
||||
TEST(madvise, badAdvice) {
|
||||
char *p;
|
||||
if (IsAarch64() && IsQemuUser()) return; // qemu doesn't validate advice
|
||||
if (IsAarch64() && IsQemuUser())
|
||||
return; // qemu doesn't validate advice
|
||||
ASSERT_NE(MAP_FAILED, (p = mmap(0, FRAMESIZE, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)));
|
||||
ASSERT_SYS(EINVAL, -1, madvise(p, FRAMESIZE, 127));
|
||||
|
@ -90,8 +93,10 @@ TEST(madvise, badAdvice) {
|
|||
}
|
||||
|
||||
TEST(madvise, missingMemory) {
|
||||
if (!IsLinux()) return; // most platforms don't care
|
||||
if (IsQemuUser()) return; // qemu claims to be linux but doesn't care
|
||||
if (!IsLinux())
|
||||
return; // most platforms don't care
|
||||
if (IsQemuUser())
|
||||
return; // qemu claims to be linux but doesn't care
|
||||
ASSERT_SYS(ENOMEM, -1,
|
||||
madvise((char *)0x83483838000, FRAMESIZE, MADV_WILLNEED));
|
||||
}
|
||||
|
|
|
@ -71,7 +71,9 @@ TEST(makedirs, test) {
|
|||
int i, n = 8;
|
||||
pthread_t *t = gc(malloc(sizeof(pthread_t) * n));
|
||||
ASSERT_EQ(0, pthread_barrier_init(&barrier, 0, n));
|
||||
for (i = 0; i < n; ++i) ASSERT_EQ(0, pthread_create(t + i, 0, Worker, 0));
|
||||
for (i = 0; i < n; ++i) EXPECT_EQ(0, pthread_join(t[i], 0));
|
||||
for (i = 0; i < n; ++i)
|
||||
ASSERT_EQ(0, pthread_create(t + i, 0, Worker, 0));
|
||||
for (i = 0; i < n; ++i)
|
||||
EXPECT_EQ(0, pthread_join(t[i], 0));
|
||||
ASSERT_EQ(0, pthread_barrier_destroy(&barrier));
|
||||
}
|
||||
|
|
|
@ -71,7 +71,8 @@ TEST(mkdir, enametoolong) {
|
|||
int i;
|
||||
size_t n = 2048;
|
||||
char *s = gc(calloc(1, n));
|
||||
for (i = 0; i < n - 1; ++i) s[i] = 'x';
|
||||
for (i = 0; i < n - 1; ++i)
|
||||
s[i] = 'x';
|
||||
s[i] = 0;
|
||||
EXPECT_SYS(ENAMETOOLONG, -1, mkdir(s, 0644));
|
||||
}
|
||||
|
@ -96,7 +97,8 @@ TEST(mkdirat, testRelativePath_opensRelativeToDirFd) {
|
|||
TEST(mkdir, longname) {
|
||||
int i;
|
||||
char *d, s[270] = {0};
|
||||
for (i = 0; i < sizeof(s) - 1; ++i) s[i] = 'x';
|
||||
for (i = 0; i < sizeof(s) - 1; ++i)
|
||||
s[i] = 'x';
|
||||
s[i] = 0;
|
||||
ASSERT_NE(NULL, (d = gc(getcwd(0, 0))));
|
||||
memcpy(s, d, strlen(d));
|
||||
|
|
|
@ -47,7 +47,8 @@ void SetUpOnce(void) {
|
|||
|
||||
TEST(open, efault) {
|
||||
ASSERT_SYS(EFAULT, -1, open(0, O_RDONLY));
|
||||
if (IsWindows() || !IsAsan()) return; // not possible
|
||||
if (IsWindows() || !IsAsan())
|
||||
return; // not possible
|
||||
ASSERT_SYS(EFAULT, -1, open((void *)77, O_RDONLY));
|
||||
}
|
||||
|
||||
|
@ -231,7 +232,8 @@ TEST(open, norm) {
|
|||
}
|
||||
|
||||
TEST(open, longNormDot) {
|
||||
if (IsWindows()) return; // todo: why won't long paths work on windows
|
||||
if (IsWindows())
|
||||
return; // todo: why won't long paths work on windows
|
||||
#define NAME \
|
||||
"funfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfu" \
|
||||
"nfunfunfunfunfunfunnfunfunfunfunfunfunnfunfunfunfunfunfununfunfunfunfunfun"
|
||||
|
@ -243,7 +245,8 @@ TEST(open, longNormDot) {
|
|||
}
|
||||
|
||||
TEST(open, longNormDotDot) {
|
||||
if (IsWindows()) return; // todo: why won't long paths work on windows
|
||||
if (IsWindows())
|
||||
return; // todo: why won't long paths work on windows
|
||||
#define NAME \
|
||||
"funfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfunfu" \
|
||||
"nfunfunfunfunfunfunnfunfunfunfunfunfunnfunfunfunfunfunfununfunfunfunfunfun"
|
||||
|
@ -258,7 +261,8 @@ TEST(open, longNormDotDot) {
|
|||
TEST(open, creat_directory) {
|
||||
ASSERT_SYS(ENOENT, -1, open("fun", O_WRONLY | O_DIRECTORY));
|
||||
ASSERT_FALSE(fileexists("fun"));
|
||||
if (1) return; // linux 5.15.122-0-lts creates file and returns error D:
|
||||
if (1)
|
||||
return; // linux 5.15.122-0-lts creates file and returns error D:
|
||||
ASSERT_SYS(ENOTDIR, -1, open("fun", O_CREAT | O_WRONLY | O_DIRECTORY, 0644));
|
||||
ASSERT_TRUE(fileexists("fun"));
|
||||
}
|
||||
|
@ -312,7 +316,8 @@ int CountFds(void) {
|
|||
}
|
||||
|
||||
TEST(open, lotsOfFds) {
|
||||
if (!IsWindows()) return;
|
||||
if (!IsWindows())
|
||||
return;
|
||||
int i, n = 200;
|
||||
ASSERT_SYS(0, 0, xbarf("hello.txt", "hello", -1));
|
||||
for (i = 3; i < n; ++i) {
|
||||
|
@ -331,7 +336,8 @@ static int64_t GetInode(const char *path) {
|
|||
}
|
||||
|
||||
TEST(open, drive) {
|
||||
if (!IsWindows()) return;
|
||||
if (!IsWindows())
|
||||
return;
|
||||
ASSERT_NE(GetInode("/"), GetInode("."));
|
||||
ASSERT_EQ(GetInode("/"), GetInode("/c")); // sorry you have to run on c:/
|
||||
ASSERT_EQ(GetInode("/"), GetInode("/c/"));
|
||||
|
@ -430,7 +436,8 @@ TEST(open, creatRdonly) {
|
|||
}
|
||||
|
||||
TEST(open, sequentialRandom_EINVAL) {
|
||||
if (!IsWindows()) return;
|
||||
if (!IsWindows())
|
||||
return;
|
||||
ASSERT_SYS(
|
||||
EINVAL, -1,
|
||||
open("foo", O_CREAT | O_TRUNC | O_RDWR | O_SEQUENTIAL | O_RANDOM, 0700));
|
||||
|
@ -442,7 +449,8 @@ TEST(open, sequentialRandom_EINVAL) {
|
|||
// timestamps of the file and the last data modification and last
|
||||
// file status change timestamps of the parent directory." -POSIX
|
||||
TEST(open, creatFile_touchesDirectory) {
|
||||
if (1) return; // TODO(jart): explain the rare flakes
|
||||
if (1)
|
||||
return; // TODO(jart): explain the rare flakes
|
||||
struct stat st;
|
||||
struct timespec birth;
|
||||
ASSERT_SYS(0, 0, mkdir("dir", 0755));
|
||||
|
|
|
@ -50,7 +50,8 @@ TEST(openatemp, unlink) {
|
|||
}
|
||||
|
||||
TEST(openatemp, mode) {
|
||||
if (IsWindows()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
unsigned omask = umask(0);
|
||||
char path[] = "foo.XXXXXX";
|
||||
ASSERT_SYS(0, 3, openatemp(AT_FDCWD, path, 0, 0, 0764));
|
||||
|
|
|
@ -26,8 +26,10 @@
|
|||
#include "libc/testlib/testlib.h"
|
||||
|
||||
void CheckPlatform(void) {
|
||||
if (IsOpenbsd()) return; // openbsd is ok
|
||||
if (IsLinux() && __is_linux_2_6_23()) return; // non-ancient linux is ok
|
||||
if (IsOpenbsd())
|
||||
return; // openbsd is ok
|
||||
if (IsLinux() && __is_linux_2_6_23())
|
||||
return; // non-ancient linux is ok
|
||||
kprintf("skipping openbsd_test\n");
|
||||
exit(0);
|
||||
}
|
||||
|
|
|
@ -38,8 +38,10 @@ TEST(pipe, einval) {
|
|||
}
|
||||
|
||||
TEST(pipe, ebadf) {
|
||||
if (IsFreebsd()) return; // somehow succeeds
|
||||
if (IsOpenbsd()) return; // somehow succeeds
|
||||
if (IsFreebsd())
|
||||
return; // somehow succeeds
|
||||
if (IsOpenbsd())
|
||||
return; // somehow succeeds
|
||||
EXPECT_SYS(0, 0, pipe(f));
|
||||
EXPECT_SYS(EBADF, -1, write(f[0], "h", 1));
|
||||
EXPECT_SYS(EBADF, -1, read(f[1], buf, 1));
|
||||
|
@ -48,8 +50,10 @@ TEST(pipe, ebadf) {
|
|||
}
|
||||
|
||||
TEST(pipe, emfile) {
|
||||
if (IsWindows()) return; // TODO
|
||||
if (IsCygwin()) return;
|
||||
if (IsWindows())
|
||||
return; // TODO
|
||||
if (IsCygwin())
|
||||
return;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
ASSERT_EQ(0, setrlimit(RLIMIT_NOFILE, &rlim));
|
||||
|
|
|
@ -41,7 +41,8 @@ void SetUp(void) {
|
|||
}
|
||||
|
||||
TEST(pledge, testSoftError) {
|
||||
if (IsOpenbsd()) return;
|
||||
if (IsOpenbsd())
|
||||
return;
|
||||
SPAWN(fork);
|
||||
__pledge_mode = PLEDGE_PENALTY_RETURN_EPERM;
|
||||
ASSERT_SYS(0, 0, pledge("stdio", 0));
|
||||
|
@ -67,7 +68,8 @@ TEST(pledge, testKillProcessMode) {
|
|||
}
|
||||
|
||||
TEST(pledge, testLogMessage_inSoftyMode) {
|
||||
if (IsOpenbsd()) return;
|
||||
if (IsOpenbsd())
|
||||
return;
|
||||
int fds[2];
|
||||
char msg[256] = {0};
|
||||
ASSERT_SYS(0, 0, pipe(fds));
|
||||
|
|
|
@ -103,7 +103,8 @@ TEST(pledge, default_allowsExit) {
|
|||
}
|
||||
|
||||
TEST(pledge, execpromises_notok) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
@ -134,7 +135,8 @@ TEST(pledge, tester) {
|
|||
}
|
||||
|
||||
TEST(pledge, withThreadMemory) {
|
||||
if (IsOpenbsd()) return; // openbsd doesn't allow it, wisely
|
||||
if (IsOpenbsd())
|
||||
return; // openbsd doesn't allow it, wisely
|
||||
pthread_t worker;
|
||||
int job[2] = {2, 2}; // create workload
|
||||
ASSERT_EQ(0, pthread_create(&worker, 0, Enclave, job)); // create worker
|
||||
|
@ -159,7 +161,8 @@ void *TgkillWorker(void *arg) {
|
|||
|
||||
TEST(pledge, tgkill) {
|
||||
// https://github.com/jart/cosmopolitan/issues/628
|
||||
if (!IsLinux()) return;
|
||||
if (!IsLinux())
|
||||
return;
|
||||
sigset_t mask;
|
||||
pthread_t worker;
|
||||
SPAWN(fork);
|
||||
|
@ -176,7 +179,8 @@ TEST(pledge, tgkill) {
|
|||
}
|
||||
|
||||
TEST(pledge, stdio_forbidsOpeningPasswd1) {
|
||||
if (!IsLinux()) return;
|
||||
if (!IsLinux())
|
||||
return;
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
@ -204,7 +208,8 @@ TEST(pledge, stdio_forbidsOpeningPasswd2) {
|
|||
}
|
||||
|
||||
TEST(pledge, multipleCalls_canOnlyBecomeMoreRestrictive1) {
|
||||
if (IsOpenbsd()) return;
|
||||
if (IsOpenbsd())
|
||||
return;
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
@ -223,7 +228,8 @@ TEST(pledge, multipleCalls_canOnlyBecomeMoreRestrictive1) {
|
|||
}
|
||||
|
||||
TEST(pledge, multipleCalls_canOnlyBecomeMoreRestrictive2) {
|
||||
if (!IsOpenbsd()) return;
|
||||
if (!IsOpenbsd())
|
||||
return;
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
@ -237,7 +243,8 @@ TEST(pledge, multipleCalls_canOnlyBecomeMoreRestrictive2) {
|
|||
}
|
||||
|
||||
TEST(pledge, multipleCalls_canOnlyBecomeMoreRestrictive3) {
|
||||
if (!IsOpenbsd()) return;
|
||||
if (!IsOpenbsd())
|
||||
return;
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
@ -252,7 +259,8 @@ TEST(pledge, multipleCalls_canOnlyBecomeMoreRestrictive3) {
|
|||
}
|
||||
|
||||
TEST(pledge, stdio_fcntl_allowsSomeFirstArgs) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
struct flock lk;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
|
@ -275,7 +283,8 @@ TEST(pledge, stdio_fcntl_allowsSomeFirstArgs) {
|
|||
}
|
||||
|
||||
TEST(pledge, stdioTty_sendtoRestricted_requiresNullAddr) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
int ws, pid, sv[2];
|
||||
ASSERT_SYS(0, 0, socketpair(AF_UNIX, SOCK_STREAM, 0, sv));
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
|
@ -303,7 +312,8 @@ TEST(pledge, stdioTty_sendtoRestricted_requiresNullAddr) {
|
|||
}
|
||||
|
||||
TEST(pledge, unix_forbidsInetSockets) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
@ -345,7 +355,8 @@ TEST(pledge, wpath_doesNotImplyRpath) {
|
|||
}
|
||||
|
||||
TEST(pledge, inet_forbidsOtherSockets) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
int ws, pid, yes = 1;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
@ -376,7 +387,8 @@ TEST(pledge, inet_forbidsOtherSockets) {
|
|||
}
|
||||
|
||||
TEST(pledge, anet_forbidsUdpSocketsAndConnect) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
@ -392,7 +404,8 @@ TEST(pledge, anet_forbidsUdpSocketsAndConnect) {
|
|||
}
|
||||
|
||||
TEST(pledge, mmap) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
char *p;
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
|
@ -413,7 +426,8 @@ TEST(pledge, mmap) {
|
|||
}
|
||||
|
||||
TEST(pledge, mmapProtExec) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
char *p;
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
|
@ -432,7 +446,8 @@ TEST(pledge, mmapProtExec) {
|
|||
}
|
||||
|
||||
TEST(pledge, chmod_ignoresDangerBits) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
ASSERT_SYS(0, 3, creat("foo", 0644));
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
|
@ -452,7 +467,8 @@ TEST(pledge, chmod_ignoresDangerBits) {
|
|||
}
|
||||
|
||||
TEST(pledge, open_rpath) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
ASSERT_SYS(0, 0, touch("foo", 0644));
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
|
@ -470,7 +486,8 @@ TEST(pledge, open_rpath) {
|
|||
}
|
||||
|
||||
TEST(pledge, open_wpath) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
ASSERT_SYS(0, 0, touch("foo", 0644));
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
|
@ -487,7 +504,8 @@ TEST(pledge, open_wpath) {
|
|||
}
|
||||
|
||||
TEST(pledge, open_cpath) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
struct stat st;
|
||||
ASSERT_SYS(0, 0, touch("foo", 0644));
|
||||
|
@ -508,7 +526,8 @@ TEST(pledge, open_cpath) {
|
|||
}
|
||||
|
||||
TEST(pledge, execpromises_ok) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
@ -522,7 +541,8 @@ TEST(pledge, execpromises_ok) {
|
|||
}
|
||||
|
||||
TEST(pledge, execpromises_notok1) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
@ -536,7 +556,8 @@ TEST(pledge, execpromises_notok1) {
|
|||
}
|
||||
|
||||
TEST(pledge, execpromises_reducesAtExecOnLinux) {
|
||||
if (IsOpenbsd()) return; // b/c testing linux bpf
|
||||
if (IsOpenbsd())
|
||||
return; // b/c testing linux bpf
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
@ -550,8 +571,10 @@ TEST(pledge, execpromises_reducesAtExecOnLinux) {
|
|||
}
|
||||
|
||||
TEST(pledge_openbsd, execpromisesIsNull_letsItDoAnything) {
|
||||
if (IsOpenbsd()) return; // mimmutable() ugh
|
||||
if (!IsOpenbsd()) return;
|
||||
if (IsOpenbsd())
|
||||
return; // mimmutable() ugh
|
||||
if (!IsOpenbsd())
|
||||
return;
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
@ -567,8 +590,10 @@ TEST(pledge_openbsd, execpromisesIsNull_letsItDoAnything) {
|
|||
}
|
||||
|
||||
TEST(pledge_openbsd, execpromisesIsSuperset_letsItDoAnything) {
|
||||
if (IsOpenbsd()) return; // mimmutable() ugh
|
||||
if (!IsOpenbsd()) return;
|
||||
if (IsOpenbsd())
|
||||
return; // mimmutable() ugh
|
||||
if (!IsOpenbsd())
|
||||
return;
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
@ -582,12 +607,14 @@ TEST(pledge_openbsd, execpromisesIsSuperset_letsItDoAnything) {
|
|||
}
|
||||
|
||||
TEST(pledge_linux, execpromisesIsSuperset_notPossible) {
|
||||
if (IsOpenbsd()) return;
|
||||
if (IsOpenbsd())
|
||||
return;
|
||||
ASSERT_SYS(EINVAL, -1, pledge("stdio exec", "stdio inet exec"));
|
||||
}
|
||||
|
||||
TEST(pledge_openbsd, execpromises_notok) {
|
||||
if (IsOpenbsd()) return; // mimmutable() ugh
|
||||
if (IsOpenbsd())
|
||||
return; // mimmutable() ugh
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
@ -608,7 +635,8 @@ TEST(pledge_openbsd, execpromises_notok) {
|
|||
}
|
||||
|
||||
TEST(pledge_openbsd, bigSyscalls) {
|
||||
if (IsOpenbsd()) return; // testing lunix
|
||||
if (IsOpenbsd())
|
||||
return; // testing lunix
|
||||
int ws, pid;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
|
|
|
@ -66,8 +66,10 @@ TEST(poll, allZero_doesNothingPrettyMuch) {
|
|||
}
|
||||
|
||||
TEST(ppoll, weCanProveItChecksForSignals) {
|
||||
if (IsXnu()) return;
|
||||
if (IsNetbsd()) return;
|
||||
if (IsXnu())
|
||||
return;
|
||||
if (IsNetbsd())
|
||||
return;
|
||||
int pipefds[2];
|
||||
sigset_t set, old;
|
||||
struct sigaction oldss;
|
||||
|
|
|
@ -31,7 +31,8 @@ void SetUpOnce(void) {
|
|||
}
|
||||
|
||||
void SetUp(void) {
|
||||
if (IsOpenbsd() || IsXnu()) exit(0);
|
||||
if (IsOpenbsd() || IsXnu())
|
||||
exit(0);
|
||||
}
|
||||
|
||||
TEST(fadvise, ebadf) {
|
||||
|
|
|
@ -78,7 +78,8 @@ TEST(read_pipe, canBeInterruptedByAlarm) {
|
|||
|
||||
TEST(read_directory, eisdir) {
|
||||
// TODO(jart): what
|
||||
if (IsWindows() || IsFreebsd()) return;
|
||||
if (IsWindows() || IsFreebsd())
|
||||
return;
|
||||
ASSERT_SYS(0, 0, mkdir("boop", 0755));
|
||||
ASSERT_SYS(0, 3, open("boop", O_RDONLY | O_DIRECTORY));
|
||||
ASSERT_SYS(EISDIR, -1, read(3, 0, 0));
|
||||
|
@ -102,7 +103,8 @@ void *GenerateData(void *arg) {
|
|||
for (;;) {
|
||||
usleep(223);
|
||||
int rc = write(fds[1], "hi", 2);
|
||||
if (rc == -1 && errno == EPIPE) break;
|
||||
if (rc == -1 && errno == EPIPE)
|
||||
break;
|
||||
ASSERT_EQ(2, rc);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -105,8 +105,10 @@ TEST(readlinkat, statReadsNameLength_countsUtf8Bytes) {
|
|||
|
||||
TEST(readlinkat, realpathReturnsLongPath) {
|
||||
char buf[PATH_MAX];
|
||||
if (!IsWindows()) return;
|
||||
if (!startswith(getcwd(buf, PATH_MAX), "/c/")) return;
|
||||
if (!IsWindows())
|
||||
return;
|
||||
if (!startswith(getcwd(buf, PATH_MAX), "/c/"))
|
||||
return;
|
||||
ASSERT_SYS(0, 0, touch("froot", 0644));
|
||||
ASSERT_STARTSWITH("/c/", realpath("froot", buf));
|
||||
}
|
||||
|
|
|
@ -90,13 +90,17 @@ TEST(rename, enotempty) {
|
|||
TEST(rename, moveIntoNonWritableDirectory_raisesEacces) {
|
||||
// old versions of linux allow this
|
||||
// new versions of linux report exdev?!
|
||||
if (IsLinux()) return;
|
||||
if (IsLinux())
|
||||
return;
|
||||
// netbsd and openbsd allow this
|
||||
if (IsNetbsd() || IsOpenbsd()) return;
|
||||
if (IsNetbsd() || IsOpenbsd())
|
||||
return;
|
||||
// windows doesn't really have permissions
|
||||
if (IsWindows()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
// looks like a freebsd kernel bug
|
||||
if (IsAarch64() && IsFreebsd()) return;
|
||||
if (IsAarch64() && IsFreebsd())
|
||||
return;
|
||||
// posix specifies this behavior
|
||||
ASSERT_SYS(0, 0, mkdir("foo", 0111));
|
||||
ASSERT_SYS(0, 0, touch("lol", 0644));
|
||||
|
|
|
@ -65,7 +65,8 @@ TEST(sched_setscheduler, test) {
|
|||
}
|
||||
|
||||
TEST(sched_setscheduler, testMidpoint) {
|
||||
if (!CanTuneRealtimeSchedulers()) return;
|
||||
if (!CanTuneRealtimeSchedulers())
|
||||
return;
|
||||
struct sched_param p = {(sched_get_priority_min(SCHED_FIFO) +
|
||||
sched_get_priority_max(SCHED_FIFO)) /
|
||||
2};
|
||||
|
|
|
@ -61,9 +61,12 @@ TEST(setrlimit, testCpuLimit) {
|
|||
struct rlimit rlim;
|
||||
struct timespec start;
|
||||
double matrices[3][3][3];
|
||||
if (IsWindows()) return; // of course it doesn't work on windows
|
||||
if (IsXnu()) return; // TODO(jart): it worked before
|
||||
if (IsOpenbsd()) return; // TODO(jart): fix flake
|
||||
if (IsWindows())
|
||||
return; // of course it doesn't work on windows
|
||||
if (IsXnu())
|
||||
return; // TODO(jart): it worked before
|
||||
if (IsOpenbsd())
|
||||
return; // TODO(jart): fix flake
|
||||
ASSERT_NE(-1, (wstatus = xspawn(0)));
|
||||
if (wstatus == -2) {
|
||||
ASSERT_EQ(0, xsigaction(SIGXCPU, OnSigxcpu, 0, 0, 0));
|
||||
|
@ -89,7 +92,8 @@ TEST(setrlimit, testFileSizeLimit) {
|
|||
char junkdata[512];
|
||||
int i, fd, wstatus;
|
||||
struct rlimit rlim;
|
||||
if (IsWindows()) return; /* of course it doesn't work on windows */
|
||||
if (IsWindows())
|
||||
return; /* of course it doesn't work on windows */
|
||||
ASSERT_NE(-1, (wstatus = xspawn(0)));
|
||||
if (wstatus == -2) {
|
||||
ASSERT_EQ(0, xsigaction(SIGXFSZ, OnSigxfsz, 0, 0, 0));
|
||||
|
@ -125,8 +129,10 @@ TEST(setrlimit, testMemoryLimit) {
|
|||
char *p;
|
||||
bool gotsome;
|
||||
int i, wstatus;
|
||||
if (IsXnu()) return;
|
||||
if (IsAsan()) return; /* b/c we use sys_mmap */
|
||||
if (IsXnu())
|
||||
return;
|
||||
if (IsAsan())
|
||||
return; /* b/c we use sys_mmap */
|
||||
ASSERT_NE(-1, (wstatus = xspawn(0)));
|
||||
if (wstatus == -2) {
|
||||
ASSERT_EQ(0, SetKernelEnforcedMemoryLimit(MEM));
|
||||
|
@ -156,10 +162,14 @@ TEST(setrlimit, testMemoryLimit) {
|
|||
TEST(setrlimit, testVirtualMemoryLimit) {
|
||||
char *p;
|
||||
int i, wstatus;
|
||||
if (IsAsan()) return;
|
||||
if (IsXnu()) return; /* doesn't work on darwin */
|
||||
if (IsOpenbsd()) return; /* unavailable on openbsd */
|
||||
if (IsWindows()) return; /* of course it doesn't work on windows */
|
||||
if (IsAsan())
|
||||
return;
|
||||
if (IsXnu())
|
||||
return; /* doesn't work on darwin */
|
||||
if (IsOpenbsd())
|
||||
return; /* unavailable on openbsd */
|
||||
if (IsWindows())
|
||||
return; /* of course it doesn't work on windows */
|
||||
ASSERT_NE(-1, (wstatus = xspawn(0)));
|
||||
if (wstatus == -2) {
|
||||
ASSERT_EQ(0, setrlimit(RLIMIT_AS, &(struct rlimit){MEM, MEM}));
|
||||
|
@ -184,12 +194,18 @@ TEST(setrlimit, testVirtualMemoryLimit) {
|
|||
TEST(setrlimit, testDataMemoryLimit) {
|
||||
char *p;
|
||||
int i, wstatus;
|
||||
if (IsAsan()) return;
|
||||
if (IsXnu()) return; /* doesn't work on darwin */
|
||||
if (IsNetbsd()) return; /* doesn't work on netbsd */
|
||||
if (IsFreebsd()) return; /* doesn't work on freebsd */
|
||||
if (IsLinux()) return; /* doesn't work on gnu/systemd */
|
||||
if (IsWindows()) return; /* of course it doesn't work on windows */
|
||||
if (IsAsan())
|
||||
return;
|
||||
if (IsXnu())
|
||||
return; /* doesn't work on darwin */
|
||||
if (IsNetbsd())
|
||||
return; /* doesn't work on netbsd */
|
||||
if (IsFreebsd())
|
||||
return; /* doesn't work on freebsd */
|
||||
if (IsLinux())
|
||||
return; /* doesn't work on gnu/systemd */
|
||||
if (IsWindows())
|
||||
return; /* of course it doesn't work on windows */
|
||||
ASSERT_NE(-1, (wstatus = xspawn(0)));
|
||||
if (wstatus == -2) {
|
||||
ASSERT_EQ(0, setrlimit(RLIMIT_DATA, &(struct rlimit){MEM, MEM}));
|
||||
|
@ -231,7 +247,8 @@ wontreturn void OnVfork(void *ctx) {
|
|||
TEST(setrlimit, isVforkSafe) {
|
||||
int ws;
|
||||
struct rlimit rlim[2];
|
||||
if (IsWindows()) return; /* of course it doesn't work on windows */
|
||||
if (IsWindows())
|
||||
return; /* of course it doesn't work on windows */
|
||||
ASSERT_EQ(0, getrlimit(RLIMIT_CPU, rlim));
|
||||
ASSERT_NE(-1, (ws = xvspawn(OnVfork, rlim, 0)));
|
||||
EXPECT_TRUE(WIFEXITED(ws));
|
||||
|
|
|
@ -90,7 +90,8 @@ wontreturn void Bouncer(void) {
|
|||
wontreturn void Sender(void) {
|
||||
|
||||
/* Wait for file to exist. */
|
||||
while (!*ready) donothing;
|
||||
while (!*ready)
|
||||
donothing;
|
||||
|
||||
/* Open the existing shared memory object and map it
|
||||
into the caller's address space. */
|
||||
|
|
|
@ -64,9 +64,11 @@ void *Worker(void *arg) {
|
|||
|
||||
TEST(SetThreadContext, test) {
|
||||
pthread_t th;
|
||||
if (!IsWindows()) return;
|
||||
if (!IsWindows())
|
||||
return;
|
||||
ASSERT_EQ(0, pthread_create(&th, 0, Worker, 0));
|
||||
while (!ready) donothing;
|
||||
while (!ready)
|
||||
donothing;
|
||||
usleep(1000);
|
||||
int64_t hand = _pthread_syshand((struct PosixThread *)th);
|
||||
ASSERT_EQ(0, SuspendThread(hand));
|
||||
|
|
|
@ -124,7 +124,8 @@ TEST(sigaction, raise) {
|
|||
// test kill()
|
||||
|
||||
TEST(sigaction, testPingPongParentChildWithSigint) {
|
||||
if (IsNetbsd()) return; // TODO: what's up with runitd on netbsd?
|
||||
if (IsNetbsd())
|
||||
return; // TODO: what's up with runitd on netbsd?
|
||||
int pid, status;
|
||||
sigset_t blockint, oldmask;
|
||||
struct sigaction oldint;
|
||||
|
@ -244,8 +245,10 @@ TEST(sigaction, ignoringSignalDiscardsSignal) {
|
|||
}
|
||||
|
||||
TEST(sigaction, autoZombieSlayer) {
|
||||
if (IsWindows()) return;
|
||||
if (IsCygwin()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
if (IsCygwin())
|
||||
return;
|
||||
int pid;
|
||||
struct sigaction sa;
|
||||
// make sure we're starting in expected state
|
||||
|
@ -253,7 +256,8 @@ TEST(sigaction, autoZombieSlayer) {
|
|||
ASSERT_EQ(SIG_DFL, sa.sa_handler);
|
||||
// verify child becomes zombie
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) _Exit(0);
|
||||
if (!pid)
|
||||
_Exit(0);
|
||||
ASSERT_SYS(0, pid, wait(0));
|
||||
// enable automatic zombie slayer
|
||||
sa.sa_handler = SIG_IGN;
|
||||
|
@ -262,17 +266,21 @@ TEST(sigaction, autoZombieSlayer) {
|
|||
ASSERT_SYS(0, 0, sigaction(SIGCHLD, &sa, &sa));
|
||||
// verify it works
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) _Exit(0);
|
||||
if (!pid)
|
||||
_Exit(0);
|
||||
// XXX: WSL does the wrong thing here.
|
||||
if (__iswsl1()) usleep(10);
|
||||
if (__iswsl1())
|
||||
usleep(10);
|
||||
ASSERT_SYS(ECHILD, -1, wait(0));
|
||||
// clean up
|
||||
ASSERT_SYS(0, 0, sigaction(SIGCHLD, &sa, 0));
|
||||
}
|
||||
|
||||
TEST(sigaction, enosys_returnsErrnoRatherThanSigsysByDefault) {
|
||||
if (IsTiny()) return; // systemfive.S disables the fix w/ tiny
|
||||
if (IsOpenbsd()) return; // TODO: Why does OpenBSD raise SIGABRT?
|
||||
if (IsTiny())
|
||||
return; // systemfive.S disables the fix w/ tiny
|
||||
if (IsOpenbsd())
|
||||
return; // TODO: Why does OpenBSD raise SIGABRT?
|
||||
ASSERT_SYS(ENOSYS, -1, sys_bogus());
|
||||
}
|
||||
|
||||
|
@ -373,7 +381,8 @@ dontubsan dontasan int Segfault(char *p) {
|
|||
int (*pSegfault)(char *) = Segfault;
|
||||
|
||||
TEST(sigaction, returnFromSegvHandler_loopsForever) {
|
||||
if (IsXnu()) return; // seems busted
|
||||
if (IsXnu())
|
||||
return; // seems busted
|
||||
segfaults = _mapshared(sizeof(*segfaults));
|
||||
SPAWN(fork);
|
||||
signal(SIGSEGV, OnSegfault);
|
||||
|
|
|
@ -30,10 +30,14 @@
|
|||
#include "libc/testlib/testlib.h"
|
||||
|
||||
void SetUp(void) {
|
||||
if (IsXnu()) exit(0);
|
||||
if (IsMetal()) exit(0);
|
||||
if (IsWindows()) exit(0);
|
||||
if (IsOpenbsd()) exit(0);
|
||||
if (IsXnu())
|
||||
exit(0);
|
||||
if (IsMetal())
|
||||
exit(0);
|
||||
if (IsWindows())
|
||||
exit(0);
|
||||
if (IsOpenbsd())
|
||||
exit(0);
|
||||
}
|
||||
|
||||
TEST(sigtimedwait, nullSet_efault) {
|
||||
|
|
|
@ -91,7 +91,8 @@ int StackOverflow(int f(), int n) {
|
|||
int (*pStackOverflow)(int (*)(), int) = StackOverflow;
|
||||
|
||||
TEST(stackoverflow, standardStack_altStack_process_longjmp) {
|
||||
if (IsTiny()) return; // TODO(jart): why?
|
||||
if (IsTiny())
|
||||
return; // TODO(jart): why?
|
||||
|
||||
int jumpcode;
|
||||
if (!(jumpcode = setjmp(recover))) {
|
||||
|
|
|
@ -94,7 +94,8 @@ TEST(timeval_toseconds, test) {
|
|||
}
|
||||
|
||||
static long mod(long x, long y) {
|
||||
if (y == -1) return 0;
|
||||
if (y == -1)
|
||||
return 0;
|
||||
return x - y * (x / y - (x % y && (x ^ y) < 0));
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,8 @@ void SetUpOnce(void) {
|
|||
|
||||
TEST(unlink, efault) {
|
||||
ASSERT_SYS(EFAULT, -1, unlink(0));
|
||||
if (IsWindows() || !IsAsan()) return; // not possible
|
||||
if (IsWindows() || !IsAsan())
|
||||
return; // not possible
|
||||
ASSERT_SYS(EFAULT, -1, unlink((void *)77));
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,8 @@ TEST(unveil, api_differences) {
|
|||
}
|
||||
|
||||
TEST(unveil, rx_readOnlyPreexistingExecutable_worksFine) {
|
||||
if (IsOpenbsd()) return; // TOOD(jart): why pledge violation?
|
||||
if (IsOpenbsd())
|
||||
return; // TOOD(jart): why pledge violation?
|
||||
SPAWN(fork);
|
||||
ASSERT_SYS(0, 0, mkdir("folder", 0755));
|
||||
testlib_extract("/zip/life.elf", "folder/life.elf", 0755);
|
||||
|
@ -151,7 +152,8 @@ TEST(unveil, rwc_createExecutableFile_isAllowedButCantBeRun) {
|
|||
}
|
||||
|
||||
TEST(unveil, rwcx_createExecutableFile_canAlsoBeRun) {
|
||||
if (IsOpenbsd()) return; // TOOD(jart): why pledge violation?
|
||||
if (IsOpenbsd())
|
||||
return; // TOOD(jart): why pledge violation?
|
||||
SPAWN(fork);
|
||||
ASSERT_SYS(0, 0, mkdir("folder", 0755));
|
||||
ASSERT_SYS(0, 0, unveil("folder", "rwcx"));
|
||||
|
@ -179,7 +181,8 @@ TEST(unveil, dirfdHacking_doesntWork) {
|
|||
}
|
||||
|
||||
TEST(unveil, mostRestrictivePolicy) {
|
||||
if (IsOpenbsd()) return; // openbsd behaves oddly; see docs
|
||||
if (IsOpenbsd())
|
||||
return; // openbsd behaves oddly; see docs
|
||||
SPAWN(fork);
|
||||
ASSERT_SYS(0, 0, mkdir("jail", 0755));
|
||||
ASSERT_SYS(0, 0, mkdir("garden", 0755));
|
||||
|
@ -221,7 +224,8 @@ TEST(unveil, overlappingDirectories_inconsistentBehavior) {
|
|||
}
|
||||
|
||||
TEST(unveil, usedTwice_allowedOnLinux) {
|
||||
if (IsOpenbsd()) return;
|
||||
if (IsOpenbsd())
|
||||
return;
|
||||
SPAWN(fork);
|
||||
ASSERT_SYS(0, 0, mkdir("jail", 0755));
|
||||
ASSERT_SYS(0, 0, xbarf("jail/ok.txt", "hello", 5));
|
||||
|
@ -259,7 +263,8 @@ TEST(unveil, truncate_isForbiddenBySeccomp) {
|
|||
}
|
||||
|
||||
TEST(unveil, ftruncate_isForbidden) {
|
||||
if (IsOpenbsd()) return; // b/c O_PATH is a Linux thing
|
||||
if (IsOpenbsd())
|
||||
return; // b/c O_PATH is a Linux thing
|
||||
SPAWN(fork);
|
||||
ASSERT_SYS(0, 0, mkdir("jail", 0755));
|
||||
ASSERT_SYS(0, 0, mkdir("garden", 0755));
|
||||
|
@ -275,7 +280,8 @@ TEST(unveil, ftruncate_isForbidden) {
|
|||
}
|
||||
|
||||
TEST(unveil, procfs_isForbiddenByDefault) {
|
||||
if (IsOpenbsd()) return;
|
||||
if (IsOpenbsd())
|
||||
return;
|
||||
SPAWN(fork);
|
||||
ASSERT_SYS(0, 0, mkdir("jail", 0755));
|
||||
ASSERT_SYS(0, 0, unveil("jail", "rw"));
|
||||
|
|
|
@ -58,7 +58,8 @@ TEST(utimes, test) {
|
|||
}
|
||||
|
||||
TEST(futimes, test) {
|
||||
if (IsLinux() && !__is_linux_2_6_23()) return;
|
||||
if (IsLinux() && !__is_linux_2_6_23())
|
||||
return;
|
||||
struct stat st;
|
||||
struct timeval tv[2] = {{1655455857, 1}, {827727928, 2}};
|
||||
EXPECT_SYS(0, 3, creat("boop", 0644));
|
||||
|
@ -123,7 +124,8 @@ TEST(utimensat, testOmit) {
|
|||
TEST(futimens, test2) {
|
||||
struct timespec ts[2];
|
||||
int fd = creat("foo", 0600);
|
||||
if (fd < 0) exit(1);
|
||||
if (fd < 0)
|
||||
exit(1);
|
||||
struct stat st;
|
||||
int64_t birth;
|
||||
ASSERT_SYS(0, 0, fstat(fd, &st));
|
||||
|
|
|
@ -66,7 +66,8 @@ TEST(write, readOnlyFd_ebadf) {
|
|||
|
||||
TEST(write, badMemory_efault) {
|
||||
ASSERT_SYS(EFAULT, -1, write(1, 0, 1));
|
||||
if (!IsAsan()) return;
|
||||
if (!IsAsan())
|
||||
return;
|
||||
ASSERT_SYS(EFAULT, -1, write(1, (void *)1, 1));
|
||||
}
|
||||
|
||||
|
@ -109,7 +110,8 @@ TEST(write, brokenPipe_sigpipeBlocked_returnsEpipe) {
|
|||
}
|
||||
|
||||
TEST(write, rlimitFsizeExceeded_raisesEfbig) {
|
||||
if (IsWindows()) return; // not supported
|
||||
if (IsWindows())
|
||||
return; // not supported
|
||||
struct rlimit rl = {1, 10};
|
||||
SPAWN(fork);
|
||||
signal(SIGXFSZ, SIG_IGN);
|
||||
|
|
|
@ -52,7 +52,8 @@ TEST(writev, negative_einvalOrEfault) {
|
|||
}
|
||||
|
||||
TEST(writev, exceedsIovMax_einval) {
|
||||
if (IsWindows()) return; // it's complicated
|
||||
if (IsWindows())
|
||||
return; // it's complicated
|
||||
int i, n = IOV_MAX + 1;
|
||||
struct iovec *v = gc(malloc(sizeof(struct iovec) * n));
|
||||
for (i = 0; i < n; ++i) {
|
||||
|
@ -96,7 +97,8 @@ TEST(writev, big_fullCompletion) {
|
|||
}
|
||||
|
||||
TEST(writev, asanError_efaults) {
|
||||
if (!IsAsan()) return;
|
||||
if (!IsAsan())
|
||||
return;
|
||||
void *malloc_(size_t) asm("malloc");
|
||||
void free_(void *) asm("free");
|
||||
void *p;
|
||||
|
|
|
@ -43,7 +43,8 @@
|
|||
*/
|
||||
static uint64_t Rando(void) {
|
||||
uint64_t x;
|
||||
do x = lemur64();
|
||||
do
|
||||
x = lemur64();
|
||||
while (((x ^ READ64LE("!!!!!!!!")) - 0x0101010101010101) &
|
||||
~(x ^ READ64LE("!!!!!!!!")) & 0x8080808080808080);
|
||||
return x;
|
||||
|
@ -247,11 +248,15 @@ TEST(kprintf, testFailure_wontClobberErrnoAndBypassesSystemCallSupport) {
|
|||
ASSERT_EQ(0, errno);
|
||||
EXPECT_SYS(0, 3, dup(2));
|
||||
// <LIMBO>
|
||||
if (close(2)) _Exit(200);
|
||||
if (close(2))
|
||||
_Exit(200);
|
||||
n = __syscount;
|
||||
if (__syscount != n) _Exit(201);
|
||||
if (errno != 0) _Exit(202);
|
||||
if (dup2(3, 2) != 2) _Exit(203);
|
||||
if (__syscount != n)
|
||||
_Exit(201);
|
||||
if (errno != 0)
|
||||
_Exit(202);
|
||||
if (dup2(3, 2) != 2)
|
||||
_Exit(203);
|
||||
// </LIMBO>
|
||||
EXPECT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
|
|
@ -132,7 +132,8 @@ void TestContendedLock(const char *name, int kind) {
|
|||
kprintf("clone failed: %s\n", strerror(rc));
|
||||
_Exit(1);
|
||||
}
|
||||
while (!atomic_load(&ready)) donothing;
|
||||
while (!atomic_load(&ready))
|
||||
donothing;
|
||||
t1 = timespec_real();
|
||||
for (i = 0; i < n; ++i) {
|
||||
ASSERT_EQ(0, pthread_mutex_lock(&mu));
|
||||
|
@ -142,7 +143,8 @@ void TestContendedLock(const char *name, int kind) {
|
|||
ASSERT_EQ(0, pthread_mutex_unlock(&mu));
|
||||
}
|
||||
t2 = timespec_real();
|
||||
while (tib.tib_tid) donothing;
|
||||
while (tib.tib_tid)
|
||||
donothing;
|
||||
ASSERT_EQ(1, atomic_load(&success));
|
||||
ASSERT_EQ(0, atomic_load(&counter));
|
||||
FreeCosmoStack(stk);
|
||||
|
@ -178,7 +180,8 @@ int main(int argc, char *argv[]) {
|
|||
#ifdef __aarch64__
|
||||
// our usage of raw clone() is probably broken in aarch64
|
||||
// we should just get rid of clone()
|
||||
if (1) return 0;
|
||||
if (1)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
if (_weaken(nsync_mu_lock)) {
|
||||
|
|
|
@ -68,8 +68,10 @@ TEST(memcmp, hug) {
|
|||
static int coerce(int result) {
|
||||
#ifdef __aarch64__
|
||||
// arm's strcmp assembly is nuts and unpredictable, but it's legal
|
||||
if (result < 0) return -1;
|
||||
if (result > 0) return +1;
|
||||
if (result < 0)
|
||||
return -1;
|
||||
if (result > 0)
|
||||
return +1;
|
||||
return 0;
|
||||
#else
|
||||
return result;
|
||||
|
|
|
@ -27,8 +27,10 @@
|
|||
|
||||
static dontasan void *golden(void *p, int c, size_t n) {
|
||||
size_t i;
|
||||
if (IsAsan()) __asan_verify(p, n);
|
||||
for (i = 0; i < n; ++i) ((char *)p)[i] = c;
|
||||
if (IsAsan())
|
||||
__asan_verify(p, n);
|
||||
for (i = 0; i < n; ++i)
|
||||
((char *)p)[i] = c;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
|
@ -175,9 +175,11 @@ struct MutexContentionArgs {
|
|||
void *MutexContentionWorker(void *arg) {
|
||||
struct MutexContentionArgs *a = arg;
|
||||
while (!atomic_load_explicit(&a->done, memory_order_relaxed)) {
|
||||
if (pthread_mutex_lock(a->mutex)) notpossible;
|
||||
if (pthread_mutex_lock(a->mutex))
|
||||
notpossible;
|
||||
atomic_store_explicit(&a->ready, 1, memory_order_relaxed);
|
||||
if (pthread_mutex_unlock(a->mutex)) notpossible;
|
||||
if (pthread_mutex_unlock(a->mutex))
|
||||
notpossible;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -204,7 +206,8 @@ BENCH(pthread_mutex_lock, bench_contended) {
|
|||
pthread_spinlock_t s = {0};
|
||||
struct SpinContentionArgs a = {&s};
|
||||
pthread_create(&t, 0, SpinContentionWorker, &a);
|
||||
while (!a.ready) sched_yield();
|
||||
while (!a.ready)
|
||||
sched_yield();
|
||||
EZBENCH2("spin 2x", donothing, BenchSpinUnspin(&s));
|
||||
a.done = true;
|
||||
pthread_join(t, 0);
|
||||
|
@ -213,7 +216,8 @@ BENCH(pthread_mutex_lock, bench_contended) {
|
|||
nsync_mu m = {0};
|
||||
struct NsyncContentionArgs a = {&m};
|
||||
pthread_create(&t, 0, NsyncContentionWorker, &a);
|
||||
while (!a.ready) sched_yield();
|
||||
while (!a.ready)
|
||||
sched_yield();
|
||||
EZBENCH2("nsync 2x", donothing, BenchLockUnlockNsync(&m));
|
||||
a.done = true;
|
||||
pthread_join(t, 0);
|
||||
|
@ -226,7 +230,8 @@ BENCH(pthread_mutex_lock, bench_contended) {
|
|||
pthread_mutex_init(&m, &attr);
|
||||
struct MutexContentionArgs a = {&m};
|
||||
pthread_create(&t, 0, MutexContentionWorker, &a);
|
||||
while (!a.ready) sched_yield();
|
||||
while (!a.ready)
|
||||
sched_yield();
|
||||
EZBENCH2("normal 2x", donothing, BenchLockUnlock(&m));
|
||||
a.done = true;
|
||||
pthread_join(t, 0);
|
||||
|
@ -239,7 +244,8 @@ BENCH(pthread_mutex_lock, bench_contended) {
|
|||
pthread_mutex_init(&m, &attr);
|
||||
struct MutexContentionArgs a = {&m};
|
||||
pthread_create(&t, 0, MutexContentionWorker, &a);
|
||||
while (!a.ready) sched_yield();
|
||||
while (!a.ready)
|
||||
sched_yield();
|
||||
EZBENCH2("recursive 2x", donothing, BenchLockUnlock(&m));
|
||||
a.done = true;
|
||||
pthread_join(t, 0);
|
||||
|
@ -252,7 +258,8 @@ BENCH(pthread_mutex_lock, bench_contended) {
|
|||
pthread_mutex_init(&m, &attr);
|
||||
struct MutexContentionArgs a = {&m};
|
||||
pthread_create(&t, 0, MutexContentionWorker, &a);
|
||||
while (!a.ready) sched_yield();
|
||||
while (!a.ready)
|
||||
sched_yield();
|
||||
EZBENCH2("errorcheck 2x", donothing, BenchLockUnlock(&m));
|
||||
a.done = true;
|
||||
pthread_join(t, 0);
|
||||
|
|
|
@ -64,7 +64,8 @@ TEST(_rand64, testLcg_doesntProduceIdenticalValues) {
|
|||
for (i = 0; i < ARRAYLEN(A); ++i) {
|
||||
EXPECT_NE(0, A[i], "i=%d", i);
|
||||
for (j = 0; j < ARRAYLEN(A); ++j) {
|
||||
if (i == j) continue;
|
||||
if (i == j)
|
||||
continue;
|
||||
EXPECT_NE(A[i], A[j], "i=%d j=%d", i, j);
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +94,8 @@ TEST(_rand64, testThreadSafety_doesntProduceIdenticalValues) {
|
|||
for (i = 0; i < ARRAYLEN(A); ++i) {
|
||||
EXPECT_NE(0, A[i], "i=%d", i);
|
||||
for (j = 0; j < ARRAYLEN(A); ++j) {
|
||||
if (i == j) continue;
|
||||
if (i == j)
|
||||
continue;
|
||||
EXPECT_NE(A[i], A[j], "i=%d j=%d", i, j);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,8 +72,10 @@ TEST(strchrnul, notFound_returnsPointerToNulByte) {
|
|||
|
||||
char *strchr_pure(const char *s, int c) {
|
||||
for (c &= 0xff;; ++s) {
|
||||
if ((*s & 0xff) == c) return (char *)s;
|
||||
if (!*s) return NULL;
|
||||
if ((*s & 0xff) == c)
|
||||
return (char *)s;
|
||||
if (!*s)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +108,8 @@ BENCH(strchr, bench) {
|
|||
char *memchr_pure(const char *m, int c, size_t n) {
|
||||
const unsigned char *p, *pe;
|
||||
for (c &= 0xff, p = (const unsigned char *)m, pe = p + n; p < pe; ++p) {
|
||||
if (*p == c) return (void *)p;
|
||||
if (*p == c)
|
||||
return (void *)p;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -126,8 +129,10 @@ TEST(memchr, fuzz) {
|
|||
|
||||
char *strchrnul_pure(const char *s, int c) {
|
||||
for (c &= 0xff;; ++s) {
|
||||
if ((*s & 0xff) == c) return (char *)s;
|
||||
if (!*s) return (void *)s;
|
||||
if ((*s & 0xff) == c)
|
||||
return (char *)s;
|
||||
if (!*s)
|
||||
return (void *)s;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,7 +152,8 @@ TEST(strchrnul, fuzz) {
|
|||
void *rawmemchr_pure(const void *m, int c) {
|
||||
const unsigned char *s;
|
||||
for (c &= 255, s = m;; ++s) {
|
||||
if (*s == c) return (void *)s;
|
||||
if (*s == c)
|
||||
return (void *)s;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -491,7 +491,8 @@ TEST(wcsncmp, testTwosComplementBane) {
|
|||
|
||||
dontinline int strcmp_pure(const char *a, const char *b) {
|
||||
for (; *a == *b; a++, b++) {
|
||||
if (!*a) break;
|
||||
if (!*a)
|
||||
break;
|
||||
}
|
||||
return (*a & 0xff) - (*b & 0xff);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,8 @@ wchar_t u32[] = L"utf32 ☻";
|
|||
|
||||
size_t strlen_pure(const char *s) {
|
||||
size_t n = 0;
|
||||
while (*s++) ++n;
|
||||
while (*s++)
|
||||
++n;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
@ -64,7 +65,8 @@ TEST(strlen, test_const) {
|
|||
TEST(strlen, test_nonconst) {
|
||||
char buf[256];
|
||||
unsigned i;
|
||||
for (i = 0; i < 255; ++i) buf[i] = i + 1;
|
||||
for (i = 0; i < 255; ++i)
|
||||
buf[i] = i + 1;
|
||||
buf[i] = '\0';
|
||||
ASSERT_EQ(255, strlen(buf));
|
||||
}
|
||||
|
@ -85,7 +87,8 @@ TEST(strlen, testnonconst) {
|
|||
"m"(*StR) */
|
||||
char buf[256];
|
||||
unsigned i;
|
||||
for (i = 0; i < 250; ++i) buf[i] = i + 1;
|
||||
for (i = 0; i < 250; ++i)
|
||||
buf[i] = i + 1;
|
||||
buf[i] = '\0';
|
||||
ASSERT_EQ(250, strlen(buf));
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@ TEST(strsignal, test) {
|
|||
}
|
||||
|
||||
TEST(strsignal, realtime) {
|
||||
if (!SIGRTMIN) return;
|
||||
if (!SIGRTMIN)
|
||||
return;
|
||||
EXPECT_STREQ("SIGTHR", strsignal(SIGTHR));
|
||||
ASSERT_STREQ("SIGRTMIN+1", strsignal(SIGRTMIN + 1));
|
||||
}
|
||||
|
|
|
@ -61,7 +61,8 @@ TEST(critbit0, testContains) {
|
|||
struct critbit0 tree[1];
|
||||
MakeTree(tree);
|
||||
for (unsigned i = 0; elems[i]; ++i) {
|
||||
if (!critbit0_contains(tree, elems[i])) abort();
|
||||
if (!critbit0_contains(tree, elems[i]))
|
||||
abort();
|
||||
}
|
||||
critbit0_clear(tree);
|
||||
}
|
||||
|
@ -73,15 +74,19 @@ TEST(critbit0, testDelete) {
|
|||
struct critbit0 tree = {0};
|
||||
for (unsigned i = 1; elems2[i]; ++i) {
|
||||
critbit0_clear(&tree);
|
||||
for (unsigned j = 0; j < i; ++j) critbit0_insert(&tree, elems2[j]);
|
||||
for (unsigned j = 0; j < i; ++j)
|
||||
critbit0_insert(&tree, elems2[j]);
|
||||
for (unsigned j = 0; j < i; ++j) {
|
||||
if (!critbit0_contains(&tree, elems2[j])) abort();
|
||||
if (!critbit0_contains(&tree, elems2[j]))
|
||||
abort();
|
||||
}
|
||||
for (unsigned j = 0; j < i; ++j) {
|
||||
if (1 != critbit0_delete(&tree, elems2[j])) abort();
|
||||
if (1 != critbit0_delete(&tree, elems2[j]))
|
||||
abort();
|
||||
}
|
||||
for (unsigned j = 0; j < i; ++j) {
|
||||
if (critbit0_contains(&tree, elems2[j])) abort();
|
||||
if (critbit0_contains(&tree, elems2[j]))
|
||||
abort();
|
||||
}
|
||||
}
|
||||
critbit0_clear(&tree);
|
||||
|
|
|
@ -97,8 +97,10 @@ TEST(djbsort, test64) {
|
|||
}
|
||||
|
||||
static int CompareInt(const void *a, const void *b) {
|
||||
if (*(const int *)a < *(const int *)b) return -1;
|
||||
if (*(const int *)a > *(const int *)b) return +1;
|
||||
if (*(const int *)a < *(const int *)b)
|
||||
return -1;
|
||||
if (*(const int *)a > *(const int *)b)
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,36 +50,46 @@
|
|||
TEST(malloc, zero) {
|
||||
char *p;
|
||||
ASSERT_NE(NULL, (p = malloc(0)));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p, 1));
|
||||
if (IsAsan())
|
||||
ASSERT_FALSE(__asan_is_valid(p, 1));
|
||||
free(p);
|
||||
}
|
||||
|
||||
TEST(realloc, bothAreZero_createsMinimalAllocation) {
|
||||
char *p;
|
||||
ASSERT_NE(NULL, (p = realloc(0, 0)));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p, 1));
|
||||
if (IsAsan())
|
||||
ASSERT_FALSE(__asan_is_valid(p, 1));
|
||||
free(p);
|
||||
}
|
||||
|
||||
TEST(realloc, ptrIsZero_createsAllocation) {
|
||||
char *p;
|
||||
ASSERT_NE(NULL, (p = realloc(0, 1)));
|
||||
if (IsAsan()) ASSERT_TRUE(__asan_is_valid(p, 1));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p + 1, 1));
|
||||
if (IsAsan())
|
||||
ASSERT_TRUE(__asan_is_valid(p, 1));
|
||||
if (IsAsan())
|
||||
ASSERT_FALSE(__asan_is_valid(p + 1, 1));
|
||||
ASSERT_EQ(p, realloc(p, 0));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p, 1));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p + 1, 1));
|
||||
if (IsAsan())
|
||||
ASSERT_FALSE(__asan_is_valid(p, 1));
|
||||
if (IsAsan())
|
||||
ASSERT_FALSE(__asan_is_valid(p + 1, 1));
|
||||
free(p);
|
||||
}
|
||||
|
||||
TEST(realloc, sizeIsZero_shrinksAllocation) {
|
||||
char *p;
|
||||
ASSERT_NE(NULL, (p = malloc(1)));
|
||||
if (IsAsan()) ASSERT_TRUE(__asan_is_valid(p, 1));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p + 1, 1));
|
||||
if (IsAsan())
|
||||
ASSERT_TRUE(__asan_is_valid(p, 1));
|
||||
if (IsAsan())
|
||||
ASSERT_FALSE(__asan_is_valid(p + 1, 1));
|
||||
ASSERT_EQ(p, realloc(p, 0));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p, 1));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p + 1, 1));
|
||||
if (IsAsan())
|
||||
ASSERT_FALSE(__asan_is_valid(p, 1));
|
||||
if (IsAsan())
|
||||
ASSERT_FALSE(__asan_is_valid(p + 1, 1));
|
||||
free(p);
|
||||
}
|
||||
|
||||
|
@ -154,9 +164,12 @@ TEST(malloc, test) {
|
|||
}
|
||||
}
|
||||
free(big);
|
||||
for (i = 0; i < ARRAYLEN(A); ++i) free(A[i]);
|
||||
for (i = 0; i < ARRAYLEN(maps); ++i) munmap(maps[i], mapsizes[i]);
|
||||
for (i = 0; i < ARRAYLEN(fds); ++i) close(fds[i]);
|
||||
for (i = 0; i < ARRAYLEN(A); ++i)
|
||||
free(A[i]);
|
||||
for (i = 0; i < ARRAYLEN(maps); ++i)
|
||||
munmap(maps[i], mapsizes[i]);
|
||||
for (i = 0; i < ARRAYLEN(fds); ++i)
|
||||
close(fds[i]);
|
||||
}
|
||||
|
||||
TEST(memalign, roundsUpAlignmentToTwoPower) {
|
||||
|
@ -211,7 +224,8 @@ void *Worker(void *arg) {
|
|||
BENCH(malloc, torture) {
|
||||
int i, n = __get_cpu_count() * 2;
|
||||
pthread_t *t = gc(malloc(sizeof(pthread_t) * n));
|
||||
if (!n) return;
|
||||
if (!n)
|
||||
return;
|
||||
printf("\nmalloc torture test w/ %d threads and %d iterations\n", n,
|
||||
ITERATIONS);
|
||||
SPAWN(fork);
|
||||
|
|
|
@ -31,8 +31,10 @@
|
|||
int CompareLow(const void *a, const void *b) {
|
||||
const int *x = a;
|
||||
const int *y = b;
|
||||
if ((char)*x < (char)*y) return -1;
|
||||
if ((char)*x > (char)*y) return +1;
|
||||
if ((char)*x < (char)*y)
|
||||
return -1;
|
||||
if ((char)*x > (char)*y)
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -72,16 +74,20 @@ TEST(sort, stability) {
|
|||
int CompareInt(const void *a, const void *b) {
|
||||
const int *x = a;
|
||||
const int *y = b;
|
||||
if (*x < *y) return -1;
|
||||
if (*x > *y) return +1;
|
||||
if (*x < *y)
|
||||
return -1;
|
||||
if (*x > *y)
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CompareLong(const void *a, const void *b) {
|
||||
const long *x = a;
|
||||
const long *y = b;
|
||||
if (*x < *y) return -1;
|
||||
if (*x > *y) return +1;
|
||||
if (*x < *y)
|
||||
return -1;
|
||||
if (*x > *y)
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -110,8 +116,10 @@ struct Record {
|
|||
int CompareRecord(const void *a, const void *b) {
|
||||
const struct Record *x = a;
|
||||
const struct Record *y = b;
|
||||
if (x->z > y->z) return -1;
|
||||
if (x->z < y->z) return +1;
|
||||
if (x->z > y->z)
|
||||
return -1;
|
||||
if (x->z < y->z)
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -119,7 +127,8 @@ TEST(qsort, records) {
|
|||
int i, n = 256;
|
||||
struct Record *A = gc(calloc(n, sizeof(struct Record)));
|
||||
struct Record *B = gc(calloc(n, sizeof(struct Record)));
|
||||
for (i = 0; i < n; ++i) A[i].z = B[i].z = lemur64();
|
||||
for (i = 0; i < n; ++i)
|
||||
A[i].z = B[i].z = lemur64();
|
||||
qsort(A, n, sizeof(struct Record), CompareRecord);
|
||||
mergesort(B, n, sizeof(struct Record), CompareRecord);
|
||||
ASSERT_EQ(0, memcmp(A, B, n * sizeof(struct Record)));
|
||||
|
@ -131,7 +140,8 @@ TEST(qsort, equivalence_random) {
|
|||
long *a = gc(malloc(n * sizeof(long)));
|
||||
long *b = gc(malloc(n * sizeof(long)));
|
||||
long *c = gc(malloc(n * sizeof(long)));
|
||||
for (i = 0; i < n; ++i) a[i] = lemur64();
|
||||
for (i = 0; i < n; ++i)
|
||||
a[i] = lemur64();
|
||||
memcpy(b, a, n * sizeof(long));
|
||||
memcpy(c, a, n * sizeof(long));
|
||||
qsort(b, n, sizeof(long), CompareLong);
|
||||
|
@ -154,7 +164,8 @@ TEST(qsort, equivalence_reverse) {
|
|||
long *a = gc(malloc(n * sizeof(long)));
|
||||
long *b = gc(malloc(n * sizeof(long)));
|
||||
long *c = gc(malloc(n * sizeof(long)));
|
||||
for (i = 0; i < n; ++i) a[n - i - 1] = i;
|
||||
for (i = 0; i < n; ++i)
|
||||
a[n - i - 1] = i;
|
||||
memcpy(b, a, n * sizeof(long));
|
||||
memcpy(c, a, n * sizeof(long));
|
||||
qsort(b, n, sizeof(long), CompareLong);
|
||||
|
@ -178,7 +189,8 @@ BENCH(qsort, bench) {
|
|||
long *p2 = gc(malloc(n * sizeof(long)));
|
||||
|
||||
printf("\n");
|
||||
for (i = 0; i < n; ++i) p1[i] = i + ((lemur64() % 3) - 1);
|
||||
for (i = 0; i < n; ++i)
|
||||
p1[i] = i + ((lemur64() % 3) - 1);
|
||||
EZBENCH2("qsort nearly", memcpy(p2, p1, n * sizeof(long)),
|
||||
qsort(p2, n, sizeof(long), CompareLong));
|
||||
EZBENCH2("qsort_r nearly", memcpy(p2, p1, n * sizeof(long)),
|
||||
|
@ -193,7 +205,8 @@ BENCH(qsort, bench) {
|
|||
_longsort(p2, n));
|
||||
|
||||
printf("\n");
|
||||
for (i = 0; i < n; ++i) p1[i] = n - i;
|
||||
for (i = 0; i < n; ++i)
|
||||
p1[i] = n - i;
|
||||
EZBENCH2("qsort reverse", memcpy(p2, p1, n * sizeof(long)),
|
||||
qsort(p2, n, sizeof(long), CompareLong));
|
||||
EZBENCH2("qsort_r reverse", memcpy(p2, p1, n * sizeof(long)),
|
||||
|
|
|
@ -43,7 +43,8 @@ void Free(char *p) {
|
|||
|
||||
void C(void) {
|
||||
x = GC(strdup("abcd"));
|
||||
if (0) PrintGarbage();
|
||||
if (0)
|
||||
PrintGarbage();
|
||||
gclongjmp(jb, 1);
|
||||
abort();
|
||||
}
|
||||
|
@ -65,12 +66,14 @@ void (*Bp)(void(void)) = B;
|
|||
void (*Cp)(void) = C;
|
||||
|
||||
TEST(gclongjmp, test) {
|
||||
if (0) PrintGarbage();
|
||||
if (0)
|
||||
PrintGarbage();
|
||||
if (!setjmp(jb)) {
|
||||
Ap(Cp, Bp);
|
||||
abort();
|
||||
}
|
||||
if (0) PrintGarbage();
|
||||
if (0)
|
||||
PrintGarbage();
|
||||
EXPECT_STREQ("FREE", x);
|
||||
EXPECT_STREQ("FREE", y);
|
||||
EXPECT_STREQ("FREE", z);
|
||||
|
@ -80,7 +83,8 @@ TEST(gclongjmp, test) {
|
|||
}
|
||||
|
||||
void crawl(const char *path) {
|
||||
if (!strcmp(path, "/") || !strcmp(path, ".")) return;
|
||||
if (!strcmp(path, "/") || !strcmp(path, "."))
|
||||
return;
|
||||
crawl(gc(xdirname(path)));
|
||||
}
|
||||
|
||||
|
@ -92,8 +96,10 @@ void *Worker(void *arg) {
|
|||
TEST(gc, torture) {
|
||||
int i, n = 32;
|
||||
pthread_t *t = gc(malloc(sizeof(pthread_t) * n));
|
||||
for (i = 0; i < n; ++i) ASSERT_SYS(0, 0, pthread_create(t + i, 0, Worker, 0));
|
||||
for (i = 0; i < n; ++i) EXPECT_SYS(0, 0, pthread_join(t[i], 0));
|
||||
for (i = 0; i < n; ++i)
|
||||
ASSERT_SYS(0, 0, pthread_create(t + i, 0, Worker, 0));
|
||||
for (i = 0; i < n; ++i)
|
||||
EXPECT_SYS(0, 0, pthread_join(t[i], 0));
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 12
|
||||
|
@ -101,7 +107,8 @@ TEST(gc, torture) {
|
|||
#endif
|
||||
|
||||
void crawl2(jmp_buf jb, const char *path) {
|
||||
if (!strcmp(path, "/") || !strcmp(path, ".")) gclongjmp(jb, 1);
|
||||
if (!strcmp(path, "/") || !strcmp(path, "."))
|
||||
gclongjmp(jb, 1);
|
||||
crawl2(jb, gc(xdirname(path)));
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,8 @@ TEST(lz4, decompress_runLengthDecode) {
|
|||
}
|
||||
|
||||
TEST(lz4, zoneFileGmt) {
|
||||
if (!fileexists("usr/share/zoneinfo.dict.lz4")) return;
|
||||
if (!fileexists("usr/share/zoneinfo.dict.lz4"))
|
||||
return;
|
||||
char *dict = gc(xslurp("usr/share/zoneinfo.dict.lz4", 0));
|
||||
char *gmt = gc(xslurp("usr/share/zoneinfo/GMT.lz4", 0));
|
||||
size_t mapsize, gmtsize;
|
||||
|
|
|
@ -65,9 +65,12 @@ TEST(execve, testArgPassing) {
|
|||
}
|
||||
|
||||
TEST(execve, ziposELF) {
|
||||
if (1) return; // TODO: rewrite
|
||||
if (IsFreebsd()) return; // TODO: fixme on freebsd
|
||||
if (IsLinux() && !__is_linux_2_6_23()) return; // TODO: fixme on old linux
|
||||
if (1)
|
||||
return; // TODO: rewrite
|
||||
if (IsFreebsd())
|
||||
return; // TODO: fixme on freebsd
|
||||
if (IsLinux() && !__is_linux_2_6_23())
|
||||
return; // TODO: fixme on old linux
|
||||
if (!IsLinux() && !IsFreebsd()) {
|
||||
EXPECT_SYS(ENOSYS, -1,
|
||||
execve("/zip/life.elf", (char *const[]){0}, (char *const[]){0}));
|
||||
|
@ -80,9 +83,12 @@ TEST(execve, ziposELF) {
|
|||
}
|
||||
|
||||
TEST(execve, ziposAPE) {
|
||||
if (1) return; // TODO: rewrite
|
||||
if (IsFreebsd()) return; // TODO: fixme on freebsd
|
||||
if (IsLinux() && !__is_linux_2_6_23()) return; // TODO: fixme on old linux
|
||||
if (1)
|
||||
return; // TODO: rewrite
|
||||
if (IsFreebsd())
|
||||
return; // TODO: fixme on freebsd
|
||||
if (IsLinux() && !__is_linux_2_6_23())
|
||||
return; // TODO: fixme on old linux
|
||||
if (!IsLinux() && !IsFreebsd()) {
|
||||
EXPECT_EQ(
|
||||
-1, execve("/zip/life-nomod", (char *const[]){0}, (char *const[]){0}));
|
||||
|
@ -137,7 +143,8 @@ void ExecveTinyElf(const char *path) {
|
|||
}
|
||||
|
||||
BENCH(execve, bench) {
|
||||
if (!IsLinux()) return;
|
||||
if (!IsLinux())
|
||||
return;
|
||||
char path[128] = "/tmp/tinyelf.XXXXXX";
|
||||
int fd = mkstemp(path);
|
||||
fchmod(fd, 0700);
|
||||
|
|
|
@ -103,7 +103,8 @@ static void OnSigusr2(int sig) {
|
|||
}
|
||||
|
||||
TEST(fork, childToChild) {
|
||||
if (IsWindows()) return; // :'(
|
||||
if (IsWindows())
|
||||
return; // :'(
|
||||
sigset_t mask, oldmask;
|
||||
int ws, parent, child1, child2;
|
||||
gotsigusr1 = false;
|
||||
|
@ -144,7 +145,8 @@ TEST(fork, preservesTlsMemory) {
|
|||
void ForkInSerial(void) {
|
||||
int pid, ws;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) _Exit(0);
|
||||
if (!pid)
|
||||
_Exit(0);
|
||||
ASSERT_NE(-1, waitpid(pid, &ws, 0));
|
||||
ASSERT_TRUE(WIFEXITED(ws));
|
||||
ASSERT_EQ(0, WEXITSTATUS(ws));
|
||||
|
|
|
@ -60,7 +60,8 @@ TEST(getpriority, higherPriorityOfSelf) {
|
|||
}
|
||||
|
||||
TEST(getpriority, lowerAndRaiseItAgain_notAllowed) {
|
||||
if (1) return; // this behavior seems limited to modern linux
|
||||
if (1)
|
||||
return; // this behavior seems limited to modern linux
|
||||
SPAWN(fork);
|
||||
ASSERT_SYS(0, 0, setpriority(PRIO_PROCESS, 0, 5));
|
||||
ASSERT_SYS(EACCES, -1, setpriority(PRIO_PROCESS, 0, 4));
|
||||
|
|
|
@ -69,7 +69,8 @@ void *Killer(void *arg) {
|
|||
|
||||
void *Killed(void *arg) {
|
||||
shm->ready = true;
|
||||
while (!shm->got_signal) donothing;
|
||||
while (!shm->got_signal)
|
||||
donothing;
|
||||
shm->handler_returned = true;
|
||||
return 0;
|
||||
}
|
||||
|
@ -88,7 +89,8 @@ TEST(handkill, main2thread_async) {
|
|||
pthread_t th;
|
||||
shm->target = pthread_self();
|
||||
pthread_create(&th, 0, Killed, 0);
|
||||
while (!shm->ready) donothing;
|
||||
while (!shm->ready)
|
||||
donothing;
|
||||
ASSERT_EQ(0, pthread_kill(th, SIGUSR1));
|
||||
ASSERT_EQ(0, pthread_join(th, 0));
|
||||
TERMS(SIGUSR1);
|
||||
|
@ -101,7 +103,8 @@ TEST(handkill, thread2main_async) {
|
|||
pthread_t th;
|
||||
shm->target = pthread_self();
|
||||
pthread_create(&th, 0, Killer, 0);
|
||||
while (!shm->got_signal) donothing;
|
||||
while (!shm->got_signal)
|
||||
donothing;
|
||||
shm->handler_returned = true;
|
||||
pthread_join(th, 0);
|
||||
TERMS(SIGUSR1);
|
||||
|
@ -122,13 +125,16 @@ TEST(handkill, thread2thread_async) {
|
|||
}
|
||||
|
||||
TEST(handkill, process_async) {
|
||||
if (IsWindows()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
SPAWN(fork);
|
||||
shm->ready = true;
|
||||
while (!shm->got_signal) donothing;
|
||||
while (!shm->got_signal)
|
||||
donothing;
|
||||
shm->handler_returned = true;
|
||||
PARENT();
|
||||
while (!shm->ready) donothing;
|
||||
while (!shm->ready)
|
||||
donothing;
|
||||
ASSERT_SYS(0, 0, kill(child, SIGUSR1));
|
||||
WAIT(term, SIGUSR1);
|
||||
EXPECT_TRUE(shm->got_signal);
|
||||
|
@ -136,13 +142,15 @@ TEST(handkill, process_async) {
|
|||
}
|
||||
|
||||
TEST(handkill, process_pause) {
|
||||
if (IsWindows()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
SPAWN(fork);
|
||||
shm->ready = true;
|
||||
pause();
|
||||
shm->handler_returned = true;
|
||||
PARENT();
|
||||
while (!shm->ready) donothing;
|
||||
while (!shm->ready)
|
||||
donothing;
|
||||
usleep(1e6 / CLK_TCK * 2);
|
||||
ASSERT_SYS(0, 0, kill(child, SIGUSR1));
|
||||
WAIT(term, SIGUSR1);
|
||||
|
|
|
@ -129,8 +129,10 @@ TEST(posix_spawn, ape) {
|
|||
}
|
||||
|
||||
TEST(posix_spawn, elf) {
|
||||
if (IsOpenbsd()) return; // mimmutable() ugh
|
||||
if (IsXnu() || IsWindows() || IsMetal()) return;
|
||||
if (IsOpenbsd())
|
||||
return; // mimmutable() ugh
|
||||
if (IsXnu() || IsWindows() || IsMetal())
|
||||
return;
|
||||
int ws, pid;
|
||||
char *prog = "./life.elf"; // assimilate -bcef
|
||||
char *args[] = {prog, 0};
|
||||
|
@ -193,7 +195,8 @@ void OhMyGoth(int sig) {
|
|||
|
||||
// time for a vfork() clone() signal bloodbath
|
||||
TEST(posix_spawn, torture) {
|
||||
if (1) return;
|
||||
if (1)
|
||||
return;
|
||||
int n = 10;
|
||||
int ws, pid;
|
||||
sigset_t allsig;
|
||||
|
@ -259,10 +262,14 @@ void EmptySigHandler(int sig) {
|
|||
}
|
||||
|
||||
TEST(posix_spawn, etxtbsy) {
|
||||
if (IsWindows()) return; // can't deliver signals between processes
|
||||
if (IsXnu()) return; // they don't appear impacted by this race condition
|
||||
if (IsNetbsd()) return; // they don't appear impacted by this race condition
|
||||
if (IsOpenbsd()) return; // they don't appear impacted by this race condition
|
||||
if (IsWindows())
|
||||
return; // can't deliver signals between processes
|
||||
if (IsXnu())
|
||||
return; // they don't appear impacted by this race condition
|
||||
if (IsNetbsd())
|
||||
return; // they don't appear impacted by this race condition
|
||||
if (IsOpenbsd())
|
||||
return; // they don't appear impacted by this race condition
|
||||
int ws, me, pid, thief;
|
||||
char *prog = "./life";
|
||||
char *args[] = {prog, 0};
|
||||
|
@ -398,12 +405,14 @@ BENCH(posix_spawn, bench) {
|
|||
EZBENCH2("vfork life-pe", donothing, VforkExecveWait("./life-pe"));
|
||||
EZBENCH2("fork life-pe", donothing, ForkExecveWait("./life-pe"));
|
||||
}
|
||||
if (IsXnu() || IsWindows() || IsMetal()) return;
|
||||
if (IsXnu() || IsWindows() || IsMetal())
|
||||
return;
|
||||
EZBENCH2("posix_spawn life.elf", donothing, PosixSpawnWait("./life.elf"));
|
||||
EZBENCH2("vfork life.elf", donothing, VforkExecveWait("./life.elf"));
|
||||
EZBENCH2("fork life.elf", donothing, ForkExecveWait("./life.elf"));
|
||||
#ifdef __x86_64__
|
||||
if (!IsLinux()) return;
|
||||
if (!IsLinux())
|
||||
return;
|
||||
EZBENCH2("posix_spawn tiny64", donothing, PosixSpawnWait("tiny64"));
|
||||
EZBENCH2("vfork tiny64", donothing, VforkExecveWait("tiny64"));
|
||||
EZBENCH2("fork tiny64", donothing, ForkExecveWait("tiny64"));
|
||||
|
|
|
@ -51,7 +51,8 @@ TEST(sched_getaffinity, firstOnly) {
|
|||
}
|
||||
|
||||
TEST(sched_getaffinity, secondOnly) {
|
||||
if (__get_cpu_count() < 2) return;
|
||||
if (__get_cpu_count() < 2)
|
||||
return;
|
||||
cpu_set_t x, y;
|
||||
CPU_ZERO(&x);
|
||||
CPU_SET(1, &x);
|
||||
|
@ -122,7 +123,8 @@ TEST(pthread_getaffinity, getpid) {
|
|||
CPU_ZERO(&x);
|
||||
CPU_SET(0, &x);
|
||||
ASSERT_SYS(0, 0, pthread_setaffinity_np(pthread_self(), sizeof(x), &x));
|
||||
if (IsWindows()) return; // win32 doesn't define GetThreadAffinityMask ;_;
|
||||
if (IsWindows())
|
||||
return; // win32 doesn't define GetThreadAffinityMask ;_;
|
||||
ASSERT_SYS(0, 0, pthread_getaffinity_np(pthread_self(), sizeof(y), &y));
|
||||
EXPECT_EQ(1, CPU_COUNT(&y));
|
||||
EXPECT_TRUE(CPU_ISSET(0, &y));
|
||||
|
|
|
@ -171,7 +171,8 @@ TEST(system, usleep) {
|
|||
|
||||
TEST(system, kill) {
|
||||
int ws = system("kill -TERM $$; usleep");
|
||||
if (!IsWindows()) ASSERT_EQ(SIGTERM, WTERMSIG(ws));
|
||||
if (!IsWindows())
|
||||
ASSERT_EQ(SIGTERM, WTERMSIG(ws));
|
||||
}
|
||||
|
||||
TEST(system, exitStatusPreservedAfterSemiColon) {
|
||||
|
|
|
@ -73,7 +73,8 @@ TEST(exit, narrowing) {
|
|||
}
|
||||
|
||||
TEST(exit, exitCode259_wontCauseParentProcessToHangForever) {
|
||||
if (!IsWindows()) return;
|
||||
if (!IsWindows())
|
||||
return;
|
||||
SPAWN(vfork);
|
||||
_Exit(259);
|
||||
EXITS(259);
|
||||
|
@ -88,7 +89,8 @@ TEST(exit, sigkill) {
|
|||
pause();
|
||||
}
|
||||
}
|
||||
while (!*ready) donothing;
|
||||
while (!*ready)
|
||||
donothing;
|
||||
ASSERT_EQ(0, kill(pid, SIGKILL));
|
||||
ASSERT_SYS(0, pid, wait(&ws));
|
||||
ASSERT_EQ(SIGKILL, ws);
|
||||
|
@ -107,7 +109,8 @@ TEST(exit, sigalrm) {
|
|||
pause();
|
||||
}
|
||||
}
|
||||
while (!*ready) donothing;
|
||||
while (!*ready)
|
||||
donothing;
|
||||
ASSERT_EQ(0, kill(pid, SIGALRM));
|
||||
ASSERT_SYS(0, pid, wait(&ws));
|
||||
ASSERT_EQ(SIGALRM, ws);
|
||||
|
|
|
@ -70,8 +70,10 @@ TEST(grow, testGrowth_clearsNewMemory) {
|
|||
memset(p, 'a', capacity);
|
||||
EXPECT_TRUE(__grow(&p, &capacity, 1, 0));
|
||||
EXPECT_GT(capacity, 123);
|
||||
for (i = 0; i < 123; ++i) ASSERT_EQ('a', p[i]);
|
||||
for (i = 123; i < capacity; ++i) ASSERT_EQ(0, p[i]);
|
||||
for (i = 0; i < 123; ++i)
|
||||
ASSERT_EQ('a', p[i]);
|
||||
for (i = 123; i < capacity; ++i)
|
||||
ASSERT_EQ(0, p[i]);
|
||||
free(p);
|
||||
}
|
||||
|
||||
|
|
|
@ -72,15 +72,18 @@ bool AreMemoryIntervalsOk(const struct MemoryIntervals *mm) {
|
|||
|
||||
static bool AreMemoryIntervalsEqual(const struct MemoryIntervals *mm1,
|
||||
const struct MemoryIntervals *mm2) {
|
||||
if (mm1->i != mm2->i) return false;
|
||||
if (memcmp(mm1->p, mm2->p, mm1->i * sizeof(*mm2->p)) != 0) return false;
|
||||
if (mm1->i != mm2->i)
|
||||
return false;
|
||||
if (memcmp(mm1->p, mm2->p, mm1->i * sizeof(*mm2->p)) != 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void PrintMemoryInterval(const struct MemoryIntervals *mm) {
|
||||
int i;
|
||||
for (i = 0; i < mm->i; ++i) {
|
||||
if (i) fprintf(stderr, ",");
|
||||
if (i)
|
||||
fprintf(stderr, ",");
|
||||
fprintf(stderr, "{%d,%d}", mm->p[i].x, mm->p[i].y);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
|
@ -294,7 +297,8 @@ TEST(__untrack_memory, TestPunchHole) {
|
|||
}
|
||||
|
||||
TEST(__untrack_memory, TestShortenLeft) {
|
||||
if (IsWindows()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
static struct MemoryIntervals mm[2] = {
|
||||
{1, OPEN_MAX, 0, {I(0, 9)}},
|
||||
{1, OPEN_MAX, 0, {I(0, 7)}},
|
||||
|
@ -305,7 +309,8 @@ TEST(__untrack_memory, TestShortenLeft) {
|
|||
}
|
||||
|
||||
TEST(__untrack_memory, TestShortenRight) {
|
||||
if (IsWindows()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
static struct MemoryIntervals mm[2] = {
|
||||
{1, OPEN_MAX, 0, {I(0, 9)}},
|
||||
{1, OPEN_MAX, 0, {I(3, 9)}},
|
||||
|
@ -316,7 +321,8 @@ TEST(__untrack_memory, TestShortenRight) {
|
|||
}
|
||||
|
||||
TEST(__untrack_memory, TestShortenLeft2) {
|
||||
if (IsWindows()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
static struct MemoryIntervals mm[2] = {
|
||||
{1, OPEN_MAX, 0, {I(0, 9)}},
|
||||
{1, OPEN_MAX, 0, {I(0, 7)}},
|
||||
|
@ -327,7 +333,8 @@ TEST(__untrack_memory, TestShortenLeft2) {
|
|||
}
|
||||
|
||||
TEST(__untrack_memory, TestShortenRight2) {
|
||||
if (IsWindows()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
static struct MemoryIntervals mm[2] = {
|
||||
{1, OPEN_MAX, 0, {I(0, 9)}},
|
||||
{1, OPEN_MAX, 0, {I(3, 9)}},
|
||||
|
|
|
@ -104,7 +104,8 @@ TEST(mmap, smallerThanPage_mapsRemainder) {
|
|||
}
|
||||
|
||||
TEST(mmap, smallerThanPage_remainderIsPoisoned) {
|
||||
if (!IsAsan()) return;
|
||||
if (!IsAsan())
|
||||
return;
|
||||
char *map;
|
||||
ASSERT_NE(MAP_FAILED, (map = mmap(0, 1, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)));
|
||||
|
@ -474,7 +475,8 @@ void BenchMmapPrivate(void) {
|
|||
void *p;
|
||||
p = mmap(0, FRAMESIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE,
|
||||
-1, 0);
|
||||
if (p == MAP_FAILED) abort();
|
||||
if (p == MAP_FAILED)
|
||||
abort();
|
||||
ptrs[count++] = p;
|
||||
}
|
||||
|
||||
|
|
|
@ -183,8 +183,10 @@ TEST(mprotect, testExecJit_actuallyWorks) {
|
|||
}
|
||||
|
||||
TEST(mprotect, testRwxMap_vonNeumannRules) {
|
||||
if (IsOpenbsd()) return; // boo
|
||||
if (IsXnuSilicon()) return; // boo
|
||||
if (IsOpenbsd())
|
||||
return; // boo
|
||||
if (IsXnuSilicon())
|
||||
return; // boo
|
||||
int (*p)(void) = gc(memalign(getauxval(AT_PAGESZ), getauxval(AT_PAGESZ)));
|
||||
memcpy(p, kRet31337, sizeof(kRet31337));
|
||||
EXPECT_NE(-1, mprotect(p, getauxval(AT_PAGESZ),
|
||||
|
@ -196,7 +198,8 @@ TEST(mprotect, testRwxMap_vonNeumannRules) {
|
|||
}
|
||||
|
||||
TEST(mprotect, testExecuteFlatFileMapOpenedAsReadonly) {
|
||||
if (IsXnuSilicon()) return; // TODO(jart): Use APE Loader SIP workaround?
|
||||
if (IsXnuSilicon())
|
||||
return; // TODO(jart): Use APE Loader SIP workaround?
|
||||
int (*p)(void);
|
||||
size_t n = sizeof(kRet31337);
|
||||
ASSERT_SYS(0, 3, creat("return31337", 0755));
|
||||
|
|
|
@ -62,7 +62,8 @@ TEST(msync, changeFileMappingAndWakeSpinLockWaiter) {
|
|||
(map = mmap(0, 1, PROT_READ | PROT_WRITE, MAP_SHARED, 3, 0)));
|
||||
if (!fork()) {
|
||||
// wait for other process to enter spin sem
|
||||
while (*sem == 0) donothing;
|
||||
while (*sem == 0)
|
||||
donothing;
|
||||
// change the file mapping
|
||||
map[0] = 1;
|
||||
// openbsd fails with this line commented out
|
||||
|
@ -72,7 +73,8 @@ TEST(msync, changeFileMappingAndWakeSpinLockWaiter) {
|
|||
_Exit(123);
|
||||
}
|
||||
*sem = 1;
|
||||
while (*sem == 1) donothing;
|
||||
while (*sem == 1)
|
||||
donothing;
|
||||
ASSERT_EQ(1, map[0]);
|
||||
ASSERT_SYS(0, 1, pread(3, &byte, 1, 0));
|
||||
ASSERT_EQ(1, byte);
|
||||
|
|
|
@ -140,7 +140,8 @@ TEST(munmap, memoryGone) {
|
|||
}
|
||||
|
||||
TEST(munmap, testTooSmallToUnmapAsan) {
|
||||
if (!IsAsan()) return;
|
||||
if (!IsAsan())
|
||||
return;
|
||||
char *p;
|
||||
ASSERT_NE(MAP_FAILED, (p = mmap(0, FRAMESIZE, PROT_READ | PROT_WRITE,
|
||||
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)));
|
||||
|
@ -150,7 +151,8 @@ TEST(munmap, testTooSmallToUnmapAsan) {
|
|||
}
|
||||
|
||||
TEST(munmap, testLargeEnoughToUnmapAsan) {
|
||||
if (!IsAsan()) return;
|
||||
if (!IsAsan())
|
||||
return;
|
||||
if (IsWindows()) {
|
||||
// we're unfortunately never able to unmap asan pages on windows
|
||||
// because the memtrack array items always have to be 64kb so we
|
||||
|
|
|
@ -35,8 +35,10 @@
|
|||
#include "libc/thread/thread.h"
|
||||
|
||||
TEST(connect, nonblocking) {
|
||||
if (IsFreebsd()) return; // TODO(jart): why did this start flaking?
|
||||
if (IsOpenbsd()) return; // TODO(jart): why did this start freezing?
|
||||
if (IsFreebsd())
|
||||
return; // TODO(jart): why did this start flaking?
|
||||
if (IsOpenbsd())
|
||||
return; // TODO(jart): why did this start freezing?
|
||||
char buf[16] = {0};
|
||||
atomic_uint *sem = _mapshared(sizeof(unsigned));
|
||||
uint32_t addrsize = sizeof(struct sockaddr_in);
|
||||
|
@ -49,7 +51,8 @@ TEST(connect, nonblocking) {
|
|||
ASSERT_SYS(0, 0, getsockname(3, (struct sockaddr *)&addr, &addrsize));
|
||||
ASSERT_SYS(0, 0, listen(3, SOMAXCONN));
|
||||
SPAWN(fork);
|
||||
while (!*sem) pthread_yield();
|
||||
while (!*sem)
|
||||
pthread_yield();
|
||||
ASSERT_SYS(0, 4, accept(3, (struct sockaddr *)&addr, &addrsize));
|
||||
ASSERT_SYS(0, 2, read(4, buf, 16)); // hi
|
||||
ASSERT_SYS(0, 5, write(4, "hello", 5));
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
|
||||
TEST(O_NONBLOCK, canBeSetBySocket_toMakeListenNonBlocking) {
|
||||
// TODO(jart): this doesn't make any sense on windows
|
||||
if (IsWindows()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
char buf[16] = {0};
|
||||
uint32_t addrsize = sizeof(struct sockaddr_in);
|
||||
struct sockaddr_in addr = {
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
// two clients send a udp packet containing their local address
|
||||
// server verifies content of packet matches the peer's address
|
||||
TEST(recvfrom, test) {
|
||||
if (!IsWindows()) return;
|
||||
if (!IsWindows())
|
||||
return;
|
||||
uint32_t addrsize = sizeof(struct sockaddr_in);
|
||||
struct sockaddr_in server = {
|
||||
.sin_family = AF_INET,
|
||||
|
|
|
@ -40,8 +40,10 @@
|
|||
#include "libc/x/x.h"
|
||||
|
||||
void SetUpOnce(void) {
|
||||
if (IsNetbsd()) exit(0);
|
||||
if (IsOpenbsd()) exit(0);
|
||||
if (IsNetbsd())
|
||||
exit(0);
|
||||
if (IsOpenbsd())
|
||||
exit(0);
|
||||
testlib_enable_tmp_setup_teardown();
|
||||
ASSERT_SYS(0, 0, pledge("stdio rpath wpath cpath proc inet", 0));
|
||||
}
|
||||
|
@ -101,7 +103,8 @@ TEST(sendfile, testSeeking) {
|
|||
|
||||
TEST(sendfile, testPositioning) {
|
||||
// TODO(jart): fix test regression on windows
|
||||
if (IsWindows()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
char buf[1024];
|
||||
uint32_t addrsize = sizeof(struct sockaddr_in);
|
||||
struct sockaddr_in addr = {
|
||||
|
|
|
@ -152,7 +152,8 @@ __attribute__((__constructor__)) static void StdioPro(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
TEST(socket, canBeUsedAsExecutedStdio) {
|
||||
if (IsWindows()) return; // TODO(jart): What broke this?
|
||||
if (IsWindows())
|
||||
return; // TODO(jart): What broke this?
|
||||
char buf[16] = {0};
|
||||
const char *prog;
|
||||
uint32_t addrsize = sizeof(struct sockaddr_in);
|
||||
|
|
|
@ -43,7 +43,8 @@ void SetUpOnce(void) {
|
|||
}
|
||||
|
||||
TEST(unix, datagram) {
|
||||
if (IsWindows()) return; // no unix datagram on windows :'(
|
||||
if (IsWindows())
|
||||
return; // no unix datagram on windows :'(
|
||||
atomic_bool *ready = _mapshared(1);
|
||||
SPAWN(fork);
|
||||
char buf[256] = {0};
|
||||
|
@ -60,7 +61,8 @@ TEST(unix, datagram) {
|
|||
EXPECT_STREQ("hello", buf);
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
PARENT();
|
||||
while (!*ready) sched_yield();
|
||||
while (!*ready)
|
||||
sched_yield();
|
||||
ASSERT_SYS(0, 3, socket(AF_UNIX, SOCK_DGRAM, 0));
|
||||
uint32_t len = sizeof(struct sockaddr_un);
|
||||
struct sockaddr_un addr = {AF_UNIX, "foo.sock"};
|
||||
|
@ -95,7 +97,8 @@ void StreamServer(atomic_bool *ready) {
|
|||
|
||||
TEST(unix, stream) {
|
||||
int ws;
|
||||
if (IsWindows() && !IsAtLeastWindows10()) return;
|
||||
if (IsWindows() && !IsAtLeastWindows10())
|
||||
return;
|
||||
atomic_bool *ready = _mapshared(1);
|
||||
// TODO(jart): move this line down when kFdProcess is gone
|
||||
ASSERT_SYS(0, 3, socket(AF_UNIX, SOCK_STREAM, 0));
|
||||
|
@ -104,7 +107,8 @@ TEST(unix, stream) {
|
|||
StreamServer(ready);
|
||||
_Exit(0);
|
||||
}
|
||||
while (!*ready) sched_yield();
|
||||
while (!*ready)
|
||||
sched_yield();
|
||||
uint32_t len = sizeof(struct sockaddr_un);
|
||||
struct sockaddr_un addr = {AF_UNIX, "foo.sock"};
|
||||
ASSERT_SYS(0, 0, connect(3, (void *)&addr, len));
|
||||
|
@ -117,8 +121,10 @@ TEST(unix, stream) {
|
|||
}
|
||||
|
||||
TEST(unix, serverGoesDown_deletedSockFile) { // field of landmine
|
||||
if (IsWindows()) return;
|
||||
if (IsCygwin()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
if (IsCygwin())
|
||||
return;
|
||||
char buf[8] = {0};
|
||||
uint32_t len = sizeof(struct sockaddr_un);
|
||||
struct sockaddr_un addr = {AF_UNIX, "foo.sock"};
|
||||
|
@ -152,8 +158,10 @@ TEST(unix, serverGoesDown_deletedSockFile) { // field of landmine
|
|||
}
|
||||
|
||||
TEST(unix, serverGoesDown_usingSendTo_unlink) { // much easier
|
||||
if (IsWindows()) return;
|
||||
if (IsCygwin()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
if (IsCygwin())
|
||||
return;
|
||||
char buf[8] = {0};
|
||||
uint32_t len = sizeof(struct sockaddr_un);
|
||||
struct sockaddr_un addr = {AF_UNIX, "foo.sock"};
|
||||
|
|
|
@ -61,7 +61,8 @@ void SetUp(void) {
|
|||
|
||||
TEST(opendir, efault) {
|
||||
ASSERT_SYS(EFAULT, NULL, opendir(0));
|
||||
if (!IsAsan()) return; // not possible
|
||||
if (!IsAsan())
|
||||
return; // not possible
|
||||
ASSERT_SYS(EFAULT, NULL, opendir((void *)77));
|
||||
}
|
||||
|
||||
|
@ -180,8 +181,10 @@ TEST(rewinddir, test) {
|
|||
readdir(dir);
|
||||
rewinddir(dir);
|
||||
while ((ent = readdir(dir))) {
|
||||
if (strcmp(ent->d_name, "foo")) hasfoo = true;
|
||||
if (strcmp(ent->d_name, "bar")) hasbar = true;
|
||||
if (strcmp(ent->d_name, "foo"))
|
||||
hasfoo = true;
|
||||
if (strcmp(ent->d_name, "bar"))
|
||||
hasbar = true;
|
||||
}
|
||||
EXPECT_TRUE(hasfoo);
|
||||
EXPECT_TRUE(hasbar);
|
||||
|
|
|
@ -35,7 +35,8 @@ void *Torturer(void *arg) {
|
|||
}
|
||||
for (i = 0; i < FDS; ++i) {
|
||||
ASSERT_EQ(2, write(fd[i], "hi", 2));
|
||||
if (!vfork()) _Exit(0);
|
||||
if (!vfork())
|
||||
_Exit(0);
|
||||
wait(0);
|
||||
}
|
||||
for (i = 0; i < FDS; ++i) {
|
||||
|
|
|
@ -53,7 +53,8 @@ void Benchmark(void) {
|
|||
f = fmemopen(gc(strdup(kHyperion)), kHyperionSize, "r+");
|
||||
for (;;) {
|
||||
line = fgets(buf, sizeof(buf), f);
|
||||
if (!line) break;
|
||||
if (!line)
|
||||
break;
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
|
||||
TEST(fprintf, testWriteError) {
|
||||
// Only Linux, NetBSD and FreeBSD are known to have /dev/full
|
||||
if (!IsLinux() && !IsNetbsd() && !IsFreebsd()) return;
|
||||
if (!IsLinux() && !IsNetbsd() && !IsFreebsd())
|
||||
return;
|
||||
|
||||
FILE *fp = fopen("/dev/full", "w");
|
||||
ASSERT_NE(fp, NULL);
|
||||
|
|
|
@ -162,7 +162,8 @@ void OnSigInt(int sig) {
|
|||
}
|
||||
|
||||
TEST(fwrite, signalStorm) {
|
||||
if (IsWindows()) return;
|
||||
if (IsWindows())
|
||||
return;
|
||||
int pid;
|
||||
struct sigaction oldchld, oldint;
|
||||
struct sigaction sachld = {.sa_handler = SIG_IGN};
|
||||
|
@ -180,7 +181,8 @@ TEST(fwrite, signalStorm) {
|
|||
pause();
|
||||
MeatyReadWriteTest();
|
||||
EXPECT_NE(-1, kill(pid, SIGINT));
|
||||
while (wait(0) == -1 && errno == EINTR) donothing;
|
||||
while (wait(0) == -1 && errno == EINTR)
|
||||
donothing;
|
||||
EXPECT_NE(-1, sigaction(SIGCHLD, &oldchld, NULL));
|
||||
EXPECT_NE(-1, sigaction(SIGINT, &oldint, NULL));
|
||||
}
|
||||
|
|
|
@ -99,7 +99,8 @@ void ReadHyperionLines(void) {
|
|||
ASSERT_NE(NULL, (f = fopen("hyperion.txt", "r")));
|
||||
for (;;) {
|
||||
rc = getline(&line, &linesize, f);
|
||||
if (rc == -1) break;
|
||||
if (rc == -1)
|
||||
break;
|
||||
data = xrealloc(data, size + rc);
|
||||
memcpy(data + size, line, rc);
|
||||
size += rc;
|
||||
|
|
|
@ -51,9 +51,11 @@ void *TortureWorker(void *arg) {
|
|||
ASSERT_SYS(0, 0, sigprocmask(SIG_SETMASK, &ss, 0));
|
||||
ready = true;
|
||||
while (!done) {
|
||||
if (!IsWindows()) pthread_kill(parent, SIGUSR1);
|
||||
if (!IsWindows())
|
||||
pthread_kill(parent, SIGUSR1);
|
||||
usleep(1);
|
||||
if (!IsWindows()) pthread_kill(parent, SIGUSR2);
|
||||
if (!IsWindows())
|
||||
pthread_kill(parent, SIGUSR2);
|
||||
usleep(1);
|
||||
}
|
||||
return 0;
|
||||
|
@ -72,7 +74,8 @@ TEST(getentropy, test) {
|
|||
ASSERT_SYS(0, 0, sigaction(SIGUSR2, &sa, 0));
|
||||
parent = pthread_self();
|
||||
ASSERT_EQ(0, pthread_create(&child, 0, TortureWorker, 0));
|
||||
while (!ready) pthread_yield();
|
||||
while (!ready)
|
||||
pthread_yield();
|
||||
for (k = 0; k < 10; ++k) {
|
||||
ASSERT_SYS(0, 0, getentropy(0, 0));
|
||||
for (i = 0; i < n; i += m) {
|
||||
|
@ -83,9 +86,11 @@ TEST(getentropy, test) {
|
|||
if ((e = MeasureEntropy(buf, n)) < w) {
|
||||
fprintf(stderr, "error: entropy suspect! got %g but want >=%g\n", e, w);
|
||||
for (i = 0; i < n;) {
|
||||
if (!(i % 16)) fprintf(stderr, "%6x ", i);
|
||||
if (!(i % 16))
|
||||
fprintf(stderr, "%6x ", i);
|
||||
fprintf(stderr, "%lc", kCp437[buf[i] & 255]);
|
||||
if (!(++i % 16)) fprintf(stderr, "\n");
|
||||
if (!(++i % 16))
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
done = true;
|
||||
|
@ -95,7 +100,8 @@ TEST(getentropy, test) {
|
|||
}
|
||||
done = true;
|
||||
ASSERT_EQ(0, pthread_join(child, 0));
|
||||
if (!IsWindows()) ASSERT_GT(gotsome, 0);
|
||||
if (!IsWindows())
|
||||
ASSERT_GT(gotsome, 0);
|
||||
}
|
||||
|
||||
#endif /* __aarch64__ */
|
||||
|
|
|
@ -35,8 +35,10 @@ void GetRandom(void *p, size_t n) {
|
|||
for (i = 0; i < n; i += rc) {
|
||||
m = MIN(n - i, 256);
|
||||
rc = getrandom((char *)p + i, m, 0);
|
||||
if (rc == -1 && errno == EINTR) continue;
|
||||
if (rc <= 0) abort();
|
||||
if (rc == -1 && errno == EINTR)
|
||||
continue;
|
||||
if (rc <= 0)
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,8 @@ void OnSig(int sig) {
|
|||
}
|
||||
|
||||
TEST(popen, complicated) {
|
||||
if (IsWindows()) return; // windows treats sigusr1 as terminate
|
||||
if (IsWindows())
|
||||
return; // windows treats sigusr1 as terminate
|
||||
char cmd[64];
|
||||
signal(SIGUSR1, OnSig);
|
||||
sprintf(cmd, "read a ; test \"x$a\" = xhello && kill -USR1 %d", getpid());
|
||||
|
@ -164,8 +165,10 @@ TEST(popen, torture) {
|
|||
int i, n = 4;
|
||||
pthread_t *t = gc(malloc(sizeof(pthread_t) * n));
|
||||
testlib_extract("/zip/echo", "echo", 0755);
|
||||
for (i = 0; i < n; ++i) ASSERT_EQ(0, pthread_create(t + i, 0, Worker, 0));
|
||||
for (i = 0; i < n; ++i) ASSERT_EQ(0, pthread_join(t[i], 0));
|
||||
for (i = 0; i < n; ++i)
|
||||
ASSERT_EQ(0, pthread_create(t + i, 0, Worker, 0));
|
||||
for (i = 0; i < n; ++i)
|
||||
ASSERT_EQ(0, pthread_join(t[i], 0));
|
||||
CheckForFdLeaks();
|
||||
}
|
||||
|
||||
|
|
|
@ -39,8 +39,10 @@ bool IsDirectoryEmpty(const char *path) {
|
|||
struct dirent *e;
|
||||
ASSERT_NE(NULL, (d = opendir(path)));
|
||||
while ((e = readdir(d))) {
|
||||
if (!strcmp(e->d_name, ".")) continue;
|
||||
if (!strcmp(e->d_name, "..")) continue;
|
||||
if (!strcmp(e->d_name, "."))
|
||||
continue;
|
||||
if (!strcmp(e->d_name, ".."))
|
||||
continue;
|
||||
res = false;
|
||||
}
|
||||
closedir(d);
|
||||
|
@ -83,7 +85,8 @@ TEST(tmpfile, test) {
|
|||
#ifndef __aarch64__
|
||||
// TODO(jart): Why does this apply to pi and qemu-aarch64?
|
||||
TEST(tmpfile, renameToRealFile) {
|
||||
if (!(IsLinux() && __is_linux_2_6_23())) return; // need non-ancient linux
|
||||
if (!(IsLinux() && __is_linux_2_6_23()))
|
||||
return; // need non-ancient linux
|
||||
FILE *f;
|
||||
f = tmpfile();
|
||||
ASSERT_EQ(2, fputs("hi", f));
|
||||
|
|
|
@ -68,7 +68,8 @@ uint32_t KnuthMultiplicativeHash32(const void *buf, size_t size) {
|
|||
uint32_t h;
|
||||
const uint32_t kPhiPrime = 0x9e3779b1;
|
||||
const unsigned char *p = (const unsigned char *)buf;
|
||||
for (h = i = 0; i < size; i++) h = (p[i] + h) * kPhiPrime;
|
||||
for (h = i = 0; i < size; i++)
|
||||
h = (p[i] + h) * kPhiPrime;
|
||||
return h;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,8 +42,10 @@ void InsertionSort(int *A, int n) {
|
|||
int CompareLong(const void *a, const void *b) {
|
||||
const long *x = a;
|
||||
const long *y = b;
|
||||
if (*x < *y) return -1;
|
||||
if (*x > *y) return +1;
|
||||
if (*x < *y)
|
||||
return -1;
|
||||
if (*x > *y)
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -61,7 +63,8 @@ TEST(_longsort, test) {
|
|||
#ifdef __x86_64__
|
||||
|
||||
TEST(vqsort_int64_avx2, test) {
|
||||
if (!X86_HAVE(AVX2)) return;
|
||||
if (!X86_HAVE(AVX2))
|
||||
return;
|
||||
size_t n = 5000;
|
||||
long *a = gc(calloc(n, sizeof(long)));
|
||||
long *b = gc(calloc(n, sizeof(long)));
|
||||
|
@ -73,7 +76,8 @@ TEST(vqsort_int64_avx2, test) {
|
|||
}
|
||||
|
||||
TEST(vqsort_int64_sse4, test) {
|
||||
if (!X86_HAVE(SSE4_2)) return;
|
||||
if (!X86_HAVE(SSE4_2))
|
||||
return;
|
||||
size_t n = 5000;
|
||||
long *a = gc(calloc(n, sizeof(long)));
|
||||
long *b = gc(calloc(n, sizeof(long)));
|
||||
|
@ -85,7 +89,8 @@ TEST(vqsort_int64_sse4, test) {
|
|||
}
|
||||
|
||||
TEST(vqsort_int64_ssse3, test) {
|
||||
if (!X86_HAVE(SSSE3)) return;
|
||||
if (!X86_HAVE(SSSE3))
|
||||
return;
|
||||
size_t n = 5000;
|
||||
long *a = gc(calloc(n, sizeof(long)));
|
||||
long *b = gc(calloc(n, sizeof(long)));
|
||||
|
@ -152,8 +157,10 @@ BENCH(_longsort, bench) {
|
|||
int CompareInt(const void *a, const void *b) {
|
||||
const int *x = a;
|
||||
const int *y = b;
|
||||
if (*x < *y) return -1;
|
||||
if (*x > *y) return +1;
|
||||
if (*x < *y)
|
||||
return -1;
|
||||
if (*x > *y)
|
||||
return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -171,7 +178,8 @@ TEST(InsertionSort, test) {
|
|||
#ifdef __x86_64__
|
||||
|
||||
TEST(vqsort_int32_avx2, test) {
|
||||
if (!X86_HAVE(AVX2)) return;
|
||||
if (!X86_HAVE(AVX2))
|
||||
return;
|
||||
size_t n = 5000;
|
||||
int *a = gc(calloc(n, sizeof(int)));
|
||||
int *b = gc(calloc(n, sizeof(int)));
|
||||
|
@ -183,7 +191,8 @@ TEST(vqsort_int32_avx2, test) {
|
|||
}
|
||||
|
||||
TEST(vqsort_int32_sse4, test) {
|
||||
if (!X86_HAVE(SSE4_2)) return;
|
||||
if (!X86_HAVE(SSE4_2))
|
||||
return;
|
||||
size_t n = 5000;
|
||||
int *a = gc(calloc(n, sizeof(int)));
|
||||
int *b = gc(calloc(n, sizeof(int)));
|
||||
|
@ -195,7 +204,8 @@ TEST(vqsort_int32_sse4, test) {
|
|||
}
|
||||
|
||||
TEST(vqsort_int32_ssse3, test) {
|
||||
if (!X86_HAVE(SSSE3)) return;
|
||||
if (!X86_HAVE(SSSE3))
|
||||
return;
|
||||
size_t n = 5000;
|
||||
int *a = gc(calloc(n, sizeof(int)));
|
||||
int *b = gc(calloc(n, sizeof(int)));
|
||||
|
|
|
@ -28,7 +28,8 @@ void *memccpy_pure(void *d, const void *s, int c, size_t n) {
|
|||
unsigned char *x;
|
||||
const unsigned char *y;
|
||||
for (c &= 0xff, x = d, y = s, i = 0; i < n; ++i) {
|
||||
if ((x[i] = y[i]) == c) return x + i + 1;
|
||||
if ((x[i] = y[i]) == c)
|
||||
return x + i + 1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -30,13 +30,18 @@
|
|||
void *memmem_naive(const void *haystk, size_t haystklen, //
|
||||
const void *needle, size_t needlelen) {
|
||||
size_t i, j;
|
||||
if (!needlelen) return (void *)haystk;
|
||||
if (needlelen > haystklen) return 0;
|
||||
if (!needlelen)
|
||||
return (void *)haystk;
|
||||
if (needlelen > haystklen)
|
||||
return 0;
|
||||
for (i = 0; i < haystklen; ++i) {
|
||||
for (j = 0;; ++j) {
|
||||
if (j == needlelen) return (/*unconst*/ char *)haystk + i;
|
||||
if (i + j == haystklen) break;
|
||||
if (((char *)haystk)[i + j] != ((char *)needle)[j]) break;
|
||||
if (j == needlelen)
|
||||
return (/*unconst*/ char *)haystk + i;
|
||||
if (i + j == haystklen)
|
||||
break;
|
||||
if (((char *)haystk)[i + j] != ((char *)needle)[j])
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -32,14 +32,19 @@
|
|||
|
||||
char *strcasestr_naive(const char *haystack, const char *needle) {
|
||||
size_t i;
|
||||
if (haystack == needle || !*needle) return (void *)haystack;
|
||||
if (haystack == needle || !*needle)
|
||||
return (void *)haystack;
|
||||
for (;;) {
|
||||
for (i = 0;; ++i) {
|
||||
if (!needle[i]) return (/*unconst*/ char *)haystack;
|
||||
if (!haystack[i]) break;
|
||||
if (kToLower[needle[i] & 255] != kToLower[haystack[i] & 255]) break;
|
||||
if (!needle[i])
|
||||
return (/*unconst*/ char *)haystack;
|
||||
if (!haystack[i])
|
||||
break;
|
||||
if (kToLower[needle[i] & 255] != kToLower[haystack[i] & 255])
|
||||
break;
|
||||
}
|
||||
if (!*haystack++) break;
|
||||
if (!*haystack++)
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -31,14 +31,19 @@
|
|||
|
||||
char *strstr_naive(const char *haystack, const char *needle) {
|
||||
size_t i;
|
||||
if (haystack == needle || !*needle) return (void *)haystack;
|
||||
if (haystack == needle || !*needle)
|
||||
return (void *)haystack;
|
||||
for (;;) {
|
||||
for (i = 0;; ++i) {
|
||||
if (!needle[i]) return (/*unconst*/ char *)haystack;
|
||||
if (!haystack[i]) break;
|
||||
if (needle[i] != haystack[i]) break;
|
||||
if (!needle[i])
|
||||
return (/*unconst*/ char *)haystack;
|
||||
if (!haystack[i])
|
||||
break;
|
||||
if (needle[i] != haystack[i])
|
||||
break;
|
||||
}
|
||||
if (!*haystack++) break;
|
||||
if (!*haystack++)
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -92,7 +92,8 @@ TEST(makecontext, crash) {
|
|||
}
|
||||
|
||||
TEST(makecontext, backtrace) {
|
||||
if (IsTiny()) return; // doesn't print full crash report
|
||||
if (IsTiny())
|
||||
return; // doesn't print full crash report
|
||||
SPAWN(fork);
|
||||
if (IsWindows()) {
|
||||
__klog_handle =
|
||||
|
@ -109,7 +110,8 @@ TEST(makecontext, backtrace) {
|
|||
makecontext(&uc, itsatrap, 2, 123, 456);
|
||||
setcontext(&uc);
|
||||
TERMS(SIGSEGV);
|
||||
if (!GetSymbolTable()) return;
|
||||
if (!GetSymbolTable())
|
||||
return;
|
||||
char *log = gc(xslurp("log", 0));
|
||||
EXPECT_NE(0, strstr(log, "itsatrap"));
|
||||
EXPECT_NE(0, strstr(log, "runcontext"));
|
||||
|
|
|
@ -41,14 +41,17 @@ int Put(long v, nsync_time abs_deadline) {
|
|||
}
|
||||
if (count != limit) {
|
||||
int i = pos + count;
|
||||
if (limit <= i) i -= limit;
|
||||
if (limit <= i)
|
||||
i -= limit;
|
||||
data[i] = v;
|
||||
if (count == 0) wake = 1;
|
||||
if (count == 0)
|
||||
wake = 1;
|
||||
count++;
|
||||
added = 1;
|
||||
}
|
||||
nsync_mu_unlock(&mu);
|
||||
if (wake) nsync_cv_broadcast(&non_empty);
|
||||
if (wake)
|
||||
nsync_cv_broadcast(&non_empty);
|
||||
return added;
|
||||
}
|
||||
|
||||
|
|
|
@ -97,10 +97,12 @@ TEST(pthread_cancel, synchronous) {
|
|||
TEST(pthread_cancel, synchronous_deferred) {
|
||||
void *rc;
|
||||
pthread_t th;
|
||||
if (!IsWindows()) return;
|
||||
if (!IsWindows())
|
||||
return;
|
||||
ASSERT_SYS(0, 0, pipe(pfds));
|
||||
ASSERT_EQ(0, pthread_create(&th, 0, Worker, 0));
|
||||
while (!ready) pthread_yield();
|
||||
while (!ready)
|
||||
pthread_yield();
|
||||
ASSERT_SYS(0, 0, usleep(10));
|
||||
EXPECT_EQ(0, pthread_cancel(th));
|
||||
EXPECT_EQ(0, pthread_join(th, &rc));
|
||||
|
@ -257,7 +259,8 @@ TEST(pthread_cancel, async) {
|
|||
is_in_infinite_loop = false;
|
||||
key_destructor_was_run = false;
|
||||
ASSERT_EQ(0, pthread_create(&th, 0, CpuBoundWorker, 0));
|
||||
while (!is_in_infinite_loop) pthread_yield();
|
||||
while (!is_in_infinite_loop)
|
||||
pthread_yield();
|
||||
ASSERT_EQ(0, pthread_cancel(th));
|
||||
ASSERT_EQ(0, pthread_join(th, &rc));
|
||||
ASSERT_EQ(PTHREAD_CANCELED, rc);
|
||||
|
@ -289,7 +292,8 @@ TEST(pthread_cancel, self_asynchronous_takesImmediateEffect) {
|
|||
atomic_bool was_completed;
|
||||
|
||||
void WaitUntilReady(void) {
|
||||
while (!ready) pthread_yield();
|
||||
while (!ready)
|
||||
pthread_yield();
|
||||
ASSERT_EQ(0, errno);
|
||||
ASSERT_SYS(0, 0, usleep(1000));
|
||||
}
|
||||
|
|
|
@ -41,14 +41,17 @@ int Put(long v, struct timespec *abs_deadline) {
|
|||
}
|
||||
if (count != limit) {
|
||||
int i = pos + count;
|
||||
if (limit <= i) i -= limit;
|
||||
if (limit <= i)
|
||||
i -= limit;
|
||||
data[i] = v;
|
||||
if (count == 0) wake = 1;
|
||||
if (count == 0)
|
||||
wake = 1;
|
||||
count++;
|
||||
added = 1;
|
||||
}
|
||||
pthread_mutex_unlock(&mu);
|
||||
if (wake) pthread_cond_broadcast(&non_empty);
|
||||
if (wake)
|
||||
pthread_cond_broadcast(&non_empty);
|
||||
return added;
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue