1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #include "cpu-features.h" 5 6 static void panic(const char* msg) { 7 fprintf(stderr, "ERROR: %s\n", msg); 8 exit(1); 9 } 10 11 int main(void) { 12 int count, cpu_count = 10; 13 uint64_t features, cpu_features = 0xaabdedf012934839ULL; 14 15 // Check that android_setCpu() can be called at program startup 16 // and that android_getCpuCount() and android_getCpuFeatures() 17 // will return the corresponding values. 18 // 19 printf("Setting cpu_count=%d, features=%08llx\n", 20 cpu_count, 21 cpu_features); 22 if (!android_setCpu(cpu_count, cpu_features)) 23 panic("Cannot call android_setCpu() at program startup!"); 24 25 count = android_getCpuCount(); 26 features = android_getCpuFeatures(); 27 28 printf("Retrieved cpu_count=%d, features=%08llx\n", 29 count, features); 30 31 if (count != cpu_count) 32 panic("android_getCpuCount() didn't return expected value!"); 33 34 if (features != cpu_features) 35 panic("android_getCpuFeatures() didn't return expected value!"); 36 37 // Once one of the android_getXXX functions has been called, 38 // android_setCpu() should always fail. 39 if (android_setCpu(cpu_count, cpu_features)) 40 panic("android_setCpu() could be called twice!"); 41 42 printf("Second call to android_setCpu() failed as expected.\n"); 43 return 0; 44 } 45 46