1 #pragma once
2 #ifndef CPUINFO_MOCK_H
3 #define CPUINFO_MOCK_H
4 
5 #include <stddef.h>
6 #include <stdint.h>
7 
8 #include <cpuinfo.h>
9 #if defined(__linux__)
10 	#include <sys/types.h>
11 #endif
12 
13 #if !defined(CPUINFO_MOCK) || !(CPUINFO_MOCK)
14 	#error This header is intended only for test use
15 #endif
16 
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 
23 #if CPUINFO_ARCH_ARM
24 	void CPUINFO_ABI cpuinfo_set_fpsid(uint32_t fpsid);
25 	void CPUINFO_ABI cpuinfo_set_wcid(uint32_t wcid);
26 #endif /* CPUINFO_ARCH_ARM */
27 
28 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
29 	struct cpuinfo_mock_cpuid {
30 		uint32_t input_eax;
31 		uint32_t input_ecx;
32 		uint32_t eax;
33 		uint32_t ebx;
34 		uint32_t ecx;
35 		uint32_t edx;
36 	};
37 
38 	void CPUINFO_ABI cpuinfo_mock_set_cpuid(struct cpuinfo_mock_cpuid* dump, size_t entries);
39 	void CPUINFO_ABI cpuinfo_mock_get_cpuid(uint32_t eax, uint32_t regs[4]);
40 	void CPUINFO_ABI cpuinfo_mock_get_cpuidex(uint32_t eax, uint32_t ecx, uint32_t regs[4]);
41 #endif /* CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64 */
42 
43 struct cpuinfo_mock_file {
44 	const char* path;
45 	size_t size;
46 	const char* content;
47 	size_t offset;
48 };
49 
50 struct cpuinfo_mock_property {
51 	const char* key;
52 	const char* value;
53 };
54 
55 #if defined(__linux__)
56 	void CPUINFO_ABI cpuinfo_mock_filesystem(struct cpuinfo_mock_file* files);
57 	int CPUINFO_ABI cpuinfo_mock_open(const char* path, int oflag);
58 	int CPUINFO_ABI cpuinfo_mock_close(int fd);
59 	ssize_t CPUINFO_ABI cpuinfo_mock_read(int fd, void* buffer, size_t capacity);
60 
61 	#if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
62 		void CPUINFO_ABI cpuinfo_set_hwcap(uint32_t hwcap);
63 	#endif
64 	#if CPUINFO_ARCH_ARM
65 		void CPUINFO_ABI cpuinfo_set_hwcap2(uint32_t hwcap2);
66 	#endif
67 #endif
68 
69 #if defined(__ANDROID__)
70 	void CPUINFO_ABI cpuinfo_mock_android_properties(struct cpuinfo_mock_property* properties);
71 	void CPUINFO_ABI cpuinfo_mock_gl_renderer(const char* renderer);
72 #endif
73 
74 #ifdef __cplusplus
75 } /* extern "C" */
76 #endif
77 
78 #endif /* CPUINFO_MOCK_H */
79