From 606425985152eb9749b52a01e9cc574b42117aa4 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Wed, 1 May 2019 18:29:33 +0200 Subject: [PATCH] simtest: Add new non regression tests Signed-off-by: Sebastien GODARD --- .gitignore | 2 +- Makefile.in | 2 +- do_test | 4 ++++ sadc.c | 6 +++--- sar.c | 12 ++++++++++++ systest.c | 30 ++++++++++++++++++++++++++++++ systest.h | 9 +++++++++ tests/00580 | 1 + tests/00582 | 1 + tests/00910 | 1 + tests/00912 | 1 + tests/00920 | 1 + tests/00922 | 1 + tests/01350 | 3 +++ tests/01352 | 2 ++ tests/01355 | 1 + tests/01360 | 1 + tests/01362 | 1 + tests/TLIST | 15 +++++++++++++++ tests/data-cd | Bin 0 -> 13440 bytes tests/expected.sadf-se | 6 ++++++ tests/expected.sar-1 | 5 +++++ tests/expected.sar-cd | 6 ++++++ tests/expected.sar-z | 34 ++++++++++++++++++++++++++++++++++ tests/expected33.sar-u | 10 ++++++++++ 25 files changed, 150 insertions(+), 5 deletions(-) create mode 100644 tests/00580 create mode 100644 tests/00582 create mode 100644 tests/00910 create mode 100644 tests/00912 create mode 100644 tests/00920 create mode 100644 tests/00922 create mode 100644 tests/01350 create mode 100644 tests/01352 create mode 100644 tests/01355 create mode 100644 tests/01360 create mode 100644 tests/01362 create mode 100644 tests/data-cd create mode 100644 tests/expected.sadf-se create mode 100644 tests/expected.sar-1 create mode 100644 tests/expected.sar-cd create mode 100644 tests/expected.sar-z create mode 100644 tests/expected33.sar-u diff --git a/.gitignore b/.gitignore index 5762bd9..53b2ea2 100644 --- a/.gitignore +++ b/.gitignore @@ -58,5 +58,5 @@ tests/01130 tests/01230 tests/rt00010 tests/rt00020 -tests/sa01 +tests/sa0[12] tests/sa19700101 diff --git a/Makefile.in b/Makefile.in index 5eebfb2..b13bfeb 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 c3f49e9..b73f1b9 100755 --- 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 74fd94f..79ede1b 100644 --- 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 9ced4ff..93f0bc1 100644 --- a/sar.c +++ b/sar.c @@ -44,6 +44,10 @@ 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) && diff --git a/systest.c b/systest.c index 67daa6f..974455d 100644 --- a/systest.c +++ b/systest.c @@ -21,14 +21,19 @@ #ifdef TEST +#include #include +#include +#include #include +#include #include #include #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 */ diff --git a/systest.h b/systest.h index 655f266..fd4e70e 100644 --- a/systest.h +++ b/systest.h @@ -18,6 +18,11 @@ #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 index 0000000..7d7230e --- /dev/null +++ b/tests/00580 @@ -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 index 0000000..2bb79f6 --- /dev/null +++ b/tests/00582 @@ -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 index 0000000..b631734 --- /dev/null +++ b/tests/00910 @@ -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 index 0000000..6bd2ef2 --- /dev/null +++ b/tests/00912 @@ -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 index 0000000..98f60e4 --- /dev/null +++ b/tests/00920 @@ -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 index 0000000..6ed0259 --- /dev/null +++ b/tests/00922 @@ -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 index 0000000..2be5a02 --- /dev/null +++ b/tests/01350 @@ -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 index 0000000..66dad3a --- /dev/null +++ b/tests/01352 @@ -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 index 0000000..71ecf34 --- /dev/null +++ b/tests/01355 @@ -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 index 0000000..e6101c6 --- /dev/null +++ b/tests/01360 @@ -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 index 0000000..de4dc8a --- /dev/null +++ b/tests/01362 @@ -0,0 +1 @@ +diff -u tests/out.sar-1.tmp tests/expected.sar-1 diff --git a/tests/TLIST b/tests/TLIST index 4c76e4b..ad54792 100644 --- a/tests/TLIST +++ b/tests/TLIST @@ -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 @@ -91,6 +93,12 @@ [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 @@ -134,3 +142,10 @@ 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 index 0000000000000000000000000000000000000000..464f35dda4198846e9a9053f634de70daa58b4ef GIT binary patch literal 13440 zcmeHN32aqG6rEPkLMc#WQJ~TSWwRx;v`{EWAzC0{C20c%NeEySLa9J0OW0MgwxCrJ zBf$uU5O)%lfIv({NvZ}3n*x%c)Uc{SKtd{5=e~1q|NQy?m45mm8s8-E-DU3FnYpu_ zKmV;eQj*XtqOlqgp`1j7o@j_6y>Fy`Gm#2B!KIpL+EPFBStdfdNJH+b`TO(}(I{&4 z^rDglMpnpd?)co?yrFr$^B&2~3%M{ANa>y0yKnL>7guUQM!!k@(r&44qY%ZvTt5^m z8ILiVZ>k?j6hpF+e9}{_O}UYl%Pbw)P?9ldta;leiwty%0#SEsYS)#ab@y;S5#nu| zQmu=nOirCOwQb_Hj@l`S>b#i^#bvdA%)a)}@?H9&M3iDheyE>f*HQD5sJ+efvqnF} ziw(tD`bD}J{ZL(|O}>_?4U(E`#*QJ)X-O2n7W%PmlEgsMX#LRG*fzGG?rdYujn-Nx ziN^Dbp5#p_S&tFzG6#@MWwMu2uar7lN}iP3d)OiB`-)_T*;fTw-Z?YD?JW?EKP~PB zxvT@#tkkS_kcT}7dA&?HsMP@qx=xjep!Pck%}^hdq5Q}9!=fY(^5bp%OKhY8(rHF3 zQ2RZb1Nin9%;xS~|MnhO0V#3*C6@Apos8=IGqv=4C#W*Z;jaq~tWL2At1{;p>ASJN zJv0e|q$z!&tXPRvaGCvIi9~^ov_Tqa2lw|^bI^_aA*m3CZiB!44v=#$p+mntU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fQ5;& z7!w_L!9;m0x;Pdsy#FE*SbqPP{)?ogA@@T<<$g%0U*{|#*qIw{3^S7J#4f3n_urv4 z2!`mK(Yz0d+GYEb?2u@%@eav>i}CHcAM*a=L%{8M;bFJHi74NZMfk9r1K8+v^u8lQ zyu9zo5C`u&vPu_J7`U!N(RkmHdEb%Id~v(a@~|LQQ*}KSm3`(@5$6)S9%buea=Wl# cuzS(^wC83v9>zq3?0Y=#J2J%OPJBo94{BSshX4Qo literal 0 HcmV?d00001 diff --git a/tests/expected.sadf-se b/tests/expected.sadf-se new file mode 100644 index 0000000..727e779 --- /dev/null +++ b/tests/expected.sadf-se @@ -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 index 0000000..43094fc --- /dev/null +++ b/tests/expected.sar-1 @@ -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 index 0000000..e41e531 --- /dev/null +++ b/tests/expected.sar-cd @@ -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 index 0000000..e81a6c8 --- /dev/null +++ b/tests/expected.sar-z @@ -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 index 0000000..846a1db --- /dev/null +++ b/tests/expected33.sar-u @@ -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 -- 2.40.0