New upstream version 18.02
[deb_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 test_memory(void)
27 {
28         uint64_t s;
29         unsigned i;
30         size_t j;
31         const struct rte_memseg *mem;
32
33         /*
34          * dump the mapped memory: the python-expect script checks
35          * that at least one line is dumped
36          */
37         printf("Dump memory layout\n");
38         rte_dump_physmem_layout(stdout);
39
40         /* check that memory size is != 0 */
41         s = rte_eal_get_physmem_size();
42         if (s == 0) {
43                 printf("No memory detected\n");
44                 return -1;
45         }
46
47         /* try to read memory (should not segfault) */
48         mem = rte_eal_get_physmem_layout();
49         for (i = 0; i < RTE_MAX_MEMSEG && mem[i].addr != NULL ; i++) {
50
51                 /* check memory */
52                 for (j = 0; j<mem[i].len; j++) {
53                         *((volatile uint8_t *) mem[i].addr + j);
54                 }
55         }
56
57         return 0;
58 }
59
60 REGISTER_TEST_COMMAND(memory_autotest, test_memory);