mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-03 11:12:27 +00:00
Improve build latency
This commit is contained in:
parent
8d8aecb6d9
commit
4ed4a1095a
7 changed files with 247 additions and 222 deletions
|
@ -326,120 +326,6 @@ TEST(open, lotsOfFds) {
|
|||
}
|
||||
}
|
||||
|
||||
static int64_t GetInode(const char *path) {
|
||||
struct stat st;
|
||||
ASSERT_SYS(0, 0, stat(path, &st));
|
||||
return st.st_ino;
|
||||
}
|
||||
|
||||
TEST(open, drive) {
|
||||
if (!IsWindows())
|
||||
return;
|
||||
ASSERT_NE(GetInode("/"), GetInode("."));
|
||||
ASSERT_EQ(GetInode("/"), GetInode("/c")); // sorry you have to run on c:/
|
||||
ASSERT_EQ(GetInode("/"), GetInode("/c/"));
|
||||
ASSERT_SYS(0, 3, open("/", O_RDONLY));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(open, readOnlyCreatMode) {
|
||||
char buf[8];
|
||||
struct stat st;
|
||||
ASSERT_SYS(0, 3, open("x", O_RDWR | O_CREAT | O_TRUNC, 0500));
|
||||
ASSERT_SYS(0, 2, pwrite(3, "MZ", 2, 0));
|
||||
ASSERT_SYS(0, 2, pread(3, buf, 8, 0));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
ASSERT_SYS(0, 0, stat("x", &st));
|
||||
ASSERT_EQ(0100500, st.st_mode);
|
||||
if (getuid()) {
|
||||
ASSERT_SYS(EACCES, -1, open("x", O_RDWR));
|
||||
ASSERT_SYS(EACCES, -1, open("x", O_RDWR | O_CREAT, 0666));
|
||||
} else {
|
||||
// root is invulnerable to eacces
|
||||
ASSERT_SYS(0, 3, open("x", O_RDWR));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
ASSERT_SYS(0, 3, open("x", O_RDWR | O_CREAT, 0666));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
SPAWN(fork);
|
||||
setuid(1000);
|
||||
setgid(1000);
|
||||
ASSERT_SYS(EACCES, -1, open("x", O_RDWR));
|
||||
ASSERT_SYS(EACCES, -1, open("x", O_RDWR | O_CREAT, 0666));
|
||||
EXITS(0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(open, parentSymlink) {
|
||||
struct stat st;
|
||||
ASSERT_SYS(0, 0, mkdir("parent", 0755));
|
||||
// create directory symlink
|
||||
ASSERT_SYS(0, 0, symlink("parent", "parent-link"));
|
||||
// test the symlink we just made is a symlink
|
||||
ASSERT_SYS(0, 0, lstat("parent-link", &st));
|
||||
ASSERT_TRUE(S_ISLNK(st.st_mode));
|
||||
// create regular file when parent component is symlink dir
|
||||
ASSERT_SYS(0, 0, touch("parent-link/regular", 0644));
|
||||
// test stat works
|
||||
ASSERT_SYS(0, 0, stat("parent-link/regular", &st));
|
||||
ASSERT_TRUE(S_ISREG(st.st_mode));
|
||||
// test open works
|
||||
ASSERT_SYS(0, 3, open("parent-link/regular", O_RDONLY));
|
||||
ASSERT_SYS(0, 0, fstat(3, &st));
|
||||
ASSERT_TRUE(S_ISREG(st.st_mode));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
// test O_NOFOLLOW doesn't apply to parent components
|
||||
ASSERT_SYS(0, 3, open("parent-link/regular", O_RDONLY | O_NOFOLLOW));
|
||||
ASSERT_SYS(0, 0, fstat(3, &st));
|
||||
ASSERT_TRUE(S_ISREG(st.st_mode));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
// create regular symlink
|
||||
ASSERT_SYS(0, 0, symlink("regular", "parent-link/regular-link"));
|
||||
// test stat works
|
||||
ASSERT_SYS(0, 0, stat("parent-link/regular-link", &st));
|
||||
ASSERT_TRUE(S_ISREG(st.st_mode));
|
||||
ASSERT_SYS(0, 0, lstat("parent-link/regular-link", &st));
|
||||
ASSERT_TRUE(S_ISLNK(st.st_mode));
|
||||
// test open works
|
||||
ASSERT_SYS(0, 3, open("parent-link/regular-link", O_RDONLY));
|
||||
ASSERT_SYS(0, 0, fstat(3, &st));
|
||||
ASSERT_TRUE(S_ISREG(st.st_mode));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
// test O_NOFOLLOW applies to last component
|
||||
ASSERT_SYS(ELOOP, -1,
|
||||
open("parent-link/regular-link", O_RDONLY | O_NOFOLLOW));
|
||||
}
|
||||
|
||||
TEST(open, readonlyCreateMode_dontChangeStatusIfExists) {
|
||||
char buf[8];
|
||||
struct stat st;
|
||||
ASSERT_SYS(0, 3, creat("wut", 0700));
|
||||
ASSERT_SYS(0, 2, pwrite(3, "MZ", 2, 0));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
// since the file already exists, unix doesn't change read-only
|
||||
ASSERT_SYS(0, 3, open("wut", O_CREAT | O_TRUNC | O_RDWR, 0500));
|
||||
ASSERT_SYS(0, 0, pread(3, buf, 8, 0));
|
||||
ASSERT_SYS(0, 0, fstat(3, &st));
|
||||
ASSERT_EQ(0100600, st.st_mode & 0700666);
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(open, creatRdonly) {
|
||||
char buf[8];
|
||||
ASSERT_SYS(EINVAL, -1, open("foo", O_CREAT | O_TRUNC | O_RDONLY, 0700));
|
||||
ASSERT_SYS(0, 3, open("foo", O_CREAT | O_RDONLY, 0700));
|
||||
ASSERT_SYS(EBADF, -1, pwrite(3, "MZ", 2, 0));
|
||||
ASSERT_SYS(0, 0, pread(3, buf, 8, 0));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(open, sequentialRandom_EINVAL) {
|
||||
if (!IsWindows())
|
||||
return;
|
||||
ASSERT_SYS(
|
||||
EINVAL, -1,
|
||||
open("foo", O_CREAT | O_TRUNC | O_RDWR | O_SEQUENTIAL | O_RANDOM, 0700));
|
||||
}
|
||||
|
||||
// "If O_CREAT is set and the file did not previously exist, upon
|
||||
// successful completion, open() shall mark for update the last data
|
||||
// access, last data modification, and last file status change
|
||||
|
@ -485,33 +371,3 @@ TEST(open, trunc_touchesMtimCtim) {
|
|||
EXPECT_EQ(1, timespec_cmp(st.st_mtim, birth));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
TEST(open, mereOpen_doesntTouch) {
|
||||
struct stat st;
|
||||
struct timespec birth;
|
||||
ASSERT_SYS(0, 0, touch("regular", 0755));
|
||||
ASSERT_SYS(0, 0, stat("regular", &st));
|
||||
birth = st.st_ctim;
|
||||
sleep(2);
|
||||
ASSERT_SYS(0, 3, open("regular", O_RDWR));
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
ASSERT_SYS(0, 0, stat("regular", &st));
|
||||
EXPECT_EQ(0, timespec_cmp(st.st_ctim, birth));
|
||||
#if 0 // todo: why flake on rhel7?
|
||||
EXPECT_EQ(0, timespec_cmp(st.st_mtim, birth));
|
||||
EXPECT_EQ(0, timespec_cmp(st.st_atim, birth));
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(open, canTruncateExistingFile) {
|
||||
struct stat st;
|
||||
ASSERT_SYS(0, 0, xbarf("foo", "hello", -1));
|
||||
ASSERT_SYS(0, 0, stat("foo", &st));
|
||||
ASSERT_EQ(5, st.st_size);
|
||||
ASSERT_SYS(0, 3, open("foo", O_RDWR | O_TRUNC));
|
||||
ASSERT_SYS(0, 0, fstat(3, &st));
|
||||
ASSERT_EQ(0, st.st_size);
|
||||
ASSERT_SYS(0, 0, close(3));
|
||||
ASSERT_SYS(0, 0, stat("foo", &st));
|
||||
ASSERT_EQ(0, st.st_size);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue