2013-03-28 18:36:52 +04:00
/*
2015-04-15 21:50:23 +03:00
* Copyright ( C ) 2013 - 2015 Red Hat , Inc .
2013-03-28 18:36:52 +04:00
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library 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
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library . If not , see
* < http : //www.gnu.org/licenses/>.
*/
# include <config.h>
# include "testutils.h"
# ifdef __linux__
2018-12-13 17:53:50 +03:00
# define LIBVIRT_VIRCGROUPPRIV_H_ALLOW
2013-03-28 18:36:52 +04:00
# include "vircgrouppriv.h"
2013-04-03 14:36:23 +04:00
# include "virstring.h"
2013-03-28 18:36:52 +04:00
# include "virerror.h"
# include "virlog.h"
# include "virfile.h"
2015-03-17 00:36:52 +03:00
# include "virbuffer.h"
2014-02-14 21:49:05 +04:00
# include "testutilslxc.h"
2016-04-13 20:53:02 +03:00
# include "virhostcpu.h"
2013-03-28 18:36:52 +04:00
# define VIR_FROM_THIS VIR_FROM_NONE
2014-02-28 16:16:17 +04:00
VIR_LOG_INIT ( " tests.cgrouptest " ) ;
2013-03-28 18:36:52 +04:00
static int validateCgroup ( virCgroupPtr cgroup ,
const char * * expectMountPoint ,
2013-04-05 14:28:04 +04:00
const char * * expectLinkPoint ,
2018-09-18 10:41:44 +03:00
const char * * expectPlacement ,
const char * expectUnifiedMountPoint ,
const char * expectUnifiedPlacement ,
unsigned int expectUnifiedControllers )
2013-03-28 18:36:52 +04:00
{
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 18:09:33 +04:00
size_t i ;
2013-03-28 18:36:52 +04:00
2013-05-21 11:53:48 +04:00
for ( i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i + + ) {
2013-03-28 18:36:52 +04:00
if ( STRNEQ_NULLABLE ( expectMountPoint [ i ] ,
2018-09-25 02:17:02 +03:00
cgroup - > legacy [ i ] . mountPoint ) ) {
2013-03-28 18:36:52 +04:00
fprintf ( stderr , " Wrong mount '%s', expected '%s' for '%s' \n " ,
2018-09-25 02:17:02 +03:00
cgroup - > legacy [ i ] . mountPoint ,
2013-03-28 18:36:52 +04:00
expectMountPoint [ i ] ,
virCgroupControllerTypeToString ( i ) ) ;
return - 1 ;
}
2013-04-05 14:28:04 +04:00
if ( STRNEQ_NULLABLE ( expectLinkPoint [ i ] ,
2018-09-25 02:17:02 +03:00
cgroup - > legacy [ i ] . linkPoint ) ) {
2013-04-05 14:28:04 +04:00
fprintf ( stderr , " Wrong link '%s', expected '%s' for '%s' \n " ,
2018-09-25 02:17:02 +03:00
cgroup - > legacy [ i ] . linkPoint ,
2013-04-05 14:28:04 +04:00
expectLinkPoint [ i ] ,
virCgroupControllerTypeToString ( i ) ) ;
return - 1 ;
}
2013-03-28 18:36:52 +04:00
if ( STRNEQ_NULLABLE ( expectPlacement [ i ] ,
2018-09-25 02:17:02 +03:00
cgroup - > legacy [ i ] . placement ) ) {
2013-03-28 18:36:52 +04:00
fprintf ( stderr , " Wrong placement '%s', expected '%s' for '%s' \n " ,
2018-09-25 02:17:02 +03:00
cgroup - > legacy [ i ] . placement ,
2013-03-28 18:36:52 +04:00
expectPlacement [ i ] ,
virCgroupControllerTypeToString ( i ) ) ;
return - 1 ;
}
}
2018-09-18 10:41:44 +03:00
if ( STRNEQ_NULLABLE ( expectUnifiedMountPoint ,
cgroup - > unified . mountPoint ) ) {
fprintf ( stderr , " Wrong mount '%s', expected '%s' for 'unified' \n " ,
cgroup - > unified . mountPoint ,
expectUnifiedMountPoint ) ;
return - 1 ;
}
if ( STRNEQ_NULLABLE ( expectUnifiedPlacement ,
cgroup - > unified . placement ) ) {
fprintf ( stderr , " Wrong placement '%s', expected '%s' for 'unified' \n " ,
cgroup - > unified . placement ,
expectUnifiedPlacement ) ;
return - 1 ;
}
if ( expectUnifiedControllers ! = cgroup - > unified . controllers ) {
for ( i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i + + ) {
int type = 1 < < i ;
if ( ( expectUnifiedControllers & type ) ! = ( cgroup - > unified . controllers & type ) ) {
const char * typeStr = virCgroupControllerTypeToString ( i ) ;
if ( expectUnifiedControllers & type ) {
fprintf ( stderr , " expected controller '%s' for 'unified', "
" but it's missing \n " , typeStr ) ;
} else {
fprintf ( stderr , " existing controller '%s' for 'unified', "
" but it's not expected \n " , typeStr ) ;
}
}
}
return - 1 ;
}
2013-03-28 18:36:52 +04:00
return 0 ;
}
const char * mountsSmall [ VIR_CGROUP_CONTROLLER_LAST ] = {
[ VIR_CGROUP_CONTROLLER_CPU ] = " /not/really/sys/fs/cgroup/cpu,cpuacct " ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = " /not/really/sys/fs/cgroup/cpu,cpuacct " ,
[ VIR_CGROUP_CONTROLLER_CPUSET ] = NULL ,
[ VIR_CGROUP_CONTROLLER_MEMORY ] = " /not/really/sys/fs/cgroup/memory " ,
[ VIR_CGROUP_CONTROLLER_DEVICES ] = NULL ,
[ VIR_CGROUP_CONTROLLER_FREEZER ] = NULL ,
[ VIR_CGROUP_CONTROLLER_BLKIO ] = NULL ,
2013-07-25 22:13:44 +04:00
[ VIR_CGROUP_CONTROLLER_SYSTEMD ] = NULL ,
2013-03-28 18:36:52 +04:00
} ;
const char * mountsFull [ VIR_CGROUP_CONTROLLER_LAST ] = {
[ VIR_CGROUP_CONTROLLER_CPU ] = " /not/really/sys/fs/cgroup/cpu,cpuacct " ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = " /not/really/sys/fs/cgroup/cpu,cpuacct " ,
[ VIR_CGROUP_CONTROLLER_CPUSET ] = " /not/really/sys/fs/cgroup/cpuset " ,
[ VIR_CGROUP_CONTROLLER_MEMORY ] = " /not/really/sys/fs/cgroup/memory " ,
[ VIR_CGROUP_CONTROLLER_DEVICES ] = NULL ,
[ VIR_CGROUP_CONTROLLER_FREEZER ] = " /not/really/sys/fs/cgroup/freezer " ,
[ VIR_CGROUP_CONTROLLER_BLKIO ] = " /not/really/sys/fs/cgroup/blkio " ,
2013-07-25 22:13:44 +04:00
[ VIR_CGROUP_CONTROLLER_SYSTEMD ] = " /not/really/sys/fs/cgroup/systemd " ,
2013-03-28 18:36:52 +04:00
} ;
2013-09-10 17:31:53 +04:00
const char * mountsAllInOne [ VIR_CGROUP_CONTROLLER_LAST ] = {
[ VIR_CGROUP_CONTROLLER_CPU ] = " /not/really/sys/fs/cgroup " ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = " /not/really/sys/fs/cgroup " ,
[ VIR_CGROUP_CONTROLLER_CPUSET ] = " /not/really/sys/fs/cgroup " ,
[ VIR_CGROUP_CONTROLLER_MEMORY ] = " /not/really/sys/fs/cgroup " ,
[ VIR_CGROUP_CONTROLLER_DEVICES ] = " /not/really/sys/fs/cgroup " ,
[ VIR_CGROUP_CONTROLLER_FREEZER ] = NULL ,
[ VIR_CGROUP_CONTROLLER_BLKIO ] = " /not/really/sys/fs/cgroup " ,
[ VIR_CGROUP_CONTROLLER_SYSTEMD ] = NULL ,
} ;
2013-03-28 18:36:52 +04:00
2013-04-05 14:28:04 +04:00
const char * links [ VIR_CGROUP_CONTROLLER_LAST ] = {
[ VIR_CGROUP_CONTROLLER_CPU ] = " /not/really/sys/fs/cgroup/cpu " ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = " /not/really/sys/fs/cgroup/cpuacct " ,
[ VIR_CGROUP_CONTROLLER_CPUSET ] = NULL ,
[ VIR_CGROUP_CONTROLLER_MEMORY ] = NULL ,
[ VIR_CGROUP_CONTROLLER_DEVICES ] = NULL ,
[ VIR_CGROUP_CONTROLLER_FREEZER ] = NULL ,
[ VIR_CGROUP_CONTROLLER_BLKIO ] = NULL ,
2013-09-10 17:31:53 +04:00
[ VIR_CGROUP_CONTROLLER_SYSTEMD ] = NULL ,
} ;
const char * linksAllInOne [ VIR_CGROUP_CONTROLLER_LAST ] = {
[ VIR_CGROUP_CONTROLLER_CPU ] = NULL ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = NULL ,
[ VIR_CGROUP_CONTROLLER_CPUSET ] = NULL ,
[ VIR_CGROUP_CONTROLLER_MEMORY ] = NULL ,
[ VIR_CGROUP_CONTROLLER_DEVICES ] = NULL ,
[ VIR_CGROUP_CONTROLLER_FREEZER ] = NULL ,
[ VIR_CGROUP_CONTROLLER_BLKIO ] = NULL ,
[ VIR_CGROUP_CONTROLLER_SYSTEMD ] = NULL ,
2013-04-05 14:28:04 +04:00
} ;
2018-09-14 14:17:07 +03:00
struct _detectMountsData {
const char * file ;
bool fail ;
} ;
2015-03-17 00:36:52 +03:00
static int
testCgroupDetectMounts ( const void * args )
{
int result = - 1 ;
2018-09-14 14:17:07 +03:00
const struct _detectMountsData * data = args ;
2015-03-17 00:36:52 +03:00
char * parsed = NULL ;
const char * actual ;
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) group = NULL ;
2020-07-03 02:35:41 +03:00
g_auto ( virBuffer ) buf = VIR_BUFFER_INITIALIZER ;
2015-03-17 00:36:52 +03:00
size_t i ;
2019-12-18 20:16:19 +03:00
g_setenv ( " VIR_CGROUP_MOCK_FILENAME " , data - > file , TRUE ) ;
2018-09-14 13:38:54 +03:00
2019-10-22 16:26:14 +03:00
parsed = g_strdup_printf ( " %s/vircgroupdata/%s.parsed " , abs_srcdir , data - > file ) ;
2018-09-14 13:38:54 +03:00
2018-09-14 14:17:07 +03:00
if ( virCgroupNewSelf ( & group ) < 0 ) {
if ( data - > fail )
result = 0 ;
2015-03-17 00:36:52 +03:00
goto cleanup ;
2018-09-14 14:17:07 +03:00
}
2015-03-17 00:36:52 +03:00
2018-09-14 14:17:07 +03:00
if ( data - > fail )
2015-03-17 00:36:52 +03:00
goto cleanup ;
for ( i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i + + ) {
virBufferAsprintf ( & buf , " %-12s %s \n " ,
virCgroupControllerTypeToString ( i ) ,
2018-09-25 02:17:02 +03:00
NULLSTR ( group - > legacy [ i ] . mountPoint ) ) ;
2015-03-17 00:36:52 +03:00
}
2018-09-24 13:28:04 +03:00
virBufferAsprintf ( & buf , " %-12s %s \n " ,
" unified " , NULLSTR ( group - > unified . mountPoint ) ) ;
2015-03-17 00:36:52 +03:00
actual = virBufferCurrentContent ( & buf ) ;
2016-05-26 18:01:53 +03:00
if ( virTestCompareToFile ( actual , parsed ) < 0 )
2015-03-17 00:36:52 +03:00
goto cleanup ;
result = 0 ;
cleanup :
2019-12-18 20:16:19 +03:00
g_unsetenv ( " VIR_CGROUP_MOCK_FILENAME " ) ;
2015-03-17 00:36:52 +03:00
VIR_FREE ( parsed ) ;
return result ;
}
2019-10-14 15:45:03 +03:00
static int testCgroupNewForSelf ( const void * args G_GNUC_UNUSED )
2013-03-28 18:36:52 +04:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) cgroup = NULL ;
2013-03-28 18:36:52 +04:00
const char * placement [ VIR_CGROUP_CONTROLLER_LAST ] = {
[ VIR_CGROUP_CONTROLLER_CPU ] = " /system " ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = " /system " ,
2013-03-22 15:11:34 +04:00
[ VIR_CGROUP_CONTROLLER_CPUSET ] = " / " ,
[ VIR_CGROUP_CONTROLLER_MEMORY ] = " / " ,
2013-03-28 18:36:52 +04:00
[ VIR_CGROUP_CONTROLLER_DEVICES ] = NULL ,
2013-03-22 15:11:34 +04:00
[ VIR_CGROUP_CONTROLLER_FREEZER ] = " / " ,
[ VIR_CGROUP_CONTROLLER_BLKIO ] = " / " ,
2013-07-25 22:13:44 +04:00
[ VIR_CGROUP_CONTROLLER_SYSTEMD ] = " /user/berrange/123 " ,
2013-03-28 18:36:52 +04:00
} ;
if ( virCgroupNewSelf ( & cgroup ) < 0 ) {
fprintf ( stderr , " Cannot create cgroup for self \n " ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-03-28 18:36:52 +04:00
}
2020-10-14 11:29:45 +03:00
return validateCgroup ( cgroup , mountsFull , links , placement , NULL , NULL , 0 ) ;
2013-03-28 18:36:52 +04:00
}
2017-11-03 15:09:47 +03:00
# define ENSURE_ERRNO(en) \
do { \
if ( ! virLastErrorIsSystemErrno ( en ) ) { \
virErrorPtr err = virGetLastError ( ) ; \
fprintf ( stderr , " Did not get " # en " error code: %d:%d \n " , \
err ? err - > code : 0 , err ? err - > int1 : 0 ) ; \
2020-09-22 13:52:26 +03:00
return - 1 ; \
2013-07-04 19:49:24 +04:00
} } while ( 0 )
/* Asking for impossible combination since CPU is co-mounted */
2019-10-14 15:45:03 +03:00
static int testCgroupNewForPartition ( const void * args G_GNUC_UNUSED )
2013-03-28 22:08:39 +04:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) cgroup = NULL ;
2013-03-28 22:08:39 +04:00
int rv ;
const char * placementSmall [ VIR_CGROUP_CONTROLLER_LAST ] = {
2013-04-26 13:23:51 +04:00
[ VIR_CGROUP_CONTROLLER_CPU ] = " /virtualmachines.partition " ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = " /virtualmachines.partition " ,
2013-03-28 22:08:39 +04:00
[ VIR_CGROUP_CONTROLLER_CPUSET ] = NULL ,
2013-04-26 13:23:51 +04:00
[ VIR_CGROUP_CONTROLLER_MEMORY ] = " /virtualmachines.partition " ,
2013-03-28 22:08:39 +04:00
[ VIR_CGROUP_CONTROLLER_DEVICES ] = NULL ,
[ VIR_CGROUP_CONTROLLER_FREEZER ] = NULL ,
[ VIR_CGROUP_CONTROLLER_BLKIO ] = NULL ,
2013-07-25 22:13:44 +04:00
[ VIR_CGROUP_CONTROLLER_SYSTEMD ] = NULL ,
2013-03-28 22:08:39 +04:00
} ;
const char * placementFull [ VIR_CGROUP_CONTROLLER_LAST ] = {
2013-04-26 13:23:51 +04:00
[ VIR_CGROUP_CONTROLLER_CPU ] = " /virtualmachines.partition " ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = " /virtualmachines.partition " ,
[ VIR_CGROUP_CONTROLLER_CPUSET ] = " /virtualmachines.partition " ,
[ VIR_CGROUP_CONTROLLER_MEMORY ] = " /virtualmachines.partition " ,
2013-03-28 22:08:39 +04:00
[ VIR_CGROUP_CONTROLLER_DEVICES ] = NULL ,
2013-04-26 13:23:51 +04:00
[ VIR_CGROUP_CONTROLLER_FREEZER ] = " /virtualmachines.partition " ,
[ VIR_CGROUP_CONTROLLER_BLKIO ] = " /virtualmachines.partition " ,
2013-07-25 22:13:44 +04:00
[ VIR_CGROUP_CONTROLLER_SYSTEMD ] = " /user/berrange/123 " ,
2013-03-28 22:08:39 +04:00
} ;
2013-07-04 19:49:24 +04:00
if ( ( rv = virCgroupNewPartition ( " /virtualmachines " , false , - 1 , & cgroup ) ) ! = - 1 ) {
2013-03-28 22:08:39 +04:00
fprintf ( stderr , " Unexpected found /virtualmachines cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-03-28 22:08:39 +04:00
}
2013-07-04 19:49:24 +04:00
ENSURE_ERRNO ( ENOENT ) ;
2013-03-28 22:08:39 +04:00
/* Asking for impossible combination since CPU is co-mounted */
if ( ( rv = virCgroupNewPartition ( " /virtualmachines " , true ,
( 1 < < VIR_CGROUP_CONTROLLER_CPU ) ,
2013-07-04 19:49:24 +04:00
& cgroup ) ) ! = - 1 ) {
2013-03-28 22:08:39 +04:00
fprintf ( stderr , " Should not have created /virtualmachines cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-03-28 22:08:39 +04:00
}
2013-07-04 19:49:24 +04:00
ENSURE_ERRNO ( EINVAL ) ;
2013-03-28 22:08:39 +04:00
/* Asking for impossible combination since devices is not mounted */
if ( ( rv = virCgroupNewPartition ( " /virtualmachines " , true ,
( 1 < < VIR_CGROUP_CONTROLLER_DEVICES ) ,
2013-07-04 19:49:24 +04:00
& cgroup ) ) ! = - 1 ) {
2013-03-28 22:08:39 +04:00
fprintf ( stderr , " Should not have created /virtualmachines cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-03-28 22:08:39 +04:00
}
2013-07-04 19:49:24 +04:00
ENSURE_ERRNO ( ENXIO ) ;
2013-03-28 22:08:39 +04:00
/* Asking for small combination since devices is not mounted */
if ( ( rv = virCgroupNewPartition ( " /virtualmachines " , true ,
( 1 < < VIR_CGROUP_CONTROLLER_CPU ) |
( 1 < < VIR_CGROUP_CONTROLLER_CPUACCT ) |
( 1 < < VIR_CGROUP_CONTROLLER_MEMORY ) ,
& cgroup ) ) ! = 0 ) {
fprintf ( stderr , " Cannot create /virtualmachines cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-03-28 22:08:39 +04:00
}
2020-10-14 11:29:45 +03:00
rv = validateCgroup ( cgroup , mountsSmall , links , placementSmall , NULL , NULL , 0 ) ;
2020-09-22 15:07:27 +03:00
virCgroupFree ( cgroup ) ;
2013-03-28 22:08:39 +04:00
if ( ( rv = virCgroupNewPartition ( " /virtualmachines " , true , - 1 , & cgroup ) ) ! = 0 ) {
fprintf ( stderr , " Cannot create /virtualmachines cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-03-28 22:08:39 +04:00
}
2020-10-14 11:29:45 +03:00
return validateCgroup ( cgroup , mountsFull , links , placementFull , NULL , NULL , 0 ) ;
2013-03-28 22:08:39 +04:00
}
2013-03-28 18:36:52 +04:00
2019-10-14 15:45:03 +03:00
static int testCgroupNewForPartitionNested ( const void * args G_GNUC_UNUSED )
2013-03-28 22:08:39 +04:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) cgroup = NULL ;
2013-03-28 22:08:39 +04:00
int rv ;
const char * placementFull [ VIR_CGROUP_CONTROLLER_LAST ] = {
2013-04-26 13:23:51 +04:00
[ VIR_CGROUP_CONTROLLER_CPU ] = " /deployment.partition/production.partition " ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = " /deployment.partition/production.partition " ,
[ VIR_CGROUP_CONTROLLER_CPUSET ] = " /deployment.partition/production.partition " ,
[ VIR_CGROUP_CONTROLLER_MEMORY ] = " /deployment.partition/production.partition " ,
2013-03-28 22:08:39 +04:00
[ VIR_CGROUP_CONTROLLER_DEVICES ] = NULL ,
2013-04-26 13:23:51 +04:00
[ VIR_CGROUP_CONTROLLER_FREEZER ] = " /deployment.partition/production.partition " ,
[ VIR_CGROUP_CONTROLLER_BLKIO ] = " /deployment.partition/production.partition " ,
2013-07-25 22:13:44 +04:00
[ VIR_CGROUP_CONTROLLER_SYSTEMD ] = " /user/berrange/123 " ,
2013-03-28 22:08:39 +04:00
} ;
2013-03-28 18:36:52 +04:00
2013-07-04 19:49:24 +04:00
if ( ( rv = virCgroupNewPartition ( " /deployment/production " , false , - 1 , & cgroup ) ) ! = - 1 ) {
2013-04-26 13:23:51 +04:00
fprintf ( stderr , " Unexpected found /deployment/production cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-03-28 22:08:39 +04:00
}
2013-07-04 19:49:24 +04:00
ENSURE_ERRNO ( ENOENT ) ;
2013-03-28 22:08:39 +04:00
2013-04-26 13:23:51 +04:00
/* Should not work, since we require /deployment to be pre-created */
2013-07-04 19:49:24 +04:00
if ( ( rv = virCgroupNewPartition ( " /deployment/production " , true , - 1 , & cgroup ) ) ! = - 1 ) {
2013-04-26 13:23:51 +04:00
fprintf ( stderr , " Unexpected created /deployment/production cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-03-28 22:08:39 +04:00
}
2013-07-04 19:49:24 +04:00
ENSURE_ERRNO ( ENOENT ) ;
2013-03-28 22:08:39 +04:00
2013-04-26 13:23:51 +04:00
if ( ( rv = virCgroupNewPartition ( " /deployment " , true , - 1 , & cgroup ) ) ! = 0 ) {
fprintf ( stderr , " Failed to create /deployment cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-03-28 22:08:39 +04:00
}
/* Should now work */
2020-09-22 15:07:27 +03:00
virCgroupFree ( cgroup ) ;
2013-04-26 13:23:51 +04:00
if ( ( rv = virCgroupNewPartition ( " /deployment/production " , true , - 1 , & cgroup ) ) ! = 0 ) {
fprintf ( stderr , " Failed to create /deployment/production cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-03-28 22:08:39 +04:00
}
2020-10-14 11:29:45 +03:00
return validateCgroup ( cgroup , mountsFull , links , placementFull , NULL , NULL , 0 ) ;
2013-04-26 13:23:51 +04:00
}
2019-10-14 15:45:03 +03:00
static int testCgroupNewForPartitionNestedDeep ( const void * args G_GNUC_UNUSED )
2013-04-26 13:23:51 +04:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) cgroup = NULL ;
2013-04-26 13:23:51 +04:00
int rv ;
const char * placementFull [ VIR_CGROUP_CONTROLLER_LAST ] = {
[ VIR_CGROUP_CONTROLLER_CPU ] = " /user/berrange.user/production.partition " ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = " /user/berrange.user/production.partition " ,
[ VIR_CGROUP_CONTROLLER_CPUSET ] = " /user/berrange.user/production.partition " ,
[ VIR_CGROUP_CONTROLLER_MEMORY ] = " /user/berrange.user/production.partition " ,
[ VIR_CGROUP_CONTROLLER_DEVICES ] = NULL ,
[ VIR_CGROUP_CONTROLLER_FREEZER ] = " /user/berrange.user/production.partition " ,
[ VIR_CGROUP_CONTROLLER_BLKIO ] = " /user/berrange.user/production.partition " ,
2013-07-25 22:13:44 +04:00
[ VIR_CGROUP_CONTROLLER_SYSTEMD ] = " /user/berrange/123 " ,
2013-04-26 13:23:51 +04:00
} ;
2013-07-04 19:49:24 +04:00
if ( ( rv = virCgroupNewPartition ( " /user/berrange.user/production " , false , - 1 , & cgroup ) ) ! = - 1 ) {
2013-04-26 13:23:51 +04:00
fprintf ( stderr , " Unexpected found /user/berrange.user/production cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-04-26 13:23:51 +04:00
}
2013-07-04 19:49:24 +04:00
ENSURE_ERRNO ( ENOENT ) ;
2013-04-26 13:23:51 +04:00
/* Should not work, since we require /user/berrange.user to be pre-created */
2013-07-04 19:49:24 +04:00
if ( ( rv = virCgroupNewPartition ( " /user/berrange.user/production " , true , - 1 , & cgroup ) ) ! = - 1 ) {
2013-04-26 13:23:51 +04:00
fprintf ( stderr , " Unexpected created /user/berrange.user/production cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-04-26 13:23:51 +04:00
}
2013-07-04 19:49:24 +04:00
ENSURE_ERRNO ( ENOENT ) ;
2013-04-26 13:23:51 +04:00
if ( ( rv = virCgroupNewPartition ( " /user " , true , - 1 , & cgroup ) ) ! = 0 ) {
fprintf ( stderr , " Failed to create /user/berrange.user cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-04-26 13:23:51 +04:00
}
2020-09-22 15:07:27 +03:00
virCgroupFree ( cgroup ) ;
2013-04-26 13:23:51 +04:00
if ( ( rv = virCgroupNewPartition ( " /user/berrange.user " , true , - 1 , & cgroup ) ) ! = 0 ) {
fprintf ( stderr , " Failed to create /user/berrange.user cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-04-26 13:23:51 +04:00
}
/* Should now work */
2020-09-22 15:07:27 +03:00
virCgroupFree ( cgroup ) ;
2013-04-26 13:23:51 +04:00
if ( ( rv = virCgroupNewPartition ( " /user/berrange.user/production " , true , - 1 , & cgroup ) ) ! = 0 ) {
fprintf ( stderr , " Failed to create /user/berrange.user/production cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-04-26 13:23:51 +04:00
}
2020-10-14 11:29:45 +03:00
return validateCgroup ( cgroup , mountsFull , links , placementFull , NULL , NULL , 0 ) ;
2013-03-28 22:08:39 +04:00
}
2019-10-14 15:45:03 +03:00
static int testCgroupNewForPartitionDomain ( const void * args G_GNUC_UNUSED )
2013-03-28 22:08:39 +04:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) partitioncgroup = NULL ;
g_autoptr ( virCgroup ) domaincgroup = NULL ;
2013-03-28 22:08:39 +04:00
int rv ;
const char * placement [ VIR_CGROUP_CONTROLLER_LAST ] = {
2013-04-26 13:23:51 +04:00
[ VIR_CGROUP_CONTROLLER_CPU ] = " /production.partition/foo.libvirt-lxc " ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = " /production.partition/foo.libvirt-lxc " ,
[ VIR_CGROUP_CONTROLLER_CPUSET ] = " /production.partition/foo.libvirt-lxc " ,
[ VIR_CGROUP_CONTROLLER_MEMORY ] = " /production.partition/foo.libvirt-lxc " ,
2013-03-28 22:08:39 +04:00
[ VIR_CGROUP_CONTROLLER_DEVICES ] = NULL ,
2013-04-26 13:23:51 +04:00
[ VIR_CGROUP_CONTROLLER_FREEZER ] = " /production.partition/foo.libvirt-lxc " ,
[ VIR_CGROUP_CONTROLLER_BLKIO ] = " /production.partition/foo.libvirt-lxc " ,
2013-07-25 22:13:44 +04:00
[ VIR_CGROUP_CONTROLLER_SYSTEMD ] = " /user/berrange/123 " ,
2013-03-28 22:08:39 +04:00
} ;
if ( ( rv = virCgroupNewPartition ( " /production " , true , - 1 , & partitioncgroup ) ) ! = 0 ) {
fprintf ( stderr , " Failed to create /production cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-03-28 22:08:39 +04:00
}
2020-10-22 02:43:57 +03:00
if ( ( rv = virCgroupNewDomainPartition ( partitioncgroup , " lxc " , " foo " , & domaincgroup ) ) ! = 0 ) {
2013-03-28 22:08:39 +04:00
fprintf ( stderr , " Cannot create LXC cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-03-28 22:08:39 +04:00
}
2020-10-14 11:29:45 +03:00
return validateCgroup ( domaincgroup , mountsFull , links , placement , NULL , NULL , 0 ) ;
2013-03-28 22:08:39 +04:00
}
2019-10-14 15:45:03 +03:00
static int testCgroupNewForPartitionDomainEscaped ( const void * args G_GNUC_UNUSED )
2013-04-26 13:50:24 +04:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) partitioncgroup1 = NULL ;
g_autoptr ( virCgroup ) partitioncgroup2 = NULL ;
g_autoptr ( virCgroup ) partitioncgroup3 = NULL ;
g_autoptr ( virCgroup ) domaincgroup = NULL ;
2013-04-26 13:50:24 +04:00
int rv ;
const char * placement [ VIR_CGROUP_CONTROLLER_LAST ] = {
[ VIR_CGROUP_CONTROLLER_CPU ] = " /_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc " ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = " /_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc " ,
[ VIR_CGROUP_CONTROLLER_CPUSET ] = " /_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc " ,
[ VIR_CGROUP_CONTROLLER_MEMORY ] = " /_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc " ,
[ VIR_CGROUP_CONTROLLER_DEVICES ] = NULL ,
[ VIR_CGROUP_CONTROLLER_FREEZER ] = " /_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc " ,
[ VIR_CGROUP_CONTROLLER_BLKIO ] = " /_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc " ,
2013-07-25 22:13:44 +04:00
[ VIR_CGROUP_CONTROLLER_SYSTEMD ] = " /user/berrange/123 " ,
2013-04-26 13:50:24 +04:00
} ;
if ( ( rv = virCgroupNewPartition ( " /cgroup.evil " , true , - 1 , & partitioncgroup1 ) ) ! = 0 ) {
fprintf ( stderr , " Failed to create /cgroup.evil cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-04-26 13:50:24 +04:00
}
if ( ( rv = virCgroupNewPartition ( " /cgroup.evil/net_cls.evil " , true , - 1 , & partitioncgroup2 ) ) ! = 0 ) {
fprintf ( stderr , " Failed to create /cgroup.evil/cpu.evil cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-04-26 13:50:24 +04:00
}
if ( ( rv = virCgroupNewPartition ( " /cgroup.evil/net_cls.evil/_evil.evil " , true , - 1 , & partitioncgroup3 ) ) ! = 0 ) {
fprintf ( stderr , " Failed to create /cgroup.evil cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-04-26 13:50:24 +04:00
}
2020-10-22 02:43:57 +03:00
if ( ( rv = virCgroupNewDomainPartition ( partitioncgroup3 , " lxc " , " cpu.foo " , & domaincgroup ) ) ! = 0 ) {
2013-04-26 13:50:24 +04:00
fprintf ( stderr , " Cannot create LXC cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-04-26 13:50:24 +04:00
}
/* NB we're not expecting 'net_cls.evil' to be escaped,
* since our fake / proc / cgroups pretends this controller
* isn ' t compiled into the kernel
*/
2020-10-14 11:29:45 +03:00
return validateCgroup ( domaincgroup , mountsFull , links , placement , NULL , NULL , 0 ) ;
2013-04-26 13:50:24 +04:00
}
2019-10-14 15:45:03 +03:00
static int testCgroupNewForSelfAllInOne ( const void * args G_GNUC_UNUSED )
2013-09-10 17:31:53 +04:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) cgroup = NULL ;
2013-09-10 17:31:53 +04:00
const char * placement [ VIR_CGROUP_CONTROLLER_LAST ] = {
[ VIR_CGROUP_CONTROLLER_CPU ] = " / " ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = " / " ,
[ VIR_CGROUP_CONTROLLER_CPUSET ] = " / " ,
[ VIR_CGROUP_CONTROLLER_MEMORY ] = " / " ,
[ VIR_CGROUP_CONTROLLER_DEVICES ] = " / " ,
[ VIR_CGROUP_CONTROLLER_FREEZER ] = NULL ,
[ VIR_CGROUP_CONTROLLER_BLKIO ] = " / " ,
} ;
if ( virCgroupNewSelf ( & cgroup ) < 0 ) {
fprintf ( stderr , " Cannot create cgroup for self \n " ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-09-10 17:31:53 +04:00
}
2020-10-14 11:29:45 +03:00
return validateCgroup ( cgroup , mountsAllInOne , linksAllInOne , placement , NULL , NULL , 0 ) ;
2013-09-10 17:31:53 +04:00
}
2019-10-14 15:45:03 +03:00
static int testCgroupNewForSelfLogind ( const void * args G_GNUC_UNUSED )
2018-09-18 10:43:09 +03:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) cgroup = NULL ;
2018-09-18 10:43:09 +03:00
if ( virCgroupNewSelf ( & cgroup ) > = 0 ) {
fprintf ( stderr , " Expected to fail, only systemd cgroup available. \n " ) ;
return - 1 ;
}
return 0 ;
}
2019-10-14 15:45:03 +03:00
static int testCgroupNewForSelfUnified ( const void * args G_GNUC_UNUSED )
2013-09-11 22:15:52 +04:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) cgroup = NULL ;
2018-09-18 10:43:09 +03:00
const char * empty [ VIR_CGROUP_CONTROLLER_LAST ] = { 0 } ;
unsigned int controllers =
( 1 < < VIR_CGROUP_CONTROLLER_CPU ) |
( 1 < < VIR_CGROUP_CONTROLLER_CPUACCT ) |
( 1 < < VIR_CGROUP_CONTROLLER_MEMORY ) |
2019-06-24 16:13:37 +03:00
( 1 < < VIR_CGROUP_CONTROLLER_DEVICES ) |
2018-09-18 10:43:09 +03:00
( 1 < < VIR_CGROUP_CONTROLLER_BLKIO ) ;
2013-09-11 22:15:52 +04:00
2018-09-18 10:43:09 +03:00
if ( virCgroupNewSelf ( & cgroup ) < 0 ) {
fprintf ( stderr , " Cannot create cgroup for self \n " ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2013-09-11 22:15:52 +04:00
}
2020-10-14 11:29:45 +03:00
return validateCgroup ( cgroup , empty , empty , empty ,
2020-09-22 13:52:26 +03:00
" /not/really/sys/fs/cgroup " , " / " , controllers ) ;
2013-09-11 22:15:52 +04:00
}
2019-10-14 15:45:03 +03:00
static int testCgroupNewForSelfHybrid ( const void * args G_GNUC_UNUSED )
2018-09-18 10:43:47 +03:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) cgroup = NULL ;
2018-09-18 10:43:47 +03:00
const char * empty [ VIR_CGROUP_CONTROLLER_LAST ] = { 0 } ;
const char * mounts [ VIR_CGROUP_CONTROLLER_LAST ] = {
[ VIR_CGROUP_CONTROLLER_CPUSET ] = " /not/really/sys/fs/cgroup/cpuset " ,
[ VIR_CGROUP_CONTROLLER_FREEZER ] = " /not/really/sys/fs/cgroup/freezer " ,
[ VIR_CGROUP_CONTROLLER_NET_CLS ] = " /not/really/sys/fs/cgroup/net_cls " ,
[ VIR_CGROUP_CONTROLLER_PERF_EVENT ] = " /not/really/sys/fs/cgroup/perf_event " ,
} ;
const char * placement [ VIR_CGROUP_CONTROLLER_LAST ] = {
[ VIR_CGROUP_CONTROLLER_CPUSET ] = " / " ,
[ VIR_CGROUP_CONTROLLER_FREEZER ] = " / " ,
[ VIR_CGROUP_CONTROLLER_NET_CLS ] = " / " ,
[ VIR_CGROUP_CONTROLLER_PERF_EVENT ] = " / " ,
} ;
unsigned int controllers =
( 1 < < VIR_CGROUP_CONTROLLER_CPU ) |
( 1 < < VIR_CGROUP_CONTROLLER_CPUACCT ) |
( 1 < < VIR_CGROUP_CONTROLLER_MEMORY ) |
2019-06-24 16:13:37 +03:00
( 1 < < VIR_CGROUP_CONTROLLER_DEVICES ) |
2018-09-18 10:43:47 +03:00
( 1 < < VIR_CGROUP_CONTROLLER_BLKIO ) ;
if ( virCgroupNewSelf ( & cgroup ) < 0 ) {
fprintf ( stderr , " Cannot create cgroup for self \n " ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2018-09-18 10:43:47 +03:00
}
2020-10-14 11:29:45 +03:00
return validateCgroup ( cgroup , mounts , empty , placement ,
2020-09-22 13:52:26 +03:00
" /not/really/sys/fs/cgroup/unified " , " / " , controllers ) ;
2018-09-18 10:43:47 +03:00
}
2020-11-05 20:39:10 +03:00
static int testCgroupNewForSelfSystemdLegacy ( const void * args G_GNUC_UNUSED )
{
g_autoptr ( virCgroup ) cgroup = NULL ;
const char * empty [ VIR_CGROUP_CONTROLLER_LAST ] = { 0 } ;
const char * mounts [ VIR_CGROUP_CONTROLLER_LAST ] = {
[ VIR_CGROUP_CONTROLLER_BLKIO ] = " /not/really/sys/fs/cgroup/blkio " ,
[ VIR_CGROUP_CONTROLLER_CPU ] = " /not/really/sys/fs/cgroup/cpu " ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = " /not/really/sys/fs/cgroup/cpuacct " ,
[ VIR_CGROUP_CONTROLLER_CPUSET ] = " /not/really/sys/fs/cgroup/cpuset " ,
[ VIR_CGROUP_CONTROLLER_DEVICES ] = " /not/really/sys/fs/cgroup/devices " ,
[ VIR_CGROUP_CONTROLLER_FREEZER ] = " /not/really/sys/fs/cgroup/freezer " ,
[ VIR_CGROUP_CONTROLLER_MEMORY ] = " /not/really/sys/fs/cgroup/memory " ,
[ VIR_CGROUP_CONTROLLER_NET_CLS ] = " /not/really/sys/fs/cgroup/net_cls " ,
[ VIR_CGROUP_CONTROLLER_PERF_EVENT ] = " /not/really/sys/fs/cgroup/perf_event " ,
} ;
const char * placement [ VIR_CGROUP_CONTROLLER_LAST ] = {
[ VIR_CGROUP_CONTROLLER_BLKIO ] = " " ,
[ VIR_CGROUP_CONTROLLER_CPU ] = " " ,
[ VIR_CGROUP_CONTROLLER_CPUACCT ] = " " ,
[ VIR_CGROUP_CONTROLLER_CPUSET ] = " " ,
[ VIR_CGROUP_CONTROLLER_DEVICES ] = " " ,
[ VIR_CGROUP_CONTROLLER_FREEZER ] = " " ,
[ VIR_CGROUP_CONTROLLER_MEMORY ] = " " ,
[ VIR_CGROUP_CONTROLLER_NET_CLS ] = " " ,
[ VIR_CGROUP_CONTROLLER_PERF_EVENT ] = " " ,
} ;
if ( virCgroupNewSelf ( & cgroup ) < 0 ) {
fprintf ( stderr , " Cannot create cgroup for self \n " ) ;
return - 1 ;
}
return validateCgroup ( cgroup , mounts , empty , placement , NULL , NULL , 0 ) ;
}
static int testCgroupNewForSelfSystemdUnified ( const void * args G_GNUC_UNUSED )
{
g_autoptr ( virCgroup ) cgroup = NULL ;
const char * empty [ VIR_CGROUP_CONTROLLER_LAST ] = { 0 } ;
unsigned int controllers =
( 1 < < VIR_CGROUP_CONTROLLER_CPU ) |
( 1 < < VIR_CGROUP_CONTROLLER_CPUACCT ) |
( 1 < < VIR_CGROUP_CONTROLLER_MEMORY ) |
( 1 < < VIR_CGROUP_CONTROLLER_DEVICES ) |
( 1 < < VIR_CGROUP_CONTROLLER_BLKIO ) ;
if ( virCgroupNewSelf ( & cgroup ) < 0 ) {
fprintf ( stderr , " Cannot create cgroup for self \n " ) ;
return - 1 ;
}
return validateCgroup ( cgroup , empty , empty , empty ,
" /not/really/sys/fs/cgroup " , " " ,
controllers ) ;
}
2013-09-11 22:15:52 +04:00
static int testCgroupAvailable ( const void * args )
{
bool got = virCgroupAvailable ( ) ;
bool want = args = = ( void * ) 0x1 ;
if ( got ! = want ) {
fprintf ( stderr , " Expected cgroup %savailable, but state was wrong \n " ,
want ? " " : " not " ) ;
return - 1 ;
}
return 0 ;
}
2019-10-14 15:45:03 +03:00
static int testCgroupControllerAvailable ( const void * args G_GNUC_UNUSED )
2015-03-31 12:39:13 +03:00
{
int ret = 0 ;
2017-11-03 15:09:47 +03:00
# define CHECK_CONTROLLER(c, present) \
if ( ( present & & ! virCgroupControllerAvailable ( c ) ) | | \
( ! present & & virCgroupControllerAvailable ( c ) ) ) { \
fprintf ( stderr , present ? \
" Expected controller %s not available \n " : \
" Unexpected controller %s available \n " , # c ) ; \
ret = - 1 ; \
2015-03-31 12:39:13 +03:00
}
CHECK_CONTROLLER ( VIR_CGROUP_CONTROLLER_CPU , true )
CHECK_CONTROLLER ( VIR_CGROUP_CONTROLLER_CPUACCT , true )
CHECK_CONTROLLER ( VIR_CGROUP_CONTROLLER_CPUSET , true )
CHECK_CONTROLLER ( VIR_CGROUP_CONTROLLER_MEMORY , true )
CHECK_CONTROLLER ( VIR_CGROUP_CONTROLLER_DEVICES , false )
CHECK_CONTROLLER ( VIR_CGROUP_CONTROLLER_FREEZER , true )
CHECK_CONTROLLER ( VIR_CGROUP_CONTROLLER_BLKIO , true )
CHECK_CONTROLLER ( VIR_CGROUP_CONTROLLER_NET_CLS , false )
CHECK_CONTROLLER ( VIR_CGROUP_CONTROLLER_PERF_EVENT , false )
CHECK_CONTROLLER ( VIR_CGROUP_CONTROLLER_SYSTEMD , true )
# undef CHECK_CONTROLLER
return ret ;
}
2019-10-14 15:45:03 +03:00
static int testCgroupGetPercpuStats ( const void * args G_GNUC_UNUSED )
2014-02-14 21:49:08 +04:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) cgroup = NULL ;
2014-02-14 21:49:08 +04:00
size_t i ;
int rv , ret = - 1 ;
2015-01-22 13:54:50 +03:00
virTypedParameterPtr params = NULL ;
# define EXPECTED_NCPUS 160
2014-02-14 21:49:08 +04:00
2015-01-23 12:30:01 +03:00
unsigned long long expected [ EXPECTED_NCPUS ] = {
2015-01-22 13:54:50 +03:00
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
2015-04-15 21:50:23 +03:00
7059492996ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4180532496ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
2015-01-22 13:54:50 +03:00
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
2015-04-15 21:50:23 +03:00
1957541268ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
2065932204ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
18228689414ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
4245525148ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
2911161568ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
1407758136ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
1836807700ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
1065296618ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
2046213266ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
747889778ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
709566900ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
444777342ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
5683512916ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
635751356ULL , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
2014-02-14 21:49:08 +04:00
} ;
2015-01-22 13:54:50 +03:00
2020-09-23 02:04:17 +03:00
params = g_new0 ( virTypedParameter , EXPECTED_NCPUS ) ;
2014-02-14 21:49:08 +04:00
if ( ( rv = virCgroupNewPartition ( " /virtualmachines " , true ,
( 1 < < VIR_CGROUP_CONTROLLER_CPU ) |
( 1 < < VIR_CGROUP_CONTROLLER_CPUACCT ) ,
& cgroup ) ) < 0 ) {
fprintf ( stderr , " Could not create /virtualmachines cgroup: %d \n " , - rv ) ;
goto cleanup ;
}
2016-04-13 20:16:16 +03:00
if ( virHostCPUGetCount ( ) ! = EXPECTED_NCPUS ) {
fprintf ( stderr , " Unexpected: virHostCPUGetCount() yields: %d \n " , virHostCPUGetCount ( ) ) ;
2014-02-14 21:49:08 +04:00
goto cleanup ;
}
if ( ( rv = virCgroupGetPercpuStats ( cgroup ,
params ,
2015-12-14 17:10:22 +03:00
1 , 0 , EXPECTED_NCPUS , NULL ) ) < 0 ) {
2014-02-14 21:49:08 +04:00
fprintf ( stderr , " Failed call to virCgroupGetPercpuStats for /virtualmachines cgroup: %d \n " , - rv ) ;
goto cleanup ;
}
2015-01-22 13:54:50 +03:00
for ( i = 0 ; i < EXPECTED_NCPUS ; i + + ) {
2015-10-20 19:15:12 +03:00
if ( STRNEQ ( params [ i ] . field , VIR_DOMAIN_CPU_STATS_CPUTIME ) ) {
2014-02-14 21:49:08 +04:00
fprintf ( stderr ,
2015-01-22 13:54:50 +03:00
" Wrong parameter name value from virCgroupGetPercpuStats at %zu (is: %s) \n " ,
i , params [ i ] . field ) ;
2014-02-14 21:49:08 +04:00
goto cleanup ;
}
if ( params [ i ] . type ! = VIR_TYPED_PARAM_ULLONG ) {
fprintf ( stderr ,
2015-01-22 13:54:50 +03:00
" Wrong parameter value type from virCgroupGetPercpuStats at %zu (is: %d) \n " ,
i , params [ i ] . type ) ;
2014-02-14 21:49:08 +04:00
goto cleanup ;
}
if ( params [ i ] . value . ul ! = expected [ i ] ) {
fprintf ( stderr ,
2018-11-08 02:18:42 +03:00
" Wrong value from virCgroupGetPercpuStats at %zu (expected %llu) \n " ,
2015-01-22 13:54:50 +03:00
i , params [ i ] . value . ul ) ;
2014-02-14 21:49:08 +04:00
goto cleanup ;
}
}
ret = 0 ;
2014-03-25 10:53:44 +04:00
cleanup :
2015-01-26 12:20:22 +03:00
VIR_FREE ( params ) ;
2014-02-14 21:49:08 +04:00
return ret ;
}
2019-10-14 15:45:03 +03:00
static int testCgroupGetMemoryUsage ( const void * args G_GNUC_UNUSED )
2014-02-14 21:49:06 +04:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) cgroup = NULL ;
int rv ;
2014-02-14 21:49:06 +04:00
unsigned long kb ;
if ( ( rv = virCgroupNewPartition ( " /virtualmachines " , true ,
( 1 < < VIR_CGROUP_CONTROLLER_MEMORY ) ,
& cgroup ) ) < 0 ) {
fprintf ( stderr , " Could not create /virtualmachines cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2014-02-14 21:49:06 +04:00
}
if ( ( rv = virCgroupGetMemoryUsage ( cgroup , & kb ) ) < 0 ) {
fprintf ( stderr , " Could not retrieve GetMemoryUsage for /virtualmachines cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2014-02-14 21:49:06 +04:00
}
if ( kb ! = 1421212UL ) {
fprintf ( stderr ,
" Wrong value from virCgroupGetMemoryUsage (expected %ld) \n " ,
1421212UL ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2014-02-14 21:49:06 +04:00
}
2020-09-22 13:52:26 +03:00
return 0 ;
2014-02-14 21:49:06 +04:00
}
2018-11-08 02:40:43 +03:00
static int
2019-10-14 15:45:03 +03:00
testCgroupGetMemoryStat ( const void * args G_GNUC_UNUSED )
2018-11-08 02:40:43 +03:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) cgroup = NULL ;
2018-11-08 02:40:43 +03:00
int rv ;
size_t i ;
const unsigned long long expected_values [ ] = {
1336619008ULL ,
67100672ULL ,
145887232ULL ,
661872640ULL ,
627400704UL ,
3690496ULL
} ;
const char * names [ ] = {
" cache " ,
" active_anon " ,
" inactive_anon " ,
" active_file " ,
" inactive_file " ,
" unevictable "
} ;
2019-10-15 14:55:26 +03:00
unsigned long long values [ G_N_ELEMENTS ( expected_values ) ] ;
2018-11-08 02:40:43 +03:00
if ( ( rv = virCgroupNewPartition ( " /virtualmachines " , true ,
( 1 < < VIR_CGROUP_CONTROLLER_MEMORY ) ,
& cgroup ) ) < 0 ) {
fprintf ( stderr , " Could not create /virtualmachines cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2018-11-08 02:40:43 +03:00
}
if ( ( rv = virCgroupGetMemoryStat ( cgroup , & values [ 0 ] ,
& values [ 1 ] , & values [ 2 ] ,
& values [ 3 ] , & values [ 4 ] ,
& values [ 5 ] ) ) < 0 ) {
fprintf ( stderr , " Could not retrieve GetMemoryStat for /virtualmachines cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2018-11-08 02:40:43 +03:00
}
2019-10-15 14:55:26 +03:00
for ( i = 0 ; i < G_N_ELEMENTS ( expected_values ) ; i + + ) {
2018-11-08 02:40:43 +03:00
/* NB: virCgroupGetMemoryStat returns a KiB scaled value */
if ( ( expected_values [ i ] > > 10 ) ! = values [ i ] ) {
fprintf ( stderr ,
" Wrong value (%llu) for %s from virCgroupGetMemoryStat "
" (expected %llu) \n " ,
values [ i ] , names [ i ] , ( expected_values [ i ] > > 10 ) ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2018-11-08 02:40:43 +03:00
}
}
2020-09-22 13:52:26 +03:00
return 0 ;
2018-11-08 02:40:43 +03:00
}
2019-10-14 15:45:03 +03:00
static int testCgroupGetBlkioIoServiced ( const void * args G_GNUC_UNUSED )
2014-02-14 21:49:05 +04:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) cgroup = NULL ;
2014-02-14 21:49:05 +04:00
size_t i ;
2020-09-22 13:52:26 +03:00
int rv ;
2014-02-14 21:49:05 +04:00
const long long expected_values [ ] = {
2014-02-22 04:21:58 +04:00
119084214273ULL ,
822880960513ULL ,
2014-02-14 21:49:05 +04:00
9665167 ,
73283807
} ;
const char * names [ ] = {
" bytes read " ,
" bytes written " ,
" requests read " ,
" requests written "
} ;
2019-10-15 14:55:26 +03:00
long long values [ G_N_ELEMENTS ( expected_values ) ] ;
2014-02-14 21:49:05 +04:00
if ( ( rv = virCgroupNewPartition ( " /virtualmachines " , true ,
( 1 < < VIR_CGROUP_CONTROLLER_BLKIO ) ,
& cgroup ) ) < 0 ) {
fprintf ( stderr , " Could not create /virtualmachines cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2014-02-14 21:49:05 +04:00
}
if ( ( rv = virCgroupGetBlkioIoServiced ( cgroup ,
values , & values [ 1 ] ,
& values [ 2 ] , & values [ 3 ] ) ) < 0 ) {
fprintf ( stderr , " Could not retrieve BlkioIoServiced for /virtualmachines cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2014-02-14 21:49:05 +04:00
}
2019-10-15 14:55:26 +03:00
for ( i = 0 ; i < G_N_ELEMENTS ( expected_values ) ; i + + ) {
2014-02-14 21:49:05 +04:00
if ( expected_values [ i ] ! = values [ i ] ) {
fprintf ( stderr ,
" Wrong value for %s from virCgroupBlkioIoServiced (expected %lld) \n " ,
names [ i ] , expected_values [ i ] ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2014-02-14 21:49:05 +04:00
}
}
2020-09-22 13:52:26 +03:00
return 0 ;
2014-02-14 21:49:05 +04:00
}
2019-10-14 15:45:03 +03:00
static int testCgroupGetBlkioIoDeviceServiced ( const void * args G_GNUC_UNUSED )
2014-02-14 21:49:05 +04:00
{
2020-09-22 13:52:26 +03:00
g_autoptr ( virCgroup ) cgroup = NULL ;
2014-02-14 21:49:05 +04:00
size_t i ;
2020-09-22 13:52:26 +03:00
int rv ;
2014-02-14 21:49:05 +04:00
const long long expected_values0 [ ] = {
2014-02-22 04:21:58 +04:00
59542107136ULL ,
411440480256ULL ,
2014-02-14 21:49:05 +04:00
4832583 ,
36641903
} ;
const long long expected_values1 [ ] = {
2014-02-22 04:21:58 +04:00
59542107137ULL ,
411440480257ULL ,
2014-02-14 21:49:05 +04:00
4832584 ,
36641904
} ;
const char * names [ ] = {
" bytes read " ,
" bytes written " ,
" requests read " ,
" requests written "
} ;
2019-10-15 14:55:26 +03:00
long long values [ G_N_ELEMENTS ( expected_values0 ) ] ;
2014-02-14 21:49:05 +04:00
if ( ( rv = virCgroupNewPartition ( " /virtualmachines " , true ,
( 1 < < VIR_CGROUP_CONTROLLER_BLKIO ) ,
& cgroup ) ) < 0 ) {
fprintf ( stderr , " Could not create /virtualmachines cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2014-02-14 21:49:05 +04:00
}
if ( ( rv = virCgroupGetBlkioIoDeviceServiced ( cgroup ,
FAKEDEVDIR0 ,
values , & values [ 1 ] ,
& values [ 2 ] , & values [ 3 ] ) ) < 0 ) {
fprintf ( stderr , " Could not retrieve BlkioIoDeviceServiced for /virtualmachines cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2014-02-14 21:49:05 +04:00
}
2019-10-15 14:55:26 +03:00
for ( i = 0 ; i < G_N_ELEMENTS ( expected_values0 ) ; i + + ) {
2014-02-14 21:49:05 +04:00
if ( expected_values0 [ i ] ! = values [ i ] ) {
fprintf ( stderr ,
" Wrong value for %s from virCgroupGetBlkioIoDeviceServiced (expected %lld) \n " ,
names [ i ] , expected_values0 [ i ] ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2014-02-14 21:49:05 +04:00
}
}
if ( ( rv = virCgroupGetBlkioIoDeviceServiced ( cgroup ,
FAKEDEVDIR1 ,
values , & values [ 1 ] ,
& values [ 2 ] , & values [ 3 ] ) ) < 0 ) {
fprintf ( stderr , " Could not retrieve BlkioIoDeviceServiced for /virtualmachines cgroup: %d \n " , - rv ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2014-02-14 21:49:05 +04:00
}
2019-10-15 14:55:26 +03:00
for ( i = 0 ; i < G_N_ELEMENTS ( expected_values1 ) ; i + + ) {
2014-02-14 21:49:05 +04:00
if ( expected_values1 [ i ] ! = values [ i ] ) {
fprintf ( stderr ,
" Wrong value for %s from virCgroupGetBlkioIoDeviceServiced (expected %lld) \n " ,
names [ i ] , expected_values1 [ i ] ) ;
2020-09-22 13:52:26 +03:00
return - 1 ;
2014-02-14 21:49:05 +04:00
}
}
2020-09-22 13:52:26 +03:00
return 0 ;
2014-02-14 21:49:05 +04:00
}
2013-09-10 17:31:53 +04:00
2015-12-04 15:38:16 +03:00
# define FAKEROOTDIRTEMPLATE abs_builddir " / fakerootdir-XXXXXX"
2013-03-28 18:36:52 +04:00
2018-09-24 13:22:54 +03:00
static char *
initFakeFS ( const char * mode ,
const char * filename )
2013-03-28 18:36:52 +04:00
{
2015-12-04 15:38:16 +03:00
char * fakerootdir ;
2013-03-28 18:36:52 +04:00
2019-10-20 14:49:46 +03:00
fakerootdir = g_strdup ( FAKEROOTDIRTEMPLATE ) ;
2013-03-28 18:36:52 +04:00
2019-11-14 00:35:47 +03:00
if ( ! g_mkdtemp ( fakerootdir ) ) {
2015-12-04 15:38:16 +03:00
fprintf ( stderr , " Cannot create fakerootdir " ) ;
2013-03-28 18:36:52 +04:00
abort ( ) ;
}
2019-12-18 20:16:19 +03:00
g_setenv ( " LIBVIRT_FAKE_ROOT_DIR " , fakerootdir , TRUE ) ;
2013-03-28 18:36:52 +04:00
2018-09-24 13:22:54 +03:00
if ( mode )
2019-12-18 20:16:19 +03:00
g_setenv ( " VIR_CGROUP_MOCK_MODE " , mode , TRUE ) ;
2018-09-24 13:22:54 +03:00
if ( filename )
2019-12-18 20:16:19 +03:00
g_setenv ( " VIR_CGROUP_MOCK_FILENAME " , filename , TRUE ) ;
2018-09-24 13:22:54 +03:00
return fakerootdir ;
}
static void
cleanupFakeFS ( char * fakerootdir )
{
if ( getenv ( " LIBVIRT_SKIP_CLEANUP " ) = = NULL )
virFileDeleteTree ( fakerootdir ) ;
VIR_FREE ( fakerootdir ) ;
2019-12-18 20:16:19 +03:00
g_unsetenv ( " LIBVIRT_FAKE_ROOT_DIR " ) ;
g_unsetenv ( " VIR_CGROUP_MOCK_MODE " ) ;
g_unsetenv ( " VIR_CGROUP_MOCK_FILENAME " ) ;
2018-09-24 13:22:54 +03:00
}
static int
mymain ( void )
{
int ret = 0 ;
char * fakerootdir ;
2018-09-14 14:17:07 +03:00
# define DETECT_MOUNTS_FULL(file, fail) \
2017-11-03 15:09:47 +03:00
do { \
2018-09-14 14:17:07 +03:00
struct _detectMountsData data = { file , fail } ; \
2017-11-03 15:09:47 +03:00
if ( virTestRun ( " Detect cgroup mounts for " file , \
testCgroupDetectMounts , \
2018-09-14 14:17:07 +03:00
& data ) < 0 ) \
2017-11-03 15:09:47 +03:00
ret = - 1 ; \
2015-03-17 00:36:52 +03:00
} while ( 0 )
2018-09-14 14:17:07 +03:00
# define DETECT_MOUNTS(file) DETECT_MOUNTS_FULL(file, false);
# define DETECT_MOUNTS_FAIL(file) DETECT_MOUNTS_FULL(file, true);
2015-03-17 00:36:52 +03:00
DETECT_MOUNTS ( " ovirt-node-6.6 " ) ;
DETECT_MOUNTS ( " ovirt-node-7.1 " ) ;
DETECT_MOUNTS ( " fedora-18 " ) ;
DETECT_MOUNTS ( " fedora-21 " ) ;
DETECT_MOUNTS ( " rhel-7.1 " ) ;
DETECT_MOUNTS ( " cgroups1 " ) ;
DETECT_MOUNTS ( " cgroups2 " ) ;
DETECT_MOUNTS ( " cgroups3 " ) ;
DETECT_MOUNTS ( " all-in-one " ) ;
2018-09-14 14:17:07 +03:00
DETECT_MOUNTS_FAIL ( " no-cgroups " ) ;
2017-07-06 18:03:31 +03:00
DETECT_MOUNTS ( " kubevirt " ) ;
2018-09-18 11:08:35 +03:00
fakerootdir = initFakeFS ( " unified " , NULL ) ;
DETECT_MOUNTS ( " unified " ) ;
cleanupFakeFS ( fakerootdir ) ;
2018-09-18 11:09:20 +03:00
fakerootdir = initFakeFS ( " hybrid " , NULL ) ;
DETECT_MOUNTS ( " hybrid " ) ;
cleanupFakeFS ( fakerootdir ) ;
2015-03-17 00:36:52 +03:00
2018-09-24 13:22:54 +03:00
fakerootdir = initFakeFS ( NULL , " systemd " ) ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " New cgroup for self " , testCgroupNewForSelf , NULL ) < 0 )
2013-03-28 18:36:52 +04:00
ret = - 1 ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " New cgroup for partition " , testCgroupNewForPartition , NULL ) < 0 )
2013-03-28 18:36:52 +04:00
ret = - 1 ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " New cgroup for partition nested " , testCgroupNewForPartitionNested , NULL ) < 0 )
2013-03-28 22:08:39 +04:00
ret = - 1 ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " New cgroup for partition nested deeply " , testCgroupNewForPartitionNestedDeep , NULL ) < 0 )
2013-04-26 13:23:51 +04:00
ret = - 1 ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " New cgroup for domain partition " , testCgroupNewForPartitionDomain , NULL ) < 0 )
2013-03-28 22:08:39 +04:00
ret = - 1 ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " New cgroup for domain partition escaped " , testCgroupNewForPartitionDomainEscaped , NULL ) < 0 )
2013-04-26 13:50:24 +04:00
ret = - 1 ;
2013-03-28 22:08:39 +04:00
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " Cgroup available " , testCgroupAvailable , ( void * ) 0x1 ) < 0 )
2013-09-11 22:15:52 +04:00
ret = - 1 ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " Cgroup controller available " , testCgroupControllerAvailable , NULL ) < 0 )
2015-03-31 12:39:13 +03:00
ret = - 1 ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " virCgroupGetBlkioIoServiced works " , testCgroupGetBlkioIoServiced , NULL ) < 0 )
2014-02-14 21:49:05 +04:00
ret = - 1 ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " virCgroupGetBlkioIoDeviceServiced works " , testCgroupGetBlkioIoDeviceServiced , NULL ) < 0 )
2014-02-14 21:49:05 +04:00
ret = - 1 ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " virCgroupGetMemoryUsage works " , testCgroupGetMemoryUsage , NULL ) < 0 )
2014-02-14 21:49:06 +04:00
ret = - 1 ;
2018-11-08 02:40:43 +03:00
if ( virTestRun ( " virCgroupGetMemoryStat works " , testCgroupGetMemoryStat , NULL ) < 0 )
ret = - 1 ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " virCgroupGetPercpuStats works " , testCgroupGetPercpuStats , NULL ) < 0 )
2014-02-14 21:49:08 +04:00
ret = - 1 ;
2018-09-24 13:22:54 +03:00
cleanupFakeFS ( fakerootdir ) ;
2014-02-14 21:49:08 +04:00
2018-09-24 13:22:54 +03:00
fakerootdir = initFakeFS ( NULL , " all-in-one " ) ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " New cgroup for self (allinone) " , testCgroupNewForSelfAllInOne , NULL ) < 0 )
2013-09-10 17:31:53 +04:00
ret = - 1 ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " Cgroup available " , testCgroupAvailable , ( void * ) 0x1 ) < 0 )
2013-09-11 22:15:52 +04:00
ret = - 1 ;
2018-09-24 13:22:54 +03:00
cleanupFakeFS ( fakerootdir ) ;
2013-09-11 22:15:52 +04:00
2018-09-24 13:22:54 +03:00
fakerootdir = initFakeFS ( NULL , " logind " ) ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " New cgroup for self (logind) " , testCgroupNewForSelfLogind , NULL ) < 0 )
2013-09-11 22:15:52 +04:00
ret = - 1 ;
2016-05-26 18:01:50 +03:00
if ( virTestRun ( " Cgroup available " , testCgroupAvailable , ( void * ) 0x0 ) < 0 )
2013-09-11 22:15:52 +04:00
ret = - 1 ;
2018-09-24 13:22:54 +03:00
cleanupFakeFS ( fakerootdir ) ;
2013-09-10 17:31:53 +04:00
2018-09-18 10:43:09 +03:00
/* cgroup unified */
2013-03-28 18:36:52 +04:00
2018-09-18 10:43:09 +03:00
fakerootdir = initFakeFS ( " unified " , " unified " ) ;
if ( virTestRun ( " New cgroup for self (unified) " , testCgroupNewForSelfUnified , NULL ) < 0 )
ret = - 1 ;
if ( virTestRun ( " Cgroup available (unified) " , testCgroupAvailable , ( void * ) 0x1 ) < 0 )
ret = - 1 ;
cleanupFakeFS ( fakerootdir ) ;
2013-03-28 18:36:52 +04:00
2018-09-18 10:43:47 +03:00
/* cgroup hybrid */
fakerootdir = initFakeFS ( " hybrid " , " hybrid " ) ;
if ( virTestRun ( " New cgroup for self (hybrid) " , testCgroupNewForSelfHybrid , NULL ) < 0 )
ret = - 1 ;
if ( virTestRun ( " Cgroup available (hybrid) " , testCgroupAvailable , ( void * ) 0x1 ) < 0 )
ret = - 1 ;
cleanupFakeFS ( fakerootdir ) ;
2020-11-05 20:39:10 +03:00
fakerootdir = initFakeFS ( " legacy " , " systemd-legacy " ) ;
if ( virTestRun ( " New cgroup for self (systemd-legacy) " ,
testCgroupNewForSelfSystemdLegacy , NULL ) < 0 ) {
ret = - 1 ;
}
cleanupFakeFS ( fakerootdir ) ;
fakerootdir = initFakeFS ( " unified " , " systemd-unified " ) ;
if ( virTestRun ( " New cgroup for self (systemd-unified) " ,
testCgroupNewForSelfSystemdUnified , NULL ) < 0 ) {
ret = - 1 ;
}
cleanupFakeFS ( fakerootdir ) ;
2014-03-17 13:38:38 +04:00
return ret = = 0 ? EXIT_SUCCESS : EXIT_FAILURE ;
2013-03-28 18:36:52 +04:00
}
2019-08-21 19:13:16 +03:00
VIR_TEST_MAIN_PRELOAD ( mymain , VIR_TEST_MOCK ( " vircgroup " ) )
2013-03-28 18:36:52 +04:00
# else
int
main ( void )
{
return EXIT_AM_SKIP ;
}
# endif