]> granicus.if.org Git - sysstat/commitdiff
simtest: Add new non regression tests
authorSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 1 May 2019 16:29:33 +0000 (18:29 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 1 May 2019 16:29:33 +0000 (18:29 +0200)
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
25 files changed:
.gitignore
Makefile.in
do_test
sadc.c
sar.c
systest.c
systest.h
tests/00580 [new file with mode: 0644]
tests/00582 [new file with mode: 0644]
tests/00910 [new file with mode: 0644]
tests/00912 [new file with mode: 0644]
tests/00920 [new file with mode: 0644]
tests/00922 [new file with mode: 0644]
tests/01350 [new file with mode: 0644]
tests/01352 [new file with mode: 0644]
tests/01355 [new file with mode: 0644]
tests/01360 [new file with mode: 0644]
tests/01362 [new file with mode: 0644]
tests/TLIST
tests/data-cd [new file with mode: 0644]
tests/expected.sadf-se [new file with mode: 0644]
tests/expected.sar-1 [new file with mode: 0644]
tests/expected.sar-cd [new file with mode: 0644]
tests/expected.sar-z [new file with mode: 0644]
tests/expected33.sar-u [new file with mode: 0644]

index 5762bd9d0661f4005bce7c941bd82f0cda54794e..53b2ea2c00b208a597dedc06fc76cf576b1bd37a 100644 (file)
@@ -58,5 +58,5 @@ tests/01130
 tests/01230
 tests/rt00010
 tests/rt00020
-tests/sa01
+tests/sa0[12]
 tests/sa19700101
index 5eebfb20671d47d08a064140ac06a6dc63853587..b13bfeb3d30f3ebbfebe7c4a07c86531d1d2055f 100644 (file)
@@ -613,7 +613,7 @@ simtest: all
 clean:
        rm -f sadc sar sadf iostat tapestat mpstat pidstat cifsiostat *.o *.a core TAGS tests/*.tmp
        rm -f nfsiostat* man/nfsiostat*
-       rm -f tests/sa01 tests/19700101
+       rm -f tests/sa0[12] tests/19700101
        find nls -name "*.gmo" -exec rm -f {} \;
 
 almost-distclean: clean nls/sysstat.pot
diff --git a/do_test b/do_test
index c3f49e90c9122a03d83ef1e063893f7a37340c0b..b73f1b9de639762264297364f4dd642db4844fea 100755 (executable)
--- a/do_test
+++ b/do_test
@@ -1,4 +1,8 @@
 #!/bin/sh
+if [ "$1" = "comp" ]
+then
+       make CFLAGS="-D DEBUG -D TEST"
+fi
 if [ "$1" = "all" ] || [ "$1" = "simtest" ]
 then
        make distclean
diff --git a/sadc.c b/sadc.c
index 74fd94f056a0700a808f8665c34da5cfa9143453..79ede1bb61b8afad613fb4b4fd392dd96322871d 100644 (file)
--- a/sadc.c
+++ b/sadc.c
@@ -226,7 +226,7 @@ void parse_sadc_S_option(char *argv[], int opt)
  */
 void alarm_handler(int sig)
 {
-       alarm(interval);
+       __alarm(interval);
 }
 
 /*
@@ -1130,7 +1130,7 @@ void rw_sa_stat_loop(long count, int stdfd, int ofd, char ofile[],
 
                if (count) {
                        /* Wait for a signal (probably SIGALRM or SIGINT) */
-                       pause();
+                       __pause();
                }
 
                if (sigint_caught)
@@ -1390,7 +1390,7 @@ int main(int argc, char **argv)
        memset(&alrm_act, 0, sizeof(alrm_act));
        alrm_act.sa_handler = alarm_handler;
        sigaction(SIGALRM, &alrm_act, NULL);
-       alarm(interval);
+       __alarm(interval);
 
        /* Main loop */
        rw_sa_stat_loop(count, stdfd, ofd, ofile, sa_dir);
