1/*
2 * Copyright (c) 2018, ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <inttypes.h>
13
14static void test_malloc(size_t bytes)
15{
16    printf("malloctest: testing allocation of %zu bytes\n", bytes);
17    uint8_t *buf = malloc(bytes);
18    if (!buf) {
19        printf("malloctest: malloc returned null\n");
20        exit(1);
21    }
22    for (size_t i = 0; i < bytes; i++) {
23        buf[i] = i % 256;
24    }
25
26    free(buf);
27
28    return;
29}
30
31int main(void)
32{
33
34    test_malloc(5);
35
36    test_malloc(1000);
37
38    test_malloc(2*1024*1024ULL);
39
40#if (UINTPTR_MAX == UINT64_MAX)
41    test_malloc(1024*1024*1024ULL);
42#else
43    test_malloc(128*1024*1024ULL);
44#endif
45
46    printf("malloctest done.\n");
47    return 0;
48}
49