]> granicus.if.org Git - sysstat/commitdiff
simtest: Add new non regression tests
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 2 Nov 2019 17:43:57 +0000 (18:43 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 2 Nov 2019 17:43:57 +0000 (18:43 +0100)
Add new tests for sar and sadf.
In particular, make sure that sar and sadf can read a binary datafile
with unknown activity type or format.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
23 files changed:
tests/00780 [new file with mode: 0644]
tests/00781 [new file with mode: 0644]
tests/00784 [new file with mode: 0644]
tests/00785 [new file with mode: 0644]
tests/00787 [new file with mode: 0644]
tests/00788 [new file with mode: 0644]
tests/00790 [new file with mode: 0644]
tests/00791 [new file with mode: 0644]
tests/00795 [new file with mode: 0644]
tests/00796 [new file with mode: 0644]
tests/01145
tests/01318 [new file with mode: 0644]
tests/01319 [new file with mode: 0644]
tests/01450 [new file with mode: 0644]
tests/TLIST
tests/create_data-extra.c [moved from tests/create_sadd.c with 99% similarity]
tests/create_data-ukwn.c [new file with mode: 0644]
tests/data-ukwn [new file with mode: 0644]
tests/data-ukwn0 [new file with mode: 0644]
tests/expected.sadf-data-ukwn [new file with mode: 0644]
tests/expected.sadf-data-ukwn0 [new file with mode: 0644]
tests/expected.sar-data-ukwn [new file with mode: 0644]
tests/expected2.sar-data-ukwn [new file with mode: 0644]

diff --git a/tests/00780 b/tests/00780
new file mode 100644 (file)
index 0000000..c247090
--- /dev/null
@@ -0,0 +1 @@
+LC_ALL=C TZ=GMT ./sar -P ALL -f tests/data-ukwn > tests/out.sar-data-ukwn.tmp
diff --git a/tests/00781 b/tests/00781
new file mode 100644 (file)
index 0000000..c7aa7dc
--- /dev/null
@@ -0,0 +1 @@
+diff -u tests/out.sar-data-ukwn.tmp tests/expected.sar-data-ukwn
diff --git a/tests/00784 b/tests/00784
new file mode 100644 (file)
index 0000000..b806500
--- /dev/null
@@ -0,0 +1 @@
+LC_ALL=C TZ=GMT ./sar -w -f tests/data-ukwn > tests/out2.sar-data-ukwn.tmp
diff --git a/tests/00785 b/tests/00785
new file mode 100644 (file)
index 0000000..f9d83a0
--- /dev/null
@@ -0,0 +1 @@
+diff -u tests/out2.sar-data-ukwn.tmp tests/expected2.sar-data-ukwn
diff --git a/tests/00787 b/tests/00787
new file mode 100644 (file)
index 0000000..9ef9dc0
--- /dev/null
@@ -0,0 +1 @@
+LC_ALL=C ./sadf -H tests/data-ukwn > tests/out.sadf-data-ukwn.tmp
diff --git a/tests/00788 b/tests/00788
new file mode 100644 (file)
index 0000000..3268640
--- /dev/null
@@ -0,0 +1 @@
+diff -u tests/out.sadf-data-ukwn.tmp tests/expected.sadf-data-ukwn
diff --git a/tests/00790 b/tests/00790
new file mode 100644 (file)
index 0000000..afa2ff6
--- /dev/null
@@ -0,0 +1 @@
+LC_ALL=C TZ=GMT ./sar -A -f tests/data-ukwn0 > tests/out.sar-data-ukwn0.tmp
diff --git a/tests/00791 b/tests/00791
new file mode 100644 (file)
index 0000000..eb49447
--- /dev/null
@@ -0,0 +1 @@
+diff -u tests/out.sar-data-ukwn0.tmp tests/expected2.sar-data-ukwn
diff --git a/tests/00795 b/tests/00795
new file mode 100644 (file)
index 0000000..5359781
--- /dev/null
@@ -0,0 +1 @@
+LC_ALL=C ./sadf -H tests/data-ukwn0 > tests/out.sadf-data-ukwn0.tmp
diff --git a/tests/00796 b/tests/00796
new file mode 100644 (file)
index 0000000..fbb8b21
--- /dev/null
@@ -0,0 +1 @@
+diff -u tests/out.sadf-data-ukwn0.tmp tests/expected.sadf-data-ukwn0
index 2d819f9b88e5ee29899d7f0928509579ff2f453d..96a86bff1214bd774573c3bec6e659f50965d3b3 100644 (file)
@@ -1 +1 @@
-./sadf tests/data0.tmp 2>&1 | grep "Requested activities not available" >/dev/null
+LC_ALL=C ./sadf tests/data0.tmp 2>&1 | grep "Requested activities not available" >/dev/null
diff --git a/tests/01318 b/tests/01318
new file mode 100644 (file)
index 0000000..3c9477d
--- /dev/null
@@ -0,0 +1 @@
+LC_ALL=C TZ=GMT ./sar -f tests > tests/out34.sar-u.tmp
diff --git a/tests/01319 b/tests/01319
new file mode 100644 (file)
index 0000000..5d8ae75
--- /dev/null
@@ -0,0 +1 @@
+diff -u tests/out34.sar-u.tmp tests/expected3.sar-u
diff --git a/tests/01450 b/tests/01450
new file mode 100644 (file)
index 0000000..1bd5e6b
--- /dev/null
@@ -0,0 +1 @@
+LC_ALL=C TZ=GMT ./sar -f tests/data-9.1.6 2>&1 | grep "cannot read the format of this file" >/dev/null
index 5efaf6f73772e1ed106104827731d15faf123bb9..3f35c282851c27be813204c358b2c5eb6f220dc8 100644 (file)
@@ -129,6 +129,18 @@ NOTES:
 00770  LC_ALL=C TZ=GMT ./sar -A -f tests/data-extra-12.1.7 > tests/out.data-extra-12.1.7.tmp
 00772  diff -u tests/out.data-extra-12.1.7.tmp tests/expected.data-extra-12.1.7
 
+=====  Reaing datafiles with unknown activity type or format
+00780  LC_ALL=C TZ=GMT ./sar -P ALL -f tests/data-ukwn > tests/out.sar-data-ukwn.tmp
+00781  diff -u tests/out.sar-data-ukwn.tmp tests/expected.sar-data-ukwn
+00784  LC_ALL=C TZ=GMT ./sar -w -f tests/data-ukwn > tests/out2.sar-data-ukwn.tmp
+00785  diff -u tests/out2.sar-data-ukwn.tmp tests/expected2.sar-data-ukwn
+00787  LC_ALL=C ./sadf -H tests/data-ukwn > tests/out.sadf-data-ukwn.tmp
+00788  diff -u tests/out.sadf-data-ukwn.tmp tests/expected.sadf-data-ukwn
+00790  LC_ALL=C TZ=GMT ./sar -A -f tests/data-ukwn0 > tests/out.sar-data-ukwn0.tmp
+00791  diff -u tests/out.sar-data-ukwn0.tmp tests/expected.sar-data-ukwn0
+00795  LC_ALL=C ./sadf -H tests/data-ukwn0 > tests/out.sadf-data-ukwn0.tmp
+00796  diff -u tests/out.sadf-data-ukwn0.tmp tests/expected.sadf-data-ukwn0
+
 =====  Testing sar's options
 00800  LC_ALL=C TZ=GMT ./sar --iface=lo,enp6s0,eth0 -n DEV,EDEV -f tests/data.tmp > tests/out.sar-iface.tmp
 00802  diff -u tests/out.sar-iface.tmp tests/expected.sar-iface
@@ -180,7 +192,7 @@ NOTES:
 01122  diff -u tests/out0.sadf-x.tmp tests/expected0.sadf-x
 01130  ./sadf -j tests/data0.tmp -- -A | $VER_JSON >/dev/null
 01140  LC_ALL=C TZ=GMT ./sar -r -f tests/data0.tmp 2>&1 | grep "Requested activities not available" >/dev/null
-01145  ./sadf tests/data0.tmp 2>&1 | grep "Requested activities not available" >/dev/null
+01145  LC_ALL=C ./sadf tests/data0.tmp 2>&1 | grep "Requested activities not available" >/dev/null
 01150  LC_ALL=C ./sadf -g tests/data0.tmp -- -A > tests/out0.sadf-g.tmp
 01152  diff -u tests/out0.sadf-g.tmp tests/expected0.sadf-g
 
@@ -203,6 +215,8 @@ NOTES:
 01312  diff -u tests/out3.sar-u.tmp tests/expected3.sar-u
 01314  LC_ALL=C TZ=GMT ./sar > tests/out31.sar-u.tmp
 01316  diff -u tests/out31.sar-u.tmp tests/expected3.sar-u
+01318  LC_ALL=C TZ=GMT ./sar -f tests > tests/out34.sar-u.tmp
+01319  diff -u tests/out34.sar-u.tmp tests/expected3.sar-u
 01320  LC_ALL=C TZ=GMT ./sadc -D -
 01330  LC_ALL=C TZ=GMT ./sar -f tests/sa19700101 > tests/out32.sar-u.tmp
 01332  diff -u tests/out32.sar-u.tmp tests/expected32.sar-u
@@ -237,6 +251,7 @@ NOTES:
 01425  LC_ALL=C ./sar 2 2 2 2>&1 | grep "Usage:" >/dev/null
 01430  LC_ALL=C ./sar -o foo 2>&1 | grep "Usage:" >/dev/null
 01440  LC_ALL=C TZ=GMT ./sar --unix_time=123456789 2>&1 | grep "Please check" >/dev/null
+01450  LC_ALL=C TZ=GMT ./sar -f tests/data-9.1.6 2>&1 | grep "cannot read the format of this file" >/dev/null
 
 =====  Specific tests for sensors statistics (basic sensor output already tested using data-11.6.5 conversion)
 01500  LC_ALL=C TZ=GMT ./sadf -d tests/data-11.6.5.tmp -- -m FAN,IN,TEMP > tests/out.data-11.6.5-sadf-d.tmp
similarity index 99%
rename from tests/create_sadd.c
rename to tests/create_data-extra.c
index a193a2bc9ba430d32b037748622ae35ab5913777..0adf30f9eb037036accae6157a67e8f20046cdf3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * create_sadd.c: Create a system activity binary data file.
+ * create_data-extra.c: Create a binary data file with extra structures
  * (C) 2019 by Sebastien GODARD (sysstat <at> orange.fr)
  *
  ***************************************************************************
diff --git a/tests/create_data-ukwn.c b/tests/create_data-ukwn.c
new file mode 100644 (file)
index 0000000..d7fdca9
--- /dev/null
@@ -0,0 +1,454 @@
+/*
+ * create_data-ukwn.c: Create a binary data file with unknown activity type or unknown activity format
+ * (C) 2019 by Sebastien GODARD (sysstat <at> orange.fr)
+ *
+ ***************************************************************************
+ * This program is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU General Public License as published  by  the *
+ * Free Software Foundation; either version 2 of the License, or (at  your *
+ * option) any later version.                                              *
+ *                                                                         *
+ * This program is distributed in the hope that it  will  be  useful,  but *
+ * WITHOUT ANY WARRANTY; without the implied warranty  of  MERCHANTABILITY *
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
+ * for more details.                                                       *
+ *                                                                         *
+ * You should have received a copy of the GNU General Public License along *
+ * with this program; if not, write to the Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA              *
+ ***************************************************************************
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+
+#define UTSNAME_LEN            65
+#define FILE_MAGIC_PADDING     48
+
+#define FALSE  0
+#define TRUE   1
+
+/*
+ *!!!!!!!!!!!!!!!!
+ * Set it to FALSE to create a binary datafile with only unknown activity type and format.
+ *!!!!!!!!!!!!!!!!
+ */
+#define INCLUDE_CPU_STAT       TRUE
+
+int main(void)
+{
+       struct file_magic_12_1_7 {
+               unsigned short sysstat_magic;
+               unsigned short format_magic;
+               unsigned char sysstat_version;
+               unsigned char sysstat_patchlevel;
+               unsigned char sysstat_sublevel;
+               unsigned char sysstat_extraversion;
+               unsigned int header_size;       /* Init me! */
+               unsigned int upgraded;
+               unsigned int hdr_types_nr[3];
+               unsigned char pad[FILE_MAGIC_PADDING];
+       };
+
+       struct file_magic_12_1_7 f_magic = {
+               .sysstat_magic = 0xd596,
+               .format_magic = 0x2175,
+               .sysstat_version = 12,
+               .sysstat_patchlevel = 1,
+               .sysstat_sublevel = 7,
+               .sysstat_extraversion = 0,
+               .upgraded = 0,
+               .hdr_types_nr = {1, 1, 12}
+       };
+
+       struct file_header_12_1_7 {
+               unsigned long long sa_ust_time;
+               unsigned long sa_hz             __attribute__ ((aligned (8)));
+               unsigned int sa_cpu_nr          __attribute__ ((aligned (8)));
+               unsigned int sa_act_nr;
+               int sa_year;
+               unsigned int act_types_nr[3];
+               unsigned int rec_types_nr[3];
+               unsigned int act_size;  /* Init me! */
+               unsigned int rec_size;  /* Init me! */
+               unsigned int extra_next;
+               unsigned char sa_day;
+               unsigned char sa_month;
+               char sa_sizeof_long;
+               char sa_sysname[UTSNAME_LEN];
+               char sa_nodename[UTSNAME_LEN];
+               char sa_release[UTSNAME_LEN];
+               char sa_machine[UTSNAME_LEN];
+       };
+
+       struct file_header_12_1_7 f_header = {
+               .sa_ust_time = 1568533161,
+               .sa_hz = 100,
+               .sa_cpu_nr = 3,
+               .sa_act_nr = (INCLUDE_CPU_STAT ? 3 : 2),
+               .sa_year = 2019,
+               .act_types_nr = {0, 0, 9},
+               .rec_types_nr = {2, 0, 1},
+               .extra_next = FALSE,
+               .sa_day = 15,
+               .sa_month = 9,
+               .sa_sizeof_long = 8,
+               .sa_sysname = "Linux",
+               .sa_nodename = "localhost.localdomain",
+               .sa_release = "5.0.16-100.fc28.x86_64",
+               .sa_machine = "x86_64"
+       };
+
+       struct file_activity_12_1_7 {
+               unsigned int id;
+               unsigned int magic;
+               int nr;
+               int nr2;
+               int has_nr;
+               int size;       /* Init me! */
+               unsigned int types_nr[3];
+       };
+
+       struct file_activity_12_1_7 f_activity_a_cpu = {
+               .id = 1,        /* A_CPU */
+               .magic = 0x8b,
+               .nr = 3,
+               .nr2 = 1,
+               .has_nr = TRUE,
+               .types_nr = {10, 0, 0}
+       };
+
+       struct file_activity_12_1_7 f_activity_a_pcsw = {
+               .id = 2,        /* A_PCSW */
+               .magic = 0xff,  /* Unknown activity format */
+               .nr = 1,
+               .nr2 = 1,
+               .has_nr = FALSE,
+               .types_nr = {0, 1, 0}
+       };
+
+       struct file_activity_12_1_7 f_activity_a_unknown = {
+               .id = 0xff,     /* Unknown activity */
+               .magic = 0x8a,  /* Unknown activity format */
+               .nr = 2,
+               .nr2 = 1,
+               .has_nr = TRUE,
+               .types_nr = {1, 1, 0}
+       };
+
+       struct record_header_12_1_7 {
+               unsigned long long uptime_cs;
+               unsigned long long ust_time;
+               unsigned int extra_next;
+               unsigned char record_type;
+               unsigned char hour;
+               unsigned char minute;
+               unsigned char second;
+       };
+
+       struct record_header_12_1_7 r_header_1 = {
+               .uptime_cs = 15000,
+               .ust_time = 1568540000,
+               .extra_next = FALSE,
+               .record_type = 1,       /* R_STATS */
+               .hour = 11,
+               .minute = 5,
+               .second = 58
+       };
+
+       struct record_header_12_1_7 r_header_2 = {
+               .uptime_cs = 15200,
+               .ust_time = 1568540200,
+               .extra_next = FALSE,
+               .record_type = 1,       /* R_STATS */
+               .hour = 11,
+               .minute = 6,
+               .second = 1
+       };
+
+       struct stats_cpu_12_1_7 {
+               unsigned long long cpu_user;
+               unsigned long long cpu_nice;
+               unsigned long long cpu_sys;
+               unsigned long long cpu_idle;
+               unsigned long long cpu_iowait;
+               unsigned long long cpu_steal;
+               unsigned long long cpu_hardirq;
+               unsigned long long cpu_softirq;
+               unsigned long long cpu_guest;
+               unsigned long long cpu_guest_nice;
+       };
+
+       struct stats_cpu_12_1_7 s_cpu_0_1 = {
+               .cpu_user = 1000,
+               .cpu_nice = 0,
+               .cpu_sys = 500,
+               .cpu_idle = 0,
+               .cpu_iowait = 0,
+               .cpu_steal = 0,
+               .cpu_hardirq = 0,
+               .cpu_softirq = 0,
+               .cpu_guest = 0,
+               .cpu_guest_nice = 0
+       };
+
+       struct stats_cpu_12_1_7 s_cpu_1_1 = {
+               .cpu_user = 1000,
+               .cpu_nice = 0,
+               .cpu_sys = 0,
+               .cpu_idle = 0,
+               .cpu_iowait = 0,
+               .cpu_steal = 0,
+               .cpu_hardirq = 0,
+               .cpu_softirq = 0,
+               .cpu_guest = 0,
+               .cpu_guest_nice = 0
+       };
+
+       struct stats_cpu_12_1_7 s_cpu_2_1 = {
+               .cpu_user = 0,
+               .cpu_nice = 0,
+               .cpu_sys = 500,
+               .cpu_idle = 0,
+               .cpu_iowait = 0,
+               .cpu_steal = 0,
+               .cpu_hardirq = 0,
+               .cpu_softirq = 0,
+               .cpu_guest = 0,
+               .cpu_guest_nice = 0
+       };
+
+       struct stats_cpu_12_1_7 s_cpu_0_2 = {
+               .cpu_user = 1100,
+               .cpu_nice = 0,
+               .cpu_sys = 500,
+               .cpu_idle = 100,
+               .cpu_iowait = 0,
+               .cpu_steal = 0,
+               .cpu_hardirq = 0,
+               .cpu_softirq = 0,
+               .cpu_guest = 0,
+               .cpu_guest_nice = 0
+       };
+
+       struct stats_cpu_12_1_7 s_cpu_1_2 = {
+               .cpu_user = 1100,
+               .cpu_nice = 0,
+               .cpu_sys = 0,
+               .cpu_idle = 0,
+               .cpu_iowait = 0,
+               .cpu_steal = 0,
+               .cpu_hardirq = 0,
+               .cpu_softirq = 0,
+               .cpu_guest = 0,
+               .cpu_guest_nice = 0
+       };
+
+       struct stats_cpu_12_1_7 s_cpu_2_2 = {
+               .cpu_user = 0,
+               .cpu_nice = 0,
+               .cpu_sys = 500,
+               .cpu_idle = 100,
+               .cpu_iowait = 0,
+               .cpu_steal = 0,
+               .cpu_hardirq = 0,
+               .cpu_softirq = 0,
+               .cpu_guest = 0,
+               .cpu_guest_nice = 0
+       };
+
+       struct stats_pcsw_ukwn {
+               unsigned long   processes       __attribute__ ((aligned (8)));
+       };
+
+       struct stats_pcsw_ukwn s_pcsw_1 = {
+               .processes = 543
+       };
+
+       struct stats_pcsw_ukwn s_pcsw_2 = {
+               .processes = 643
+       };
+
+       struct stats_unknown {
+               unsigned long long unknown_ull;
+               unsigned long      unknown_ul    __attribute__ ((aligned (8)));
+       };
+
+       struct stats_unknown s_ukwn_0_1 = {
+               .unknown_ull = 123456789,
+               .unknown_ul  = 12345
+       };
+
+       struct stats_unknown s_ukwn_1_1 = {
+               .unknown_ull = 987654321,
+               .unknown_ul  = 54321
+       };
+
+       struct stats_unknown s_ukwn_0_2 = {
+               .unknown_ull = 234567891,
+               .unknown_ul  = 23456
+       };
+
+       struct stats_unknown s_ukwn_1_2 = {
+               .unknown_ull = 198765432,
+               .unknown_ul  = 65432
+       };
+
+       int fd;
+       int nr_cpu, nr_ukwn;
+       char fname[16];
+
+       /* Open data file */
+       if (INCLUDE_CPU_STAT) {
+               strcpy(fname, "data-ukwn");
+       }
+       else {
+               strcpy(fname, "data-ukwn0");
+       }
+       if ((fd = open(fname, O_CREAT | O_WRONLY,
+                      S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) {
+               perror("open");
+               exit(1);
+       }
+
+       /* Write file magic structure */
+       f_magic.header_size = sizeof(struct file_header_12_1_7);
+       if (write(fd, &f_magic, sizeof(struct file_magic_12_1_7)) < 0) {
+               perror("write file magic");
+               exit(1);
+       }
+
+       /* Write file header structure */
+       f_header.act_size = sizeof(struct file_activity_12_1_7);
+       f_header.rec_size = sizeof(struct record_header_12_1_7);
+       if (write(fd, &f_header, sizeof(struct file_header_12_1_7)) < 0) {
+               perror("write file header");
+               exit(1);
+       }
+
+       /* Write file activity list */
+       if (INCLUDE_CPU_STAT) {
+               f_activity_a_cpu.size = sizeof(struct stats_cpu_12_1_7);
+               if (write(fd, &f_activity_a_cpu, sizeof(struct file_activity_12_1_7)) < 0) {
+                       perror("write file activity A_CPU");
+                       exit(1);
+               }
+       }
+       f_activity_a_pcsw.size = sizeof(struct stats_pcsw_ukwn);
+       if (write(fd, &f_activity_a_pcsw, sizeof(struct file_activity_12_1_7)) < 0) {
+               perror("write file activity A_PCSW");
+               exit(1);
+       }
+       f_activity_a_unknown.size = sizeof(struct stats_unknown);
+       if (write(fd, &f_activity_a_unknown, sizeof(struct file_activity_12_1_7)) < 0) {
+               perror("write file activity A_UNKNOWN");
+               exit(1);
+       }
+
+       /* Write R_STAT #1 record */
+       if (write(fd, &r_header_1, sizeof(struct record_header_12_1_7)) < 0) {
+               perror("write STAT #1 record");
+               exit(1);
+       }
+
+       if (INCLUDE_CPU_STAT) {
+               /* Write A_CPU stats */
+               nr_cpu = 3;
+               if (write(fd, &nr_cpu, sizeof(int)) < 0) {
+                       perror("write nr_cpu #1");
+                       exit(1);
+               }
+               if (write(fd, &s_cpu_0_1, sizeof(struct stats_cpu_12_1_7)) < 0) {
+                       perror("write CPU stats 0_1");
+                       exit(1);
+               }
+               if (write(fd, &s_cpu_1_1, sizeof(struct stats_cpu_12_1_7)) < 0) {
+                       perror("write CPU stats 1_1");
+                       exit(1);
+               }
+               if (write(fd, &s_cpu_2_1, sizeof(struct stats_cpu_12_1_7)) < 0) {
+                       perror("write CPU stats 2_1");
+                       exit(1);
+               }
+       }
+
+       /* Write A_PCSW stats */
+       if (write(fd, &s_pcsw_1, sizeof(struct stats_pcsw_ukwn)) < 0) {
+               perror("write PCSW stats 1");
+               exit(1);
+       }
+
+       /* Write A_UNKNOWN stats */
+       nr_ukwn = 2;
+       if (write(fd, &nr_ukwn, sizeof(int)) < 0) {
+               perror("write nr_ukwn #1");
+               exit(1);
+       }
+       if (write(fd, &s_ukwn_0_1, sizeof(struct stats_unknown)) < 0) {
+               perror("write UNKNOWN stats 0_1");
+               exit(1);
+       }
+       if (write(fd, &s_ukwn_1_1, sizeof(struct stats_unknown)) < 0) {
+               perror("write UNKNOWN stats 1_1");
+               exit(1);
+       }
+
+       /* Write R_STAT #2 record */
+       if (write(fd, &r_header_2, sizeof(struct record_header_12_1_7)) < 0) {
+               perror("write STAT #2 record");
+               exit(1);
+       }
+
+       if (INCLUDE_CPU_STAT) {
+               /* Write A_CPU stats */
+               nr_cpu = 3;
+               if (write(fd, &nr_cpu, sizeof(int)) < 0) {
+                       perror("write nr_cpu #2");
+                       exit(1);
+               }
+               if (write(fd, &s_cpu_0_2, sizeof(struct stats_cpu_12_1_7)) < 0) {
+                       perror("write CPU stats 0_2");
+                       exit(1);
+               }
+               if (write(fd, &s_cpu_1_2, sizeof(struct stats_cpu_12_1_7)) < 0) {
+                       perror("write CPU stats 1_2");
+                       exit(1);
+               }
+               if (write(fd, &s_cpu_2_2, sizeof(struct stats_cpu_12_1_7)) < 0) {
+                       perror("write CPU stats 2_2");
+                       exit(1);
+               }
+       }
+
+       /* Write A_PCSW stats */
+       if (write(fd, &s_pcsw_2, sizeof(struct stats_pcsw_ukwn)) < 0) {
+               perror("write PCSW stats 2");
+               exit(1);
+       }
+
+       /* Write A_UNKNOWN stats */
+       nr_ukwn = 2;
+       if (write(fd, &nr_ukwn, sizeof(int)) < 0) {
+               perror("write nr_ukwn #2");
+               exit(1);
+       }
+       if (write(fd, &s_ukwn_0_2, sizeof(struct stats_unknown)) < 0) {
+               perror("write UNKNOWN stats 0_2");
+               exit(1);
+       }
+       if (write(fd, &s_ukwn_1_2, sizeof(struct stats_unknown)) < 0) {
+               perror("write UNKNOWN stats 1_2");
+               exit(1);
+       }
+
+       /* Close data file */
+       close(fd);
+
+       return 0;
+}
diff --git a/tests/data-ukwn b/tests/data-ukwn
new file mode 100644 (file)
index 0000000..8423909
Binary files /dev/null and b/tests/data-ukwn differ
diff --git a/tests/data-ukwn0 b/tests/data-ukwn0
new file mode 100644 (file)
index 0000000..8381ae5
Binary files /dev/null and b/tests/data-ukwn0 differ
diff --git a/tests/expected.sadf-data-ukwn b/tests/expected.sadf-data-ukwn
new file mode 100644 (file)
index 0000000..f9a10c8
--- /dev/null
@@ -0,0 +1,16 @@
+System activity data file: tests/data-ukwn (0x2175)
+File created by sar/sadc from sysstat version 12.1.7
+Genuine sa datafile: yes (0)
+Host: Linux 5.0.16-100.fc28.x86_64 (localhost.localdomain)     09/15/19        _x86_64_        (2 CPU)
+File date: 2019-09-15
+File time: 07:39:21 UTC (1568533161)
+Timezone: 
+File composition: (1,1,12),(0,0,9),(2,0,1)
+Size of a long int: 8
+HZ = 100
+Number of activities in file: 3
+Extra structures available: N
+List of activities:
+01: [8b] A_CPU                Y:   3   (10,0,0)
+02: [ff] A_PCSW               N:   1   (0,1,0)         [Unknown format]
+255: [8a] Unknown activity     Y:   2  (1,1,0)
diff --git a/tests/expected.sadf-data-ukwn0 b/tests/expected.sadf-data-ukwn0
new file mode 100644 (file)
index 0000000..9d7dce0
--- /dev/null
@@ -0,0 +1,15 @@
+System activity data file: tests/data-ukwn0 (0x2175)
+File created by sar/sadc from sysstat version 12.1.7
+Genuine sa datafile: yes (0)
+Host: Linux 5.0.16-100.fc28.x86_64 (localhost.localdomain)     09/15/19        _x86_64_        (2 CPU)
+File date: 2019-09-15
+File time: 07:39:21 UTC (1568533161)
+Timezone: 
+File composition: (1,1,12),(0,0,9),(2,0,1)
+Size of a long int: 8
+HZ = 100
+Number of activities in file: 2
+Extra structures available: N
+List of activities:
+02: [ff] A_PCSW               N:   1   (0,1,0)         [Unknown format]
+255: [8a] Unknown activity     Y:   2  (1,1,0)
diff --git a/tests/expected.sar-data-ukwn b/tests/expected.sar-data-ukwn
new file mode 100644 (file)
index 0000000..2646ded
--- /dev/null
@@ -0,0 +1,9 @@
+Linux 5.0.16-100.fc28.x86_64 (localhost.localdomain)   09/15/19        _x86_64_        (2 CPU)
+
+09:33:20        CPU     %user     %nice   %system   %iowait    %steal     %idle
+09:36:40        all     50.00      0.00      0.00      0.00      0.00     50.00
+09:36:40          0    100.00      0.00      0.00      0.00      0.00      0.00
+09:36:40          1      0.00      0.00      0.00      0.00      0.00    100.00
+Average:        all     50.00      0.00      0.00      0.00      0.00     50.00
+Average:          0    100.00      0.00      0.00      0.00      0.00      0.00
+Average:          1      0.00      0.00      0.00      0.00      0.00    100.00
diff --git a/tests/expected2.sar-data-ukwn b/tests/expected2.sar-data-ukwn
new file mode 100644 (file)
index 0000000..464dc9a
--- /dev/null
@@ -0,0 +1 @@
+Linux 5.0.16-100.fc28.x86_64 (localhost.localdomain)   09/15/19        _x86_64_        (2 CPU)