diff --git a/sar.c b/sar.c
index 9ced4ff96bf447341b2c093ccd7e1fe1af1ba3a5..93f0bc105699746283a561b3b68eac263e5b7a74 100644 (file)
--- a/sar.c
+++ b/sar.c
 char *sccsid(void) { return (SCCSID); }
 #endif
 
+#ifdef TEST
+extern time_t __unix_time;
+#endif
+
 /* Interval and count parameters */
 long interval = -1, count = 0;
 
@@ -1410,6 +1414,14 @@ int main(int argc, char **argv)
                        }
                }
 
+#ifdef TEST
+               else if (!strncmp(argv[opt], "--unix_time=", 12)) {
+                       if (strspn(argv[opt] + 12, DIGITS) != strlen(argv[opt] + 12)) {
+                               usage(argv[0]);
+                       }
+                       __unix_time = atoll(argv[opt++] + 12);
+               }
+#endif
                else if ((strlen(argv[opt]) > 1) &&
                         (strlen(argv[opt]) < 4) &&
                         !strncmp(argv[opt], "-", 1) &&
index 67daa6f09218e310f4f0b47964c10f161b93baf4..974455d0eef5dc3d3bca58c933a1773e74f7d6ab 100644 (file)
--- a/systest.c
+++ b/systest.c
 
 #ifdef TEST
 
+#include <stdio.h>
 #include <string.h>
+#include <errno.h>
+#include <stdlib.h>
 #include <time.h>
+#include <unistd.h>
 #include <sys/utsname.h>
 #include <sys/statvfs.h>
 
 #include "systest.h"
 
 time_t __unix_time = 0;
+extern long interval;
 
 /*
  ***************************************************************************
@@ -103,5 +108,30 @@ char *get_env_value(char *c)
        return NULL;
 }
 
+/*
+ ***************************************************************************
+ * Test mode: Go to next time period.
+ ***************************************************************************
+ */
+
+void next_time_step(void)
+{
+       static int root_nr = 1;
+       char rootf[64];
+
+       __unix_time += interval;
+
+       if ((unlink(ROOTDIR) < 0) && (errno != ENOENT)) {
+               perror("unlink");
+               exit(1);
+       }
+
+       sprintf(rootf, "%s%d", ROOTFILE, ++root_nr);
+       if (symlink(rootf, ROOTDIR) < 0) {
+               perror("link");
+               exit(1);
+       }
+}
+
 #endif /* TEST */
 
index 655f266f4bed3cc0c6276391d5d22a1b8b21d128..fd4e70ee98fe1a505a5a70825f31fe9154f17a47 100644 (file)
--- a/systest.h
+++ b/systest.h
 #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 ROOTDIR                "./tests/root"
+#define ROOTFILE       "root"
 
 #else
 
@@ -27,6 +32,8 @@
 #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()
 
 #endif
 
@@ -45,6 +52,8 @@ void get_uname
        (struct utsname *);
 void get_unix_time
        (time_t *);
+void next_time_step
+       ();
 #endif
 
 #endif  /* _SYSTEST_H */
diff --git a/tests/00580 b/tests/00580
new file mode 100644 (file)
index 0000000..7d7230e
--- /dev/null
@@ -0,0 +1 @@
+./sadf -d -s 13:20:20 -e 13:20:40 --iface=enp6s1 --dev=sda --fs=/dev/sda6 tests/data.tmp -- -n DEV -Fdp > tests/out.sadf-se.tmp
diff --git a/tests/00582 b/tests/00582
new file mode 100644 (file)
index 0000000..2bb79f6
--- /dev/null
@@ -0,0 +1 @@
+diff -u tests/out.sadf-se.tmp tests/expected.sadf-se
diff --git a/tests/00910 b/tests/00910
new file mode 100644 (file)
index 0000000..b631734
--- /dev/null
@@ -0,0 +1 @@
+LC_ALL=C TZ=GMT ./sar -f tests/data-cd -s 23:59:58 -e 00:00:00 > tests/out.sar-cd.tmp
diff --git a/tests/00912 b/tests/00912
new file mode 100644 (file)
index 0000000..6bd2ef2
--- /dev/null
@@ -0,0 +1 @@
+diff -u tests/out.sar-cd.tmp tests/expected.sar-cd
diff --git a/tests/00920 b/tests/00920
new file mode 100644 (file)
index 0000000..98f60e4
--- /dev/null
@@ -0,0 +1 @@
+LC_ALL=C TZ=GMT ./sar -f tests/data.tmp -e 13:30 -z -n DEV -dp > tests/out.sar-z.tmp
diff --git a/tests/00922 b/tests/00922
new file mode 100644 (file)
index 0000000..6ed0259
--- /dev/null
@@ -0,0 +1 @@
+diff -u tests/out.sar-z.tmp tests/expected.sar-z
diff --git a/tests/01350 b/tests/01350
new file mode 100644 (file)
index 0000000..2be5a02
--- /dev/null
@@ -0,0 +1,3 @@
+rm -f tests/sa01 tests/sa02 tests/root
+ln -s root1 tests/root
+TZ=GMT ./sadc --unix_time=1556755199 - 1 3
diff --git a/tests/01352 b/tests/01352
new file mode 100644 (file)
index 0000000..66dad3a
--- /dev/null
@@ -0,0 +1,2 @@
+LC_ALL=C TZ=GMT ./sar -f tests/sa01 > tests/out33.sar-u.tmp
+LC_ALL=C TZ=GMT ./sar -f tests/sa02 >> tests/out33.sar-u.tmp
diff --git a/tests/01355 b/tests/01355
new file mode 100644 (file)
index 0000000..71ecf34
--- /dev/null
@@ -0,0 +1 @@
+diff -u tests/out33.sar-u.tmp tests/expected33.sar-u
diff --git a/tests/01360 b/tests/01360
new file mode 100644 (file)
index 0000000..e6101c6
--- /dev/null
@@ -0,0 +1 @@
+LC_ALL=C TZ=GMT ./sar --unix_time=1556755203 -1 > tests/out.sar-1.tmp
diff --git a/tests/01362 b/tests/01362
new file mode 100644 (file)
index 0000000..de4dc8a
--- /dev/null
@@ -0,0 +1 @@
+diff -u tests/out.sar-1.tmp tests/expected.sar-1
index 4c76e4b84f5682ee82412d1a6cd5f48f60492314..ad5479279c779dc5a2dbc8edd04e77c4831e0992 100644 (file)
@@ -57,6 +57,8 @@
 00561  diff -u tests/out.sadf-H.tmp tests/expected.sadf-H
 00570  ./sadf -r -O debug tests/data.tmp -C -- -A > tests/out.sadf-r.tmp
 00571  diff -u tests/out.sadf-r.tmp tests/expected.sadf-r
+00580  ./sadf -d -s 13:20:20 -e 13:20:40 --iface=enp6s0 --dev=sda --fs=/dev/sda6 tests/data.tmp -- -n DEV -Fdp > tests/out.sadf-se.tmp
+00582  diff -u tests/out.sadf-se.tmp tests/expected.sadf-se
 
 =====  Checking sadf conversion
 00600  ./sadf -c tests/data-9.1.6 > tests/data-9.1.6.tmp
        [WARNING: /proc/uptime files are not consistent with unix_time values used. Don't trust timestamps!]
 00900  LC_ALL=C TZ=GMT ./sar -h -j UUID -f tests/data.tmp > tests/out.sar-jUUID.tmp
 00902  diff -u tests/out.sar-jUUID.tmp tests/expected.sar-jUUID
+00910  LC_ALL=C TZ=GMT ./sar -f tests/data-cd -s 23:59:58 -e 00:00:00 > tests/out.sar-cd.tmp
+       [Testing options -s/-e on a file contents spanning two consecutive days]
+       [Work only with very simple file contents (no LINUX RESTART or COMMENT records)]
+00912  diff -u tests/out.sar-cd.tmp tests/expected.sar-cd
+00920  LC_ALL=C TZ=GMT ./sar -f tests/data.tmp -e 13:30 -z -n DEV -dp > > tests/out.sar-z.tmp
+00922  diff -u tests/out.sar-z.tmp tests/expected.sar-z
 
 =====  Creating data0.tmp with no data inside
 01000  ./sadc --unix_time=1555593609 -S A_NULL,A_PCSW tests/data0.tmp >/dev/null
 01337  diff -u tests/out33.sar-u.tmp tests/expected32.sar-u
 01340  ./sadf > tests/out3.sadf.tmp
 01342  diff -u tests/out3.sadf.tmp tests/expected3.sadf
+01350  TZ=GMT ./sadc --unix_time=1556755199 - 1 3
+       [Create sa01 and sa02 - Timestamp can be obtained with: date +%s --date='Wed May  1 23:59:59 CEST 2019']
+01352  LC_ALL=C TZ=GMT ./sar -f tests/sa01 > tests/out33.sar-u.tmp; LC_ALL=C TZ=GMT ./sar -f tests/sa02 >> tests/out33.sar-u.tmp
+01355  diff -u tests/out33.sar-u.tmp tests/expected33.sar-u
+01360  LC_ALL=C TZ=GMT ./sar --unix_time=1556755203 -1 > tests/out.sar-1.tmp
+       [Go to day 02 and try to read sa01]
+01362  diff -u tests/out.sar-1.tmp tests/expected.sar-1
diff --git a/tests/data-cd b/tests/data-cd
new file mode 100644 (file)
index 0000000..464f35d
Binary files /dev/null and b/tests/data-cd differ
diff --git a/tests/expected.sadf-se b/tests/expected.sadf-se
new file mode 100644 (file)
index 0000000..727e779
--- /dev/null
@@ -0,0 +1,6 @@
+# hostname;interval;timestamp;DEV;tps;rkB/s;wkB/s;dkB/s;areq-sz;aqu-sz;await;%util
+SYSSTAT.TEST;39;2019-04-18 13:20:39 UTC;sda;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00
+# hostname;interval;timestamp;IFACE;rxpck/s;txpck/s;rxkB/s;txkB/s;rxcmp/s;txcmp/s;rxmcst/s;%ifutil
+SYSSTAT.TEST;39;2019-04-18 13:20:39 UTC;enp6s1;1.90;1.17;0.23;0.21;0.00;0.00;2.31;0.00
+# hostname;interval;timestamp;FILESYSTEM;MBfsfree;MBfsused;%fsused;%ufsused;Ifree;Iused;%Iused
+SYSSTAT.TEST;39;2019-04-18 13:20:39 UTC;/dev/sda6;85582;7774;8.33;13.45;6008414;102818;1.68
diff --git a/tests/expected.sar-1 b/tests/expected.sar-1
new file mode 100644 (file)
index 0000000..43094fc
--- /dev/null
@@ -0,0 +1,5 @@
+Linux 1.2.3-TEST (SYSSTAT.TEST)        05/01/19        _x86_64_        (8 CPU)
+
+23:59:59        CPU     %user     %nice   %system   %iowait    %steal     %idle
+00:00:00        all      2.15     12.50      2.36      0.12      0.00     82.88
+Average:        all      2.15     12.50      2.36      0.12      0.00     82.88
diff --git a/tests/expected.sar-cd b/tests/expected.sar-cd
new file mode 100644 (file)
index 0000000..e41e531
--- /dev/null
@@ -0,0 +1,6 @@
+Linux 1.2.3-TEST (SYSSTAT.TEST)        05/01/19        _x86_64_        (8 CPU)
+
+23:59:58        CPU     %user     %nice   %system   %iowait    %steal     %idle
+23:59:59        all      2.28      0.00      1.93      0.50      0.00     95.29
+00:00:00        all      2.66     23.20      2.27      0.16      0.00     71.71
+Average:        all      2.52     14.28      2.14      0.29      0.00     80.78
diff --git a/tests/expected.sar-z b/tests/expected.sar-z
new file mode 100644 (file)
index 0000000..e81a6c8
--- /dev/null
@@ -0,0 +1,34 @@
+Linux 1.2.3-TEST (SYSSTAT.TEST)        04/18/19        _x86_64_        (8 CPU)
+
+13:20:09          DEV       tps     rkB/s     wkB/s     dkB/s   areq-sz    aqu-sz     await     %util
+
+13:20:19          DEV       tps     rkB/s     wkB/s     dkB/s   areq-sz    aqu-sz     await     %util
+13:20:29          sdb      0.67     22.60      0.00      0.00     33.62      0.10     47.00      0.05
+
+13:20:29          DEV       tps     rkB/s     wkB/s     dkB/s   areq-sz    aqu-sz     await     %util
+13:20:39          sdf      1.22     54.34      0.00      0.00     44.51      0.08     62.51      0.09
+13:20:39          sdg      2.91    114.91      0.31      0.00     39.61      0.07     24.75      0.19
+
+13:20:39          DEV       tps     rkB/s     wkB/s     dkB/s   areq-sz    aqu-sz     await     %util
+13:20:49          sdg      0.94     22.33      0.22      0.00     24.05      0.04      6.19      0.09
+
+Average:          DEV       tps     rkB/s     wkB/s     dkB/s   areq-sz    aqu-sz     await     %util
+Average:          sdf      0.38     16.97      0.00      0.00     44.51      0.02     62.51      0.03
+Average:          sdg      1.08     39.94      0.14      0.00     37.15      0.03     21.82      0.08
+
+13:20:09        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
+
+13:20:19        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
+13:20:29       enp6s0     53.55     17.45     64.37      3.38      0.00      0.00      9.25      0.05
+
+13:20:29        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
+13:20:39       enp6s1      1.90      1.17      0.23      0.21      0.00      0.00      2.31      0.00
+13:20:39       wlp5s1      0.39      0.13      0.03      0.01      0.00      0.00      0.00      0.00
+
+13:20:39        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
+13:20:49    virbr0-nic      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
+13:20:49       enp6s0   7397.68   2412.77   8891.46    466.82      0.00      0.00    116.21      7.28
+
+Average:        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
+Average:       enp6s1      0.59      0.36      0.07      0.06      0.00      0.00      0.72      0.00
+Average:       wlp5s1      0.12      0.04      0.01      0.00      0.00      0.00      0.00      0.00
diff --git a/tests/expected33.sar-u b/tests/expected33.sar-u
new file mode 100644 (file)
index 0000000..846a1db
--- /dev/null
@@ -0,0 +1,10 @@
+Linux 1.2.3-TEST (SYSSTAT.TEST)        05/01/19        _x86_64_        (8 CPU)
+
+23:59:59        CPU     %user     %nice   %system   %iowait    %steal     %idle
+00:00:00        all      2.15     12.50      2.36      0.12      0.00     82.88
+Average:        all      2.15     12.50      2.36      0.12      0.00     82.88
+Linux 1.2.3-TEST (SYSSTAT.TEST)        05/02/19        _x86_64_        (8 CPU)
+
+00:00:00        CPU     %user     %nice   %system   %iowait    %steal     %idle
+00:00:01        all      2.28      0.00      1.93      0.50      0.00     95.29
+Average:        all      2.28      0.00      1.93      0.50      0.00     95.29