From 075e15c16496cadc69e481c26add1ec176830629 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 15 Nov 2016 15:27:20 -0700 Subject: [PATCH] scsi/init_ut: use the public conf API Rather than building a configuration file data structure up by hand, just write the configuration to a temporary file and read it via the spdk_conf_read() API. Change-Id: I07b9fefc307fd2e07185c8655f22d6f188425327 Signed-off-by: Daniel Verkamp --- test/lib/scsi/init/Makefile | 1 + test/lib/scsi/init/init_ut.c | 79 +++++++++++------------------------- 2 files changed, 24 insertions(+), 56 deletions(-) diff --git a/test/lib/scsi/init/Makefile b/test/lib/scsi/init/Makefile index 45dffcb34..13a3678eb 100644 --- a/test/lib/scsi/init/Makefile +++ b/test/lib/scsi/init/Makefile @@ -40,6 +40,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \ $(SPDK_ROOT_DIR)/lib/util/libspdk_util.a CFLAGS += -I$(SPDK_ROOT_DIR)/lib/scsi $(ENV_CFLAGS) +CFLAGS += -I$(SPDK_ROOT_DIR)/test LIBS += $(SPDK_LIBS) $(ENV_LINKER_ARGS) LIBS += -lcunit diff --git a/test/lib/scsi/init/init_ut.c b/test/lib/scsi/init/init_ut.c index 3de26fcfb..5e2363e0c 100644 --- a/test/lib/scsi/init/init_ut.c +++ b/test/lib/scsi/init/init_ut.c @@ -39,7 +39,7 @@ #include "spdk/event.h" #include "spdk/scsi.h" -#include "CUnit/Basic.h" +#include "spdk_cunit.h" #include "scsi.c" @@ -72,67 +72,32 @@ static struct spdk_conf * spdk_config_init_scsi_params(char *key, char *value) { struct spdk_conf *spdk_config; - struct spdk_conf_section *sp; - struct spdk_conf_item *ip; - struct spdk_conf_value *val; + FILE *f; + int fd, rc; + char filename[] = "/tmp/scsi_init_ut.XXXXXX"; - spdk_config = calloc(1, sizeof(struct spdk_conf)); - if (!spdk_config) { - perror("spdk_config"); - return NULL; - } + /* Create temporary file to hold config */ + fd = mkstemp(filename); + SPDK_CU_ASSERT_FATAL(fd != -1); - sp = calloc(1, sizeof(struct spdk_conf_section)); - if (!sp) { - perror("sp"); - free(spdk_config); - return NULL; - } + f = fdopen(fd, "wb+"); + SPDK_CU_ASSERT_FATAL(f != NULL); - ip = calloc(1, sizeof(struct spdk_conf_item)); - if (!ip) { - perror("ip"); - free(spdk_config); - free(sp); - return NULL; - } + fprintf(f, "[Scsi]\n"); + fprintf(f, "%s %s\n", key, value); - val = calloc(1, sizeof(struct spdk_conf_value)); - if (!val) { - perror("val"); - free(spdk_config); - free(sp); - free(ip); - return NULL; - } + fclose(f); - sp->name = "Scsi"; - ip->key = malloc(strlen(key) + 1); - if (!ip->key) { - free(spdk_config); - free(sp); - free(ip); - free(val); - return NULL; - } - val->value = malloc(strlen(value) + 1); - if (!val->value) { - free(spdk_config); - free(sp); - free(ip->key); - free(ip); - free(val); - return NULL; - } - strcpy(ip->key, key); - strcpy(val->value, value); + spdk_config = spdk_conf_allocate(); + SPDK_CU_ASSERT_FATAL(spdk_config != NULL); - ip->val = val; - sp->item = ip; - spdk_config->section = sp; + rc = spdk_conf_read(spdk_config, filename); + SPDK_CU_ASSERT_FATAL(rc == 0); spdk_conf_set_as_default(spdk_config); + remove(filename); + return spdk_config; } @@ -151,12 +116,13 @@ set_default_scsi_params(struct spdk_scsi_parameters *params) static void scsi_init_sp_null(void) { - struct spdk_conf config; + struct spdk_conf *config; int rc; - memset(&config, 0, sizeof(config)); + config = spdk_conf_allocate(); + SPDK_CU_ASSERT_FATAL(config != NULL); - spdk_conf_set_as_default(&config); + spdk_conf_set_as_default(config); rc = spdk_scsi_subsystem_init(); @@ -164,6 +130,7 @@ scsi_init_sp_null(void) CU_ASSERT_EQUAL(rc, 0); spdk_conf_set_as_default(NULL); + spdk_conf_free(config); } static void