Skip to content

Commit

Permalink
validation: shm: test capa and maximum reservation
Browse files Browse the repository at this point in the history
Added test which uses capability API, and tries to reserve
and use maximum sized block. 100 MB shm memory is assumed
to be available to ODP validation tests.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>
Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
  • Loading branch information
Petri Savolainen authored and muvarov committed Feb 12, 2018
1 parent f78fe47 commit bde4740
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/validation/api/shmem/shmem.c
Expand Up @@ -22,6 +22,8 @@
#define STRESS_SIZE 32 /* power of 2 and <=256 */
#define STRESS_RANDOM_SZ 5
#define STRESS_ITERATION 5000
#define MAX_SIZE_TESTED (100 * 1000000UL)
#define MAX_ALIGN_TESTED (1024 * 1024)

typedef enum {
STRESS_FREE, /* entry is free and can be allocated */
Expand Down Expand Up @@ -212,6 +214,57 @@ void shmem_test_basic(void)
CU_ASSERT(0 == odp_shm_free(shm));
}

/*
* maximum size reservation
*/
static void shmem_test_max_reserve(void)
{
odp_shm_capability_t capa;
odp_shm_t shm;
uint64_t size, align;
uint8_t *data;
uint64_t i;

memset(&capa, 0, sizeof(odp_shm_capability_t));
CU_ASSERT_FATAL(odp_shm_capability(&capa) == 0);

CU_ASSERT(capa.max_blocks > 0);

size = capa.max_size;
align = capa.max_align;

/* Assuming that system has at least MAX_SIZE_TESTED bytes available */
if (capa.max_size == 0 || capa.max_size > MAX_SIZE_TESTED)
size = MAX_SIZE_TESTED;

if (capa.max_align == 0 || capa.max_align > MAX_ALIGN_TESTED)
align = MAX_ALIGN_TESTED;

printf("\n size: %" PRIu64 "\n", size);
printf(" align: %" PRIu64 "\n", align);

shm = odp_shm_reserve("test_max_reserve", size, align, 0);
CU_ASSERT(shm != ODP_SHM_INVALID);

data = odp_shm_addr(shm);
CU_ASSERT(data != NULL);

if (data) {
memset(data, 0xde, size);
for (i = 0; i < size; i++) {
if (data[i] != 0xde) {
printf(" data error i:%" PRIu64 ", data %x"
"\n", i, data[i]);
CU_FAIL("Data error");
break;
}
}
}

if (shm != ODP_SHM_INVALID)
CU_ASSERT(odp_shm_free(shm) == 0);
}

/*
* thread part for the shmem_test_reserve_after_fork
*/
Expand Down Expand Up @@ -769,6 +822,7 @@ void shmem_test_stress(void)

odp_testinfo_t shmem_suite[] = {
ODP_TEST_INFO(shmem_test_basic),
ODP_TEST_INFO(shmem_test_max_reserve),
ODP_TEST_INFO(shmem_test_reserve_after_fork),
ODP_TEST_INFO(shmem_test_singleva_after_fork),
ODP_TEST_INFO(shmem_test_stress),
Expand Down

0 comments on commit bde4740

Please sign in to comment.