Branch data Line data Source code
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_eal.h> 9 : : #include <rte_errno.h> 10 : : #include <rte_memory.h> 11 : : #include <rte_common.h> 12 : : #include <rte_memzone.h> 13 : : 14 : : #include "test.h" 15 : : 16 : : /* 17 : : * Memory 18 : : * ====== 19 : : * 20 : : * - Dump the mapped memory. The python-expect script checks that at 21 : : * least one line is dumped. 22 : : * 23 : : * - Check that memory size is different than 0. 24 : : * 25 : : * - Try to read all memory; it should not segfault. 26 : : */ 27 : : 28 : : /* 29 : : * ASan complains about accessing unallocated memory. 30 : : * See: https://bugs.dpdk.org/show_bug.cgi?id=880 31 : : */ 32 : : __rte_no_asan 33 : : static int 34 : 1 : check_mem(const struct rte_memseg_list *msl __rte_unused, 35 : : const struct rte_memseg *ms, void *arg __rte_unused) 36 : : { 37 : 1 : volatile uint8_t *mem = (volatile uint8_t *) ms->addr; 38 : 1 : size_t i, max = ms->len; 39 : : 40 [ + + ]: 2097153 : for (i = 0; i < max; i++, mem++) 41 : 2097152 : *mem; 42 : 1 : return 0; 43 : : } 44 : : 45 : : static int 46 : 1 : check_seg_fds(const struct rte_memseg_list *msl, const struct rte_memseg *ms, 47 : : void *arg __rte_unused) 48 : : { 49 : : size_t offset; 50 : : int ret; 51 : : 52 : : /* skip external segments */ 53 [ + - ]: 1 : if (msl->external) 54 : : return 0; 55 : : 56 : : /* try segment fd first. we're in a callback, so thread-unsafe */ 57 : 1 : ret = rte_memseg_get_fd_thread_unsafe(ms); 58 [ - + ]: 1 : if (ret < 0) { 59 : : /* ENOTSUP means segment is valid, but there is not support for 60 : : * segment fd API (e.g. on FreeBSD). 61 : : */ 62 [ # # ]: 0 : if (rte_errno == ENOTSUP) 63 : : return 1; 64 : : /* all other errors are treated as failures */ 65 : 0 : return -1; 66 : : } 67 : : 68 : : /* we're able to get memseg fd - try getting its offset */ 69 : 1 : ret = rte_memseg_get_fd_offset_thread_unsafe(ms, &offset); 70 [ - + ]: 1 : if (ret < 0) { 71 [ # # ]: 0 : if (rte_errno == ENOTSUP) 72 : : return 1; 73 : 0 : return -1; 74 : : } 75 : : return 0; 76 : : } 77 : : 78 : : static int 79 : 1 : test_memory(void) 80 : : { 81 : : uint64_t s; 82 : : int ret; 83 : : 84 : : /* 85 : : * dump the mapped memory: the python-expect script checks 86 : : * that at least one line is dumped 87 : : */ 88 : : printf("Dump memory layout\n"); 89 : 1 : rte_dump_physmem_layout(stdout); 90 : : 91 : : /* check that memory size is != 0 */ 92 : 1 : s = rte_eal_get_physmem_size(); 93 [ - + ]: 1 : if (s == 0) { 94 : : printf("No memory detected\n"); 95 : 0 : return -1; 96 : : } 97 : : 98 : : /* try to read memory (should not segfault) */ 99 : 1 : rte_memseg_walk(check_mem, NULL); 100 : : 101 : : /* check segment fd support */ 102 : 1 : ret = rte_memseg_walk(check_seg_fds, NULL); 103 [ - + ]: 1 : if (ret == 1) { 104 : : printf("Segment fd API is unsupported\n"); 105 [ - + ]: 1 : } else if (ret == -1) { 106 : : printf("Error getting segment fd's\n"); 107 : 0 : return -1; 108 : : } 109 : : 110 : : return 0; 111 : : } 112 : : 113 : 252 : REGISTER_FAST_TEST(memory_autotest, false, true, test_memory);