Skip to content

Commit

Permalink
test: linux: zynqmp: Add ion shmem test
Browse files Browse the repository at this point in the history
Add ION shared memory test to ZynqMP

Signed-off-by: Wendy Liang <wendy.liang@xilinx.com>
  • Loading branch information
Wendy Liang committed Mar 6, 2019
1 parent dc77e45 commit d75522e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/system/linux/zynqmp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
collect (PROJECT_LIB_TESTS ion-shmem.c)

# vim: expandtab:ts=2:sw=2:smartindent
53 changes: 53 additions & 0 deletions test/system/linux/zynqmp/ion-shmem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2015, Xilinx Inc. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include "metal-test.h"
#include <metal/log.h>
#include <metal/scatterlist.h>
#include <metal/shmem.h>
#include <stdlib.h>

#define MB(n) (0x100000U * (n))
#define SHM_SIZE MB(4)

static int ion_shmem(void)
{
struct metal_generic_shmem *shm;
struct metal_scatter_list *sg;
char *shm_name = "ion.reserved/shm0";
struct metal_io_region *io;
size_t size;
int ret;
void *va;
unsigned int *a;

size = SHM_SIZE;
ret = metal_shmem_open(shm_name,
SHM_SIZE, METAL_SHM_NOTCACHED, &shm);
if (ret) {
metal_log(METAL_LOG_ERROR,
"failed to open shared memory %s.\n",
shm_name);
return -EINVAL;
}

sg = metal_shmem_mmap(shm, size);
if (sg == NULL) {
metal_log(METAL_LOG_ERROR,
"failed to mmap shared memory from pool.\n");
return -EINVAL;
}
io = sg->ios;
va = metal_io_virt(io, 0);
a = va;
*a = 0xdeadbeff;
metal_shm_sync_for_cpu(shm, METAL_SHM_DIR_DEV_RW);
metal_shmem_munmap(shm, sg);
metal_shmem_close(shm);
return 0;
}
METAL_ADD_TEST(ion_shmem);

0 comments on commit d75522e

Please sign in to comment.