15129044dSC.J. Collier/*-
25129044dSC.J. Collier *   BSD LICENSE
35129044dSC.J. Collier *
45129044dSC.J. Collier *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
55129044dSC.J. Collier *   All rights reserved.
65129044dSC.J. Collier *
75129044dSC.J. Collier *   Redistribution and use in source and binary forms, with or without
85129044dSC.J. Collier *   modification, are permitted provided that the following conditions
95129044dSC.J. Collier *   are met:
105129044dSC.J. Collier *
115129044dSC.J. Collier *     * Redistributions of source code must retain the above copyright
125129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer.
135129044dSC.J. Collier *     * Redistributions in binary form must reproduce the above copyright
145129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer in
155129044dSC.J. Collier *       the documentation and/or other materials provided with the
165129044dSC.J. Collier *       distribution.
175129044dSC.J. Collier *     * Neither the name of Intel Corporation nor the names of its
185129044dSC.J. Collier *       contributors may be used to endorse or promote products derived
195129044dSC.J. Collier *       from this software without specific prior written permission.
205129044dSC.J. Collier *
215129044dSC.J. Collier *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
225129044dSC.J. Collier *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
235129044dSC.J. Collier *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
245129044dSC.J. Collier *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
255129044dSC.J. Collier *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
265129044dSC.J. Collier *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
275129044dSC.J. Collier *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
285129044dSC.J. Collier *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
295129044dSC.J. Collier *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
305129044dSC.J. Collier *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
315129044dSC.J. Collier *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
325129044dSC.J. Collier */
335129044dSC.J. Collier
345129044dSC.J. Collier#include <stdio.h>
355129044dSC.J. Collier#include <stdint.h>
365129044dSC.J. Collier
375129044dSC.J. Collier#include <rte_memory.h>
385129044dSC.J. Collier#include <rte_common.h>
395129044dSC.J. Collier
405129044dSC.J. Collier#include "test.h"
415129044dSC.J. Collier
425129044dSC.J. Collier/*
435129044dSC.J. Collier * Memory
445129044dSC.J. Collier * ======
455129044dSC.J. Collier *
465129044dSC.J. Collier * - Dump the mapped memory. The python-expect script checks that at
475129044dSC.J. Collier *   least one line is dumped.
485129044dSC.J. Collier *
495129044dSC.J. Collier * - Check that memory size is different than 0.
505129044dSC.J. Collier *
515129044dSC.J. Collier * - Try to read all memory; it should not segfault.
525129044dSC.J. Collier */
535129044dSC.J. Collier
545129044dSC.J. Collierstatic int
555129044dSC.J. Colliertest_memory(void)
565129044dSC.J. Collier{
575129044dSC.J. Collier	uint64_t s;
585129044dSC.J. Collier	unsigned i;
595129044dSC.J. Collier	size_t j;
605129044dSC.J. Collier	const struct rte_memseg *mem;
615129044dSC.J. Collier
625129044dSC.J. Collier	/*
635129044dSC.J. Collier	 * dump the mapped memory: the python-expect script checks
645129044dSC.J. Collier	 * that at least one line is dumped
655129044dSC.J. Collier	 */
665129044dSC.J. Collier	printf("Dump memory layout\n");
675129044dSC.J. Collier	rte_dump_physmem_layout(stdout);
685129044dSC.J. Collier
695129044dSC.J. Collier	/* check that memory size is != 0 */
705129044dSC.J. Collier	s = rte_eal_get_physmem_size();
715129044dSC.J. Collier	if (s == 0) {
725129044dSC.J. Collier		printf("No memory detected\n");
735129044dSC.J. Collier		return -1;
745129044dSC.J. Collier	}
755129044dSC.J. Collier
765129044dSC.J. Collier	/* try to read memory (should not segfault) */
775129044dSC.J. Collier	mem = rte_eal_get_physmem_layout();
785129044dSC.J. Collier	for (i = 0; i < RTE_MAX_MEMSEG && mem[i].addr != NULL ; i++) {
795129044dSC.J. Collier
805129044dSC.J. Collier		/* check memory */
815129044dSC.J. Collier		for (j = 0; j<mem[i].len; j++) {
825129044dSC.J. Collier			*((volatile uint8_t *) mem[i].addr + j);
835129044dSC.J. Collier		}
845129044dSC.J. Collier	}
855129044dSC.J. Collier
865129044dSC.J. Collier	return 0;
875129044dSC.J. Collier}
885129044dSC.J. Collier
899ecc306dSRicardo SalvetiREGISTER_TEST_COMMAND(memory_autotest, test_memory);
90