mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 06:48:31 +00:00
Add epoll and do more release readiness changes
This change also pays off some of the remaining technical debt with stdio, file descriptors, and memory managemnt polyfills.
This commit is contained in:
parent
a9ea949df8
commit
3e4fd4b0ad
271 changed files with 5706 additions and 1365 deletions
|
@ -40,14 +40,14 @@ TEST(parsehoststxt, testEmpty) {
|
|||
}
|
||||
|
||||
TEST(parsehoststxt, testCorrectlyTokenizesAndSorts) {
|
||||
const char kInput[] =
|
||||
"# this is a comment\n"
|
||||
"# IP HOST1 HOST2\n"
|
||||
"203.0.113.1 lol.example. lol\n"
|
||||
"203.0.113.2 cat.example. cat\n";
|
||||
const char kInput[] = "# this is a comment\n"
|
||||
"# IP HOST1 HOST2\n"
|
||||
"203.0.113.1 lol.example. lol\n"
|
||||
"203.0.113.2 cat.example. cat\n";
|
||||
struct HostsTxt *ht = calloc(1, sizeof(struct HostsTxt));
|
||||
FILE *f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
ASSERT_EQ(strlen(kInput), fwrite(kInput, 1, strlen(kInput), f));
|
||||
fwrite(kInput, 1, strlen(kInput), f);
|
||||
rewind(f);
|
||||
ASSERT_EQ(0, parsehoststxt(ht, f));
|
||||
sorthoststxt(ht);
|
||||
ASSERT_EQ(4, ht->entries.i);
|
||||
|
@ -68,12 +68,10 @@ TEST(parsehoststxt, testCorrectlyTokenizesAndSorts) {
|
|||
}
|
||||
|
||||
TEST(parsehoststxt, testIpv6_isIgnored) {
|
||||
const char kInput[] =
|
||||
"::1 boop\n"
|
||||
"203.0.113.2 cat # ignore me\n";
|
||||
const char kInput[] = "::1 boop\n"
|
||||
"203.0.113.2 cat # ignore me\n";
|
||||
struct HostsTxt *ht = calloc(1, sizeof(struct HostsTxt));
|
||||
FILE *f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
ASSERT_EQ(strlen(kInput), fwrite(kInput, 1, strlen(kInput), f));
|
||||
FILE *f = fmemopen(kInput, strlen(kInput), "r+");
|
||||
ASSERT_EQ(0, parsehoststxt(ht, f));
|
||||
ASSERT_EQ(1, ht->entries.i);
|
||||
EXPECT_STREQ("cat", &ht->strings.p[ht->entries.p[0].name]);
|
||||
|
|
|
@ -46,8 +46,7 @@ TEST(parseresolvconf, testCorrectlyTokenizes) {
|
|||
"nameserver 203.0.113.2 \n"
|
||||
" nameserver 203.0.113.1\n";
|
||||
struct ResolvConf *rv = calloc(1, sizeof(struct ResolvConf));
|
||||
FILE *f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
ASSERT_EQ(strlen(kInput), fwrite(kInput, 1, strlen(kInput), f));
|
||||
FILE *f = fmemopen(kInput, strlen(kInput), "r+");
|
||||
ASSERT_EQ(2, parseresolvconf(rv, f));
|
||||
ASSERT_EQ(2, rv->nameservers.i);
|
||||
EXPECT_EQ(AF_INET, rv->nameservers.p[0].sin_family);
|
||||
|
|
|
@ -48,8 +48,7 @@ static const char kInput[] = "127.0.0.1 localhost\n"
|
|||
|
||||
TEST(resolvehoststxt, testBasicLookups) {
|
||||
struct HostsTxt *ht = calloc(1, sizeof(struct HostsTxt));
|
||||
FILE *f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
ASSERT_EQ(strlen(kInput), fwrite(kInput, 1, strlen(kInput), f));
|
||||
FILE *f = fmemopen(kInput, strlen(kInput), "r+");
|
||||
ASSERT_EQ(0, parsehoststxt(ht, f));
|
||||
sorthoststxt(ht);
|
||||
ASSERT_EQ(5, ht->entries.i);
|
||||
|
@ -66,8 +65,7 @@ TEST(resolvehoststxt, testBasicLookups) {
|
|||
|
||||
TEST(resolvehoststxt, testCanonicalize) {
|
||||
struct HostsTxt *ht = calloc(1, sizeof(struct HostsTxt));
|
||||
FILE *f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
ASSERT_EQ(strlen(kInput), fwrite(kInput, 1, strlen(kInput), f));
|
||||
FILE *f = fmemopen(kInput, strlen(kInput), "r+");
|
||||
ASSERT_EQ(0, parsehoststxt(ht, f));
|
||||
sorthoststxt(ht);
|
||||
ASSERT_EQ(5, ht->entries.i);
|
||||
|
|
|
@ -25,6 +25,7 @@ o/$(MODE)/test/libc/release/smoke.com: \
|
|||
-nostdlib \
|
||||
-nostdinc \
|
||||
-Wl,--oformat=binary \
|
||||
-Wl,-z,max-page-size=0x1000 \
|
||||
-Wl,-T,o/$(MODE)/ape/ape.lds \
|
||||
-include o/cosmopolitan.h \
|
||||
test/libc/release/smoke.c \
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
TEST(fgetwc, testAscii_oneChar) {
|
||||
FILE *f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
EXPECT_EQ('A', fputc('A', f));
|
||||
rewind(f);
|
||||
EXPECT_EQ('A', fgetc(f));
|
||||
fclose(f);
|
||||
}
|
||||
|
@ -32,6 +33,7 @@ TEST(fgetwc, testAscii_twoChar) {
|
|||
FILE *f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
EXPECT_EQ('A', fputc('A', f));
|
||||
EXPECT_EQ('B', fputc('B', f));
|
||||
rewind(f);
|
||||
EXPECT_EQ('A', fgetc(f));
|
||||
EXPECT_EQ('B', fgetc(f));
|
||||
fclose(f);
|
||||
|
@ -40,6 +42,7 @@ TEST(fgetwc, testAscii_twoChar) {
|
|||
TEST(fgetwc, testUnicode_oneChar) {
|
||||
FILE *f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
EXPECT_EQ(L'𐌰', fputwc(L'𐌰', f));
|
||||
rewind(f);
|
||||
EXPECT_EQ(L'𐌰', fgetwc(f));
|
||||
fclose(f);
|
||||
}
|
||||
|
@ -50,7 +53,20 @@ TEST(fgetwc, testUnicode_oneChar_writtenAsRawUtf8) {
|
|||
EXPECT_EQ(0x90, fputc(0x90, f));
|
||||
EXPECT_EQ(0x8C, fputc(0x8C, f));
|
||||
EXPECT_EQ(0xB0, fputc(0xB0, f));
|
||||
rewind(f);
|
||||
EXPECT_EQ(L'𐌰', fgetwc(f));
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
TEST(fgetwc, testUnicode_spuriousContChars_synchronizedBeforeRead) {
|
||||
FILE *f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
EXPECT_EQ(0x90, fputc(0x90, f));
|
||||
EXPECT_EQ(0x90, fputc(0x90, f));
|
||||
EXPECT_EQ(0xF0, fputc(0xF0, f));
|
||||
EXPECT_EQ(0x90, fputc(0x90, f));
|
||||
EXPECT_EQ(0x8C, fputc(0x8C, f));
|
||||
EXPECT_EQ(0xB0, fputc(0xB0, f));
|
||||
rewind(f);
|
||||
EXPECT_EQ(L'𐌰', fgetwc(f));
|
||||
EXPECT_EQ(-1u, fgetwc(f));
|
||||
fclose(f);
|
||||
}
|
||||
|
|
|
@ -17,54 +17,23 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
int pipefd[2];
|
||||
FILE *f, *reader, *writer;
|
||||
|
||||
TEST(fgetc, testEnd) {
|
||||
f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
EXPECT_EQ(EOF, fgetc(f));
|
||||
EXPECT_TRUE(feof(f));
|
||||
EXPECT_FALSE(ferror(f));
|
||||
EXPECT_EQ(0, fclose(f));
|
||||
TEST(fmemopen, testWriteRewindRead) {
|
||||
char c;
|
||||
FILE *f;
|
||||
f = fmemopen(NULL, BUFSIZ, "w+");
|
||||
EXPECT_EQ(1, fwrite("c", 1, 1, f));
|
||||
rewind(f);
|
||||
EXPECT_EQ(1, fread(&c, 1, 1, f));
|
||||
EXPECT_EQ('c', c);
|
||||
}
|
||||
|
||||
TEST(fgetwc, testEnd) {
|
||||
f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
EXPECT_EQ(WEOF, fgetwc(f));
|
||||
EXPECT_TRUE(feof(f));
|
||||
EXPECT_FALSE(ferror(f));
|
||||
EXPECT_EQ(0, fclose(f));
|
||||
}
|
||||
|
||||
TEST(fgetwc, testMultibyte) {
|
||||
f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
EXPECT_EQ(L'𝑥', fputwc(L'𝑥', f));
|
||||
EXPECT_EQ(L'𝑦', fputwc(L'𝑦', f));
|
||||
EXPECT_EQ(L'𝑧', fputwc(L'𝑧', f));
|
||||
EXPECT_EQ(L'𝑥', fgetwc(f));
|
||||
EXPECT_EQ(L'𝑦', fgetwc(f));
|
||||
EXPECT_EQ(L'𝑧', fgetwc(f));
|
||||
EXPECT_EQ(WEOF, fgetwc(f));
|
||||
EXPECT_TRUE(feof(f));
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
TEST(fgetc, testPipe) {
|
||||
ASSERT_NE(-1, pipe(pipefd));
|
||||
writer = fdopen(pipefd[1], "w");
|
||||
reader = fdopen(pipefd[0], "r");
|
||||
EXPECT_EQ('a', fputc('a', writer));
|
||||
EXPECT_EQ('b', fputc('b', writer));
|
||||
EXPECT_EQ('c', fputc('c', writer));
|
||||
EXPECT_EQ(3, fflush(writer));
|
||||
EXPECT_EQ('a', fgetc(reader));
|
||||
EXPECT_EQ('b', fgetc(reader));
|
||||
EXPECT_EQ('c', fgetc(reader));
|
||||
EXPECT_EQ(0, fclose(reader));
|
||||
EXPECT_EQ(0, fclose(writer));
|
||||
}
|
||||
/* TEST(fmemopen, testWriteRead_readsNothingButNotEof) { */
|
||||
/* char c; */
|
||||
/* FILE *f; */
|
||||
/* f = fmemopen(NULL, BUFSIZ, "w+"); */
|
||||
/* EXPECT_EQ(1, fwrite("c", 1, 1, f)); */
|
||||
/* EXPECT_EQ(0, fread(&c, 1, 1, f)); */
|
||||
/* } */
|
|
@ -20,10 +20,11 @@
|
|||
#include "libc/bits/bits.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(getline, testEmpty) {
|
||||
FILE *f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
FILE *f = fmemopen("", 0, "r+");
|
||||
char *line = NULL;
|
||||
size_t linesize = 0;
|
||||
EXPECT_EQ(-1, getline(&line, &linesize, f));
|
||||
|
@ -34,8 +35,7 @@ TEST(getline, testEmpty) {
|
|||
}
|
||||
|
||||
TEST(getline, testOneWithoutLineFeed) {
|
||||
FILE *f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
ASSERT_EQ(5, fwrite("hello", 1, 5, f));
|
||||
FILE *f = fmemopen("hello", 5, "r+");
|
||||
char *line = NULL;
|
||||
size_t linesize = 0;
|
||||
ASSERT_EQ(5, getline(&line, &linesize, f));
|
||||
|
@ -48,8 +48,8 @@ TEST(getline, testOneWithoutLineFeed) {
|
|||
}
|
||||
|
||||
TEST(getline, testTwoLines) {
|
||||
FILE *f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
ASSERT_EQ(12, fwrite("hello\nthere\n", 1, 12, f));
|
||||
const char *s = "hello\nthere\n";
|
||||
FILE *f = fmemopen(s, strlen(s), "r+");
|
||||
char *line = NULL;
|
||||
size_t linesize = 0;
|
||||
ASSERT_EQ(6, getline(&line, &linesize, f));
|
||||
|
@ -64,8 +64,8 @@ TEST(getline, testTwoLines) {
|
|||
}
|
||||
|
||||
TEST(getline, testBinaryLine_countExcludesOnlyTheBonusNul) {
|
||||
FILE *f = fmemopen(NULL, BUFSIZ, "r+");
|
||||
fwrite("he\0\3o\n", 1, 6, f);
|
||||
const char s[] = "he\0\3o\n";
|
||||
FILE *f = fmemopen(s, sizeof(s), "r+");
|
||||
char *line = NULL;
|
||||
size_t linesize = 0;
|
||||
ASSERT_EQ(6, getline(&line, &linesize, f));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue