• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
4# Copyright (c) 2018-2019 ARM Ltd. All Rights Reserved.
5
6. tst_test.sh
7
8# Find mountpoint to given subsystem
9# get_cgroup_mountpoint SUBSYSTEM
10# RETURN: 0 if mountpoint found, otherwise 1
11get_cgroup_mountpoint()
12{
13	local subsystem=$1
14	local mntpoint
15
16	[ $# -eq 0 ] && tst_brk TBROK "get_cgroup_mountpoint: subsystem not defined"
17
18	mntpoint=$(grep cgroup /proc/mounts | grep -w $subsystem | awk '{ print $2 }')
19	[ -z "$mntpoint" ] && return 1
20
21	echo $mntpoint
22	return 0
23}
24
25# Check if given subsystem is supported and enabled
26# is_cgroup_subsystem_available_and_enabled SUBSYSTEM
27# RETURN: 0 if subsystem supported and enabled, otherwise 1
28is_cgroup_subsystem_available_and_enabled()
29{
30	local val
31	local subsystem=$1
32
33	[ $# -eq 0 ] && tst_brk TBROK "is_cgroup_subsystem_available_and_enabled: subsystem not defined"
34
35	val=$(grep -w $subsystem /proc/cgroups | awk '{ print $4 }')
36	[ "$val" = "1" ] && return 0
37
38	return 1
39}
40