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 <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2016-11-15 15:27:20 -07:00
parent 04c48172b9
commit 075e15c164
2 changed files with 24 additions and 56 deletions

View File

@ -40,6 +40,7 @@ SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a \
$(SPDK_ROOT_DIR)/lib/util/libspdk_util.a $(SPDK_ROOT_DIR)/lib/util/libspdk_util.a
CFLAGS += -I$(SPDK_ROOT_DIR)/lib/scsi $(ENV_CFLAGS) CFLAGS += -I$(SPDK_ROOT_DIR)/lib/scsi $(ENV_CFLAGS)
CFLAGS += -I$(SPDK_ROOT_DIR)/test
LIBS += $(SPDK_LIBS) $(ENV_LINKER_ARGS) LIBS += $(SPDK_LIBS) $(ENV_LINKER_ARGS)
LIBS += -lcunit LIBS += -lcunit

View File

@ -39,7 +39,7 @@
#include "spdk/event.h" #include "spdk/event.h"
#include "spdk/scsi.h" #include "spdk/scsi.h"
#include "CUnit/Basic.h" #include "spdk_cunit.h"
#include "scsi.c" #include "scsi.c"
@ -72,67 +72,32 @@ static struct spdk_conf *
spdk_config_init_scsi_params(char *key, char *value) spdk_config_init_scsi_params(char *key, char *value)
{ {
struct spdk_conf *spdk_config; struct spdk_conf *spdk_config;
struct spdk_conf_section *sp; FILE *f;
struct spdk_conf_item *ip; int fd, rc;
struct spdk_conf_value *val; char filename[] = "/tmp/scsi_init_ut.XXXXXX";
spdk_config = calloc(1, sizeof(struct spdk_conf)); /* Create temporary file to hold config */
if (!spdk_config) { fd = mkstemp(filename);
perror("spdk_config"); SPDK_CU_ASSERT_FATAL(fd != -1);
return NULL;
}
sp = calloc(1, sizeof(struct spdk_conf_section)); f = fdopen(fd, "wb+");
if (!sp) { SPDK_CU_ASSERT_FATAL(f != NULL);
perror("sp");
free(spdk_config);
return NULL;
}
ip = calloc(1, sizeof(struct spdk_conf_item)); fprintf(f, "[Scsi]\n");
if (!ip) { fprintf(f, "%s %s\n", key, value);
perror("ip");
free(spdk_config);
free(sp);
return NULL;
}
val = calloc(1, sizeof(struct spdk_conf_value)); fclose(f);
if (!val) {
perror("val");
free(spdk_config);
free(sp);
free(ip);
return NULL;
}
sp->name = "Scsi"; spdk_config = spdk_conf_allocate();
ip->key = malloc(strlen(key) + 1); SPDK_CU_ASSERT_FATAL(spdk_config != NULL);
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);
ip->val = val; rc = spdk_conf_read(spdk_config, filename);
sp->item = ip; SPDK_CU_ASSERT_FATAL(rc == 0);
spdk_config->section = sp;
spdk_conf_set_as_default(spdk_config); spdk_conf_set_as_default(spdk_config);
remove(filename);
return spdk_config; return spdk_config;
} }
@ -151,12 +116,13 @@ set_default_scsi_params(struct spdk_scsi_parameters *params)
static void static void
scsi_init_sp_null(void) scsi_init_sp_null(void)
{ {
struct spdk_conf config; struct spdk_conf *config;
int rc; 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(); rc = spdk_scsi_subsystem_init();
@ -164,6 +130,7 @@ scsi_init_sp_null(void)
CU_ASSERT_EQUAL(rc, 0); CU_ASSERT_EQUAL(rc, 0);
spdk_conf_set_as_default(NULL); spdk_conf_set_as_default(NULL);
spdk_conf_free(config);
} }
static void static void