MOS Source Code
Loading...
Searching...
No Matches
test_kmalloc.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include "test_engine_impl.h"
4
5#include <mos_stdlib.h>
6#include <mos_string.h>
7
9{
10 void *p = kmalloc(1024);
11 MOS_TEST_ASSERT(p != NULL, "kmalloc failed");
12 memset(p, 0, 1024);
13 kfree(p);
14}
15
17{
18 void *p;
19 int i;
20 for (i = 0; i < 100; i++)
21 {
22 p = kmalloc(1024);
23 MOS_TEST_ASSERT(p != NULL, "kmalloc failed");
24 memset(p, 0, 1024);
25 kfree(p);
26 }
27}
28
30{
31 char *p = 0;
32 p = kmalloc(1 MB);
33 MOS_TEST_ASSERT(p != NULL, "kmalloc failed");
34 memset(p, 0, 1 MB);
35 kfree(p);
36
37 p = kmalloc(100 MB);
38 MOS_TEST_ASSERT(p != NULL, "kmalloc failed");
39 memset(p, 0, 100 MB);
40 kfree(p);
41
42 // we won't test larger allocations because for (32-bit) x86, the kernel
43 // heap starts at 0xd0000000, while the initrd is placed at 0xec000000,
44 // That only leaves 0x1c000000 bytes for the kernel heap i.e. ~460 MB.
45}
46
48{
49 void *pointers[100];
50 for (int t = 0; t < 20; t++)
51 {
52 for (int i = 0; i < 50; i++)
53 {
54 pointers[i] = kmalloc(71);
55 MOS_TEST_ASSERT(pointers[i] != NULL, "failed to allocate memory");
56 memset(pointers[i], 0, 71);
57 }
58
59 for (int i = 0; i < 50; i++)
60 {
61 kfree(pointers[i]);
62 }
63 }
64}
#define MB
Definition mos_global.h:89
#define NULL
Definition pb_syshdr.h:46
static void * memset(void *s, int c, size_t n)
Definition pb_syshdr.h:101
#define MOS_TEST_CASE(_TestName)
#define MOS_TEST_ASSERT(condition, format,...)
static void kmalloc_a_lot(mos_test_result_t *, bool *, bool *)
static void kmalloc_large(mos_test_result_t *, bool *, bool *)
static void kmalloc_single(mos_test_result_t *, bool *, bool *)
static void kmalloc_stress(mos_test_result_t *, bool *, bool *)