ObjFW  Diff

Differences From Artifact [f3db5fbea9]:

To Artifact [89e82ce05a]:


11
12
13
14
15
16
17
18





19
20
21
22

23
24
25
26
27
28
29
30

31
32
33
34

35
36
37
38
39
40


41
42

43
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

81
82
83

84
85
86
87


88
89
90

91
92
93

94
95
96

97
98
99

100
101

102
103
104
105
106
107
108





109
110
111
112
113
114





115
116
117


118
119

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167



































168
169
170

171
172

173
174
175

176
177

178
179
180

181
182

183
184
185

186
187

188
189
190
191


192
193
194
195


196
197
198
199


200
201
202
203
204


205
206





207
208
209

210
211
212
213
214
215
216

217
218
219
220

221
222
223

224
225


226

227
228


229
230

231
232


233
234

235

236
237
238
239
240
241
242
243
244
245
246

247
248
249

250

251

252

253
254
255
256

257


258

259
260
261

262
263
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33

34
35
36
37

38
39
40
41
42


43
44
45

46
47
48
49
50
51






























52



53



54




55
56



57



58



59



60


61
62






63
64
65
66
67






68
69
70
71
72



73
74


75






















76

























77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111



112


113



114


115



116


117



118


119




120
121




122
123




124
125
126
127
128


129
130
131
132
133
134
135
136
137
138
139

140
141
142
143
144
145
146

147
148
149
150

151
152
153
154
155


156
157
158
159


160
161
162
163
164


165
166
167
168
169

170
171
172
173
174
175
176
177
178
179
180

181
182
183
184
185

186
187
188

189
190
191
192

193
194
195
196

197
198
199

200
201
202







-
+
+
+
+
+



-
+







-
+



-
+




-
-
+
+

-
+


+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
+
-
-
-
+
-
-
-
-
+
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
+

-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
-
-
+
-
-
-
+
-
-
+
-
-
-
+
-
-
+
-
-
-
+
-
-
+
-
-
-
-
+
+
-
-
-
-
+
+
-
-
-
-
+
+



-
-
+
+


+
+
+
+
+


-
+






-
+



-
+



+
-
-
+
+

+
-
-
+
+


+
-
-
+
+


+
-
+










-
+



+
-
+

+
-
+



-
+

+
+
-
+


-
+


 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "TestsAppDelegate.h"
#import "ObjFW.h"
#import "ObjFWTest.h"

@interface OFSystemInfoTests: OTTestCase
@end

#ifdef OF_HAVE_SOCKETS
static void
printAddresses(OFData *addresses, bool *firstAddress)
appendAddresses(OFMutableString *string, OFData *addresses, bool *firstAddress)
{
	size_t count = addresses.count;

	for (size_t i = 0; i < count; i++) {
		const OFSocketAddress *address = [addresses itemAtIndex: i];

		if (!*firstAddress)
			[OFStdOut writeString: @", "];
			[string appendString: @", "];

		*firstAddress = false;

		[OFStdOut writeString: OFSocketAddressString(address)];
		[string appendString: OFSocketAddressString(address)];
	}
}
#endif

@implementation TestsAppDelegate (OFSystemInfoTests)
- (void)systemInfoTests
@implementation OFSystemInfoTests
+ (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, id) *) *)summary
{
	void *pool = objc_autoreleasePoolPush();
	OFMutableArray *summary = [OFMutableArray array];
#ifdef OF_HAVE_SOCKETS
	OFDictionary *networkInterfaces;
	OFMutableString *networkInterfacesString;
	bool firstInterface = true;
#endif

	[OFStdOut setForegroundColor: [OFColor lime]];

	[OFStdOut writeFormat: @"[OFSystemInfo] Page size: %zd\n",
	    [OFSystemInfo pageSize]];

	[OFStdOut writeFormat: @"[OFSystemInfo] Number of CPUs: %zd\n",
	    [OFSystemInfo numberOfCPUs]];

	[OFStdOut writeFormat: @"[OFSystemInfo] ObjFW version: %@\n",
	    [OFSystemInfo ObjFWVersion]];

	[OFStdOut writeFormat: @"[OFSystemInfo] ObjFW version major: %u\n",
	    [OFSystemInfo ObjFWVersionMajor]];

	[OFStdOut writeFormat: @"[OFSystemInfo] ObjFW version minor: %u\n",
	    [OFSystemInfo ObjFWVersionMinor]];

	[OFStdOut writeFormat: @"[OFSystemInfo] Operating system name: %@\n",
	    [OFSystemInfo operatingSystemName]];

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Operating system version: %@\n",
	    [OFSystemInfo operatingSystemVersion]];

	[OFStdOut writeFormat: @"[OFSystemInfo] User config IRI: %@\n",
	    [OFSystemInfo userConfigIRI].string];

	[OFStdOut writeFormat: @"[OFSystemInfo] User data IRI: %@\n",
	    [OFSystemInfo userDataIRI].string];

	[OFStdOut writeFormat: @"[OFSystemInfo] Temporary directory IRI: %@\n",
	    [OFSystemInfo temporaryDirectoryIRI].string];

