cpuid_unittest.cc revision 28e20752806a492f5a6a5d343c02f9556f39b1cd
128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org/* 228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * libjingle 328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * Copyright 2011 Google Inc. 428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * Redistribution and use in source and binary forms, with or without 628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * modification, are permitted provided that the following conditions are met: 728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 1. Redistributions of source code must retain the above copyright notice, 928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * this list of conditions and the following disclaimer. 1028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 2. Redistributions in binary form must reproduce the above copyright notice, 1128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * this list of conditions and the following disclaimer in the documentation 1228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * and/or other materials provided with the distribution. 1328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 3. The name of the author may not be used to endorse or promote products 1428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * derived from this software without specific prior written permission. 1528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 1628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 1728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 1928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 2228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 2428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 2528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org */ 2728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 2828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/media/base/cpuid.h" 2928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 3028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include <iostream> 3128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 3228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/base/basictypes.h" 3328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/base/gunit.h" 3428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#include "talk/base/systeminfo.h" 3528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 3628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST(CpuInfoTest, CpuId) { 3728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org LOG(LS_INFO) << "ARM: " 3828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org << cricket::CpuInfo::TestCpuFlag(cricket::CpuInfo::kCpuHasARM); 3928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org LOG(LS_INFO) << "NEON: " 4028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org << cricket::CpuInfo::TestCpuFlag(cricket::CpuInfo::kCpuHasNEON); 4128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org LOG(LS_INFO) << "X86: " 4228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org << cricket::CpuInfo::TestCpuFlag(cricket::CpuInfo::kCpuHasX86); 4328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org LOG(LS_INFO) << "SSE2: " 4428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org << cricket::CpuInfo::TestCpuFlag(cricket::CpuInfo::kCpuHasSSE2); 4528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org LOG(LS_INFO) << "SSSE3: " 4628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org << cricket::CpuInfo::TestCpuFlag(cricket::CpuInfo::kCpuHasSSSE3); 4728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org LOG(LS_INFO) << "SSE41: " 4828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org << cricket::CpuInfo::TestCpuFlag(cricket::CpuInfo::kCpuHasSSE41); 4928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org LOG(LS_INFO) << "SSE42: " 5028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org << cricket::CpuInfo::TestCpuFlag(cricket::CpuInfo::kCpuHasSSE42); 5128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org LOG(LS_INFO) << "AVX: " 5228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org << cricket::CpuInfo::TestCpuFlag(cricket::CpuInfo::kCpuHasAVX); 5328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org bool has_arm = cricket::CpuInfo::TestCpuFlag(cricket::CpuInfo::kCpuHasARM); 5428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org bool has_x86 = cricket::CpuInfo::TestCpuFlag(cricket::CpuInfo::kCpuHasX86); 5528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org EXPECT_FALSE(has_arm && has_x86); 5628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 5728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 5828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgTEST(CpuInfoTest, IsCoreIOrBetter) { 5928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org bool core_i_or_better = cricket::IsCoreIOrBetter(); 6028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Tests the function is callable. Run on known hardware to confirm. 6128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org LOG(LS_INFO) << "IsCoreIOrBetter: " << core_i_or_better; 6228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 6328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // All Core I CPUs have SSE 4.1. 6428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org if (core_i_or_better) { 6528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org EXPECT_TRUE(cricket::CpuInfo::TestCpuFlag(cricket::CpuInfo::kCpuHasSSE41)); 6628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org EXPECT_TRUE(cricket::CpuInfo::TestCpuFlag(cricket::CpuInfo::kCpuHasSSSE3)); 6728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org } 6828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 6928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // All CPUs that lack SSE 4.1 are not Core I CPUs. 7028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org if (!cricket::CpuInfo::TestCpuFlag(cricket::CpuInfo::kCpuHasSSE41)) { 7128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org EXPECT_FALSE(core_i_or_better); 7228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org } 7328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 7428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 75