]> granicus.if.org Git - sysstat/blob - systest.c
simtest: Add new non regression tests
[sysstat] / systest.c
1 /*
2  * sysstat test functions.
3  * (C) 2019 by Sebastien GODARD (sysstat <at> orange.fr)
4  *
5  ***************************************************************************
6  * This program is free software; you can redistribute it and/or modify it *
7  * under the terms of the GNU General Public License as published  by  the *
8  * Free Software Foundation; either version 2 of the License, or (at  your *
9  * option) any later version.                                              *
10  *                                                                         *
11  * This program is distributed in the hope that it  will  be  useful,  but *
12  * WITHOUT ANY WARRANTY; without the implied warranty  of  MERCHANTABILITY *
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
14  * for more details.                                                       *
15  *                                                                         *
16  * You should have received a copy of the GNU General Public License along *
17  * with this program; if not, write to the Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA              *
19  ***************************************************************************
20  */
21
22 #ifdef TEST
23
24 #include <stdio.h>
25 #include <string.h>
26 #include <errno.h>
27 #include <stdlib.h>
28 #include <time.h>
29 #include <unistd.h>
30 #include <sys/utsname.h>
31 #include <sys/statvfs.h>
32
33 #include "systest.h"
34
35 time_t __unix_time = 0;
36 extern long interval;
37
38 /*
39  ***************************************************************************
40  * Test mode: Instead of reading system time, use time given on the command
41  * line.
42  *
43  * OUT:
44  * @t   Number of seconds since the epoch, as given on the command line.
45  ***************************************************************************
46  */
47
48 void get_unix_time(time_t *t)
49 {
50         *t = __unix_time;
51 }
52
53 /*
54  ***************************************************************************
55  * Test mode: Send bogus information about current kernel.
56  *
57  * OUT:
58  * @h   Structure with kernel information.
59  ***************************************************************************
60  */
61
62 void get_uname(struct utsname *h)
63 {
64         strcpy(h->sysname, "Linux");
65         strcpy(h->nodename, "SYSSTAT.TEST");
66         strcpy(h->release, "1.2.3-TEST");
67         strcpy(h->machine, "x86_64");
68 }
69
70 /*
71  ***************************************************************************
72  * Test mode: Send bogus information about current filesystem.
73  *
74  * OUT:
75  * @buf Structure with filesystem information.
76  ***************************************************************************
77  */
78
79 int get_fs_stat(char *c, struct statvfs *buf)
80 {
81         static int p = 0;
82         unsigned long long bfree[4] = {89739427840, 293286670336, 11696156672, 292616732672};
83         unsigned long long blocks[4] = {97891291136, 309502345216, 30829043712, 309502345216};
84         unsigned long long bavail[4] = {84722675712, 277541253120, 10106515456, 276871315456};
85         unsigned long long files[4] = {6111232, 19202048, 1921360, 19202048};
86         unsigned long long ffree[4] = {6008414, 19201593, 1621550, 19051710};
87
88         buf->f_bfree = bfree[p];
89         buf->f_blocks = blocks[p];
90         buf->f_bavail = bavail[p];
91         buf->f_frsize = 1;
92         buf->f_files = files[p];
93         buf->f_ffree = ffree[p];
94
95         p = (p + 1) & 0x11;
96
97         return 0;
98 }
99
100 /*
101  ***************************************************************************
102  * Test mode: Ignore environment variable value.
103  ***************************************************************************
104  */
105
106 char *get_env_value(char *c)
107 {
108         return NULL;
109 }
110
111 /*
112  ***************************************************************************
113  * Test mode: Go to next time period.
114  ***************************************************************************
115  */
116
117 void next_time_step(void)
118 {
119         static int root_nr = 1;
120         char rootf[64];
121
122         __unix_time += interval;
123
124         if ((unlink(ROOTDIR) < 0) && (errno != ENOENT)) {
125                 perror("unlink");
126                 exit(1);
127         }
128
129         sprintf(rootf, "%s%d", ROOTFILE, ++root_nr);
130         if (symlink(rootf, ROOTDIR) < 0) {
131                 perror("link");
132                 exit(1);
133         }
134 }
135
136 #endif  /* TEST */
137