logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git

memsys (1658B)


  1. #!/usr/bin/env atf-sh
  2. # SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
  4. atf_test_case basic cleanup
  5. basic_body() {
  6. command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found"
  7. [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set"
  8. atf_check touch ./tmp-memsys
  9. atf_check -- "${BWRAP:-bwrap}" --bind / / --bind ./tmp-memsys /sys/power/state ../sbin/memsys
  10. atf_check -o 'inline:mem' cat tmp-memsys
  11. }
  12. basic_cleanup() {
  13. rm -f tmp-memsys
  14. }
  15. atf_test_case chmod_000 cleanup
  16. chmod_000_body() {
  17. command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found"
  18. [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set"
  19. atf_check touch ./tmp-memsys.000
  20. atf_check chmod 000 ./tmp-memsys.000
  21. atf_check -s exit:1 -e 'inline:memsys: open("/sys/power/state"): Permission denied\n' -- "${BWRAP:-bwrap}" --bind / / --bind ./tmp-memsys.000 /sys/power/state ../sbin/memsys
  22. atf_check chmod 600 ./tmp-memsys.000
  23. atf_check -o empty cat tmp-memsys.000
  24. }
  25. chmod_000_cleanup() {
  26. rm -f tmp-memsys.000
  27. }
  28. atf_test_case devfull
  29. devfull_body() {
  30. command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found"
  31. [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set"
  32. atf_check -s exit:1 -e 'inline:memsys: open("/sys/power/state"): Permission denied\n' -- "${BWRAP:-bwrap}" --bind / / --bind /dev/full /sys/power/state ../sbin/memsys
  33. }
  34. atf_init_test_cases() {
  35. cd "$(atf_get_srcdir)" || exit 1
  36. atf_add_test_case basic
  37. atf_add_test_case chmod_000
  38. atf_add_test_case devfull
  39. }