mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-12 05:59:10 +00:00
Make more fixes and improvements
- Remove PAGESIZE constant - Fix realloc() documentation - Fix ttyname_r() error reporting - Make forking more reliable on Windows - Make execvp() a few microseconds faster - Make system() a few microseconds faster - Tighten up the socket-related magic numbers - Loosen restrictions on mmap() offset alignment - Improve GetProgramExecutableName() with getenv("_") - Use mkstemp() as basis for mktemp(), tmpfile(), tmpfd() - Fix flakes in pthread_cancel_test, unix_test, fork_test - Fix recently introduced futex stack overflow regression - Let sockets be passed as stdio to subprocesses on Windows - Improve security of bind() on Windows w/ SO_EXCLUSIVEADDRUSE
This commit is contained in:
parent
140a8a52e5
commit
18bb5888e1
311 changed files with 1239 additions and 2622 deletions
|
@ -1,107 +0,0 @@
|
|||
/*-*- 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 2021 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/log/libfatal.internal.h"
|
||||
#include "libc/mem/arena.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/stdio/append.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(arena, test) {
|
||||
EXPECT_STREQ("hello", gc(strdup("hello")));
|
||||
__arena_push();
|
||||
EXPECT_STREQ("hello", strdup("hello"));
|
||||
__arena_push();
|
||||
EXPECT_STREQ("hello", strdup("hello"));
|
||||
for (int i = 0; i < 5000; ++i) {
|
||||
EXPECT_STREQ("hello", strdup("hello"));
|
||||
}
|
||||
free(strdup("hello"));
|
||||
__arena_pop();
|
||||
EXPECT_STREQ("", calloc(1, 16));
|
||||
EXPECT_STREQ("hello", strdup("hello"));
|
||||
__arena_pop();
|
||||
}
|
||||
|
||||
TEST(arena, testRealloc) {
|
||||
char *b = 0;
|
||||
size_t i, n = 0;
|
||||
__arena_push();
|
||||
for (i = 0; i < kHyperionSize; ++i) {
|
||||
b = realloc(b, ++n * sizeof(*b));
|
||||
b[n - 1] = kHyperion[i];
|
||||
}
|
||||
ASSERT_EQ(0, memcmp(b, kHyperion, kHyperionSize));
|
||||
__arena_pop();
|
||||
}
|
||||
|
||||
void *memalign_(size_t, size_t) asm("memalign");
|
||||
void *calloc_(size_t, size_t) asm("calloc");
|
||||
|
||||
void Ca(size_t n) {
|
||||
__arena_push();
|
||||
for (int i = 0; i < n; ++i) {
|
||||
memalign_(1, 1);
|
||||
}
|
||||
__arena_pop();
|
||||
}
|
||||
|
||||
void Cb(size_t n) {
|
||||
void **P;
|
||||
P = malloc(n * sizeof(void *));
|
||||
for (int i = 0; i < n; ++i) {
|
||||
P[i] = calloc_(1, 1);
|
||||
}
|
||||
bulk_free(P, n);
|
||||
free(P);
|
||||
}
|
||||
|
||||
BENCH(arena, benchMalloc) {
|
||||
EZBENCH2("arena calloc(1)", donothing, Ca(100));
|
||||
EZBENCH2("dlmalloc calloc(1)", donothing, Cb(100));
|
||||
}
|
||||
|
||||
void Ra(void) {
|
||||
long *b = 0;
|
||||
size_t i, n = 0;
|
||||
__arena_push();
|
||||
for (i = 0; i < kHyperionSize; ++i) {
|
||||
b = realloc(b, ++n * sizeof(*b));
|
||||
b[n - 1] = kHyperion[i];
|
||||
}
|
||||
__arena_pop();
|
||||
}
|
||||
|
||||
void Rb(void) {
|
||||
long *b = 0;
|
||||
size_t i, n = 0;
|
||||
for (i = 0; i < kHyperionSize; ++i) {
|
||||
b = realloc(b, ++n * sizeof(*b));
|
||||
b[n - 1] = kHyperion[i];
|
||||
}
|
||||
free(b);
|
||||
}
|
||||
|
||||
BENCH(arena, benchRealloc) {
|
||||
EZBENCH2("arena realloc", donothing, Ra());
|
||||
EZBENCH2("dlmalloc realloc", donothing, Rb());
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ 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/log/libfatal.internal.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/mem/arraylist.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
struct string {
|
||||
size_t i, n;
|
||||
char *p;
|
||||
};
|
||||
|
||||
struct string16 {
|
||||
size_t i, n;
|
||||
char16_t *p;
|
||||
};
|
||||
|
||||
struct ArrayListInteger {
|
||||
size_t i, n;
|
||||
int *p;
|
||||
};
|
||||
|
||||
TEST(append, worksGreatForScalars) {
|
||||
char c = 'a';
|
||||
struct string s;
|
||||
memset(&s, 0, sizeof(s));
|
||||
for (size_t i = 0; i < 1024; ++i) {
|
||||
ASSERT_EQ(i, append(&s, &c));
|
||||
}
|
||||
ASSERT_EQ(1024, s.i);
|
||||
for (size_t i = 0; i < s.i; ++i) ASSERT_EQ('a', s.p[i]);
|
||||
free(s.p);
|
||||
s.p = 0;
|
||||
}
|
||||
|
||||
TEST(append, isGenericallyTyped) {
|
||||
int c = 0x31337;
|
||||
struct ArrayListInteger s;
|
||||
memset(&s, 0, sizeof(s));
|
||||
for (size_t i = 0; i < 1024; ++i) {
|
||||
ASSERT_EQ(i, append(&s, &c));
|
||||
}
|
||||
ASSERT_EQ(1024, s.i);
|
||||
ASSERT_GT(malloc_usable_size(s.p), 1024 * sizeof(int));
|
||||
for (size_t i = 0; i < s.i; ++i) {
|
||||
ASSERT_EQ(0x31337, s.p[i]);
|
||||
}
|
||||
free(s.p);
|
||||
s.p = 0;
|
||||
}
|
||||
|
||||
TEST(concat, worksGreatForStrings) {
|
||||
const char *ks = "Und wird die Welt auch in Flammen stehen\n"
|
||||
"Wir werden wieder auferstehen\n";
|
||||
struct string s;
|
||||
memset(&s, 0, sizeof(s));
|
||||
ASSERT_EQ(0, concat(&s, ks, strlen(ks)));
|
||||
ASSERT_EQ(strlen(ks), concat(&s, ks, strlen(ks) + 1));
|
||||
ASSERT_STREQ("Und wird die Welt auch in Flammen stehen\n"
|
||||
"Wir werden wieder auferstehen\n"
|
||||
"Und wird die Welt auch in Flammen stehen\n"
|
||||
"Wir werden wieder auferstehen\n",
|
||||
s.p);
|
||||
ASSERT_EQ(strlen(ks) * 2 + 1, s.i);
|
||||
free(s.p);
|
||||
s.p = 0;
|
||||
}
|
||||
|
||||
TEST(concat, isGenericallyTyped) {
|
||||
const char16_t *ks = u"Drum hoch die Fäuste, hoch zum Licht.\n"
|
||||
u"Unsere schwarzen Seelen bekommt ihr nicht.\n";
|
||||
struct string16 s;
|
||||
memset(&s, 0, sizeof(s));
|
||||
ASSERT_EQ(0, concat(&s, ks, strlen16(ks)));
|
||||
ASSERT_EQ(strlen16(ks), concat(&s, ks, strlen16(ks) + 1));
|
||||
ASSERT_STREQ(u"Drum hoch die Fäuste, hoch zum Licht.\n"
|
||||
u"Unsere schwarzen Seelen bekommt ihr nicht.\n"
|
||||
u"Drum hoch die Fäuste, hoch zum Licht.\n"
|
||||
u"Unsere schwarzen Seelen bekommt ihr nicht.\n",
|
||||
s.p);
|
||||
ASSERT_EQ(strlen16(ks) * 2 + 1, s.i);
|
||||
free(s.p);
|
||||
s.p = 0;
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ 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/mem/alg.h"
|
||||
#include "libc/mem/bisectcarleft.internal.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(bisectcarleft, testEmpty) {
|
||||
const int32_t cells[][2] = {};
|
||||
EXPECT_EQ(0, bisectcarleft(cells, ARRAYLEN(cells), 123));
|
||||
}
|
||||
|
||||
TEST(bisectcarleft, testOneEntry) {
|
||||
const int32_t cells[][2] = {{123, 31337}};
|
||||
EXPECT_EQ(0, bisectcarleft(cells, ARRAYLEN(cells), 122));
|
||||
EXPECT_EQ(0, bisectcarleft(cells, ARRAYLEN(cells), 123));
|
||||
EXPECT_EQ(0, bisectcarleft(cells, ARRAYLEN(cells), 124));
|
||||
}
|
||||
|
||||
TEST(bisectcarleft, testNegativity_usesSignedBehavior) {
|
||||
const int32_t cells[][2] = {{-2, 31337}};
|
||||
EXPECT_EQ(0, bisectcarleft(cells, ARRAYLEN(cells), -3));
|
||||
EXPECT_EQ(0, bisectcarleft(cells, ARRAYLEN(cells), -2));
|
||||
EXPECT_EQ(0, bisectcarleft(cells, ARRAYLEN(cells), -1));
|
||||
}
|
||||
|
||||
TEST(bisectcarleft, testMultipleEntries) {
|
||||
const int32_t cells[][2] = {{00, 0}, {11, 0}, {20, 0}, {33, 0}, {40, 0},
|
||||
{50, 0}, {60, 0}, {70, 0}, {80, 0}, {90, 0}};
|
||||
EXPECT_EQ(0, bisectcarleft(cells, ARRAYLEN(cells), 10));
|
||||
EXPECT_EQ(1, bisectcarleft(cells, ARRAYLEN(cells), 11));
|
||||
EXPECT_EQ(1, bisectcarleft(cells, ARRAYLEN(cells), 12));
|
||||
EXPECT_EQ(1, bisectcarleft(cells, ARRAYLEN(cells), 19));
|
||||
EXPECT_EQ(2, bisectcarleft(cells, ARRAYLEN(cells), 20));
|
||||
EXPECT_EQ(2, bisectcarleft(cells, ARRAYLEN(cells), 21));
|
||||
EXPECT_EQ(2, bisectcarleft(cells, ARRAYLEN(cells), 32));
|
||||
EXPECT_EQ(3, bisectcarleft(cells, ARRAYLEN(cells), 33));
|
||||
EXPECT_EQ(3, bisectcarleft(cells, ARRAYLEN(cells), 34));
|
||||
}
|
|
@ -20,6 +20,7 @@
|
|||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/cxaatexit.internal.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
|
@ -51,12 +52,59 @@ void SetUp(void) {
|
|||
if (IsWindows()) exit(0);
|
||||
}
|
||||
|
||||
TEST(malloc, zeroMeansOne) {
|
||||
ASSERT_GE(malloc_usable_size(gc(malloc(0))), 1);
|
||||
TEST(malloc, zero) {
|
||||
char *p;
|
||||
ASSERT_NE(NULL, (p = malloc(0)));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p, 1));
|
||||
free(p);
|
||||
}
|
||||
|
||||
TEST(calloc, zerosMeansOne) {
|
||||
ASSERT_GE(malloc_usable_size(gc(calloc(0, 0))), 1);
|
||||
TEST(realloc, bothAreZero_createsMinimalAllocation) {
|
||||
char *p;
|
||||
ASSERT_NE(NULL, (p = realloc(0, 0)));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p, 1));
|
||||
free(p);
|
||||
}
|
||||
|
||||
TEST(realloc, ptrIsZero_createsAllocation) {
|
||||
char *p;
|
||||
ASSERT_NE(NULL, (p = realloc(0, 1)));
|
||||
if (IsAsan()) ASSERT_TRUE(__asan_is_valid(p, 1));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p + 1, 1));
|
||||
ASSERT_EQ(p, realloc(p, 0));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p, 1));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p + 1, 1));
|
||||
free(p);
|
||||
}
|
||||
|
||||
TEST(realloc, sizeIsZero_shrinksAllocation) {
|
||||
char *p;
|
||||
ASSERT_NE(NULL, (p = malloc(1)));
|
||||
if (IsAsan()) ASSERT_TRUE(__asan_is_valid(p, 1));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p + 1, 1));
|
||||
ASSERT_EQ(p, realloc(p, 0));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p, 1));
|
||||
if (IsAsan()) ASSERT_FALSE(__asan_is_valid(p + 1, 1));
|
||||
free(p);
|
||||
}
|
||||
|
||||
TEST(realloc_in_place, test) {
|
||||
char *x = malloc(16);
|
||||
EXPECT_EQ(x, realloc_in_place(x, 0));
|
||||
EXPECT_EQ(x, realloc_in_place(x, 1));
|
||||
*x = 2;
|
||||
free(x);
|
||||
}
|
||||
|
||||
BENCH(realloc_in_place, bench) {
|
||||
volatile int i = 1000;
|
||||
volatile char *x = malloc(i);
|
||||
EZBENCH2("malloc", donothing, free(malloc(i)));
|
||||
EZBENCH2("memalign", donothing, free(memalign(16, i)));
|
||||
EZBENCH2("memalign", donothing, free(memalign(32, i)));
|
||||
EZBENCH2("realloc", donothing, x = realloc(x, --i));
|
||||
EZBENCH2("realloc_in_place", donothing, realloc_in_place(x, --i));
|
||||
free(x);
|
||||
}
|
||||
|
||||
void AppendStuff(char **p, size_t *n) {
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
/*-*- 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 2021 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/mem/mem.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(realloc_in_place, test) {
|
||||
char *x = malloc(16);
|
||||
EXPECT_EQ(x, realloc_in_place(x, 0));
|
||||
EXPECT_EQ(x, realloc_in_place(x, 1));
|
||||
*x = 2;
|
||||
free(x);
|
||||
}
|
||||
|
||||
BENCH(realloc_in_place, bench) {
|
||||
volatile int i = 1000;
|
||||
volatile char *x = malloc(i);
|
||||
EZBENCH2("malloc", donothing, free(malloc(i)));
|
||||
EZBENCH2("malloc", donothing, free(malloc(i)));
|
||||
EZBENCH2("memalign", donothing, free(memalign(16, i)));
|
||||
EZBENCH2("memalign", donothing, free(memalign(32, i)));
|
||||
EZBENCH2("realloc", donothing, x = realloc(x, --i));
|
||||
EZBENCH2("realloc_in_place", donothing, realloc_in_place(x, --i));
|
||||
free(x);
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ 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/mem/reverse.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(reverse, test) {
|
||||
/* this test gets DCE'd :) */
|
||||
int A[3] = {1, 2, 3};
|
||||
reverse(A, ARRAYLEN(A));
|
||||
EXPECT_EQ(3, A[0]);
|
||||
EXPECT_EQ(2, A[1]);
|
||||
EXPECT_EQ(1, A[2]);
|
||||
}
|
||||
|
||||
TEST(reverse, testEmpty) {
|
||||
int A[3] = {1, 2, 3};
|
||||
reverse(A, 0);
|
||||
EXPECT_EQ(1, A[0]);
|
||||
EXPECT_EQ(2, A[1]);
|
||||
EXPECT_EQ(3, A[2]);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue