Commit 64f9b729 authored by Changpeng Liu's avatar Changpeng Liu Committed by Jim Harris
Browse files

test/nvme/aer: add an option to enable temperature tests



Refactoring the existing AER test code which add an option
to enable temperature tests of AER, this will enable coming
patch which add Namespace attribute notice tests support.

Change-Id: I514a1d6d0d3aacf4e207fb437406b5cf048f2a71
Signed-off-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/406026


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent a28294b0
Loading
Loading
Loading
Loading
+63 −40
Original line number Diff line number Diff line
@@ -60,6 +60,9 @@ static int temperature_done = 0;
static int failed = 0;
static struct spdk_nvme_transport_id g_trid;

/* Enable AER temperature test */
static int enable_temp_test = 0;

static void
set_temp_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl)
{
@@ -141,7 +144,7 @@ print_health_page(struct dev *dev, struct spdk_nvme_health_information_page *hip
}

static void
get_log_page_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl)
get_health_log_page_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl)
{
	struct dev *dev = cb_arg;

@@ -164,7 +167,7 @@ get_health_log_page(struct dev *dev)

	rc = spdk_nvme_ctrlr_cmd_get_log_page(dev->ctrlr, SPDK_NVME_LOG_HEALTH_INFORMATION,
					      SPDK_NVME_GLOBAL_NS_TAG, dev->health_page, sizeof(*dev->health_page), 0,
					      get_log_page_completion, dev);
					      get_health_log_page_completion, dev);
	if (rc == 0) {
		outstanding_commands++;
	}
@@ -212,6 +215,7 @@ usage(const char *program_name)
	printf("%s [options]", program_name);
	printf("\n");
	printf("options:\n");
	printf(" -T         enable temperature tests\n");
	printf(" -r trid    remote NVMe over Fabrics target address\n");
	printf("    Format: 'key:value [key:value] ...'\n");
	printf("    Keys:\n");
@@ -236,7 +240,7 @@ parse_args(int argc, char **argv)
	g_trid.trtype = SPDK_NVME_TRANSPORT_PCIE;
	snprintf(g_trid.subnqn, sizeof(g_trid.subnqn), "%s", SPDK_NVMF_DISCOVERY_NQN);

	while ((op = getopt(argc, argv, "r:t:H")) != -1) {
	while ((op = getopt(argc, argv, "r:t:H:T")) != -1) {
		switch (op) {
		case 't':
			rc = spdk_log_set_trace_flag(optarg);
@@ -259,6 +263,9 @@ parse_args(int argc, char **argv)
				return 1;
			}
			break;
		case 'T':
			enable_temp_test = 1;
			break;
		case 'H':
		default:
			usage(argv[0]);
@@ -341,41 +348,10 @@ get_feature_test(struct dev *dev)
	outstanding_commands++;
}

int main(int argc, char **argv)
static int
spdk_aer_temperature_test(void)
{
	struct dev *dev;
	int			i;
	struct spdk_env_opts	opts;
	int			rc;

	rc = parse_args(argc, argv);
	if (rc != 0) {
		return rc;
	}

	spdk_env_opts_init(&opts);
	opts.name = "aer";
	opts.core_mask = "0x1";
	if (spdk_env_init(&opts) < 0) {
		fprintf(stderr, "Unable to initialize SPDK env\n");
		return 1;
	}

	printf("Asynchronous Event Request test\n");

	if (spdk_nvme_probe(&g_trid, NULL, probe_cb, attach_cb, NULL) != 0) {
		fprintf(stderr, "spdk_nvme_probe() failed\n");
		return 1;
	}

	if (failed) {
		goto done;
	}

	printf("Registering asynchronous event callbacks...\n");
	foreach_dev(dev) {
		spdk_nvme_ctrlr_register_aer_callback(dev->ctrlr, aer_cb, dev);
	}

	printf("Getting temperature thresholds of all controllers...\n");
	foreach_dev(dev) {
@@ -390,9 +366,10 @@ int main(int argc, char **argv)
	}

	if (failed) {
		goto done;
		return failed;
	}
	temperature_done = 0;
	aer_done = 0;

	/* Send admin commands to test admin queue wraparound while waiting for the AER */
	foreach_dev(dev) {
@@ -400,7 +377,7 @@ int main(int argc, char **argv)
	}

	if (failed) {
		goto done;
		return failed;
	}

	printf("Waiting for all controllers to trigger AER...\n");
@@ -410,7 +387,7 @@ int main(int argc, char **argv)
	}

	if (failed) {
		goto done;
		return failed;
	}

	while (!failed && (aer_done < num_devs || temperature_done < num_devs)) {
@@ -420,8 +397,54 @@ int main(int argc, char **argv)
	}

	if (failed) {
		return failed;
	}

	return 0;
}

int main(int argc, char **argv)
{
	struct dev		*dev;
	int			i;
	struct spdk_env_opts	opts;
	int			rc;

	rc = parse_args(argc, argv);
	if (rc != 0) {
		return rc;
	}

	spdk_env_opts_init(&opts);
	opts.name = "aer";
	opts.core_mask = "0x1";
	if (spdk_env_init(&opts) < 0) {
		fprintf(stderr, "Unable to initialize SPDK env\n");
		return 1;
	}

	printf("Asynchronous Event Request test\n");

	if (spdk_nvme_probe(&g_trid, NULL, probe_cb, attach_cb, NULL) != 0) {
		fprintf(stderr, "spdk_nvme_probe() failed\n");
		return 1;
	}

	if (failed) {
		goto done;
	}

	printf("Registering asynchronous event callbacks...\n");
	foreach_dev(dev) {
		spdk_nvme_ctrlr_register_aer_callback(dev->ctrlr, aer_cb, dev);
	}

	/* AER temperature test */
	if (enable_temp_test) {
		if (spdk_aer_temperature_test()) {
			goto done;
		}
	}

	printf("Cleaning up...\n");