Add non regression tests for tapestat command.
These tests are intended to be run in sysstat's simulation test
environment (use do_test script).
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <sys/statvfs.h>
+#include <sys/time.h>
#include "systest.h"
*t = __unix_time;
}
+/*
+ ***************************************************************************
+ * Test mode: Get time of the day using __unix_time variable contents.
+ *
+ * OUT:
+ * @tv Number of seconds since the Epoch.
+ ***************************************************************************
+ */
+void get_day_time(struct timeval *tv)
+{
+ __unix_time += interval;
+ tv->tv_sec = __unix_time;
+ tv->tv_usec = 0;
+}
+
/*
***************************************************************************
* Test mode: Send bogus information about current kernel.
/* Test mode: Use alternate files and syscalls */
#ifdef TEST
-#define PRE "./tests/root"
-#define __time(m) get_unix_time(m)
-#define __uname(m) get_uname(m)
-#define __statvfs(m,n) get_fs_stat(m,n)
-#define __getenv(m) get_env_value(m)
+#define PRE "./tests/root"
+#define __time(m) get_unix_time(m)
+#define __uname(m) get_uname(m)
+#define __statvfs(m,n) get_fs_stat(m,n)
+#define __getenv(m) get_env_value(m)
#define __alarm(m)
-#define __pause() next_time_step()
-#define __stat(m,n) virtual_stat(m,n)
-#define __opendir(m) open_list(m)
-#define __readdir(m) read_list(m)
-#define __closedir(m) close_list(m)
-#define __realpath(m,n) get_realname(m,n)
+#define __pause() next_time_step()
+#define __stat(m,n) virtual_stat(m,n)
+#define __opendir(m) open_list(m)
+#define __readdir(m) read_list(m)
+#define __closedir(m) close_list(m)
+#define __realpath(m,n) get_realname(m,n)
+#define __gettimeofday(m,n) get_day_time(m)
#define ROOTDIR "./tests/root"
#define ROOTFILE "root"
#define PRE ""
-#define __time(m) time(m)
-#define __uname(m) uname(m)
-#define __statvfs(m,n) statvfs(m,n)
-#define __getenv(m) getenv(m)
-#define __alarm(m) alarm(m)
-#define __pause() pause()
-#define __stat(m,n) stat(m,n)
-#define __opendir(m) opendir(m)
-#define __readdir(m) readdir(m)
-#define __closedir(m) closedir(m)
-#define __realpath(m,n) realpath(m,n)
+#define __time(m) time(m)
+#define __uname(m) uname(m)
+#define __statvfs(m,n) statvfs(m,n)
+#define __getenv(m) getenv(m)
+#define __alarm(m) alarm(m)
+#define __pause() pause()
+#define __stat(m,n) stat(m,n)
+#define __opendir(m) opendir(m)
+#define __readdir(m) readdir(m)
+#define __closedir(m) closedir(m)
+#define __realpath(m,n) realpath(m,n)
+#define __gettimeofday(m,n) gettimeofday(m,n)
#endif
#ifdef TEST
void close_list
(DIR *);
+void get_day_time
+ (struct timeval *);
char *get_env_value
(const char *);
int get_fs_stat
#include "version.h"
#include "tapestat.h"
-#include "common.h"
#include "rd_stats.h"
#include "count.h"
tape_new_stats[i].valid = TAPE_STATS_VALID;
tape_old_stats[i].valid = TAPE_STATS_VALID;
- gettimeofday(&tape_old_stats[i].tv, NULL);
+ __gettimeofday(&tape_old_stats[i].tv, NULL);
tape_new_stats[i].tv.tv_sec = tape_old_stats[i].tv.tv_sec;
tape_new_stats[i].tv.tv_usec = tape_old_stats[i].tv.tv_usec;
* to open a file gets the tape drive marked invalid.
*/
tape_new_stats[i].valid = TAPE_STATS_VALID;
- gettimeofday(&tape_new_stats[i].tv, NULL);
+ __gettimeofday(&tape_new_stats[i].tv, NULL);
TAPE_STAT_FILE_VAL(TAPE_STAT_PATH "read_ns", read_time)
TAPE_STAT_FILE_VAL(TAPE_STAT_PATH "write_ns", write_time)
/* If duration is zero we need to calculate the ms since boot time */
if (duration == 0) {
- fp = fopen("/proc/uptime", "r");
+ fp = fopen(UPTIME, "r");
/*
* Get uptime from /proc/uptime and if we can't then just set duration to
}
if (count) {
- pause();
+ __pause();
}
}
while (count);
get_localtime(&rectime, 0);
/* Get system name, release number and hostname */
- uname(&header);
+ __uname(&header);
if (print_gal_header(&rectime, header.sysname, header.release,
header.nodename, header.machine, cpu_nr,
PLAIN_OUTPUT)) {
#ifndef _TAPESTAT_H
#define _TAPESTAT_H
+#include "common.h"
+
/* T_: tapestat - D_: Display - F_: Flag */
#define T_D_TIMESTAMP 0x00001
#define T_D_KILOBYTES 0x00002
#define TAPE_STATS_VALID 1
#define TAPE_STATS_INVALID 0
-#define SYSFS_CLASS_TAPE_DIR "/sys/class/scsi_tape"
-#define TAPE_STAT_PATH "/sys/class/scsi_tape/st%i/stats/"
+#define SYSFS_CLASS_TAPE_DIR PRE "/sys/class/scsi_tape"
+#define TAPE_STAT_PATH PRE "/sys/class/scsi_tape/st%i/stats/"
#define TAPE_STAT_FILE_VAL(A, B) \
snprintf(filename, MAXPATHLEN, A, i); \
--- /dev/null
+rm -f tests/root
+ln -s root1 tests/root
+LC_ALL=C TZ=GMT ./tapestat > tests/out.tapestat.tmp
--- /dev/null
+diff -u tests/out.tapestat.tmp tests/expected.tapestat
--- /dev/null
+rm -f tests/root
+ln -s root1 tests/root
+LC_ALL=C TZ=GMT ./tapestat -m 1 2 > tests/out.tapestat-m.tmp
--- /dev/null
+diff -u tests/out.tapestat-m.tmp tests/expected.tapestat-m
--- /dev/null
+rm -f tests/root
+ln -s root1 tests/root
+LC_ALL=C TZ=GMT ./tapestat --human -y 1 2 > tests/out.tapestat-y.tmp
--- /dev/null
+diff -u tests/out.tapestat-y.tmp tests/expected.tapestat-y
--- /dev/null
+rm -f tests/root
+ln -s root1 tests/root
+LC_ALL=C TZ=GMT ./tapestat -z 1 2 > tests/out.tapestat-z.tmp
--- /dev/null
+diff -u tests/out.tapestat-z.tmp tests/expected.tapestat-z
--- /dev/null
+rm -f tests/root
+ln -s root1 tests/root
+LC_ALL=C TZ=GMT ./tapestat -t 1 2 > tests/out.tapestat-t.tmp
--- /dev/null
+diff -u tests/out.tapestat-t.tmp tests/expected.tapestat-t
--- /dev/null
+rm -f tests/root
+ln -s root4 tests/root
+LC_ALL=C TZ=GMT ./tapestat 1 2 2>&1 | grep "No tape drives" >/dev/null
--- /dev/null
+LC_ALL=C ./tapestat -1 2>&1 | grep "Usage:" >/dev/null
--- /dev/null
+LC_ALL=C ./tapestat 0 0 2>&1 | grep "Usage:" >/dev/null
--- /dev/null
+LC_ALL=C ./tapestat 0 2 2>&1 | grep "Usage:" >/dev/null
--- /dev/null
+LC_ALL=C ./tapestat 2 0 2>&1 | grep "Usage:" >/dev/null
--- /dev/null
+LC_ALL=C ./tapestat 2 2 2 2>&1 | grep "Usage:" >/dev/null
03130 LC_ALL=C ./mpstat -N -1 2>&1 | grep "Usage:" >/dev/null
03135 LC_ALL=C ./mpstat -P 16 2>&1 | grep "Usage:" >/dev/null
+===== tapestat: Basic tests
+04000 LC_ALL=C TZ=GMT ./tapestat > tests/out.tapestat.tmp
+04005 diff -u tests/out.tapestat.tmp tests/expected.tapestat
+04010 LC_ALL=C TZ=GMT ./tapestat -m 1 2 > tests/out.tapestat-m.tmp
+04015 diff -u tests/out.tapestat-m.tmp tests/expected.tapestat-m
+04020 LC_ALL=C TZ=GMT ./tapestat --human -y 1 2 > tests/out.tapestat-y.tmp
+04025 diff -u tests/out.tapestat-y.tmp tests/expected.tapestat-y
+04030 LC_ALL=C TZ=GMT ./tapestat -z 1 2 > tests/out.tapestat-z.tmp
+04035 diff -u tests/out.tapestat-z.tmp tests/expected.tapestat-z
+04040 LC_ALL=C TZ=GMT ./tapestat -t 1 2 > tests/out.tapestat-t.tmp
+04045 diff -u tests/out.tapestat-t.tmp tests/expected.tapestat-t
+
+===== Tests tapestat error cases
+04100 LC_ALL=C TZ=GMT ./tapestat 1 2 2>&1 | grep "No tape drives" >/dev/null
+04102 LC_ALL=C ./tapestat -1 2>&1 | grep "Usage:" >/dev/null
+04105 LC_ALL=C ./tapestat 0 0 2>&1 | grep "Usage:" >/dev/null
+04110 LC_ALL=C ./tapestat 0 2 2>&1 | grep "Usage:" >/dev/null
+04115 LC_ALL=C ./tapestat 2 0 2>&1 | grep "Usage:" >/dev/null
+04120 LC_ALL=C ./tapestat 2 2 2 2>&1 | grep "Usage:" >/dev/null
+
===== Tests to be done at the very end
09900 grep -i FIXME *.c *.h *.in && exit 1 || exit 0
--- /dev/null
+Linux 1.2.3-TEST (SYSSTAT.TEST) 01/01/70 _x86_64_ (8 CPU)
+
+Tape: r/s w/s kB_read/s kB_wrtn/s %Rd %Wr %Oa Rs/s Ot/s
+st0 1 139 24 2673 0 4 6 1 0
+st1 1 139 24 2673 0 4 6 1 0
+
--- /dev/null
+Linux 1.2.3-TEST (SYSSTAT.TEST) 01/01/70 _x86_64_ (8 CPU)
+
+Tape: r/s w/s MB_read/s MB_wrtn/s %Rd %Wr %Oa Rs/s Ot/s
+st0 1 139 0 2 0 4 6 1 0
+st1 1 139 0 2 0 4 6 1 0
+
+Tape: r/s w/s MB_read/s MB_wrtn/s %Rd %Wr %Oa Rs/s Ot/s
+st0 3 26 0 0 0 0 0 6 0
+st1 0 0 0 0 0 0 0 0 0
+
--- /dev/null
+Linux 1.2.3-TEST (SYSSTAT.TEST) 01/01/70 _x86_64_ (8 CPU)
+
+01/01/70 00:00:02
+Tape: r/s w/s kB_read/s kB_wrtn/s %Rd %Wr %Oa Rs/s Ot/s
+st0 1 139 24 2673 0 4 6 1 0
+st1 1 139 24 2673 0 4 6 1 0
+
+01/01/70 00:00:05
+Tape: r/s w/s kB_read/s kB_wrtn/s %Rd %Wr %Oa Rs/s Ot/s
+st0 3 26 0 0 0 0 0 6 0
+st1 0 0 0 0 0 0 0 0 0
+
--- /dev/null
+Linux 1.2.3-TEST (SYSSTAT.TEST) 01/01/70 _x86_64_ (8 CPU)
+
+Tape: r/s w/s kB_read/s kB_wrtn/s %Rd %Wr %Oa Rs/s Ot/s
+st0 3 26 0.0k 0.0k 0% 0% 0% 6 0
+st1 0 0 0.0k 0.0k 0% 0% 0% 0 0
+
+Tape: r/s w/s kB_read/s kB_wrtn/s %Rd %Wr %Oa Rs/s Ot/s
+
--- /dev/null
+Linux 1.2.3-TEST (SYSSTAT.TEST) 01/01/70 _x86_64_ (8 CPU)
+
+Tape: r/s w/s kB_read/s kB_wrtn/s %Rd %Wr %Oa Rs/s Ot/s
+st0 1 139 24 2673 0 4 6 1 0
+st1 1 139 24 2673 0 4 6 1 0
+
+Tape: r/s w/s kB_read/s kB_wrtn/s %Rd %Wr %Oa Rs/s Ot/s
+st0 3 26 0 0 0 0 0 6 0
+
--- /dev/null
+454045641944
--- /dev/null
+8746055278
--- /dev/null
+19691612160
--- /dev/null
+333563196949
--- /dev/null
+454045641944
--- /dev/null
+8746055278
--- /dev/null
+19691612160
--- /dev/null
+333563196949
--- /dev/null
+454045651944
--- /dev/null
+8746065278
--- /dev/null
+19691613160
--- /dev/null
+333563197949
--- /dev/null
+454045641944
--- /dev/null
+8746055278
--- /dev/null
+19691612160
--- /dev/null
+333563196949