1 // Copyright (C) 2014 The Android Open Source Project 2 // 3 // This software is licensed under the terms of the GNU General Public 4 // License version 2, as published by the Free Software Foundation, and 5 // may be copied, distributed, and modified under those terms. 6 // 7 // This program is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 // GNU General Public License for more details. 11 12 #include "android/emulation/CpuAccelerator.h" 13 14 #include <stdio.h> 15 16 #include <gtest/gtest.h> 17 18 namespace android { 19 20 class CpuAcceleratorTest : public ::testing::Test { 21 public: 22 CpuAcceleratorTest() { 23 saved_accel_ = GetCurrentCpuAccelerator(); 24 saved_status_ = GetCurrentCpuAcceleratorStatus(); 25 } 26 27 ~CpuAcceleratorTest() { 28 // Restore previous state. 29 SetCurrentCpuAcceleratorForTesting(saved_accel_, 30 saved_status_.c_str()); 31 } 32 private: 33 CpuAccelerator saved_accel_; 34 String saved_status_; 35 }; 36 37 // Not really a test, but a simple way to print the current accelerator 38 // value for simple verification. 39 TEST_F(CpuAcceleratorTest, Default) { 40 CpuAccelerator accel = GetCurrentCpuAccelerator(); 41 String status = GetCurrentCpuAcceleratorStatus(); 42 43 switch (accel) { 44 case CPU_ACCELERATOR_NONE: 45 printf("No acceleration possible on this machine!\n"); 46 break; 47 48 case CPU_ACCELERATOR_KVM: 49 printf("KVM acceleration usable on this machine!\n"); 50 break; 51 52 case CPU_ACCELERATOR_HAX: 53 printf("HAX acceleration usable on this machine!\n"); 54 break; 55 56 default: 57 ASSERT_FALSE(1) << "Invalid accelerator value: " << accel; 58 } 59 printf("Status: %s\n", status.c_str()); 60 } 61 62 } // namespace android 63