test-tool: add test_get_clock_sec() helper

Useful for test IO timeouts.

Signed-off-by: David Disseldorp <ddiss@suse.de>
This commit is contained in:
David Disseldorp
2016-03-22 19:50:55 +01:00
parent f117b6c96d
commit bfd614053e
2 changed files with 22 additions and 0 deletions

View File

@@ -3028,3 +3028,22 @@ test_iscsi_tur_until_good(struct scsi_device *iscsi_sd, int *num_uas)
return -ETIMEDOUT;
}
uint64_t
test_get_clock_sec(void)
{
uint64_t secs;
int res;
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
res = clock_gettime(CLOCK_MONOTONIC, &ts);
secs = ts.tv_sec;
#else
struct timeval tv;
res = gettimeofday(&tv, NULL);
secs = tv.tv_sec;
#endif
assert(res == 0);
return secs;
}

View File

@@ -859,4 +859,7 @@ int receive_copy_results(struct scsi_task **task, struct scsi_device *sdev,
void **datap, int status, enum scsi_sense_key key,
int *ascq, int num_ascq);
int test_iscsi_tur_until_good(struct scsi_device *iscsi_sd, int *num_uas);
uint64_t test_get_clock_sec(void);
#endif /* _ISCSI_SUPPORT_H_ */