memsys (1658B)
- #!/usr/bin/env atf-sh
- # SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
- atf_test_case basic cleanup
- basic_body() {
- command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found"
- [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set"
- atf_check touch ./tmp-memsys
- atf_check -- "${BWRAP:-bwrap}" --bind / / --bind ./tmp-memsys /sys/power/state ../sbin/memsys
- atf_check -o 'inline:mem' cat tmp-memsys
- }
- basic_cleanup() {
- rm -f tmp-memsys
- }
- atf_test_case chmod_000 cleanup
- chmod_000_body() {
- command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found"
- [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set"
- atf_check touch ./tmp-memsys.000
- atf_check chmod 000 ./tmp-memsys.000
- 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
- atf_check chmod 600 ./tmp-memsys.000
- atf_check -o empty cat tmp-memsys.000
- }
- chmod_000_cleanup() {
- rm -f tmp-memsys.000
- }
- atf_test_case devfull
- devfull_body() {
- command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found"
- [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set"
- 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
- }
- atf_init_test_cases() {
- cd "$(atf_get_srcdir)" || exit 1
- atf_add_test_case basic
- atf_add_test_case chmod_000
- atf_add_test_case devfull
- }