1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #include "cpu-features.h" 5 6 #ifndef __arm__ 7 #error "This source file should only be compiled on ARM!" 8 #endif 9 10 static void panic(const char* msg) { 11 fprintf(stderr, "ERROR: %s\n", msg); 12 exit(1); 13 } 14 15 int main(void) { 16 int count, cpu_count = 10; 17 uint64_t features, cpu_features = 0xaabdedf012934839ULL; 18 uint32_t id, cpu_id = 0x436723ee; 19 20 // Check that android_setCpuArm() can be called at program startup 21 // and that android_getCpuCount() and android_getCpuFeatures() 22 // will return the corresponding values. 23 // 24 printf("Setting cpu_count=%d, features=%08llx cpu_id=%08x\n", 25 cpu_count, cpu_features, cpu_id); 26 27 if (!android_setCpuArm(cpu_count, cpu_features, cpu_id)) 28 panic("Cannot call android_setCpu() at program startup!"); 29 30 count = android_getCpuCount(); 31 features = android_getCpuFeatures(); 32 id = android_getCpuIdArm(); 33 34 printf("Retrieved cpu_count=%d, features=%08llx cpu_id=%08x\n", 35 count, features, id); 36 37 if (count != cpu_count) 38 panic("android_getCpuCount() didn't return expected value!"); 39 40 if (features != cpu_features) 41 panic("android_getCpuFeatures() didn't return expected value!"); 42 43 if (id != cpu_id) 44 panic("android_getCpuIdArm() didn't return expected value!"); 45 46 // Once one of the android_getXXX functions has been called, 47 // android_setCpu() should always fail. 48 if (android_setCpuArm(cpu_count, cpu_features, cpu_id)) 49 panic("android_setCpuArm() could be called twice!"); 50 51 printf("Second call to android_setCpu() failed as expected.\n"); 52 53 if (android_setCpu(cpu_count, cpu_features)) 54 panic("android_setCpu() could be called after android_setCpuArm()!"); 55 56 printf("Call to android_setCpu() failed as expected.\n"); 57 58 return 0; 59 } 60 61