xref: /xnu-11417.101.15/tests/apple_generic_timer.c (revision e3723e1f17661b24996789d8afc084c0c3303b26)
1*e3723e1fSApple OSS Distributions #include <darwintest.h>
2*e3723e1fSApple OSS Distributions #include <sys/sysctl.h>
3*e3723e1fSApple OSS Distributions #include "apple_generic_timer.h"
4*e3723e1fSApple OSS Distributions #include "test_utils.h"
5*e3723e1fSApple OSS Distributions 
6*e3723e1fSApple OSS Distributions T_GLOBAL_META(
7*e3723e1fSApple OSS Distributions 	T_META_NAMESPACE("xnu.arm"),
8*e3723e1fSApple OSS Distributions 	T_META_RADAR_COMPONENT_NAME("xnu"),
9*e3723e1fSApple OSS Distributions 	T_META_RADAR_COMPONENT_VERSION("arm"),
10*e3723e1fSApple OSS Distributions 	T_META_ENABLED(TARGET_CPU_ARM64),
11*e3723e1fSApple OSS Distributions 	T_META_OWNER("xi_han"),
12*e3723e1fSApple OSS Distributions 	T_META_RUN_CONCURRENTLY(true),
13*e3723e1fSApple OSS Distributions 	XNU_T_META_SOC_SPECIFIC
14*e3723e1fSApple OSS Distributions 	);
15*e3723e1fSApple OSS Distributions 
16*e3723e1fSApple OSS Distributions #define AIDR_AGT (1ULL << 32)
17*e3723e1fSApple OSS Distributions T_DECL(apple_generic_timer,
18*e3723e1fSApple OSS Distributions     "Test that CNTFRQ_EL0 reads the correct frequency")
19*e3723e1fSApple OSS Distributions {
20*e3723e1fSApple OSS Distributions 	uint64_t aidr;
21*e3723e1fSApple OSS Distributions 	size_t sysctl_size = sizeof(aidr);
22*e3723e1fSApple OSS Distributions 	sysctlbyname("machdep.cpu.sysreg_AIDR_EL1", &aidr, &sysctl_size, NULL, 0);
23*e3723e1fSApple OSS Distributions 
24*e3723e1fSApple OSS Distributions 	const bool has_agt = aidr & AIDR_AGT;
25*e3723e1fSApple OSS Distributions 
26*e3723e1fSApple OSS Distributions 	/* When AIDR_AGT is set, expect 1 GHz; otherwise expect 24 MHz. */
27*e3723e1fSApple OSS Distributions 	agt_test_helper(has_agt);
28*e3723e1fSApple OSS Distributions }
29