From 179d7b4f55db87ab8e4877f263cea3605ca1c96f Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sun, 6 Jan 2013 15:04:31 -0800 Subject: [PATCH] TESTS: Add different log levels to the TUR test test suite and see how it looks Add different log levels and update the TUR testsute. Update the helper for testunitready() so that it * prints FAILURE messages for normal and verbose levels * prints selfdocumenting messages for which SCSI command it sends and the expected result for the verbose level --- test-tool/iscsi-support.c | 38 ++++++++++++++++++++++++++++++-------- test-tool/iscsi-support.h | 5 +++++ test-tool/iscsi-test-cu.c | 3 +++ test-tool/iscsi-test.c | 1 + test-tool/iscsi-test.h | 1 - 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index 8a402b4..54d0136 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,27 @@ int data_loss; int (*real_iscsi_queue_pdu)(struct iscsi_context *iscsi, struct iscsi_pdu *pdu); +static void logging(int level, const char *format, ...) +{ + va_list ap; + static char message[1024]; + int ret; + + if (loglevel < level) { + return; + } + + va_start(ap, format); + ret = vsnprintf(message, 1024, format, ap); + va_end(ap); + + if (ret < 0) { + return; + } + + printf("%s\n", message); +} + struct iscsi_context * iscsi_context_login(const char *initiatorname, const char *url, int *lun) @@ -642,23 +664,23 @@ testunitready(struct iscsi_context *iscsi, int lun) { struct scsi_task *task; - printf("Send TESTUNITREADY ... "); + logging(LOG_VERBOSE, "\nSend TESTUNITREADY (Expecting SUCCESS)"); task = iscsi_testunitready_sync(iscsi, lun); if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send TESTUNITREADY command: %s\n", - iscsi_get_error(iscsi)); + logging(LOG_NORMAL, + "[FAILED] Failed to send TESTUNITREADY command: %s", + iscsi_get_error(iscsi)); return -1; } if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("TESTUNITREADY command: failed with sense. %s\n", - iscsi_get_error(iscsi)); + logging(LOG_NORMAL, + "[FAILED] TESTUNITREADY command: failed with sense. %s", + iscsi_get_error(iscsi)); scsi_free_scsi_task(task); return -1; } scsi_free_scsi_task(task); - printf("[OK]\n"); + logging(LOG_VERBOSE, "[OK] TestUnitReady returned SUCCESS."); return 0; } diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index 89daa8f..dde550d 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -29,6 +29,11 @@ extern const char *initiatorname1; extern const char *initiatorname2; extern const char *tgt_url; +extern int loglevel; +#define LOG_SILENT 0 +#define LOG_NORMAL 1 +#define LOG_VERBOSE 2 + extern uint32_t block_size; extern uint64_t num_blocks; extern int lbpme; diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index a34ebc3..a9ed2cb 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -47,6 +47,7 @@ #define PROG "iscsi-test-cu" +int loglevel = LOG_NORMAL; /* XXX what is this for? */ int (*real_iscsi_queue_pdu)(struct iscsi_context *iscsi, struct iscsi_pdu *pdu); @@ -319,12 +320,14 @@ main(int argc, char *argv[]) break; case 's': mode = CU_BRM_SILENT; + loglevel = LOG_SILENT; break; case 'n': mode = CU_BRM_NORMAL; break; case 'v': mode = CU_BRM_VERBOSE; /* default */ + loglevel = LOG_VERBOSE; break; default: fprintf(stderr, diff --git a/test-tool/iscsi-test.c b/test-tool/iscsi-test.c index b91b829..1e6bcfa 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -40,6 +40,7 @@ #define discard_const(ptr) ((void *)((intptr_t)(ptr))) #endif +int loglevel = LOG_VERBOSE; int (*real_iscsi_queue_pdu)(struct iscsi_context *iscsi, struct iscsi_pdu *pdu); diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index a8b85c7..d214fda 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -30,7 +30,6 @@ extern int show_info; - int T0000_testunitready_simple(const char *initiator, const char *url); int T0100_read10_simple(const char *initiator, const char *url);