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
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <poll.h>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user