mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 22:02:27 +00:00
Make build hermetic without shell scripts
- Fix some minor issues in ar.com - Have execve() look for `ape` command - Rewrite NT paths using /c/ rather /??/c:/ - Replace broken GCC symlinks with .sym files - Rewrite $PATH environment variables on startup - Make $(APE_NO_MODIFY_SELF) the default bootloader - Add all build command dependencies to build/bootstrap - Get the repository mostly building from source on non-Linux
This commit is contained in:
parent
d44ff6ce1f
commit
d230a01222
160 changed files with 2754 additions and 1342 deletions
|
@ -50,7 +50,7 @@ o/$(MODE)/test/libc/alg/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/alg/alg.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
$(TEST_LIBC_ALG_OBJS): test/libc/alg/test.mk
|
||||
|
|
|
@ -46,7 +46,7 @@ o/$(MODE)/test/libc/bits/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/bits/bits.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
$(TEST_LIBC_BITS_OBJS): \
|
||||
|
|
|
@ -35,7 +35,7 @@ TEST(clock_gettime, test) {
|
|||
ASSERT_NE(0, ts.tv_sec);
|
||||
ASSERT_NE(0, ts.tv_nsec);
|
||||
if (__is_linux_2_6_23()) {
|
||||
ASSERT_GT((intptr_t)__get_clock_gettime(&isfast),
|
||||
ASSERT_GT((intptr_t)__clock_gettime_get(&isfast),
|
||||
getauxval(AT_SYSINFO_EHDR));
|
||||
ASSERT_TRUE(isfast);
|
||||
}
|
||||
|
|
|
@ -45,5 +45,5 @@ TEST(getcwd, testWindows_addsFunnyPrefix) {
|
|||
if (!IsWindows()) return;
|
||||
char path[PATH_MAX];
|
||||
ASSERT_NE(0, getcwd(path, sizeof(path)));
|
||||
EXPECT_STARTSWITH("//?/", path);
|
||||
EXPECT_STARTSWITH("/C/", path);
|
||||
}
|
||||
|
|
|
@ -20,17 +20,18 @@
|
|||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
char tmp[ARG_MAX];
|
||||
char16_t envvars[ARG_MAX / 2];
|
||||
|
||||
TEST(mkntenvblock, emptyList_onlyOutputsDoubleNulStringTerminator) {
|
||||
char *envp[] = {NULL};
|
||||
ASSERT_NE(-1, mkntenvblock(envvars, envp, NULL));
|
||||
ASSERT_NE(-1, mkntenvblock(envvars, envp, NULL, tmp));
|
||||
ASSERT_BINEQ(u" ", envvars);
|
||||
}
|
||||
|
||||
TEST(mkntenvblock, envp_becomesSortedDoubleNulTerminatedUtf16String) {
|
||||
char *envp[] = {"u=b", "c=d", "韩=非", "uh=d", "hduc=d", NULL};
|
||||
ASSERT_NE(-1, mkntenvblock(envvars, envp, NULL));
|
||||
ASSERT_NE(-1, mkntenvblock(envvars, envp, NULL, tmp));
|
||||
ASSERT_BINEQ(u"C = d "
|
||||
u"H D U C = d "
|
||||
u"U = b "
|
||||
|
@ -42,7 +43,7 @@ TEST(mkntenvblock, envp_becomesSortedDoubleNulTerminatedUtf16String) {
|
|||
|
||||
TEST(mkntenvblock, extraVar_getsAdded) {
|
||||
char *envp[] = {"u=b", "c=d", "韩=非", "uh=d", "hduc=d", NULL};
|
||||
ASSERT_NE(-1, mkntenvblock(envvars, envp, "a=a"));
|
||||
ASSERT_NE(-1, mkntenvblock(envvars, envp, "a=a", tmp));
|
||||
ASSERT_BINEQ(u"A = a "
|
||||
u"C = d "
|
||||
u"H D U C = d "
|
||||
|
@ -52,3 +53,11 @@ TEST(mkntenvblock, extraVar_getsAdded) {
|
|||
u" ",
|
||||
envvars);
|
||||
}
|
||||
|
||||
TEST(mkntenvblock, pathvars_getUpdated) {
|
||||
char *envp[] = {"PATH=/c/foo:/d/bar", NULL};
|
||||
ASSERT_NE(-1, mkntenvblock(envvars, envp, 0, tmp));
|
||||
ASSERT_BINEQ(u"P A T H = c : \\ f o o ; d : \\ b a r "
|
||||
u" ",
|
||||
envvars);
|
||||
}
|
||||
|
|
|
@ -101,9 +101,10 @@ TEST(readlinkat, statReadsNameLength) {
|
|||
}
|
||||
|
||||
TEST(readlinkat, realpathReturnsLongPath) {
|
||||
if (!IsWindows()) return;
|
||||
struct stat st;
|
||||
char buf[PATH_MAX];
|
||||
if (!IsWindows()) return;
|
||||
if (!startswith(getcwd(buf, PATH_MAX), "/c/")) return;
|
||||
ASSERT_SYS(0, 0, touch("froot", 0644));
|
||||
ASSERT_STARTSWITH("//?/", realpath("froot", buf));
|
||||
ASSERT_STARTSWITH("/c/", realpath("froot", buf));
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ o/$(MODE)/test/libc/calls/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/calls/calls.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
.PHONY: o/$(MODE)/test/libc/calls
|
||||
|
|
|
@ -53,7 +53,7 @@ o/$(MODE)/test/libc/dns/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/dns/dns.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
.PHONY: o/$(MODE)/test/libc/dns
|
||||
|
|
|
@ -278,6 +278,11 @@ TEST(fmt, p) {
|
|||
gc(xasprintf("% 10p", 0xffff800000031337)));
|
||||
}
|
||||
|
||||
TEST(fmt, quoted) {
|
||||
ASSERT_STREQ(" \"hello\"", gc(xasprintf("%`*.*s", 10, 5, "hello")));
|
||||
ASSERT_STREQ("\"hello\" ", gc(xasprintf("%-`*.*s", 10, 5, "hello")));
|
||||
}
|
||||
|
||||
TEST(fmt, regress) {
|
||||
char buf[512];
|
||||
const char *meth = "GET";
|
||||
|
|
|
@ -49,7 +49,7 @@ o/$(MODE)/test/libc/fmt/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/fmt/fmt.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
$(TEST_LIBC_FMT_OBJS): test/libc/fmt/test.mk
|
||||
|
|
|
@ -54,7 +54,7 @@ o/$(MODE)/test/libc/intrin/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/intrin/intrin.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
$(TEST_LIBC_INTRIN_OBJS): \
|
||||
|
|
132
test/libc/log/backtrace.c
Normal file
132
test/libc/log/backtrace.c
Normal file
|
@ -0,0 +1,132 @@
|
|||
/*-*- 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 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
int StackOverflow(int f(), int n) {
|
||||
if (n < INT_MAX) {
|
||||
return f(f, n + 1) - 1;
|
||||
} else {
|
||||
return INT_MAX;
|
||||
}
|
||||
}
|
||||
|
||||
void FpuCrash(void) {
|
||||
typedef char xmm_t __attribute__((__vector_size__(16)));
|
||||
xmm_t v = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||
0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
|
||||
volatile int x = 0;
|
||||
asm volatile("fldpi");
|
||||
asm volatile("mov\t%0,%%r15" : /* no outputs */ : "g"(0x3133731337));
|
||||
asm volatile("movaps\t%0,%%xmm15" : /* no outputs */ : "x"(v));
|
||||
fputc(7 / x, stdout);
|
||||
}
|
||||
|
||||
char bss[10];
|
||||
void BssOverrunCrash(int n) {
|
||||
int i;
|
||||
for (i = 0; i < n; ++i) {
|
||||
bss[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
char data[10] = "abcdeabcde";
|
||||
void DataOverrunCrash(int n) {
|
||||
int i;
|
||||
for (i = 0; i < n; ++i) {
|
||||
data[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
const char rodata[10] = "abcdeabcde";
|
||||
int RodataOverrunCrash(int i) {
|
||||
return rodata[i];
|
||||
}
|
||||
|
||||
char *StackOverrunCrash(int n) {
|
||||
int i;
|
||||
char stack[10];
|
||||
bzero(stack, sizeof(stack));
|
||||
for (i = 0; i < n; ++i) {
|
||||
stack[i] = i;
|
||||
}
|
||||
return strdup(stack);
|
||||
}
|
||||
|
||||
char *MemoryLeakCrash(void) {
|
||||
char *p = strdup("doge");
|
||||
CheckForMemoryLeaks();
|
||||
return p;
|
||||
}
|
||||
|
||||
int NpeCrash(char *p) {
|
||||
asm("nop"); // xxx: due to backtrace addr-1 thing
|
||||
return *p;
|
||||
}
|
||||
|
||||
void (*pFpuCrash)(void) = FpuCrash;
|
||||
void (*pBssOverrunCrash)(int) = BssOverrunCrash;
|
||||
void (*pDataOverrunCrash)(int) = DataOverrunCrash;
|
||||
int (*pRodataOverrunCrash)(int) = RodataOverrunCrash;
|
||||
char *(*pStackOverrunCrash)(int) = StackOverrunCrash;
|
||||
char *(*pMemoryLeakCrash)(void) = MemoryLeakCrash;
|
||||
int (*pNpeCrash)(char *) = NpeCrash;
|
||||
int (*pStackOverflow)(int (*)(), int) = StackOverflow;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
ShowCrashReports();
|
||||
if (argc > 1) {
|
||||
switch (atoi(argv[1])) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
pFpuCrash();
|
||||
exit(0);
|
||||
case 2:
|
||||
pBssOverrunCrash(10 + 1);
|
||||
exit(0);
|
||||
case 3:
|
||||
exit(pRodataOverrunCrash(10 + 1));
|
||||
case 4:
|
||||
pDataOverrunCrash(10 + 1);
|
||||
exit(0);
|
||||
case 5:
|
||||
exit((intptr_t)pStackOverrunCrash(10 + 1));
|
||||
case 6:
|
||||
exit((intptr_t)pMemoryLeakCrash());
|
||||
case 7:
|
||||
exit(pNpeCrash(0));
|
||||
case 8:
|
||||
__cxa_finalize(0);
|
||||
exit(pNpeCrash(0));
|
||||
case 9:
|
||||
exit(pStackOverflow(pStackOverflow, 0));
|
||||
default:
|
||||
fputs("error: unrecognized argument\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
fputs("error: too few args\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@
|
|||
#include "libc/limits.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/io.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
|
@ -40,115 +41,30 @@
|
|||
#include "libc/x/x.h"
|
||||
#include "net/http/escape.h"
|
||||
|
||||
int StackOverflow(int f(), int n) {
|
||||
if (n < INT_MAX) {
|
||||
return f(f, n + 1) - 1;
|
||||
} else {
|
||||
return INT_MAX;
|
||||
}
|
||||
STATIC_YOINK("zip_uri_support");
|
||||
STATIC_YOINK("backtrace.com");
|
||||
STATIC_YOINK("backtrace.com.dbg");
|
||||
|
||||
char testlib_enable_tmp_setup_teardown_once;
|
||||
|
||||
void Extract(const char *from, const char *to, int mode) {
|
||||
ASSERT_SYS(0, 3, open(from, O_RDONLY));
|
||||
ASSERT_SYS(0, 4, creat(to, mode));
|
||||
ASSERT_NE(-1, _copyfd(3, 4, -1));
|
||||
EXPECT_SYS(0, 0, close(4));
|
||||
EXPECT_SYS(0, 0, close(3));
|
||||
}
|
||||
|
||||
void SetUpOnce(void) {
|
||||
ASSERT_NE(-1, mkdir("bin", 0755));
|
||||
Extract("/zip/backtrace.com", "bin/backtrace.com", 0755);
|
||||
Extract("/zip/backtrace.com.dbg", "bin/backtrace.com.dbg", 0755);
|
||||
}
|
||||
|
||||
static bool OutputHasSymbol(const char *output, const char *s) {
|
||||
return strstr(output, s) || (!FindDebugBinary() && strstr(output, "NULL"));
|
||||
}
|
||||
|
||||
void FpuCrash(void) {
|
||||
typedef char xmm_t __attribute__((__vector_size__(16)));
|
||||
xmm_t v = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7,
|
||||
0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
|
||||
volatile int x = 0;
|
||||
asm volatile("fldpi");
|
||||
asm volatile("mov\t%0,%%r15" : /* no outputs */ : "g"(0x3133731337));
|
||||
asm volatile("movaps\t%0,%%xmm15" : /* no outputs */ : "x"(v));
|
||||
fputc(7 / x, stdout);
|
||||
}
|
||||
|
||||
char bss[10];
|
||||
void BssOverrunCrash(int n) {
|
||||
int i;
|
||||
for (i = 0; i < n; ++i) {
|
||||
bss[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
char data[10] = "abcdeabcde";
|
||||
void DataOverrunCrash(int n) {
|
||||
int i;
|
||||
for (i = 0; i < n; ++i) {
|
||||
data[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
const char rodata[10] = "abcdeabcde";
|
||||
int RodataOverrunCrash(int i) {
|
||||
return rodata[i];
|
||||
}
|
||||
|
||||
char *StackOverrunCrash(int n) {
|
||||
int i;
|
||||
char stack[10];
|
||||
bzero(stack, sizeof(stack));
|
||||
for (i = 0; i < n; ++i) {
|
||||
stack[i] = i;
|
||||
}
|
||||
return strdup(stack);
|
||||
}
|
||||
|
||||
char *MemoryLeakCrash(void) {
|
||||
char *p = strdup("doge");
|
||||
CheckForMemoryLeaks();
|
||||
return p;
|
||||
}
|
||||
|
||||
int NpeCrash(char *p) {
|
||||
asm("nop"); // xxx: due to backtrace addr-1 thing
|
||||
return *p;
|
||||
}
|
||||
|
||||
void (*pFpuCrash)(void) = FpuCrash;
|
||||
void (*pBssOverrunCrash)(int) = BssOverrunCrash;
|
||||
void (*pDataOverrunCrash)(int) = DataOverrunCrash;
|
||||
int (*pRodataOverrunCrash)(int) = RodataOverrunCrash;
|
||||
char *(*pStackOverrunCrash)(int) = StackOverrunCrash;
|
||||
char *(*pMemoryLeakCrash)(void) = MemoryLeakCrash;
|
||||
int (*pNpeCrash)(char *) = NpeCrash;
|
||||
int (*pStackOverflow)(int (*)(), int) = StackOverflow;
|
||||
|
||||
void SetUp(void) {
|
||||
ShowCrashReports();
|
||||
if (__argc == 2) {
|
||||
switch (atoi(__argv[1])) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
pFpuCrash();
|
||||
exit(0);
|
||||
case 2:
|
||||
pBssOverrunCrash(10 + 1);
|
||||
exit(0);
|
||||
case 3:
|
||||
exit(pRodataOverrunCrash(10 + 1));
|
||||
case 4:
|
||||
pDataOverrunCrash(10 + 1);
|
||||
exit(0);
|
||||
case 5:
|
||||
exit((intptr_t)pStackOverrunCrash(10 + 1));
|
||||
case 6:
|
||||
exit((intptr_t)pMemoryLeakCrash());
|
||||
case 7:
|
||||
exit(pNpeCrash(0));
|
||||
case 8:
|
||||
__cxa_finalize(0);
|
||||
exit(pNpeCrash(0));
|
||||
case 9:
|
||||
exit(pStackOverflow(pStackOverflow, 0));
|
||||
default:
|
||||
printf("preventing fork recursion: %s\n", __argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UNFREED MEMORY
|
||||
// o/dbg/test/libc/log/backtrace_test.com
|
||||
// max allocated space 655,360
|
||||
|
@ -189,9 +105,8 @@ TEST(ShowCrashReports, testMemoryLeakCrash) {
|
|||
if (!pid) {
|
||||
dup2(fds[1], 1);
|
||||
dup2(fds[1], 2);
|
||||
execv(GetProgramExecutableName(),
|
||||
(char *const[]){GetProgramExecutableName(), "6", 0});
|
||||
_exit(127);
|
||||
execv("bin/backtrace.com", (char *const[]){"bin/backtrace.com", "6", 0});
|
||||
_Exit(127);
|
||||
}
|
||||
close(fds[1]);
|
||||
output = 0;
|
||||
|
@ -267,9 +182,8 @@ TEST(ShowCrashReports, testStackOverrunCrash) {
|
|||
if (!pid) {
|
||||
dup2(fds[1], 1);
|
||||
dup2(fds[1], 2);
|
||||
execv(GetProgramExecutableName(),
|
||||
(char *const[]){GetProgramExecutableName(), "5", 0});
|
||||
_exit(127);
|
||||
execv("bin/backtrace.com", (char *const[]){"bin/backtrace.com", "5", 0});
|
||||
_Exit(127);
|
||||
}
|
||||
close(fds[1]);
|
||||
output = 0;
|
||||
|
@ -376,9 +290,8 @@ TEST(ShowCrashReports, testDivideByZero) {
|
|||
if (!pid) {
|
||||
dup2(fds[1], 1);
|
||||
dup2(fds[1], 2);
|
||||
execv(GetProgramExecutableName(),
|
||||
(char *const[]){GetProgramExecutableName(), "1", 0});
|
||||
_exit(127);
|
||||
execv("bin/backtrace.com", (char *const[]){"bin/backtrace.com", "1", 0});
|
||||
_Exit(127);
|
||||
}
|
||||
close(fds[1]);
|
||||
output = 0;
|
||||
|
@ -454,9 +367,8 @@ TEST(ShowCrashReports, testStackOverflow) {
|
|||
if (!pid) {
|
||||
dup2(fds[1], 1);
|
||||
dup2(fds[1], 2);
|
||||
execv(GetProgramExecutableName(),
|
||||
(char *const[]){GetProgramExecutableName(), "9", "--strace", 0});
|
||||
_exit(127);
|
||||
execv("bin/backtrace.com", (char *const[]){"bin/backtrace.com", "9", 0});
|
||||
_Exit(127);
|
||||
}
|
||||
close(fds[1]);
|
||||
output = 0;
|
||||
|
@ -571,9 +483,8 @@ TEST(ShowCrashReports, testBssOverrunCrash) {
|
|||
if (!pid) {
|
||||
dup2(fds[1], 1);
|
||||
dup2(fds[1], 2);
|
||||
execv(GetProgramExecutableName(),
|
||||
(char *const[]){GetProgramExecutableName(), "2", 0});
|
||||
_exit(127);
|
||||
execv("bin/backtrace.com", (char *const[]){"bin/backtrace.com", "2", 0});
|
||||
_Exit(127);
|
||||
}
|
||||
close(fds[1]);
|
||||
output = 0;
|
||||
|
@ -650,9 +561,8 @@ TEST(ShowCrashReports, testNpeCrash) {
|
|||
if (!pid) {
|
||||
dup2(fds[1], 1);
|
||||
dup2(fds[1], 2);
|
||||
execv(GetProgramExecutableName(),
|
||||
(char *const[]){GetProgramExecutableName(), "7", 0});
|
||||
_exit(127);
|
||||
execv("bin/backtrace.com", (char *const[]){"bin/backtrace.com", "7", 0});
|
||||
_Exit(127);
|
||||
}
|
||||
close(fds[1]);
|
||||
output = 0;
|
||||
|
@ -710,9 +620,8 @@ TEST(ShowCrashReports, testDataOverrunCrash) {
|
|||
if (!pid) {
|
||||
dup2(fds[1], 1);
|
||||
dup2(fds[1], 2);
|
||||
execv(GetProgramExecutableName(),
|
||||
(char *const[]){GetProgramExecutableName(), "4", 0});
|
||||
_exit(127);
|
||||
execv("bin/backtrace.com", (char *const[]){"bin/backtrace.com", "4", 0});
|
||||
_Exit(127);
|
||||
}
|
||||
close(fds[1]);
|
||||
output = 0;
|
||||
|
@ -765,9 +674,8 @@ TEST(ShowCrashReports, testNpeCrashAfterFinalize) {
|
|||
if (!pid) {
|
||||
dup2(fds[1], 1);
|
||||
dup2(fds[1], 2);
|
||||
execv(GetProgramExecutableName(),
|
||||
(char *const[]){GetProgramExecutableName(), "8", 0});
|
||||
_exit(127);
|
||||
execv("bin/backtrace.com", (char *const[]){"bin/backtrace.com", "8", 0});
|
||||
_Exit(127);
|
||||
}
|
||||
close(fds[1]);
|
||||
output = 0;
|
||||
|
|
|
@ -6,56 +6,82 @@ PKGS += TEST_LIBC_LOG
|
|||
TEST_LIBC_LOG_SRCS := $(wildcard test/libc/log/*.c)
|
||||
TEST_LIBC_LOG_SRCS_TEST = $(filter %_test.c,$(TEST_LIBC_LOG_SRCS))
|
||||
|
||||
TEST_LIBC_LOG_OBJS = \
|
||||
$(TEST_LIBC_LOG_SRCS:%.c=o/$(MODE)/%.o)
|
||||
TEST_LIBC_LOG_OBJS = \
|
||||
$(TEST_LIBC_LOG_SRCS:%.c=o/$(MODE)/%.o) \
|
||||
o/$(MODE)/test/libc/log/backtrace.com.zip.o \
|
||||
o/$(MODE)/test/libc/log/backtrace.com.dbg.zip.o
|
||||
|
||||
TEST_LIBC_LOG_COMS = \
|
||||
TEST_LIBC_LOG_COMS = \
|
||||
$(TEST_LIBC_LOG_SRCS:%.c=o/$(MODE)/%.com)
|
||||
|
||||
TEST_LIBC_LOG_BINS = \
|
||||
$(TEST_LIBC_LOG_COMS) \
|
||||
TEST_LIBC_LOG_BINS = \
|
||||
$(TEST_LIBC_LOG_COMS) \
|
||||
$(TEST_LIBC_LOG_COMS:%=%.dbg)
|
||||
|
||||
TEST_LIBC_LOG_TESTS = \
|
||||
TEST_LIBC_LOG_TESTS = \
|
||||
$(TEST_LIBC_LOG_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
|
||||
|
||||
TEST_LIBC_LOG_CHECKS = \
|
||||
TEST_LIBC_LOG_CHECKS = \
|
||||
$(TEST_LIBC_LOG_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
|
||||
|
||||
TEST_LIBC_LOG_DIRECTDEPS = \
|
||||
LIBC_CALLS \
|
||||
LIBC_RUNTIME \
|
||||
NET_HTTP \
|
||||
LIBC_STDIO \
|
||||
LIBC_X \
|
||||
LIBC_INTRIN \
|
||||
LIBC_FMT \
|
||||
LIBC_MEM \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_LOG \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_TESTLIB \
|
||||
LIBC_SYSV \
|
||||
LIBC_LOG
|
||||
TEST_LIBC_LOG_DIRECTDEPS = \
|
||||
LIBC_CALLS \
|
||||
LIBC_RUNTIME \
|
||||
NET_HTTP \
|
||||
LIBC_STDIO \
|
||||
LIBC_X \
|
||||
LIBC_INTRIN \
|
||||
LIBC_FMT \
|
||||
LIBC_MEM \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_LOG \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_TESTLIB \
|
||||
LIBC_SYSV \
|
||||
LIBC_LOG \
|
||||
LIBC_ZIPOS
|
||||
|
||||
TEST_LIBC_LOG_DEPS := \
|
||||
TEST_LIBC_LOG_DEPS := \
|
||||
$(call uniq,$(foreach x,$(TEST_LIBC_LOG_DIRECTDEPS),$($(x))))
|
||||
|
||||
o/$(MODE)/test/libc/log/log.pkg: \
|
||||
$(TEST_LIBC_LOG_OBJS) \
|
||||
o/$(MODE)/test/libc/log/log.pkg: \
|
||||
$(TEST_LIBC_LOG_OBJS) \
|
||||
$(foreach x,$(TEST_LIBC_LOG_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
o/$(MODE)/test/libc/log/%.com.dbg: \
|
||||
$(TEST_LIBC_LOG_DEPS) \
|
||||
o/$(MODE)/test/libc/log/%.o \
|
||||
o/$(MODE)/test/libc/log/log.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
o/$(MODE)/test/libc/log/%.com.dbg: \
|
||||
$(TEST_LIBC_LOG_DEPS) \
|
||||
o/$(MODE)/test/libc/log/%.o \
|
||||
o/$(MODE)/test/libc/log/log.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/test/libc/log/backtrace_test.com.dbg: \
|
||||
$(TEST_LIBC_LOG_DEPS) \
|
||||
o/$(MODE)/test/libc/log/backtrace.com.zip.o \
|
||||
o/$(MODE)/test/libc/log/backtrace.com.dbg.zip.o \
|
||||
o/$(MODE)/test/libc/log/backtrace_test.o \
|
||||
o/$(MODE)/test/libc/log/log.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/test/libc/log/backtrace.com.dbg: \
|
||||
$(TEST_LIBC_LOG_DEPS) \
|
||||
o/$(MODE)/test/libc/log/backtrace.o \
|
||||
$(CRT) \
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/test/libc/log/backtrace.com.zip.o \
|
||||
o/$(MODE)/test/libc/log/backtrace.com.dbg.zip.o: \
|
||||
ZIPOBJ_FLAGS += \
|
||||
-B
|
||||
|
||||
.PHONY: o/$(MODE)/test/libc/log
|
||||
o/$(MODE)/test/libc/log: \
|
||||
$(TEST_LIBC_LOG_BINS) \
|
||||
o/$(MODE)/test/libc/log: \
|
||||
$(TEST_LIBC_LOG_BINS) \
|
||||
$(TEST_LIBC_LOG_CHECKS)
|
||||
|
|
|
@ -58,7 +58,7 @@ o/$(MODE)/test/libc/mem/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/mem/mem.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
$(TEST_LIBC_MEM_OBJS): \
|
||||
|
|
|
@ -55,7 +55,7 @@ o/$(MODE)/test/libc/nexgen32e/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/nexgen32e/nexgen32e.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
$(TEST_LIBC_NEXGEN32E_OBJS): \
|
||||
|
|
|
@ -52,7 +52,7 @@ o/$(MODE)/test/libc/rand/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/rand/rand.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
$(TEST_LIBC_RAND_OBJS): test/libc/rand/test.mk
|
||||
|
|
|
@ -10,7 +10,7 @@ if [ "$MODE" = opt ] || [ "$MODE" = optlinux ]; then
|
|||
exit
|
||||
fi
|
||||
|
||||
mkdir -p o/$MODE/test/libc/release/
|
||||
$MKDIR o/$MODE/test/libc/release/
|
||||
|
||||
# smoke test booting on bare metal and printing data to serial uart
|
||||
CMD="o/$MODE/tool/build/blinkenlights.com.dbg -r o/$MODE/examples/hello.com"
|
||||
|
|
|
@ -124,17 +124,17 @@ o/$(MODE)/test/libc/release/smokeansi.com.dbg: \
|
|||
o/$(MODE)/ape/ape.o \
|
||||
o/$(MODE)/cosmopolitan.a
|
||||
|
||||
o/$(MODE)/test/libc/release/metal.ok: \
|
||||
test/libc/release/metal.sh \
|
||||
o/$(MODE)/examples/hello.com \
|
||||
o/$(MODE)/tool/build/blinkenlights.com.dbg
|
||||
@$(COMPILE) -ASHTEST -tT$@ $<
|
||||
|
||||
o/$(MODE)/test/libc/release/emulate.ok: \
|
||||
test/libc/release/emulate.sh \
|
||||
o/$(MODE)/examples/hello.com \
|
||||
o/$(MODE)/tool/build/blinkenlights.com.dbg
|
||||
@$(COMPILE) -ASHTEST -tT$@ $<
|
||||
# TODO(jart): Rewrite these shell scripts as C code.
|
||||
# o/$(MODE)/test/libc/release/metal.ok: \
|
||||
# test/libc/release/metal.sh \
|
||||
# o/$(MODE)/examples/hello.com \
|
||||
# o/$(MODE)/tool/build/blinkenlights.com.dbg
|
||||
# @$(COMPILE) -ASHTEST -tT$@ $<
|
||||
# o/$(MODE)/test/libc/release/emulate.ok: \
|
||||
# test/libc/release/emulate.sh \
|
||||
# o/$(MODE)/examples/hello.com \
|
||||
# o/$(MODE)/tool/build/blinkenlights.com.dbg
|
||||
# @$(COMPILE) -ASHTEST -tT$@ $<
|
||||
|
||||
.PHONY: o/$(MODE)/test/libc/release
|
||||
o/$(MODE)/test/libc/release: \
|
||||
|
@ -145,6 +145,4 @@ o/$(MODE)/test/libc/release: \
|
|||
o/$(MODE)/test/libc/release/smokecxx.com \
|
||||
o/$(MODE)/test/libc/release/smokecxx.com.runs \
|
||||
o/$(MODE)/test/libc/release/smokeansi.com \
|
||||
o/$(MODE)/test/libc/release/smokeansi.com.runs \
|
||||
o/$(MODE)/test/libc/release/emulate.ok \
|
||||
o/$(MODE)/test/libc/release/metal.ok
|
||||
o/$(MODE)/test/libc/release/smokeansi.com.runs
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/linux/mmap.h"
|
||||
#include "libc/linux/munmap.h"
|
||||
#include "libc/log/log.h"
|
||||
|
@ -228,6 +229,7 @@ TEST(mmap, cow) {
|
|||
char *p;
|
||||
char path[PATH_MAX];
|
||||
sprintf(path, "%s%s.%ld", kTmpPath, program_invocation_short_name, lemur64());
|
||||
kprintf("path = %#s\n", path);
|
||||
ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644)));
|
||||
EXPECT_EQ(5, write(fd, "hello", 5));
|
||||
EXPECT_NE(-1, fdatasync(fd));
|
||||
|
|
|
@ -58,7 +58,7 @@ o/$(MODE)/test/libc/runtime/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/runtime/runtime.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/test/libc/runtime/ape_test.com.dbg: \
|
||||
|
@ -67,7 +67,7 @@ o/$(MODE)/test/libc/runtime/ape_test.com.dbg: \
|
|||
o/$(MODE)/test/libc/runtime/runtime.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
$(TEST_LIBC_RUNTIME_OBJS): \
|
||||
|
|
|
@ -51,7 +51,7 @@ o/$(MODE)/test/libc/sock/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/sock/sock.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
$(TEST_LIBC_SOCK_OBJS): test/libc/sock/test.mk
|
||||
|
|
|
@ -57,7 +57,7 @@ o/$(MODE)/test/libc/stdio/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/stdio/stdio.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
$(TEST_LIBC_STDIO_OBJS): \
|
||||
|
|
|
@ -72,7 +72,7 @@ o/$(MODE)/test/libc/str/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/str/str.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/test/libc/str/blake2.com.dbg: \
|
||||
|
@ -82,7 +82,7 @@ o/$(MODE)/test/libc/str/blake2.com.dbg: \
|
|||
o/$(MODE)/test/libc/str/str.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
$(TEST_LIBC_STR_OBJS): \
|
||||
|
|
|
@ -48,7 +48,7 @@ o/$(MODE)/test/libc/thread/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/thread/thread.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
$(TEST_LIBC_THREAD_OBJS): \
|
||||
|
|
|
@ -43,7 +43,7 @@ o/$(MODE)/test/libc/time/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/time/time.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
.PHONY: o/$(MODE)/test/libc/time
|
||||
|
|
|
@ -53,7 +53,7 @@ o/$(MODE)/test/libc/tinymath/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/tinymath/tinymath.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
$(TEST_LIBC_TINYMATH_OBJS): \
|
||||
|
|
|
@ -47,7 +47,7 @@ o/$(MODE)/test/libc/unicode/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/unicode/unicode.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
.PHONY: o/$(MODE)/test/libc/unicode
|
||||
|
|
|
@ -53,7 +53,7 @@ o/$(MODE)/test/libc/x/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/x/x.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
.PHONY: o/$(MODE)/test/libc/x
|
||||
|
|
27
test/libc/x/xfixpath_test.c
Normal file
27
test/libc/x/xfixpath_test.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*-*- 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 2022 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
TEST(xfixpath, test) {
|
||||
setenv("PATH", "C:\\bin;C:\\usr\\bin;C:\\usr\\local\\bin", true);
|
||||
xfixpath();
|
||||
ASSERT_STREQ("/C/bin:/C/usr/bin:/C/usr/local/bin", getenv("PATH"));
|
||||
}
|
|
@ -93,7 +93,7 @@ o/$(MODE)/test/libc/xed/%.com.dbg: \
|
|||
o/$(MODE)/test/libc/xed/xed.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
$(APE_NO_MODIFY_SELF)
|
||||
@$(APELINK)
|
||||
|
||||
#───────────────────────────────────────────────────────────────────────────────
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue