test/vtophys: refactor the app to use CUnit
The vtophys tests are about to be expanded with extra cases, for which CU_ASSERT macros will come useful. Change-Id: Id52e8df5e4bb2a0d842c174e5ac2969cc9dbbaee Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/c/438448 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
641c5b0018
commit
daa3b8b2e0
86
test/env/vtophys/vtophys.c
vendored
86
test/env/vtophys/vtophys.c
vendored
@ -35,86 +35,64 @@
|
|||||||
|
|
||||||
#include "spdk/env.h"
|
#include "spdk/env.h"
|
||||||
|
|
||||||
static int
|
#include "CUnit/Basic.h"
|
||||||
vtophys_negative_test(void)
|
|
||||||
|
static void
|
||||||
|
vtophys_malloc_test(void)
|
||||||
{
|
{
|
||||||
void *p = NULL;
|
void *p = NULL;
|
||||||
int i;
|
int i;
|
||||||
unsigned int size = 1;
|
unsigned int size = 1;
|
||||||
int rc = 0;
|
uint64_t paddr;
|
||||||
|
|
||||||
|
/* Verify vtophys doesn't work on regular malloc memory */
|
||||||
for (i = 0; i < 31; i++) {
|
for (i = 0; i < 31; i++) {
|
||||||
p = malloc(size);
|
p = malloc(size);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spdk_vtophys(p) != SPDK_VTOPHYS_ERROR) {
|
paddr = spdk_vtophys(p);
|
||||||
rc = -1;
|
CU_ASSERT(paddr == SPDK_VTOPHYS_ERROR);
|
||||||
printf("Err: VA=%p is mapped to a huge_page,\n", p);
|
|
||||||
free(p);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(p);
|
free(p);
|
||||||
size = size << 1;
|
size = size << 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test addresses that are not in the valid x86-64 usermode range */
|
/* Test addresses that are not in the valid x86-64 usermode range */
|
||||||
|
paddr = spdk_vtophys((void *)0x0000800000000000ULL);
|
||||||
if (spdk_vtophys((void *)0x0000800000000000ULL) != SPDK_VTOPHYS_ERROR) {
|
CU_ASSERT(paddr == SPDK_VTOPHYS_ERROR)
|
||||||
rc = -1;
|
|
||||||
printf("Err: kernel-mode address incorrectly allowed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rc) {
|
|
||||||
printf("vtophys_negative_test passed\n");
|
|
||||||
} else {
|
|
||||||
printf("vtophys_negative_test failed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static void
|
||||||
vtophys_positive_test(void)
|
vtophys_spdk_malloc_test(void)
|
||||||
{
|
{
|
||||||
void *p = NULL;
|
void *p = NULL;
|
||||||
int i;
|
int i;
|
||||||
unsigned int size = 1;
|
unsigned int size = 1;
|
||||||
int rc = 0;
|
uint64_t paddr;
|
||||||
|
|
||||||
|
/* Test vtophys on memory allocated through SPDK */
|
||||||
for (i = 0; i < 31; i++) {
|
for (i = 0; i < 31; i++) {
|
||||||
p = spdk_dma_zmalloc(size, 512, NULL);
|
p = spdk_dma_zmalloc(size, 512, NULL);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spdk_vtophys(p) == SPDK_VTOPHYS_ERROR) {
|
paddr = spdk_vtophys(p);
|
||||||
rc = -1;
|
CU_ASSERT(paddr != SPDK_VTOPHYS_ERROR);
|
||||||
printf("Err: VA=%p is not mapped to a huge_page,\n", p);
|
|
||||||
spdk_dma_free(p);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
spdk_dma_free(p);
|
spdk_dma_free(p);
|
||||||
size = size << 1;
|
size = size << 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rc) {
|
|
||||||
printf("vtophys_positive_test passed\n");
|
|
||||||
} else {
|
|
||||||
printf("vtophys_positive_test failed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int rc;
|
struct spdk_env_opts opts;
|
||||||
struct spdk_env_opts opts;
|
CU_pSuite suite = NULL;
|
||||||
|
unsigned num_failures;
|
||||||
|
|
||||||
spdk_env_opts_init(&opts);
|
spdk_env_opts_init(&opts);
|
||||||
opts.name = "vtophys";
|
opts.name = "vtophys";
|
||||||
@ -124,11 +102,27 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = vtophys_negative_test();
|
if (CU_initialize_registry() != CUE_SUCCESS) {
|
||||||
if (rc < 0) {
|
return CU_get_error();
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = vtophys_positive_test();
|
suite = CU_add_suite("components_suite", NULL, NULL);
|
||||||
return rc;
|
if (suite == NULL) {
|
||||||
|
CU_cleanup_registry();
|
||||||
|
return CU_get_error();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
CU_add_test(suite, "vtophys_malloc_test", vtophys_malloc_test) == NULL ||
|
||||||
|
CU_add_test(suite, "vtophys_spdk_malloc_test", vtophys_spdk_malloc_test) == NULL
|
||||||
|
) {
|
||||||
|
CU_cleanup_registry();
|
||||||
|
return CU_get_error();
|
||||||
|
}
|
||||||
|
|
||||||
|
CU_basic_set_mode(CU_BRM_VERBOSE);
|
||||||
|
CU_basic_run_tests();
|
||||||
|
num_failures = CU_get_number_of_failures();
|
||||||
|
CU_cleanup_registry();
|
||||||
|
return num_failures;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user