cgroup_lib.sh 1023 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. . tst_test.sh
  6. # Find mountpoint to given subsystem
  7. # get_cgroup_mountpoint SUBSYSTEM
  8. # RETURN: 0 if mountpoint found, otherwise 1
  9. get_cgroup_mountpoint()
  10. {
  11. local subsystem=$1
  12. local mntpoint
  13. [ $# -eq 0 ] && tst_brk TBROK "get_cgroup_mountpoint: subsystem not defined"
  14. mntpoint=$(grep cgroup /proc/mounts | grep -w $subsystem | awk '{ print $2 }')
  15. [ -z "$mntpoint" ] && return 1
  16. echo $mntpoint
  17. return 0
  18. }
  19. # Check if given subsystem is supported and enabled
  20. # is_cgroup_subsystem_available_and_enabled SUBSYSTEM
  21. # RETURN: 0 if subsystem supported and enabled, otherwise 1
  22. is_cgroup_subsystem_available_and_enabled()
  23. {
  24. local val
  25. local subsystem=$1
  26. [ $# -eq 0 ] && tst_brk TBROK "is_cgroup_subsystem_available_and_enabled: subsystem not defined"
  27. val=$(grep -w $subsystem /proc/cgroups | awk '{ print $4 }')
  28. [ "$val" = "1" ] && return 0
  29. return 1
  30. }