mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-31 15:00:28 +00:00
Initial import
This commit is contained in:
commit
c91b3c5006
14915 changed files with 590219 additions and 0 deletions
25
test/ape/lib/flattenhighmemory_test.c
Normal file
25
test/ape/lib/flattenhighmemory_test.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*-*- 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/testlib/testlib.h"
|
||||
|
||||
TEST(flattenhighmemory, test) {
|
||||
/* EXPECT_EQ(0, flattenhighmemory()); */
|
||||
/* EXPECT_STREQ("", flattenhighmemory()); */
|
||||
}
|
66
test/ape/lib/getpagetableentry_test.c
Normal file
66
test/ape/lib/getpagetableentry_test.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*-*- 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 "ape/lib/pc.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(getpagetableentry, testLowestAddress) {
|
||||
static struct PageTable pml4t;
|
||||
static struct PageTable stack[3];
|
||||
uint64_t ptsp = (uintptr_t)&stack + sizeof(stack);
|
||||
memset(&pml4t, 0, sizeof(pml4t));
|
||||
memset(&stack, 0, sizeof(stack));
|
||||
uint64_t vaddr = 0;
|
||||
uint64_t paddr = 0x31337000;
|
||||
*getpagetableentry(vaddr, 3, &pml4t, &ptsp) = paddr | PAGE_V;
|
||||
EXPECT_EQ(&stack[2].p[0], pml4t.p[0] & PAGE_TA); /* pml4t → pdpt */
|
||||
EXPECT_EQ(&stack[1].p[0], stack[2].p[0] & PAGE_TA); /* pdpt → pdt */
|
||||
EXPECT_EQ(&stack[0].p[0], stack[1].p[0] & PAGE_TA); /* pdt → pd */
|
||||
EXPECT_EQ(stack[0].p[0] & PAGE_TA, paddr); /* page */
|
||||
EXPECT_EQ(&stack, ptsp);
|
||||
EXPECT_TRUE(pml4t.p[0] & PAGE_V);
|
||||
EXPECT_TRUE(stack[2].p[0] & PAGE_V);
|
||||
EXPECT_TRUE(stack[1].p[0] & PAGE_V);
|
||||
EXPECT_TRUE(stack[0].p[0] & PAGE_V);
|
||||
EXPECT_FALSE(stack[0].p[1] & PAGE_V);
|
||||
}
|
||||
|
||||
TEST(getpagetableentry, testHigherAddress) {
|
||||
static struct PageTable pml4t;
|
||||
static struct PageTable stack[3];
|
||||
uint64_t ptsp = (uintptr_t)&stack + sizeof(stack);
|
||||
memset(&pml4t, 0, sizeof(pml4t));
|
||||
memset(&stack, 0, sizeof(stack));
|
||||
uint64_t vaddr = 0x133731337000;
|
||||
uint64_t paddr = 0x123000;
|
||||
*getpagetableentry(vaddr, 3, &pml4t, &ptsp) = paddr | PAGE_V;
|
||||
EXPECT_EQ(&stack[2].p[0], pml4t.p[38] & PAGE_TA); /* pml4t → pdpt */
|
||||
EXPECT_EQ(&stack[1].p[0], stack[2].p[220] & PAGE_TA); /* pdpt → pdt */
|
||||
EXPECT_EQ(&stack[0].p[0], stack[1].p[393] & PAGE_TA); /* pdt → pd */
|
||||
EXPECT_EQ(stack[0].p[311] & PAGE_TA, paddr); /* page */
|
||||
EXPECT_EQ(&stack, ptsp);
|
||||
EXPECT_TRUE(pml4t.p[38] & PAGE_V);
|
||||
EXPECT_TRUE(stack[2].p[220] & PAGE_V);
|
||||
EXPECT_TRUE(stack[1].p[393] & PAGE_V);
|
||||
EXPECT_TRUE(stack[0].p[311] & PAGE_V);
|
||||
EXPECT_FALSE(stack[0].p[0] & PAGE_V);
|
||||
}
|
81
test/ape/lib/smapsort_test.c
Normal file
81
test/ape/lib/smapsort_test.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
/*-*- 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 "ape/lib/pc.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(smapsort, testEmpty_doesntOverrunBuffer) {
|
||||
struct SmapEntry *smap = tmalloc(sizeof(struct SmapEntry));
|
||||
memset(smap, 0, sizeof(struct SmapEntry));
|
||||
smapsort(smap);
|
||||
EXPECT_EQ(0, smap[0].addr);
|
||||
EXPECT_EQ(0, smap[0].size);
|
||||
tfree(smap);
|
||||
}
|
||||
|
||||
/* TEST(smapsort, testSorted_doesNothing) { */
|
||||
/* struct SmapEntry *smap = tmalloc(4 * sizeof(struct SmapEntry)); */
|
||||
/* memset(smap, 0, 4 * sizeof(struct SmapEntry)); */
|
||||
/* smap[0].addr = 0; */
|
||||
/* smap[0].size = 0x7000; */
|
||||
/* smap[0].type = kMemoryUsable; */
|
||||
/* smap[1].addr = 0x7000; */
|
||||
/* smap[1].size = 0x1000; */
|
||||
/* smap[1].type = kMemoryUnusable; */
|
||||
/* smap[2].addr = 0x14000; */
|
||||
/* smap[2].size = 0x1000; */
|
||||
/* smap[2].type = kMemoryBad; */
|
||||
/* smapsort(smap); */
|
||||
/* EXPECT_EQ(0, smap[0].addr); */
|
||||
/* EXPECT_EQ(0x7000, smap[0].size); */
|
||||
/* EXPECT_EQ(kMemoryUsable, smap[0].type); */
|
||||
/* EXPECT_EQ(0x7000, smap[1].addr); */
|
||||
/* EXPECT_EQ(0x1000, smap[1].size); */
|
||||
/* EXPECT_EQ(kMemoryUnusable, smap[1].type); */
|
||||
/* EXPECT_EQ(0x14000, smap[2].addr); */
|
||||
/* EXPECT_EQ(0x1000, smap[2].size); */
|
||||
/* EXPECT_EQ(kMemoryBad, smap[2].type); */
|
||||
/* tfree(smap); */
|
||||
/* } */
|
||||
|
||||
/* TEST(smapsort, testUnsorted_sortsByAddress) { */
|
||||
/* struct SmapEntry *smap = tmalloc(4 * sizeof(struct SmapEntry)); */
|
||||
/* memset(smap, 0, 4 * sizeof(struct SmapEntry)); */
|
||||
/* smap[2].addr = 0; */
|
||||
/* smap[2].size = 0x7000; */
|
||||
/* smap[2].type = kMemoryUsable; */
|
||||
/* smap[0].addr = 0x7000; */
|
||||
/* smap[0].size = 0x1000; */
|
||||
/* smap[0].type = kMemoryUnusable; */
|
||||
/* smap[1].addr = 0x14000; */
|
||||
/* smap[1].size = 0x1000; */
|
||||
/* smap[1].type = kMemoryBad; */
|
||||
/* smapsort(smap); */
|
||||
/* EXPECT_EQ(0, smap[0].addr); */
|
||||
/* EXPECT_EQ(0x7000, smap[0].size); */
|
||||
/* EXPECT_EQ(kMemoryUsable, smap[0].type); */
|
||||
/* EXPECT_EQ(0x7000, smap[1].addr); */
|
||||
/* EXPECT_EQ(0x1000, smap[1].size); */
|
||||
/* EXPECT_EQ(kMemoryUnusable, smap[1].type); */
|
||||
/* EXPECT_EQ(0x14000, smap[2].addr); */
|
||||
/* EXPECT_EQ(0x1000, smap[2].size); */
|
||||
/* EXPECT_EQ(kMemoryBad, smap[2].type); */
|
||||
/* tfree(smap); */
|
||||
/* } */
|
52
test/ape/lib/test.mk
Normal file
52
test/ape/lib/test.mk
Normal file
|
@ -0,0 +1,52 @@
|
|||
#-*-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_APE_LIB
|
||||
|
||||
TEST_APE_LIB_SRCS := $(wildcard test/ape/lib/*.c)
|
||||
TEST_APE_LIB_SRCS_TEST = $(filter %_test.c,$(TEST_APE_LIB_SRCS))
|
||||
TEST_APE_LIB_COMS = $(TEST_APE_LIB_OBJS:%.o=%.com)
|
||||
|
||||
TEST_APE_LIB_OBJS = \
|
||||
$(TEST_APE_LIB_SRCS:%=o/$(MODE)/%.zip.o) \
|
||||
$(TEST_APE_LIB_SRCS:%.c=o/$(MODE)/%.o)
|
||||
|
||||
TEST_APE_LIB_BINS = \
|
||||
$(TEST_APE_LIB_COMS) \
|
||||
$(TEST_APE_LIB_COMS:%=%.dbg)
|
||||
|
||||
TEST_APE_LIB_TESTS = \
|
||||
$(TEST_APE_LIB_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
|
||||
|
||||
TEST_APE_LIB_CHECKS = \
|
||||
$(TEST_APE_LIB_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
|
||||
|
||||
TEST_APE_LIB_DIRECTDEPS = \
|
||||
APE_LIB \
|
||||
LIBC_CALLS_HEFTY \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_TESTLIB \
|
||||
LIBC_X
|
||||
|
||||
TEST_APE_LIB_DEPS := \
|
||||
$(call uniq,$(foreach x,$(TEST_APE_LIB_DIRECTDEPS),$($(x))))
|
||||
|
||||
o/$(MODE)/test/ape/lib.pkg: \
|
||||
$(TEST_APE_LIB_OBJS) \
|
||||
$(foreach x,$(TEST_APE_LIB_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
o/$(MODE)/test/ape/lib/%.com.dbg: \
|
||||
$(TEST_APE_LIB_DEPS) \
|
||||
o/$(MODE)/test/ape/lib/%.o \
|
||||
o/$(MODE)/test/ape/lib.pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
@$(APELINK)
|
||||
|
||||
.PHONY: o/$(MODE)/test/ape/lib
|
||||
o/$(MODE)/test/ape/lib: $(TEST_APE_LIB_BINS) \
|
||||
$(TEST_APE_LIB_CHECKS)
|
Loading…
Add table
Add a link
Reference in a new issue