1 // Copyright (c) 1999-2018 David Muse
2 // See the file COPYING for more information
3 
4 #include <rudiments/sys.h>
5 #include <rudiments/charstring.h>
6 #include <rudiments/stdio.h>
7 #include <rudiments/process.h>
8 #include "test.cpp"
9 
10 #ifdef RUDIMENTS_HAVE_LONG_LONG
11 	#define LONG_LONG long long
12 #else
13 	#define LONG_LONG long
14 #endif
15 
main(int argc,const char ** argv)16 int main(int argc, const char **argv) {
17 
18 	header("sys");
19 
20 	char	*osname=sys::getOperatingSystemName();
21 	char	*release=sys::getOperatingSystemRelease();
22 	char	*version=sys::getOperatingSystemVersion();
23 	char	*arch=sys::getOperatingSystemArchitecture();
24 	char	*hostname=sys::getHostName();
25 
26 #if 0
27 	stdoutput.printf("OS Name	: %s\n",osname);
28 	stdoutput.printf("OS Release	: %s\n",release);
29 	stdoutput.printf("OS Version	: %s\n",version);
30 	stdoutput.printf("OS Arch	: %s\n",arch);
31 	stdoutput.printf("Host Name	: %s\n",hostname);
32 
33 	double	onemin;
34 	double	fivemin;
35 	double	fifteenmin;
36 	sys::getLoadAverages(&onemin,&fivemin,&fifteenmin);
37 	stdoutput.printf("Load Averages	: %0.2f  %0.2f  %0.2f\n",
38 					onemin,fivemin,fifteenmin);
39 
40 	stdoutput.printf("Max Cmd Line Arg Length"
41 			"			: %lld\n",
42 			(LONG_LONG)sys::getMaxCommandLineArgumentLength());
43 
44 	stdoutput.printf("Max Processes Per User"
45 			"			: %lld\n",
46 			(LONG_LONG)sys::getMaxProcessesPerUser());
47 
48 	stdoutput.printf("Max Host Name Length"
49 			"			: %lld\n",
50 			(LONG_LONG)sys::getMaxHostNameLength());
51 
52 	stdoutput.printf("Max Login Name Length"
53 			"			: %lld\n",
54 			(LONG_LONG)sys::getMaxLoginNameLength());
55 
56 	stdoutput.printf("Clock Ticks Per Second"
57 			"			: %lld\n",
58 			(LONG_LONG)sys::getClockTicksPerSecond());
59 
60 	stdoutput.printf("Max Open Files Per Process"
61 			"		: %lld\n",
62 			(LONG_LONG)sys::getMaxOpenFilesPerProcess());
63 
64 	stdoutput.printf("Page Size"
65 			"				: %lld\n",
66 			(LONG_LONG)sys::getPageSize());
67 
68 	stdoutput.printf("Allocation Granularity"
69 			"			: %lld\n",
70 			(LONG_LONG)sys::getAllocationGranularity());
71 
72 	stdoutput.printf("Max Open Streams Per Process"
73 			"		: %lld\n",
74 			(LONG_LONG)sys::getMaxOpenStreamsPerProcess());
75 
76 	stdoutput.printf("Max Symlink Loops"
77 			"			: %lld\n",
78 			(LONG_LONG)sys::getMaxSymlinkLoops());
79 
80 	stdoutput.printf("Max Terminal Device Name Length"
81 			"		: %lld\n",
82 			(LONG_LONG)sys::getMaxTerminalDeviceNameLength());
83 
84 	stdoutput.printf("Max Timezone Name Length"
85 			"		: %lld\n",
86 			(LONG_LONG)sys::getMaxTimezoneNameLength());
87 
88 	stdoutput.printf("Max Line Length"
89 			"				: %lld\n",
90 			(LONG_LONG)sys::getMaxLineLength());
91 
92 	stdoutput.printf("Physical Page Count"
93 			"			: %lld\n",
94 			(LONG_LONG)sys::getPhysicalPageCount());
95 
96 	stdoutput.printf("Available Physical Page Count"
97 			"		: %lld\n",
98 			(LONG_LONG)sys::getAvailablePhysicalPageCount());
99 
100 	stdoutput.printf("Processor Count"
101 			"				: %lld\n",
102 			(LONG_LONG)sys::getProcessorCount());
103 
104 	stdoutput.printf("Max Processor Count"
105 			"			: %lld\n",
106 			(LONG_LONG)sys::getMaxProcessorCount());
107 
108 	stdoutput.printf("Processors Online"
109 			"			: %lld\n",
110 			(LONG_LONG)sys::getProcessorsOnline());
111 
112 	stdoutput.printf("Max Supplemental Groups Per User"
113 			"	: %lld\n",
114 			(LONG_LONG)sys::getMaxSupplementalGroupsPerUser());
115 
116 	stdoutput.printf("Max Delay Timer Expirations"
117 			"		: %lld\n",
118 			(LONG_LONG)sys::getMaxDelayTimerExpirations());
119 
120 	stdoutput.printf("Max Realtime Signals"
121 			"			: %lld\n",
122 			(LONG_LONG)sys::getMaxRealtimeSignals());
123 
124 	stdoutput.printf("Max Sempahores Per Process"
125 			"		: %lld\n",
126 			(LONG_LONG)sys::getMaxSemaphoresPerProcess());
127 
128 	stdoutput.printf("Max Semaphore Value"
129 			"			: %lld\n",
130 			(LONG_LONG)sys::getMaxSemaphoreValue());
131 
132 	stdoutput.printf("Max Signal Queue Length"
133 			"			: %lld\n",
134 			(LONG_LONG)sys::getMaxSignalQueueLength());
135 
136 	stdoutput.printf("Max Timers Per Process"
137 			"			: %lld\n",
138 			(LONG_LONG)sys::getMaxTimersPerProcess());
139 
140 	stdoutput.printf("Suggested Group Entry Buffer Size"
141 			"	: %lld\n",
142 			(LONG_LONG)sys::getSuggestedGroupEntryBufferSize());
143 
144 	stdoutput.printf("Suggested Passwd Entry Buffer Size"
145 			"	: %lld\n",
146 			(LONG_LONG)sys::getSuggestedPasswordEntryBufferSize());
147 
148 	stdoutput.printf("Min Thread Stack Size"
149 			"			: %lld\n",
150 			(LONG_LONG)sys::getMinThreadStackSize());
151 
152 	stdoutput.printf("Max Threads Per Process"
153 			"			: %lld\n",
154 			(LONG_LONG)sys::getMaxThreadsPerProcess());
155 
156 	stdoutput.printf("Thread Destructor Iterations"
157 			"		: %lld\n",
158 			(LONG_LONG)sys::getThreadDestructorIterations());
159 
160 	stdoutput.printf("Max Thread Keys"
161 			"				: %lld\n",
162 			(LONG_LONG)sys::getMaxThreadKeys());
163 
164 	stdoutput.printf("Max At-Exit Functions"
165 			"			: %lld\n",
166 			(LONG_LONG)sys::getMaxAtExitFunctions());
167 
168 	stdoutput.printf("CPUSet Size"
169 			"				: %lld\n",
170 			(LONG_LONG)sys::getCpuSetSize());
171 
172 	stdoutput.printf("Max Password Length"
173 			"			: %lld\n",
174 			(LONG_LONG)sys::getMaxPasswordLength());
175 
176 	stdoutput.printf("Max Log Name Length"
177 			"			: %lld\n",
178 			(LONG_LONG)sys::getMaxLogNameLength());
179 
180 	stdoutput.printf("Max Process ID"
181 			"				: %lld\n",
182 			(LONG_LONG)sys::getMaxProcessId());
183 #endif
184 
185 	// these should be non-empty/non-null
186 	test("OS Name",!charstring::isNullOrEmpty(osname));
187 	test("OS Release",!charstring::isNullOrEmpty(release));
188 	test("OS Version",!charstring::isNullOrEmpty(version));
189 	test("OS Arch",!charstring::isNullOrEmpty(arch));
190 	test("Rudiments Version",
191 		!charstring::compare(sys::getRudimentsVersion(),
192 						RUDIMENTS_VERSION));
193 	test("Host Name",!charstring::isNullOrEmpty(hostname));
194 
195 	// these should either return non-zero or -1 for unsupported
196 	test("Max Cmd Line Arg Length",
197 			sys::getMaxCommandLineArgumentLength()!=0);
198 	test("Max Processes Per User",
199 			sys::getMaxProcessesPerUser()!=0);
200 	test("Max Host Name Length",
201 			sys::getMaxHostNameLength()!=0);
202 	test("Max Login Name Length",
203 			sys::getMaxLoginNameLength()!=0);
204 	test("Clock Ticks Per Second",
205 			sys::getClockTicksPerSecond()!=0);
206 	test("Max Open Files Per Process",
207 			sys::getMaxOpenFilesPerProcess()!=0);
208 	test("Page Size",
209 			sys::getPageSize()!=0);
210 	test("Allocation Granularity",
211 			sys::getAllocationGranularity()!=0);
212 	test("Max Open Streams Per Process",
213 			sys::getMaxOpenStreamsPerProcess()!=0);
214 	test("Max Symlink Loops",
215 			sys::getMaxSymlinkLoops()!=0);
216 	test("Max Terminal Device Name Length",
217 			sys::getMaxTerminalDeviceNameLength()!=0);
218 	test("Max Timezone Name Length",
219 			sys::getMaxTimezoneNameLength()!=0);
220 	test("Max Line Length",
221 			sys::getMaxLineLength()!=0);
222 	test("Physical Page Count",
223 			sys::getPhysicalPageCount()!=0);
224 	test("Available Physical Page Count",
225 			sys::getAvailablePhysicalPageCount()!=0);
226 	test("Processor Count",
227 			sys::getProcessorCount()!=0);
228 	test("Max Processor Count",
229 			sys::getMaxProcessorCount()!=0);
230 	test("Processors Online",
231 			sys::getProcessorsOnline()!=0);
232 	test("Max Supplemental Groups Per User",
233 			sys::getMaxSupplementalGroupsPerUser()!=0);
234 	test("Max Delay Timer Expirations",
235 			sys::getMaxDelayTimerExpirations()!=0);
236 	test("Max Realtime Signals",
237 			sys::getMaxRealtimeSignals()!=0);
238 	test("Max Sempahores Per Process",
239 			sys::getMaxSemaphoresPerProcess()!=0);
240 	test("Max Semaphore Value",
241 			sys::getMaxSemaphoreValue()!=0);
242 	test("Max Signal Queue Length",
243 			sys::getMaxSignalQueueLength()!=0);
244 	test("Max Timers Per Process",
245 			sys::getMaxTimersPerProcess()!=0);
246 	test("Suggested Group Entry Buffer Size",
247 			sys::getSuggestedGroupEntryBufferSize()!=0);
248 	test("Suggested Passwd Entry Buffer Size",
249 			sys::getSuggestedPasswordEntryBufferSize()!=0);
250 	test("Min Thread Stack Size",
251 			sys::getMinThreadStackSize()!=0);
252 	test("Max Threads Per Process",
253 			sys::getMaxThreadsPerProcess()!=0);
254 	test("Thread Destructor Iterations",
255 			sys::getThreadDestructorIterations()!=0);
256 	test("Max Thread Keys",
257 			sys::getMaxThreadKeys()!=0);
258 	test("Max At-Exit Functions",
259 			sys::getMaxAtExitFunctions()!=0);
260 	test("CPUSet Size",
261 			sys::getCpuSetSize()!=0);
262 	test("Max Password Length",
263 			sys::getMaxPasswordLength()!=0);
264 	test("Max Log Name Length",
265 			sys::getMaxLogNameLength()!=0);
266 	test("Max Process ID",
267 			sys::getMaxProcessId()!=0);
268 
269 	// this just shouldn't crash
270 	sys::sync();
271 
272 	// clean up
273 	delete[] osname;
274 	delete[] release;
275 	delete[] version;
276 	delete[] arch;
277 	delete[] hostname;
278 
279 	stdoutput.printf("\n");
280 }
281