#define ADD(name, value)						\
	[OFStdOut writeFormat: @"[OFSystemInfo] CPU vendor: %@\n",
	    [OFSystemInfo CPUVendor]];

	[summary addObject: [OFPair pairWithFirstObject: name		\
	[OFStdOut writeFormat: @"[OFSystemInfo] CPU model: %@\n",
	    [OFSystemInfo CPUModel]];

#if defined(OF_AMD64) || defined(OF_X86)
					   secondObject: value]];
#define ADD_UINT(name, value)						\
	[OFStdOut writeFormat: @"[OFSystemInfo] Supports MMX: %d\n",
	    [OFSystemInfo supportsMMX]];

	ADD(name, [OFNumber numberWithUnsignedInt: value]);
	[OFStdOut writeFormat: @"[OFSystemInfo] Supports 3DNow!: %d\n",
	    [OFSystemInfo supports3DNow]];

#define ADD_ULONGLONG(name, value)					\
	[OFStdOut writeFormat: @"[OFSystemInfo] Supports enhanced 3DNow!: %d\n",
	    [OFSystemInfo supportsEnhanced3DNow]];

	ADD(name, [OFNumber numberWithUnsignedLongLong: value]);
	[OFStdOut writeFormat: @"[OFSystemInfo] Supports SSE: %d\n",
	    [OFSystemInfo supportsSSE]];

#define ADD_BOOL(name, value)						\
	[OFStdOut writeFormat: @"[OFSystemInfo] Supports SSE2: %d\n",
	    [OFSystemInfo supportsSSE2]];
	ADD(name, [OFNumber numberWithBool: value]);

	[OFStdOut writeFormat: @"[OFSystemInfo] Supports SSE3: %d\n",
	    [OFSystemInfo supportsSSE3]];

	[OFStdOut writeFormat: @"[OFSystemInfo] Supports SSSE3: %d\n",
	    [OFSystemInfo supportsSSSE3]];

	ADD(@"ObjFW version", [OFSystemInfo ObjFWVersion])
	ADD_UINT(@"ObjFW version major", [OFSystemInfo ObjFWVersionMajor])
	ADD_UINT(@"ObjFW version minor", [OFSystemInfo ObjFWVersionMinor])
	ADD(@"Operating system name", [OFSystemInfo operatingSystemName]);
	ADD(@"Operating system version", [OFSystemInfo operatingSystemVersion]);
	[OFStdOut writeFormat: @"[OFSystemInfo] Supports SSE4.1: %d\n",
	    [OFSystemInfo supportsSSE41]];

	[OFStdOut writeFormat: @"[OFSystemInfo] Supports SSE4.2: %d\n",
	    [OFSystemInfo supportsSSE42]];

	ADD_ULONGLONG(@"Page size", [OFSystemInfo pageSize]);
	ADD_ULONGLONG(@"Number of CPUs", [OFSystemInfo numberOfCPUs]);
	ADD(@"User config IRI", [OFSystemInfo userConfigIRI].string);
	ADD(@"User data IRI", [OFSystemInfo userDataIRI].string);
	ADD(@"Temporary directory IRI",
	[OFStdOut writeFormat: @"[OFSystemInfo] Supports AVX: %d\n",
	    [OFSystemInfo supportsAVX]];

	    [OFSystemInfo temporaryDirectoryIRI].string);
	ADD(@"CPU vendor", [OFSystemInfo CPUVendor]);
	[OFStdOut writeFormat: @"[OFSystemInfo] Supports AVX2: %d\n",
	    [OFSystemInfo supportsAVX2]];
	ADD(@"CPU model", [OFSystemInfo CPUModel]);

	[OFStdOut writeFormat: @"[OFSystemInfo] Supports AES-NI: %d\n",
	    [OFSystemInfo supportsAESNI]];

	[OFStdOut writeFormat: @"[OFSystemInfo] Supports SHA extensions: %d\n",
	    [OFSystemInfo supportsSHAExtensions]];

	[OFStdOut writeFormat: @"[OFSystemInfo] Supports fused multiply-add: "
	    @"%d\n",
	    [OFSystemInfo supportsFusedMultiplyAdd]];

	[OFStdOut writeFormat: @"[OFSystemInfo] Supports F16C: %d\n",
	    [OFSystemInfo supportsF16C]];

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 Foundation: %d\n",
	    [OFSystemInfo supportsAVX512Foundation]];

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 Conflict Detection Instructions: "
	    @"%d\n",
	    [OFSystemInfo supportsAVX512ConflictDetectionInstructions]];

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 Exponential and Reciprocal "
	    @"Instructions: %d\n",
	    [OFSystemInfo supportsAVX512ExponentialAndReciprocalInstructions]];

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 Prefetch Instructions: %d\n",
	    [OFSystemInfo supportsAVX512PrefetchInstructions]];

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 Vector Length Extensions: %d\n",
	    [OFSystemInfo supportsAVX512VectorLengthExtensions]];

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 Doubleword and Quadword "
	    @"Instructions: %d\n",
	    [OFSystemInfo supportsAVX512DoublewordAndQuadwordInstructions]];

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 Byte and Word Instructions: %d\n",
	    [OFSystemInfo supportsAVX512ByteAndWordInstructions]];

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 Integer Fused Multiply Add: %d\n",
	    [OFSystemInfo supportsAVX512IntegerFusedMultiplyAdd]];
