Loading...
--- libmalloc/libmalloc-140.50.6/tests/stress_test.c
+++ libmalloc/libmalloc-792.41.1/tests/stress_test.c
@@ -30,11 +30,30 @@
#include <string.h>
#include <time.h>
#include <errno.h>
+
+#include "../src/platform.h"
+
+#if !MALLOC_TARGET_EXCLAVES
#include <err.h>
+#endif // !MALLOC_TARGET_EXCLAVES
#if DARWINTEST
#include <darwintest.h>
-#endif
+T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true), T_META_TAG_ALL_ALLOCATORS, T_META_TAG_VM_NOT_PREFERRED);
+#endif
+
+static time_t time_seconds(void) {
+#if !MALLOC_TARGET_EXCLAVES
+ return time(0);
+#else
+ struct timespec t;
+ int rc = clock_gettime(CLOCK_MONOTONIC_RAW, &t);
+ if (rc) {
+ return -1;
+ }
+ return t.tv_sec;
+#endif // !MALLOC_TARGET_EXCLAVES
+}
/* globals */
int rseed; /* initial random seed value */
@@ -68,6 +87,7 @@
/* Generate a random percentage (1-100) */
#define D100 (1 + (rand() % 100))
+#if !MALLOC_TARGET_EXCLAVES
int signal_happened = 0; /* gets set to signal# if one happens */
void
@@ -91,6 +111,7 @@
};
}
}
+#endif // !MALLOC_TARGET_EXCLAVES
/* Display a brief usage message and exit with status 99 */
void
@@ -153,6 +174,7 @@
for (mx = 0; mx < malloc_calls_made; mx++) {
if (!(minfo_array[mx].this_buffer_freed)) {
free(minfo_array[mx].buf_ptr);
+#if !MALLOC_TARGET_EXCLAVES
if (signal_happened) {
#if DARWINTEST
T_FAIL("Signal %d occurred during free(0x%llx)", signal_happened, (unsigned long long)(minfo_array[mx].buf_ptr));
@@ -162,6 +184,7 @@
exit(1);
#endif
}
+#endif // !MALLOC_TARGET_EXCLAVES
}
}
return;
@@ -212,7 +235,7 @@
mem_allocated = 0;
/* Set defaults */
- rseed = (int)time(0);
+ rseed = (int)time_seconds();
min_bytes = 1;
max_bytes = (1024 * 1024); /* 1mb */
max_mem = 0; /* Continue until malloc() returns NULL */
@@ -334,10 +357,15 @@
void
do_test(void)
{
- time_t start_time = time(0);
-
+ time_t start_time = time_seconds();
+#if DARWINTEST
+ T_ASSERT_NE(start_time, (time_t)-1, "Failed to get start time");
+#endif // DARWINTEST
+
+#if !MALLOC_TARGET_EXCLAVES
/* Trap all signals that are possible to trap */
trap_signals();
+#endif // !MALLOC_TARGET_EXCLAVES
/*
* Loop until we have some reason to quit.
@@ -350,7 +378,7 @@
int save_errno;
/* Have we exceeded our execution time limit? */
- if (time_limit > 0 && (time(0) - start_time >= time_limit)) {
+ if (time_limit > 0 && (time_seconds() - start_time >= time_limit)) {
#if DARWINTEST
cleanup();
T_PASS("Ran until time limit without incident.");
@@ -374,6 +402,7 @@
random_buf = rand() % malloc_calls_made;
if (!(minfo_array[random_buf].this_buffer_freed)) {
free(minfo_array[random_buf].buf_ptr);
+#if !MALLOC_TARGET_EXCLAVES
/* If a signal happened, Fail */
if (signal_happened) {
#if DARWINTEST
@@ -387,6 +416,7 @@
exit(1);
#endif
}
+#endif // !MALLOC_TARGET_EXCLAVES
minfo_array[random_buf].this_buffer_freed = 1;
malloc_bufs--; /* decrease the count of allocated bufs */
@@ -408,6 +438,7 @@
malloc_buf = malloc(buf_size);
save_errno = errno;
+#if !MALLOC_TARGET_EXCLAVES
/* If a signal was caught, summarize and FAIL */
if (signal_happened) {
#if DARWINTEST
@@ -420,6 +451,7 @@
exit(1);
#endif
}
+#endif // !MALLOC_TARGET_EXCLAVES
if (debug_dump) {
printf("INFO: Allocated buffer (%d bytes) at address 0x%llx\n", buf_size, (unsigned long long)malloc_buf);
@@ -480,6 +512,7 @@
char byte;
*((volatile char *)&byte) = *((volatile char *)malloc_buf + bx);
+#if !MALLOC_TARGET_EXCLAVES
if (signal_happened) {
#if DARWINTEST
T_FAIL("Signal %d caught reading buffer!", signal_happened);
@@ -490,6 +523,7 @@
exit(1);
#endif
}
+#endif // !MALLOC_TARGET_EXCLAVES
}
/*
@@ -528,6 +562,7 @@
*((long double *)malloc_buf) = 7.2;
}
+#if !MALLOC_TARGET_EXCLAVES
if (signal_happened) {
#if DARWINTEST
T_FAIL("Signal %d occurred storing numeric types at address 0x%llx (%d bytes)", signal_happened,
@@ -540,10 +575,12 @@
exit(1);
#endif
}
+#endif // !MALLOC_TARGET_EXCLAVES
/* Pick a random byte value to set the bytes of the buffer to */
set_buf_val = rand() & 0xFF;
memset(malloc_buf, set_buf_val, buf_size);
+#if !MALLOC_TARGET_EXCLAVES
if (signal_happened) {
#if DARWINTEST
T_FAIL("Signal %d caught initializing buffer to byte value %d!", signal_happened, set_buf_val);
@@ -554,6 +591,7 @@
exit(1);
#endif
}
+#endif // !MALLOC_TARGET_EXCLAVES
/* Save the new malloc info */
@@ -622,6 +660,7 @@
}
}
+#if !MALLOC_TARGET_EXCLAVES
/* If any signal occurred, that's a FAIL too. */
if (signal_happened) {
#if DARWINTEST
@@ -633,6 +672,7 @@
exit(1);
#endif
}
+#endif // !MALLOC_TARGET_EXCLAVES
} /* end then malloc succeeded */
@@ -655,7 +695,9 @@
time_limit = 15;
debug_dump = 0;
-
+
+ malloc_calls_made = 0;
+
do_test();
}
@@ -664,11 +706,17 @@
setup_and_test();
}
-T_DECL(malloc_stress_msl_full, "Stress the heck out of malloc() - enable malloc stack logging, full mode", T_META_ENVVAR("MallocStackLogging=1"))
+T_DECL(malloc_stress_nano, "Stress the heck out of malloc() with nano",
+ T_META_ENVVAR("MallocNanoZone=1"))
{
setup_and_test();
}
+T_DECL(malloc_stress_msl_full, "Stress the heck out of malloc() - enable malloc stack logging, full mode", T_META_ENVVAR("MallocStackLogging=full"))
+{
+ setup_and_test();
+}
+
T_DECL(malloc_stress_msl_malloc, "Stress the heck out of malloc() - enable malloc stack logging, malloc mode", T_META_ENVVAR("MallocStackLogging=malloc"))
{
setup_and_test();