xref: /third_party/musl/libc-test/src/regression/malloc-pressure.c
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/musl/libc-test/src/regression/
1570af302Sopenharmony_ci#include <malloc.h>
2570af302Sopenharmony_ci#include <time.h>
3570af302Sopenharmony_ci#include "test.h"
4570af302Sopenharmony_ci
5570af302Sopenharmony_ci#define SIZE_ALIGN (4 * sizeof(size_t))
6570af302Sopenharmony_ci#define THRESHOLD (0x1c00 * SIZE_ALIGN)
7570af302Sopenharmony_ci#define ITER_TIME 20
8570af302Sopenharmony_ci
9570af302Sopenharmony_ciint main(int argc, char *argv[])
10570af302Sopenharmony_ci{
11570af302Sopenharmony_ci	struct timespec ts[2];
12570af302Sopenharmony_ci
13570af302Sopenharmony_ci	clock_gettime(CLOCK_REALTIME, &ts[0]);
14570af302Sopenharmony_ci	for (int i = 0; i < ITER_TIME; ++i) {
15570af302Sopenharmony_ci		for (size_t size = 0; size < THRESHOLD; size += SIZE_ALIGN + 1) {
16570af302Sopenharmony_ci			void *ptr = malloc(size);
17570af302Sopenharmony_ci			if (!ptr) {
18570af302Sopenharmony_ci				t_error("Malloc failed for size %u\n", size);
19570af302Sopenharmony_ci				return -1;
20570af302Sopenharmony_ci			}
21570af302Sopenharmony_ci			free(ptr);
22570af302Sopenharmony_ci		}
23570af302Sopenharmony_ci	}
24570af302Sopenharmony_ci
25570af302Sopenharmony_ci	return t_status;
26570af302Sopenharmony_ci}
27

Indexes created Thu Nov 07 10:32:03 CST 2024