#if defined(OF_AMD64) || defined(OF_X86)
	ADD_BOOL(@"Supports MMX", [OFSystemInfo supportsMMX]);
	ADD_BOOL(@"Supports 3DNow!", [OFSystemInfo supports3DNow]);
	ADD_BOOL(@"Supports enhanced 3DNow!",
	    [OFSystemInfo supportsEnhanced3DNow]);
	ADD_BOOL(@"Supports SSE", [OFSystemInfo supportsSSE]);
	ADD_BOOL(@"Supports SSE2", [OFSystemInfo supportsSSE2]);
	ADD_BOOL(@"Supports SSE3", [OFSystemInfo supportsSSE3]);
	ADD_BOOL(@"Supports SSSE3", [OFSystemInfo supportsSSSE3]);
	ADD_BOOL(@"Supports SSE4.1", [OFSystemInfo supportsSSE41]);
	ADD_BOOL(@"Supports SSE4.2", [OFSystemInfo supportsSSE42]);
	ADD_BOOL(@"Supports AVX", [OFSystemInfo supportsAVX]);
	ADD_BOOL(@"Supports AVX2", [OFSystemInfo supportsAVX2]);
	ADD_BOOL(@"Supports AES-NI", [OFSystemInfo supportsAESNI]);
	ADD_BOOL(@"Supports SHA extensions",
	    [OFSystemInfo supportsSHAExtensions]);
	ADD_BOOL(@"Supports fused multiply-add",
	    [OFSystemInfo supportsFusedMultiplyAdd]);
	ADD_BOOL(@"Supports F16C", [OFSystemInfo supportsF16C]);
	ADD_BOOL(@"Supports AVX-512 Foundation",
	    [OFSystemInfo supportsAVX512Foundation]);
	ADD_BOOL(@"Supports AVX-512 Conflict Detection Instructions",
	    [OFSystemInfo supportsAVX512ConflictDetectionInstructions]);
	ADD_BOOL(@"Supports AVX-512 Exponential and Reciprocal Instructions",
	    [OFSystemInfo supportsAVX512ExponentialAndReciprocalInstructions]);
	ADD_BOOL(@"Supports AVX-512 Prefetch Instructions",
	    [OFSystemInfo supportsAVX512PrefetchInstructions]);
	ADD_BOOL(@"Supports AVX-512 Vector Length Extensions",
	    [OFSystemInfo supportsAVX512VectorLengthExtensions]);
	ADD_BOOL(@"Supports AVX-512 Doubleword and Quadword Instructions",
	    [OFSystemInfo supportsAVX512DoublewordAndQuadwordInstructions]);
	ADD_BOOL(@"Supports AVX-512 Byte and Word Instructions",
	    [OFSystemInfo supportsAVX512ByteAndWordInstructions]);
	ADD_BOOL(@"Supports AVX-512 Integer Fused Multiply Add",
	    [OFSystemInfo supportsAVX512IntegerFusedMultiplyAdd]);

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 Vector Byte Manipulation "
	ADD_BOOL(@"Supports AVX-512 Vector Byte Manipulation Instructions",
	    @"Instructions: %d\n",
	    [OFSystemInfo supportsAVX512VectorByteManipulationInstructions]];
	    [OFSystemInfo supportsAVX512VectorByteManipulationInstructions]);

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 Vector Population Count "
	ADD_BOOL(@"Supports AVX-512 Vector Population Count Instruction",
	    @"Instruction: %d\n",
	    [OFSystemInfo supportsAVX512VectorPopulationCountInstruction]];
	    [OFSystemInfo supportsAVX512VectorPopulationCountInstruction]);

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 Vector Neutral Network "
	ADD_BOOL(@"Supports AVX-512 Vector Neutral Network Instructions",
	    @"Instructions: %d\n",
	    [OFSystemInfo supportsAVX512VectorNeuralNetworkInstructions]];
	    [OFSystemInfo supportsAVX512VectorNeuralNetworkInstructions]);

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 Vector Byte Manipulation "
	ADD_BOOL(@"Supports AVX-512 Vector Byte Manipulation Instructions 2",
	    @"Instructions 2: %d\n",
	    [OFSystemInfo supportsAVX512VectorByteManipulationInstructions2]];
	    [OFSystemInfo supportsAVX512VectorByteManipulationInstructions2]);

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 Bit Algorithms: %d\n",
	    [OFSystemInfo supportsAVX512BitAlgorithms]];
	ADD_BOOL(@"Supports AVX-512 Bit Algorithms",
	    [OFSystemInfo supportsAVX512BitAlgorithms]);

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 Float16 Instructions: %d\n",
	    [OFSystemInfo supportsAVX512Float16Instructions]];
	ADD_BOOL(@"Supports AVX-512 Float16 Instructions",
	    [OFSystemInfo supportsAVX512Float16Instructions]);

	[OFStdOut writeFormat:
	    @"[OFSystemInfo] Supports AVX-512 BFloat16 Instructions: %d\n",
	    [OFSystemInfo supportsAVX512BFloat16Instructions]];
	ADD_BOOL(@"Supports AVX-512 BFloat16 Instructions",
	    [OFSystemInfo supportsAVX512BFloat16Instructions]);
