File tree Expand file tree Collapse file tree 6 files changed +89
-1
lines changed Expand file tree Collapse file tree 6 files changed +89
-1
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ CFLAGS += -I. -I../../include -Wall -O2 -fsanitize=address \
6
6
-fsanitize=undefined -D CONFIG_PHYS_ADDR_T_64BIT
7
7
LDFLAGS += -fsanitize=address -fsanitize=undefined
8
8
TARGETS = main
9
- OFILES = main.o memblock.o lib/slab.o mmzone.o slab.o
9
+ TEST_OFILES = tests/basic_api.o tests/common.o
10
+ DEP_OFILES = memblock.o lib/slab.o mmzone.o slab.o
11
+ OFILES = main.o $(DEP_OFILES ) $(TEST_OFILES )
10
12
EXTR_SRC = ../../../mm/memblock.c
11
13
12
14
ifeq ($(BUILD ) , 32)
Original file line number Diff line number Diff line change 1
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
+ #include "tests/basic_api.h"
2
3
3
4
int main (int argc , char * * argv )
4
5
{
6
+ memblock_basic_checks ();
5
7
return 0 ;
6
8
}
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ #include <string.h>
3
+ #include <linux/memblock.h>
4
+ #include "basic_api.h"
5
+
6
+ #define EXPECTED_MEMBLOCK_REGIONS 128
7
+
8
+ static int memblock_initialization_check (void )
9
+ {
10
+ reset_memblock ();
11
+
12
+ assert (memblock .memory .regions );
13
+ assert (memblock .memory .cnt == 1 );
14
+ assert (memblock .memory .max == EXPECTED_MEMBLOCK_REGIONS );
15
+ assert (strcmp (memblock .memory .name , "memory" ) == 0 );
16
+
17
+ assert (memblock .reserved .regions );
18
+ assert (memblock .reserved .cnt == 1 );
19
+ assert (memblock .memory .max == EXPECTED_MEMBLOCK_REGIONS );
20
+ assert (strcmp (memblock .reserved .name , "reserved" ) == 0 );
21
+
22
+ assert (!memblock .bottom_up );
23
+ assert (memblock .current_limit == MEMBLOCK_ALLOC_ANYWHERE );
24
+
25
+ return 0 ;
26
+ }
27
+
28
+ int memblock_basic_checks (void )
29
+ {
30
+ memblock_initialization_check ();
31
+ return 0 ;
32
+ }
Original file line number Diff line number Diff line change
1
+ /* SPDX-License-Identifier: GPL-2.0-or-later */
2
+ #ifndef _MEMBLOCK_BASIC_H
3
+ #define _MEMBLOCK_BASIC_H
4
+
5
+ #include <assert.h>
6
+ #include "common.h"
7
+
8
+ int memblock_basic_checks (void );
9
+
10
+ #endif
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ #include "tests/common.h"
3
+ #include <string.h>
4
+
5
+ #define INIT_MEMBLOCK_REGIONS 128
6
+ #define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS
7
+
8
+ void reset_memblock (void )
9
+ {
10
+ memset (memblock .memory .regions , 0 ,
11
+ memblock .memory .cnt * sizeof (struct memblock_region ));
12
+ memset (memblock .reserved .regions , 0 ,
13
+ memblock .reserved .cnt * sizeof (struct memblock_region ));
14
+
15
+ memblock .memory .cnt = 1 ;
16
+ memblock .memory .max = INIT_MEMBLOCK_REGIONS ;
17
+ memblock .memory .name = "memory" ;
18
+ memblock .memory .total_size = 0 ;
19
+
20
+ memblock .reserved .cnt = 1 ;
21
+ memblock .reserved .max = INIT_MEMBLOCK_RESERVED_REGIONS ;
22
+ memblock .reserved .name = "reserved" ;
23
+ memblock .reserved .total_size = 0 ;
24
+
25
+ memblock .bottom_up = false;
26
+ memblock .current_limit = MEMBLOCK_ALLOC_ANYWHERE ;
27
+ }
Original file line number Diff line number Diff line change
1
+ /* SPDX-License-Identifier: GPL-2.0-or-later */
2
+ #ifndef _MEMBLOCK_TEST_H
3
+ #define _MEMBLOCK_TEST_H
4
+
5
+ #include <linux/types.h>
6
+ #include <linux/memblock.h>
7
+
8
+ struct region {
9
+ phys_addr_t base ;
10
+ phys_addr_t size ;
11
+ };
12
+
13
+ void reset_memblock (void );
14
+
15
+ #endif
You can’t perform that action at this time.
0 commit comments