2014-03-12 15:36:17 +04:00
# Copyright (C) 2013, 2014 Red Hat, Inc.
2013-03-18 01:06:52 +04:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
2013-10-28 00:59:47 +04:00
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
2013-03-18 01:06:52 +04:00
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
2013-08-09 04:47:17 +04:00
import os
2013-03-18 01:06:52 +04:00
import unittest
2013-08-09 04:47:17 +04:00
2014-03-13 15:52:51 +04:00
from tests import utils
2013-03-18 01:06:52 +04:00
2015-04-03 19:40:16 +03:00
from virtinst import Capabilities
from virtinst import DomainCapabilities
from virtinst . capabilities import _CPUMapFileValues
2013-04-13 22:34:52 +04:00
2013-03-18 01:06:52 +04:00
2015-04-03 19:40:16 +03:00
conn = utils . open_testdriver ( )
2013-03-18 01:06:52 +04:00
2013-04-13 22:34:52 +04:00
2013-03-18 01:06:52 +04:00
class TestCapabilities ( unittest . TestCase ) :
2015-04-03 19:40:16 +03:00
def _buildCaps ( self , filename ) :
path = os . path . join ( " tests/capabilities-xml " , filename )
return Capabilities ( conn , file ( path ) . read ( ) )
2013-03-18 01:06:52 +04:00
def testCapsCPUFeaturesOldSyntax ( self ) :
2015-04-23 00:06:35 +03:00
filename = " test-old-vmx.xml "
2013-03-18 01:06:52 +04:00
host_feature_list = [ " vmx " ]
caps = self . _buildCaps ( filename )
2015-04-03 19:40:16 +03:00
for f in host_feature_list :
self . assertEquals ( caps . host . cpu . has_feature ( f ) , True )
2013-03-18 01:06:52 +04:00
def testCapsCPUFeaturesOldSyntaxSVM ( self ) :
2015-04-23 00:06:35 +03:00
filename = " test-old-svm.xml "
2013-03-18 01:06:52 +04:00
host_feature_list = [ " svm " ]
caps = self . _buildCaps ( filename )
2015-04-03 19:40:16 +03:00
for f in host_feature_list :
self . assertEquals ( caps . host . cpu . has_feature ( f ) , True )
2013-03-18 01:06:52 +04:00
def testCapsCPUFeaturesNewSyntax ( self ) :
2015-04-23 00:06:35 +03:00
filename = " test-qemu-with-kvm.xml "
2013-03-18 01:06:52 +04:00
host_feature_list = [ ' lahf_lm ' , ' xtpr ' , ' cx16 ' , ' tm2 ' , ' est ' , ' vmx ' ,
2015-04-03 19:40:16 +03:00
' ds_cpl ' , ' pbe ' , ' tm ' , ' ht ' , ' ss ' , ' acpi ' , ' ds ' ]
2013-03-18 01:06:52 +04:00
caps = self . _buildCaps ( filename )
2015-04-03 19:40:16 +03:00
for f in host_feature_list :
self . assertEquals ( caps . host . cpu . has_feature ( f ) , True )
2013-03-18 01:06:52 +04:00
self . assertEquals ( caps . host . cpu . model , " core2duo " )
self . assertEquals ( caps . host . cpu . vendor , " Intel " )
2015-04-03 19:40:16 +03:00
self . assertEquals ( caps . host . cpu . threads , 3 )
self . assertEquals ( caps . host . cpu . cores , 5 )
self . assertEquals ( caps . host . cpu . sockets , 7 )
2013-03-18 01:06:52 +04:00
def testCapsUtilFuncs ( self ) :
2015-04-23 00:06:35 +03:00
caps_with_kvm = self . _buildCaps ( " test-qemu-with-kvm.xml " )
caps_no_kvm = self . _buildCaps ( " test-qemu-no-kvm.xml " )
caps_empty = self . _buildCaps ( " test-old-vmx.xml " )
2013-03-18 01:06:52 +04:00
2015-04-03 23:42:07 +03:00
def test_utils ( caps , has_guests , is_kvm ) :
2015-07-10 13:06:48 +03:00
if caps . guests :
self . assertEquals ( caps . guests [ 0 ] . has_install_options ( ) , has_guests )
self . assertEquals ( caps . guests [ 0 ] . is_kvm_available ( ) , is_kvm )
2015-04-03 23:39:47 +03:00
2015-04-23 00:06:35 +03:00
test_utils ( caps_empty , False , False )
test_utils ( caps_with_kvm , True , True )
test_utils ( caps_no_kvm , True , False )
################################################
# Test cpu_map.xml/getCPUModel output handling #
################################################
2013-03-18 01:06:52 +04:00
2015-04-03 23:09:25 +03:00
def _testCPUMap ( self , api ) :
2015-04-23 00:06:35 +03:00
caps = self . _buildCaps ( " test-qemu-with-kvm.xml " )
2015-04-03 23:09:25 +03:00
setattr ( _CPUMapFileValues , " _cpu_filename " ,
" tests/capabilities-xml/cpu_map.xml " )
setattr ( caps , " _force_cpumap " , not api )
cpu_64 = caps . get_cpu_values ( " x86_64 " )
cpu_32 = caps . get_cpu_values ( " i486 " )
cpu_random = caps . get_cpu_values ( " mips " )
2013-03-18 01:06:52 +04:00
2014-03-12 23:59:33 +04:00
def test_cpu_map ( cpumap , cpus ) :
2015-04-03 23:09:25 +03:00
cpunames = sorted ( cpumap , key = str . lower )
2013-03-18 01:06:52 +04:00
for c in cpus :
self . assertTrue ( c in cpunames )
self . assertEquals ( cpu_64 , cpu_32 )
x86_cpunames = [
' 486 ' , ' athlon ' , ' Conroe ' , ' core2duo ' , ' coreduo ' , ' n270 ' ,
' Nehalem ' , ' Opteron_G1 ' , ' Opteron_G2 ' , ' Opteron_G3 ' , ' Penryn ' ,
' pentium ' , ' pentium2 ' , ' pentium3 ' , ' pentiumpro ' , ' phenom ' ,
' qemu32 ' , ' qemu64 ' ]
2014-03-12 23:59:33 +04:00
test_cpu_map ( cpu_64 , x86_cpunames )
test_cpu_map ( cpu_random , [ ] )
2013-03-18 01:06:52 +04:00
2015-04-03 23:09:25 +03:00
cpu_64 = caps . get_cpu_values ( " x86_64 " )
2014-03-13 15:52:51 +04:00
self . assertTrue ( len ( cpu_64 ) > 0 )
2015-04-03 23:09:25 +03:00
def testCPUMapFile ( self ) :
self . _testCPUMap ( api = True )
def testCPUMapAPI ( self ) :
self . _testCPUMap ( api = False )
2015-04-23 00:06:35 +03:00
##############################
# domcapabilities.py testing #
##############################
2014-09-17 22:56:52 +04:00
def testDomainCapabilities ( self ) :
2015-04-23 00:06:35 +03:00
xml = file ( " tests/capabilities-xml/test-domcaps.xml " ) . read ( )
2014-09-17 22:56:52 +04:00
caps = DomainCapabilities ( utils . open_testdriver ( ) , xml )
self . assertEqual ( caps . os . loader . supported , True )
self . assertEquals ( caps . os . loader . get_values ( ) ,
[ " /foo/bar " , " /tmp/my_path " ] )
self . assertEquals ( caps . os . loader . enum_names ( ) , [ " type " , " readonly " ] )
self . assertEquals ( caps . os . loader . get_enum ( " type " ) . get_values ( ) ,
[ " rom " , " pflash " ] )
2014-03-13 15:52:51 +04:00
2013-03-18 01:06:52 +04:00
if __name__ == " __main__ " :
unittest . main ( )