test: use memseg walk instead of iteration
[dpdk.git] / test / test / test_memory.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #include <stdio.h>
6 #include <stdint.h>
7
8 #include <rte_memory.h>
9 #include <rte_common.h>
10
11 #include "test.h"
12
13 /*
14  * Memory
15  * ======
16  *
17  * - Dump the mapped memory. The python-expect script checks that at
18  *   least one line is dumped.
19  *
20  * - Check that memory size is different than 0.
21  *
22  * - Try to read all memory; it should not segfault.
23  */
24
25 static int
26 check_mem(const struct rte_memseg *ms, void *arg __rte_unused)
27 {
28         volatile uint8_t *mem = (volatile uint8_t *) ms->addr;
29         size_t i;
30
31         for (i = 0; i < ms->len; i++, mem++)
32                 *mem;
33         return 0;
34 }
35
36 static int
37 test_memory(void)
38 {
39         uint64_t s;
40
41         /*
42          * dump the mapped memory: the python-expect script checks
43          * that at least one line is dumped
44          */
45         printf("Dump memory layout\n");
46         rte_dump_physmem_layout(stdout);
47
48         /* check that memory size is != 0 */
49         s = rte_eal_get_physmem_size();
50         if (s == 0) {
51                 printf("No memory detected\n");
52                 return -1;
53         }
54
55         /* try to read memory (should not segfault) */
56         rte_memseg_walk(check_mem, NULL);
57
58         return 0;
59 }
60
61 REGISTER_TEST_COMMAND(memory_autotest, test_memory);