diff options
Diffstat (limited to 'src/regress/lib/libc/malloc/malloc_general')
| -rw-r--r-- | src/regress/lib/libc/malloc/malloc_general/Makefile | 43 | ||||
| -rw-r--r-- | src/regress/lib/libc/malloc/malloc_general/malloc_general.c | 123 |
2 files changed, 0 insertions, 166 deletions
diff --git a/src/regress/lib/libc/malloc/malloc_general/Makefile b/src/regress/lib/libc/malloc/malloc_general/Makefile deleted file mode 100644 index 367b33b9c5..0000000000 --- a/src/regress/lib/libc/malloc/malloc_general/Makefile +++ /dev/null | |||
| @@ -1,43 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.7 2023/05/09 19:07:37 otto Exp $ | ||
| 2 | |||
| 3 | REGRESS_TARGETS= t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 | ||
| 4 | PROG= malloc_general | ||
| 5 | |||
| 6 | .include <bsd.regress.mk> | ||
| 7 | |||
| 8 | t1: malloc_general | ||
| 9 | MALLOC_OPTIONS=su ${.OBJDIR}/malloc_general | ||
| 10 | |||
| 11 | t2: malloc_general | ||
| 12 | MALLOC_OPTIONS=suC ${.OBJDIR}/malloc_general | ||
| 13 | |||
| 14 | t3: malloc_general | ||
| 15 | MALLOC_OPTIONS=suJ ${.OBJDIR}/malloc_general | ||
| 16 | |||
| 17 | t4: malloc_general | ||
| 18 | MALLOC_OPTIONS=suF ${.OBJDIR}/malloc_general | ||
| 19 | |||
| 20 | t5: malloc_general | ||
| 21 | MALLOC_OPTIONS=suG ${.OBJDIR}/malloc_general | ||
| 22 | |||
| 23 | t6: malloc_general | ||
| 24 | MALLOC_OPTIONS=suS ${.OBJDIR}/malloc_general | ||
| 25 | |||
| 26 | t7: malloc_general | ||
| 27 | MALLOC_OPTIONS=suFGJ ${.OBJDIR}/malloc_general | ||
| 28 | |||
| 29 | t8: malloc_general | ||
| 30 | MALLOC_OPTIONS=suCJ ${.OBJDIR}/malloc_general | ||
| 31 | |||
| 32 | t9: malloc_general | ||
| 33 | MALLOC_OPTIONS=suCJJ ${.OBJDIR}/malloc_general | ||
| 34 | |||
| 35 | t10: malloc_general | ||
| 36 | MALLOC_OPTIONS=suJS ${.OBJDIR}/malloc_general | ||
| 37 | |||
| 38 | t11: malloc_general | ||
| 39 | MALLOC_OPTIONS=suFGJJ ${.OBJDIR}/malloc_general | ||
| 40 | |||
| 41 | t12: malloc_general | ||
| 42 | MALLOC_OPTIONS=suFCJJ ${.OBJDIR}/malloc_general | ||
| 43 | |||
diff --git a/src/regress/lib/libc/malloc/malloc_general/malloc_general.c b/src/regress/lib/libc/malloc/malloc_general/malloc_general.c deleted file mode 100644 index b243787bcf..0000000000 --- a/src/regress/lib/libc/malloc/malloc_general/malloc_general.c +++ /dev/null | |||
| @@ -1,123 +0,0 @@ | |||
| 1 | /* $OpenBSD: malloc_general.c,v 1.7 2022/01/09 07:18:50 otto Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2017 Otto Moerbeek <otto@drijf.net> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <err.h> | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <stdlib.h> | ||
| 21 | #include <string.h> | ||
| 22 | |||
| 23 | /* #define VERBOSE */ | ||
| 24 | |||
| 25 | #define N 1000 | ||
| 26 | |||
| 27 | size_t | ||
| 28 | size(void) | ||
| 29 | { | ||
| 30 | int p = arc4random_uniform(17) + 3; | ||
| 31 | return arc4random_uniform(1 << p); | ||
| 32 | } | ||
| 33 | |||
| 34 | struct { void *p; size_t sz; } a[N]; | ||
| 35 | |||
| 36 | void | ||
| 37 | fill(u_char *p, size_t sz) | ||
| 38 | { | ||
| 39 | size_t i; | ||
| 40 | |||
| 41 | for (i = 0; i < sz; i++) | ||
| 42 | p[i] = i % 256; | ||
| 43 | } | ||
| 44 | |||
| 45 | void | ||
| 46 | check(u_char *p, size_t sz) | ||
| 47 | { | ||
| 48 | size_t i; | ||
| 49 | |||
| 50 | for (i = 0; i < sz; i++) | ||
| 51 | if (p[i] != i % 256) | ||
| 52 | errx(1, "check"); | ||
| 53 | } | ||
| 54 | |||
| 55 | int | ||
| 56 | main(int argc, char *argv[]) | ||
| 57 | { | ||
| 58 | int count, p, r, i; | ||
| 59 | void * q; | ||
| 60 | size_t sz; | ||
| 61 | |||
| 62 | for (count = 0; count < 800000; count++) { | ||
| 63 | if (count % 10000 == 0) { | ||
| 64 | printf("."); | ||
| 65 | fflush(stdout); | ||
| 66 | } | ||
| 67 | p = arc4random_uniform(2); | ||
| 68 | i = arc4random_uniform(N); | ||
| 69 | switch (p) { | ||
| 70 | case 0: | ||
| 71 | if (a[i].p) { | ||
| 72 | #ifdef VERBOSE | ||
| 73 | printf("F %p\n", a[i].p); | ||
| 74 | #endif | ||
| 75 | if (a[i].p) | ||
| 76 | check(a[i].p, a[i].sz); | ||
| 77 | free(a[i].p); | ||
| 78 | a[i].p = NULL; | ||
| 79 | } | ||
| 80 | sz = size(); | ||
| 81 | #ifdef VERBOSE | ||
| 82 | printf("M %zu=", sz); | ||
| 83 | #endif | ||
| 84 | r = arc4random_uniform(2); | ||
| 85 | a[i].p = r == 0 ? malloc_conceal(sz) : malloc(sz); | ||
| 86 | a[i].sz = sz; | ||
| 87 | #ifdef VERBOSE | ||
| 88 | printf("%p\n", a[i].p); | ||
| 89 | #endif | ||
| 90 | if (a[i].p) | ||
| 91 | fill(a[i].p, sz); | ||
| 92 | break; | ||
| 93 | case 1: | ||
| 94 | sz = size(); | ||
| 95 | #ifdef VERBOSE | ||
| 96 | printf("R %p %zu=", a[i].p, sz); | ||
| 97 | #endif | ||
| 98 | q = realloc(a[i].p, sz); | ||
| 99 | #ifdef VERBOSE | ||
| 100 | printf("%p\n", q); | ||
| 101 | #endif | ||
| 102 | if (a[i].p && q) | ||
| 103 | check(q, a[i].sz < sz ? a[i].sz : sz); | ||
| 104 | if (q) { | ||
| 105 | a[i].p = q; | ||
| 106 | a[i].sz = sz; | ||
| 107 | fill(a[i].p, sz); | ||
| 108 | } | ||
| 109 | break; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | for (i = 0; i < N; i++) { | ||
| 113 | if (a[i].p) | ||
| 114 | check(a[i].p, a[i].sz); | ||
| 115 | r = arc4random_uniform(2); | ||
| 116 | if (r) | ||
| 117 | free(a[i].p); | ||
| 118 | else | ||
| 119 | freezero(a[i].p, a[i].sz); | ||
| 120 | } | ||
| 121 | printf("\n"); | ||
| 122 | return 0; | ||
| 123 | } | ||