#endif

#ifdef OF_POWERPC
	[OFStdOut writeFormat: @"[OFSystemInfo] Supports AltiVec: %d\n",
	    [OFSystemInfo supportsAltiVec]];
	ADD_BOOL(@"[OFSystemInfo] Supports AltiVec",
	    [OFSystemInfo supportsAltiVec]);
#endif

#undef ADD
#undef ADD_UINT
#undef ADD_ULONGLONG
#undef ADD_BOOL

#ifdef OF_HAVE_SOCKETS
	networkInterfaces = [OFSystemInfo networkInterfaces];
	[OFStdOut writeString: @"[OFSystemInfo] Network interfaces: "];
	networkInterfacesString = [OFMutableString string];
	for (OFString *name in networkInterfaces) {
		bool firstAddress = true;
		OFNetworkInterface interface;
		OFData *hardwareAddress;

		if (!firstInterface)
			[OFStdOut writeString: @"; "];
			[networkInterfacesString appendString: @"; "];

		firstInterface = false;

		[OFStdOut writeFormat: @"%@(", name];
		[networkInterfacesString appendFormat: @"%@(", name];

		interface = [networkInterfaces objectForKey: name];

		appendAddresses(networkInterfacesString,
		printAddresses([interface objectForKey:
		    OFNetworkInterfaceIPv4Addresses], &firstAddress);
		    [interface objectForKey: OFNetworkInterfaceIPv4Addresses],
		    &firstAddress);
# ifdef OF_HAVE_IPV6
		appendAddresses(networkInterfacesString,
		printAddresses([interface objectForKey:
		    OFNetworkInterfaceIPv6Addresses], &firstAddress);
		    [interface objectForKey: OFNetworkInterfaceIPv6Addresses],
		    &firstAddress);
# endif
# ifdef OF_HAVE_IPX
		appendAddresses(networkInterfacesString,
		printAddresses([interface objectForKey:
		    OFNetworkInterfaceIPXAddresses], &firstAddress);
		    [interface objectForKey: OFNetworkInterfaceIPXAddresses],
		    &firstAddress);
# endif
# ifdef OF_HAVE_APPLETALK
		appendAddresses(networkInterfacesString,
		printAddresses([interface objectForKey:
		    [interface objectForKey:
		    OFNetworkInterfaceAppleTalkAddresses], &firstAddress);
# endif

		hardwareAddress = [interface
		    objectForKey: OFNetworkInterfaceHardwareAddress];
		if (hardwareAddress != nil) {
			const unsigned char *bytes = hardwareAddress.items;
			size_t length = hardwareAddress.count;

			if (!firstAddress)
				[OFStdOut writeString: @", "];
				[networkInterfacesString appendString: @", "];

			for (size_t i = 0; i < length; i++) {
				if (i > 0)
					[networkInterfacesString
					[OFStdOut writeString: @":"];
					    appendString: @":"];

				[networkInterfacesString
				[OFStdOut writeFormat: @"%02X", bytes[i]];
				    appendFormat: @"%02X", bytes[i]];
			}
		}

		[OFStdOut writeString: @")"];
		[networkInterfacesString appendString: @")"];
	}
	[summary addObject:
	    [OFPair pairWithFirstObject: @"Network interfaces"
	[OFStdOut writeString: @"\n"];
			   secondObject: networkInterfacesString]];
#endif

	objc_autoreleasePoolPop(pool);
	return summary;
}
@end