mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-24 14:22:28 +00:00
Initial import
This commit is contained in:
commit
c91b3c5006
14915 changed files with 590219 additions and 0 deletions
40
test/libc/calls/access_test.c
Normal file
40
test/libc/calls/access_test.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/sysv/consts/ok.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
textstartup static void init(void) {
|
||||
/* xxx: need better test environment thing */
|
||||
if (!fileexists("test/libc/access_test.c")) exit(0);
|
||||
}
|
||||
const void *const ctors[] initarray = {init};
|
||||
|
||||
TEST(access, readDirectory) { ASSERT_EQ(0, access("test/libc/", F_OK)); }
|
||||
|
||||
TEST(access, readThisCode) {
|
||||
ASSERT_EQ(0, access("test/libc/access_test.c", R_OK));
|
||||
}
|
||||
|
||||
TEST(access, runThisExecutable) {
|
||||
ASSERT_EQ(0, access(program_invocation_name, R_OK | X_OK));
|
||||
}
|
90
test/libc/calls/fallocate_test.c
Normal file
90
test/libc/calls/fallocate_test.c
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
int rc;
|
||||
struct stat st;
|
||||
const char *path;
|
||||
int64_t fd, emptyspace, physicalspace;
|
||||
|
||||
TEST(fallocate_000, setup) {
|
||||
mkdir("o", 0755);
|
||||
mkdir("o/tmp", 0755);
|
||||
}
|
||||
|
||||
TEST(fallocate_010, testBadFileDescriptor) {
|
||||
if (IsFreebsd()) return; /* TODO: FreeBSD failing to set carry flag bug */
|
||||
ASSERT_EQ(-1, fallocate(/*RHEL*/ 5, 0, 0, 1));
|
||||
if (errno == ENOSYS) exit(0);
|
||||
EXPECT_EQ(EBADF, errno);
|
||||
}
|
||||
|
||||
TEST(fallocate_020, test) {
|
||||
path = gc(xasprintf("o/tmp/%s.%d", program_invocation_short_name));
|
||||
ASSERT_NE(-1, (fd = creat(path, 0755)));
|
||||
ASSERT_EQ(5, write(fd, "hello", 5));
|
||||
errno = 31337;
|
||||
ASSERT_NE(-1, fallocate(fd, 0, 0, 31337));
|
||||
EXPECT_EQ(31337, errno);
|
||||
ASSERT_EQ(5, write(fd, "world", 5));
|
||||
ASSERT_NE(-1, close(fd));
|
||||
ASSERT_NE(-1, stat(path, &st));
|
||||
ASSERT_EQ(31337, st.st_size);
|
||||
ASSERT_BINEQ(u"helloworld", gc(slurp(path, NULL)));
|
||||
unlink(path);
|
||||
}
|
||||
|
||||
TEST(fallocate_020, testSparseFile) {
|
||||
ASSERT_NE(-1, stat("o", &st));
|
||||
emptyspace = rounddown(6 * 1000 * 1000 * 1000, st.st_blksize);
|
||||
physicalspace = roundup(4096, st.st_blksize);
|
||||
path = gc(xasprintf("o/tmp/%s.%d", program_invocation_short_name, getpid()));
|
||||
ASSERT_NE(-1, (fd = creat(path, 0755)));
|
||||
rc = fallocate(fd, 0, emptyspace, physicalspace);
|
||||
if (rc == -1) {
|
||||
/*
|
||||
* most important feature is failing w/ enosys if not possible to
|
||||
* allocate storage like a central banker prints money.
|
||||
*/
|
||||
ASSERT_EQ(ENOSYS, errno);
|
||||
}
|
||||
ASSERT_EQ(emptyspace, lseek(fd, emptyspace, SEEK_SET));
|
||||
ASSERT_EQ(5, write(fd, "hello", 5));
|
||||
ASSERT_NE(-1, fsync(fd));
|
||||
ASSERT_NE(-1, close(fd));
|
||||
ASSERT_NE(-1, stat(path, &st));
|
||||
EXPECT_EQ(emptyspace + physicalspace, st.st_size);
|
||||
/*
|
||||
* don't care how much physical space system needs, so long as it's
|
||||
* transparent and less than 10 percent the fake space
|
||||
*/
|
||||
EXPECT_NE(0, st.st_blocks);
|
||||
EXPECT_LT(st.st_blocks * 512, emptyspace / 10);
|
||||
unlink(path);
|
||||
}
|
49
test/libc/calls/ftruncate_test.c
Normal file
49
test/libc/calls/ftruncate_test.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
int64_t fd;
|
||||
struct stat st;
|
||||
const char *path;
|
||||
|
||||
TEST(ftruncate, test) {
|
||||
mkdir("o", 0755);
|
||||
mkdir("o/tmp", 0755);
|
||||
path = gc(xasprintf("o/tmp/%s.%d", program_invocation_short_name, getpid()));
|
||||
ASSERT_NE(-1, (fd = creat(path, 0755)));
|
||||
ASSERT_EQ(5, write(fd, "hello", 5));
|
||||
errno = 31337;
|
||||
ASSERT_NE(-1, ftruncate(fd, 31337));
|
||||
EXPECT_EQ(31337, errno);
|
||||
ASSERT_EQ(5, write(fd, "world", 5));
|
||||
ASSERT_NE(-1, close(fd));
|
||||
ASSERT_NE(-1, stat(path, &st));
|
||||
ASSERT_EQ(31337, st.st_size);
|
||||
ASSERT_BINEQ(u"helloworld", gc(slurp(path, NULL)));
|
||||
unlink(path);
|
||||
}
|
77
test/libc/calls/hefty/commandv_test.c
Normal file
77
test/libc/calls/hefty/commandv_test.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
uint64_t i;
|
||||
const char *oldpath, *bindir, *homedir, *binsh, *sh;
|
||||
|
||||
TEST(commandv_00, todo) { /* TODO(jart): Improve this on Windows. */
|
||||
if (IsWindows()) exit(0);
|
||||
}
|
||||
|
||||
TEST(commandv_001, setupFiles) {
|
||||
mkdir("o", 0755);
|
||||
mkdir("o/tmp", 0755);
|
||||
oldpath = strdup(getenv("PATH"));
|
||||
homedir = xasprintf("o/tmp/home.%d", getpid());
|
||||
bindir = xasprintf("o/tmp/bin.%d", getpid());
|
||||
binsh = xasprintf("%s/sh.com", bindir);
|
||||
ASSERT_NE(-1, mkdir(homedir, 0755));
|
||||
ASSERT_NE(-1, mkdir(bindir, 0755));
|
||||
ASSERT_NE(-1, touch(binsh, 0755));
|
||||
ASSERT_NE(-1, setenv("PATH", bindir, true));
|
||||
}
|
||||
|
||||
TEST(commandv_010, testSlashes_wontSearchPath_butChecksAccess) {
|
||||
sh = defer(unlink, gc(xasprintf("%s/sh.com", homedir)));
|
||||
EXPECT_NE(-1, touch(sh, 0755));
|
||||
i = g_syscount;
|
||||
EXPECT_STREQ(sh, commandv(sh));
|
||||
if (!IsWindows()) EXPECT_EQ(i + 1 /* access() */, g_syscount);
|
||||
}
|
||||
|
||||
TEST(commandv_010, testNoSlashes_searchesPath_withMemoization) {
|
||||
if (IsTiny()) return;
|
||||
i = g_syscount;
|
||||
EXPECT_STREQ(binsh, commandv("sh.com"));
|
||||
if (!IsWindows()) EXPECT_GT(g_syscount, i);
|
||||
i = g_syscount;
|
||||
EXPECT_STREQ(binsh, commandv("sh.com"));
|
||||
if (!IsWindows()) EXPECT_EQ(g_syscount, i);
|
||||
}
|
||||
|
||||
TEST(commandv_999, teardown) {
|
||||
setenv("PATH", oldpath, true);
|
||||
unlink(binsh);
|
||||
rmdir(bindir);
|
||||
rmdir(homedir);
|
||||
free(bindir);
|
||||
free(binsh);
|
||||
free(homedir);
|
||||
free(oldpath);
|
||||
}
|
54
test/libc/calls/hefty/dirstream_test.c
Normal file
54
test/libc/calls/hefty/dirstream_test.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/dirent.h"
|
||||
#include "libc/rand/rand.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
TEST(dirstream, test) {
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
char *dpath, *file1, *file2;
|
||||
dpath = gc(xasprintf("%s%s%lu", kTmpPath, "dirstream", rand32()));
|
||||
file1 = gc(xasprintf("%s/%s", dpath, "foo"));
|
||||
file2 = gc(xasprintf("%s/%s", dpath, "bar"));
|
||||
EXPECT_NE(-1, mkdir(dpath, 0755));
|
||||
EXPECT_NE(-1, touch(file1, 0644));
|
||||
EXPECT_NE(-1, touch(file2, 0644));
|
||||
|
||||
EXPECT_TRUE(NULL != (dir = opendir(dpath)));
|
||||
bool hasfoo = false;
|
||||
bool hasbar = false;
|
||||
while ((ent = readdir(dir))) {
|
||||
if (strcmp(ent->d_name, "foo")) hasfoo = true;
|
||||
if (strcmp(ent->d_name, "bar")) hasbar = true;
|
||||
}
|
||||
EXPECT_TRUE(hasfoo);
|
||||
EXPECT_TRUE(hasbar);
|
||||
EXPECT_NE(-1, closedir(dir));
|
||||
|
||||
EXPECT_NE(-1, unlink(file2));
|
||||
EXPECT_NE(-1, unlink(file1));
|
||||
EXPECT_NE(-1, rmdir(dpath));
|
||||
}
|
77
test/libc/calls/hefty/mkntcmdline_test.c
Normal file
77
test/libc/calls/hefty/mkntcmdline_test.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/hefty/ntspawn.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(mkntcmdline, emptyArgvList_isntValidCommandLine) {
|
||||
char *argv[] = {NULL};
|
||||
EXPECT_EQ(NULL, gc(mkntcmdline(argv)));
|
||||
EXPECT_EQ(EINVAL, errno);
|
||||
}
|
||||
|
||||
TEST(mkntcmdline, emptyArgs_isEmptyString) {
|
||||
char *argv[] = {"", NULL};
|
||||
EXPECT_STREQ(u"", gc(mkntcmdline(argv)));
|
||||
}
|
||||
|
||||
TEST(mkntcmdline, ignoranceIsBliss) {
|
||||
char *argv[] = {"echo", "hello", "world", NULL};
|
||||
EXPECT_STREQ(u"echo hello world", gc(mkntcmdline(argv)));
|
||||
}
|
||||
|
||||
TEST(mkntcmdline, spaceInArgument_getQuotesWrappedAround) {
|
||||
char *argv[] = {"echo", "hello there", "world", NULL};
|
||||
EXPECT_STREQ(u"echo \"hello there\" world", gc(mkntcmdline(argv)));
|
||||
}
|
||||
|
||||
TEST(mkntcmdline, justQuote) {
|
||||
char *argv[] = {"\"", NULL};
|
||||
EXPECT_STREQ(u"\"\\\"\"", gc(mkntcmdline(argv)));
|
||||
}
|
||||
|
||||
TEST(mkntcmdline, justSlash) {
|
||||
char *argv[] = {"\\", NULL};
|
||||
EXPECT_STREQ(u"\\", gc(mkntcmdline(argv)));
|
||||
}
|
||||
|
||||
TEST(mkntcmdline, justSlashQuote) {
|
||||
char *argv[] = {"\\\"", NULL};
|
||||
EXPECT_STREQ(u"\"\\\\\\\"\"" /* "\\\"" */, gc(mkntcmdline(argv)));
|
||||
}
|
||||
|
||||
TEST(mkntcmdline, basicQuoting) {
|
||||
char *argv[] = {"a\"b c", "d", NULL};
|
||||
EXPECT_STREQ(u"\"a\\\"b c\" d" /* "a\"b c" d */, gc(mkntcmdline(argv)));
|
||||
}
|
||||
|
||||
TEST(mkntcmdline, testUnicode) {
|
||||
char *argv1[] = {
|
||||
gc(strdup("(╯°□°)╯")),
|
||||
gc(strdup("要依法治国是赞美那些谁是公义的和惩罚恶人。 - 韩非")),
|
||||
NULL,
|
||||
};
|
||||
EXPECT_STREQ(
|
||||
u"(╯°□°)╯ \"要依法治国是赞美那些谁是公义的和惩罚恶人。 - 韩非\"",
|
||||
gc(mkntcmdline(memcpy(gc(malloc(sizeof(argv1))), argv1, sizeof(argv1)))));
|
||||
}
|
39
test/libc/calls/hefty/mkntenvblock_test.c
Normal file
39
test/libc/calls/hefty/mkntenvblock_test.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/calls/hefty/ntspawn.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(mkntenvblock, emptyList_onlyOutputsDoubleNulStringTerminator) {
|
||||
char *envp[] = {NULL};
|
||||
ASSERT_BINEQ(u" ", gc(mkntenvblock(envp)));
|
||||
}
|
||||
|
||||
TEST(mkntenvblock, envp_becomesSortedDoubleNulTerminatedUtf16String) {
|
||||
char *envp[] = {"u=b", "c=d", "韩=非", "uh=d", "hduc=d", NULL};
|
||||
ASSERT_BINEQ(
|
||||
u"c = d "
|
||||
u"h d u c = d "
|
||||
u"u = b "
|
||||
u"u h = d "
|
||||
u"Θù= ^ù "
|
||||
u" ",
|
||||
gc(mkntenvblock(envp)));
|
||||
}
|
33
test/libc/calls/hefty/sortenvp_test.c
Normal file
33
test/libc/calls/hefty/sortenvp_test.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/calls/hefty/ntspawn.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(sortenvp, test) {
|
||||
char *envp[] = {"u=b", "c=d", "韩=非", "uh=d", "hduc=d", NULL};
|
||||
char **sortedenvp = gc(sortenvp(envp));
|
||||
EXPECT_STREQ("c=d", sortedenvp[0]);
|
||||
EXPECT_STREQ("hduc=d", sortedenvp[1]);
|
||||
EXPECT_STREQ("u=b", sortedenvp[2]);
|
||||
EXPECT_STREQ("uh=d", sortedenvp[3]);
|
||||
EXPECT_STREQ("韩=非", sortedenvp[4]);
|
||||
EXPECT_EQ(NULL, sortedenvp[5]);
|
||||
}
|
74
test/libc/calls/hefty/spawnve_test.c
Normal file
74
test/libc/calls/hefty/spawnve_test.c
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/hefty/spawn.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/auxv.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
#define CMD (IsWindows() ? "cmd" : "sh")
|
||||
#define ARG (IsWindows() ? "/c" : "-c")
|
||||
#define COD (IsWindows() ? "echo %BOOP%" : "echo $BOOP")
|
||||
#define OUT (IsWindows() ? u"hello♪◙" : u"hello◙")
|
||||
|
||||
TEST(spawnve, testIpc) {
|
||||
ssize_t got;
|
||||
int pid, wstatus;
|
||||
char buf[16] = {0};
|
||||
int tubes[3] = {STDIN_FILENO, -1, STDERR_FILENO};
|
||||
errno = 0;
|
||||
setenv("BOOP", "hello", true);
|
||||
ASSERT_EQ(0, errno);
|
||||
ASSERT_NE(-1, (pid = spawnlp(0, tubes, CMD, CMD, ARG, COD, NULL)));
|
||||
ASSERT_EQ(0, errno);
|
||||
ASSERT_NE(-1, (got = read(tubes[1], buf, sizeof(buf))));
|
||||
ASSERT_EQ(0, errno);
|
||||
ASSERT_NE(-1, waitpid(pid, &wstatus, 0));
|
||||
ASSERT_EQ(0, errno);
|
||||
EXPECT_EQ(0, WEXITSTATUS(wstatus));
|
||||
EXPECT_BINEQ(OUT, buf);
|
||||
}
|
||||
|
||||
TEST(spawnve, testExit) {
|
||||
int pid, wstatus;
|
||||
ASSERT_NE(-1, (pid = spawnlp(0, NULL, CMD, CMD, ARG, "exit 42", NULL)));
|
||||
ASSERT_NE(-1, waitpid(pid, &wstatus, 0));
|
||||
EXPECT_EQ(42, WEXITSTATUS(wstatus));
|
||||
}
|
||||
|
||||
TEST(spawnve, testSpawnSelf) {
|
||||
int pid, wstatus;
|
||||
ASSERT_NE(-1,
|
||||
(pid = spawnlp(0, NULL, (const char *)getauxval(AT_EXECFN),
|
||||
program_invocation_name, "--testSpawnSelf", NULL)));
|
||||
ASSERT_NE(-1, waitpid(pid, &wstatus, 0));
|
||||
EXPECT_EQ(123, WEXITSTATUS(wstatus));
|
||||
}
|
||||
static textstartup void onspawnself() {
|
||||
if (g_argc > 1 && strcmp(g_argv[1], "--testSpawnSelf") == 0) {
|
||||
_exit(123);
|
||||
}
|
||||
}
|
||||
const void *const onspawnself_ctor[] initarray = {onspawnself};
|
45
test/libc/calls/mkntpath_test.c
Normal file
45
test/libc/calls/mkntpath_test.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
char16_t p[PATH_MAX];
|
||||
|
||||
TEST(mkntpath, testEmpty) {
|
||||
EXPECT_EQ(0, mkntpath("", p));
|
||||
EXPECT_STREQ(u"", p);
|
||||
}
|
||||
|
||||
TEST(mkntpath, testSlashes) {
|
||||
/*
|
||||
* The Windows command prompt works fine with all reasonable
|
||||
* unix-style paths. There only seems to be one exception, and that's
|
||||
* all it takes to make the feature entirely useless to us, similar to
|
||||
* the law of noncontradiction. We address the issue as follows:
|
||||
*/
|
||||
EXPECT_EQ(9, mkntpath("o/foo.com", p));
|
||||
EXPECT_STREQ(u"o\\foo.com", p);
|
||||
}
|
||||
|
||||
TEST(mkntpath, testUnicode) {
|
||||
EXPECT_EQ(20, mkntpath("C:\\𐌰𐌱𐌲𐌳\\𐌴𐌵𐌶𐌷", p));
|
||||
EXPECT_STREQ(u"C:\\𐌰𐌱𐌲𐌳\\𐌴𐌵𐌶𐌷", p);
|
||||
}
|
34
test/libc/calls/signal_test.c
Normal file
34
test/libc/calls/signal_test.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
testonly void OnCtrlC(int sig) { _exit(0); }
|
||||
|
||||
TEST(signal, test) {
|
||||
if (IsWindows()) return; /* omg */
|
||||
ASSERT_NE(SIG_ERR, signal(SIGINT, OnCtrlC));
|
||||
ASSERT_NE(-1, raise(SIGINT));
|
||||
die();
|
||||
}
|
43
test/libc/calls/stat_test.c
Normal file
43
test/libc/calls/stat_test.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/nt/files.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
char *pathname;
|
||||
struct stat st;
|
||||
|
||||
TEST(stat_000, setupFiles) {
|
||||
mkdir("o", 0755);
|
||||
mkdir("o/tmp", 0755);
|
||||
}
|
||||
|
||||
TEST(stat_010, testEmptyFile_sizeIsZero) {
|
||||
pathname = defer(
|
||||
unlink,
|
||||
gc(xasprintf("o/tmp/%s.%d", program_invocation_short_name, getpid())));
|
||||
ASSERT_NE(-1, touch(pathname, 0755));
|
||||
EXPECT_NE(-1, stat(pathname, &st));
|
||||
EXPECT_EQ(0, st.st_size);
|
||||
}
|
60
test/libc/calls/test.mk
Normal file
60
test/libc/calls/test.mk
Normal file
|
@ -0,0 +1,60 @@
|
|||
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
|
||||
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
|
||||
|
||||
PKGS += TEST_LIBC_CALLS
|
||||
|
||||
TEST_LIBC_CALLS_SRCS := \
|
||||
$(wildcard test/libc/calls/*.c) \
|
||||
$(wildcard test/libc/calls/hefty/*.c)
|
||||
TEST_LIBC_CALLS_SRCS_TEST = $(filter %_test.c,$(TEST_LIBC_CALLS_SRCS))
|
||||
TEST_LIBC_CALLS_COMS = $(TEST_LIBC_CALLS_OBJS:%.o=%.com)
|
||||
|
||||
TEST_LIBC_CALLS_OBJS = \
|
||||
$(TEST_LIBC_CALLS_SRCS:%=o/$(MODE)/%.zip.o) \
|
||||
$(TEST_LIBC_CALLS_SRCS:%.c=o/$(MODE)/%.o)
|
||||
|
||||
TEST_LIBC_CALLS_BINS = \
|
||||
$(TEST_LIBC_CALLS_COMS) \
|
||||
$(TEST_LIBC_CALLS_COMS:%=%.dbg)
|
||||
|
||||
TEST_LIBC_CALLS_TESTS = \
|
||||
$(TEST_LIBC_CALLS_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
|
||||
|
||||
TEST_LIBC_CALLS_CHECKS = \
|
||||
$(TEST_LIBC_CALLS_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
|
||||
|
||||
TEST_LIBC_CALLS_DIRECTDEPS = \
|
||||
LIBC_CALLS \
|
||||
LIBC_CALLS_HEFTY \
|
||||
LIBC_FMT \
|
||||
LIBC_LOG \
|
||||
LIBC_MEM \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_STR \
|
||||
LIBC_RAND \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV \
|
||||
LIBC_TESTLIB \
|
||||
LIBC_X
|
||||
|
||||
TEST_LIBC_CALLS_DEPS := \
|
||||
$(call uniq,$(foreach x,$(TEST_LIBC_CALLS_DIRECTDEPS),$($(x))))
|
||||
|
||||
o/$(MODE)/test/libc/calls/calls.pkg: \
|
||||
$(TEST_LIBC_CALLS_OBJS) \
|
||||
$(foreach x,$(TEST_LIBC_CALLS_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
o/$(MODE)/test/libc/calls/%.com.dbg: \
|
||||
$(TEST_LIBC_CALLS_DEPS) \
|
||||
o/$(MODE)/test/libc/calls/%.o \
|
||||
o/$(MODE)/test/libc/calls/calls.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
@$(APELINK)
|
||||
|
||||
.PHONY: o/$(MODE)/test/libc/calls
|
||||
o/$(MODE)/test/libc/calls: \
|
||||
$(TEST_LIBC_CALLS_BINS) \
|
||||
$(TEST_LIBC_CALLS_CHECKS)
|
Loading…
Add table
Add a link
Reference in a new issue