public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [tests/selinux] pr775-checkpolicy-revdeps: Add basic test which covers systemd-oomd
@ 2026-09-11 13:23 Zdenek Pytela
0 siblings, 0 replies; only message in thread
From: Zdenek Pytela @ 2026-09-11 13:23 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : tests/selinux
Branch : pr775-checkpolicy-revdeps
Commit : fc90e6893021dc261f901c7b5d87437aaad7b70a
Author : Zdenek Pytela <zpytela@redhat.com>
Date : 2025-07-23T15:37:36+00:00
Stats : +310/-0 in 6 file(s)
URL : https://src.fedoraproject.org/tests/selinux/c/fc90e6893021dc261f901c7b5d87437aaad7b70a?branch=pr775-checkpolicy-revdeps
Log:
Add basic test which covers systemd-oomd
---
diff --git a/selinux-policy/systemd-oomd/Makefile b/selinux-policy/systemd-oomd/Makefile
new file mode 100644
index 0000000..d8c2bcd
--- /dev/null
+++ b/selinux-policy/systemd-oomd/Makefile
@@ -0,0 +1,79 @@
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Makefile of /CoreOS/selinux-policy/Sanity/systemd-oomd
+# Description: Testing systemd-oomd service
+# Author: Zdenek Pytela <zpytela@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Copyright (c) 2010 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing
+# to use, modify, copy, or redistribute it subject to the terms
+# and conditions of the GNU General Public License version 2.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+export TEST=/CoreOS/selinux-policy/Sanity/systemd-oomd
+export TESTVERSION=1.0
+
+BUILT_FILES=
+
+FILES=$(METADATA) runtest.sh Makefile PURPOSE ssh-sleep40.exp ssh-nosleep.exp
+
+.PHONY: all install download clean
+
+run: $(FILES) build
+ ./runtest.sh
+
+build: $(BUILT_FILES)
+ chmod a+x runtest.sh
+ chcon -t bin_t runtest.sh
+
+clean:
+ rm -f *~ $(BUILT_FILES)
+
+include /usr/share/rhts/lib/rhts-make.include
+
+$(METADATA): Makefile
+ @echo "Owner: Zdenek Pytela <zpytela@redhat.com>" > $(METADATA)
+ @echo "Name: $(TEST)" >> $(METADATA)
+ @echo "TestVersion: $(TESTVERSION)" >> $(METADATA)
+ @echo "Path: $(TEST_DIR)" >> $(METADATA)
+ @echo "Description: Testing systemd-oomd" >> $(METADATA)
+ @echo "Type: Sanity" >> $(METADATA)
+ @echo "TestTime: 15m" >> $(METADATA)
+ @echo "RunFor: selinux-policy" >> $(METADATA)
+ @echo "Requires: audit" >> $(METADATA)
+ @echo "Requires: expect" >> $(METADATA)
+ @echo "Requires: libselinux-utils" >> $(METADATA)
+ @echo "Requires: policycoreutils" >> $(METADATA)
+ @echo "Requires: selinux-policy" >> $(METADATA)
+ @echo "Requires: selinux-policy-targeted" >> $(METADATA)
+ @echo "RhtsRequires: library(selinux-policy/common)" >> $(METADATA)
+ @echo "Priority: Normal" >> $(METADATA)
+ @echo "License: GPLv2" >> $(METADATA)
+ @echo "Confidential: no" >> $(METADATA)
+ @echo "Destructive: no" >> $(METADATA)
+ @echo "Environment: AVC_ERROR=+no_avc_check" >> $(METADATA)
+ @echo "Environment: SYSTEMD_PAGER=\"\"" >> $(METADATA)
+ @echo "Releases: -RHEL4" >> $(METADATA)
+ @echo "Releases: -RHEL5" >> $(METADATA)
+ @echo "Releases: -RHEL6" >> $(METADATA)
+ @echo "Releases: -RHEL7" >> $(METADATA)
+ @echo "Releases: -RHEL8" >> $(METADATA)
+ @echo "Releases: -RHEL9" >> $(METADATA)
+ @echo "Releases: -RHEL10" >> $(METADATA)
+
+ rhts-lint $(METADATA)
+
diff --git a/selinux-policy/systemd-oomd/PURPOSE b/selinux-policy/systemd-oomd/PURPOSE
new file mode 100644
index 0000000..90bc7a4
--- /dev/null
+++ b/selinux-policy/systemd-oomd/PURPOSE
@@ -0,0 +1,5 @@
+PURPOSE of /CoreOS/selinux-policy/Sanity/systemd-oomd
+Author: Zdenek Pytela <zpytela@redhat.com>
+
+Test systemd-oomd service
+
diff --git a/selinux-policy/systemd-oomd/main.fmf b/selinux-policy/systemd-oomd/main.fmf
new file mode 100644
index 0000000..cd29105
--- /dev/null
+++ b/selinux-policy/systemd-oomd/main.fmf
@@ -0,0 +1,39 @@
+summary: systemd-oomd - userspace out-of-memory (OOM) killer
+description: |+
+ Testing systemd-oomd service
+
+contact: Zdenek Pytela <zpytela@redhat.com>
+component:
+ - selinux-policy
+ - systemd
+test: ./runtest.sh
+framework: beakerlib
+require:
+ - library(selinux-policy/common)
+recommend:
+ - audit
+ - expect
+ - libselinux-utils
+ - policycoreutils
+ - selinux-policy
+ - selinux-policy-targeted
+ - setools-console
+environment:
+ AVC_ERROR: +no_avc_check
+duration: 5m
+enabled: true
+tag:
+ - NoRHEL4
+ - NoRHEL5
+ - NoRHEL6
+ - NoRHEL7
+ - NoRHEL8
+ - NoRHEL9
+ - NoRHEL10
+ - TierCandidatesPASS
+ - targeted
+ - NoRHIVOS
+adjust:
+ - enabled: false
+ when: distro == rhel-4, rhel-5, rhel-6, rhel-7, rhel-8, rhel-9, rhel-10
+ continue: false
diff --git a/selinux-policy/systemd-oomd/runtest.sh b/selinux-policy/systemd-oomd/runtest.sh
new file mode 100755
index 0000000..1534656
--- /dev/null
+++ b/selinux-policy/systemd-oomd/runtest.sh
@@ -0,0 +1,147 @@
+#!/bin/bash
+# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# runtest.sh of /CoreOS/selinux-policy/Sanity/systemd-oomd
+# Description: Testing systemd-oomd service
+# Author: Zdenek Pytela <zpytela@redhat.com>
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# Copyright (c) 2010 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing
+# to use, modify, copy, or redistribute it subject to the terms
+# and conditions of the GNU General Public License version 2.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+# Include rhts environment
+. /usr/share/beakerlib/beakerlib.sh || exit 1
+
+PACKAGE="selinux-policy"
+SERVICE_NAME="systemd-oomd"
+FILE_PATH="/usr/lib/systemd/systemd-oomd"
+FILE_CONTEXT="systemd_oomd_exec_t"
+PROCESS_NAME="systemd-oomd"
+PROCESS_CONTEXT="systemd_oomd_t"
+
+### systemd-oomd is a system service that uses cgroups-v2 and pressure stall
+### information (PSI) to monitor and take a corrective action before an OOM occurs
+### in the kernel space.
+### Monitoring and actions on units can be enabled by setting ManagedOOMSwap=
+### and ManagedOOMMemoryPressure=. Cgroups of units with ManagedOOMSwap= or
+### ManagedOOMMemoryPressure= set to kill will be monitored.
+
+rlJournalStart
+ if [ ! -x ${FILE_PATH} ]; then
+ rlLog "Not applicable to this OS version."
+ rlJournalEnd
+ exit 0
+ fi
+
+ rlPhaseStartSetup
+ rlRun "rlImport 'selinux-policy/common'" 0,1
+ rlSESatisfyRequires
+ rlAssertRpm ${PACKAGE}
+ rlAssertRpm ${PACKAGE}-targeted
+ rlSEConfigureSSH
+ rlSESetEnforce
+ rlSEStatus
+ rlSESetTimestamp
+ rlRun "cat /etc/system-release"
+ rlRun "uname -a"
+ rlRun "rpm -qa \"selinux-*\" \"systemd*\"|sort"
+ rlPhaseEnd
+
+ rlPhaseStartTest "SELinux contexts and rules"
+ # Is the service SELinux confined?
+ CONTEXT=$(stat -c"%C" "${FILE_PATH}")
+ if [[ ${CONTEXT} =~ ":init_exec_t:" ]] ; then
+ rlLog "The ${SERVICE_NAME} service is not SELinux confined."
+ else
+ rlSEMatchPathCon "${FILE_PATH}" "${FILE_CONTEXT}"
+ rlSEMatchPathCon "/proc/pressure" "proc_psi_t"
+ rlSESearchRule "allow systemd_oomd_t proc_psi_t : file { getattr ioctl lock open read } [ ]"
+ rlSESearchRule "allow systemd_oomd_t domain : dir { getattr ioctl lock open read search } [ ]"
+ rlSESearchRule "allow systemd_oomd_t domain : file { getattr ioctl lock open read } [ ]"
+ rlSESearchRule "allow systemd_oomd_t cgroup_t : dir { getattr ioctl lock open read search setattr write } [ ]"
+ rlSESearchRule "allow systemd_oomd_t domain : process { sigkill } [ ]"
+ rlSESearchRule "allow systemd_oomd_t self : capability { kill } [ ]"
+ fi
+ rlPhaseEnd
+
+ ### Basic systemd-oomd setup
+ ### https://fedoraproject.org/wiki/Changes/EnableSystemdOomd#How_to_test
+ rlPhaseStartTest "Real scenario"
+
+ # sd-oomd conflicts earlyoom
+ if systemctl list-unit-files earlyoom.service &>/dev/null; then
+ rlRun "systemctl disable --now --quiet earlyoom.service"
+ fi
+ rlRun "systemctl enable --now ${SERVICE_NAME}"
+ rlRun "systemctl status ${SERVICE_NAME}"
+
+ # enable swap-based killing on all units in the root slice
+ cat >> /etc/systemd/system/-.slice.d/override.conf << EOF
+[Slice]
+ManagedOOMSwap=kill
+EOF
+
+ # memory pressure example settings
+ cat >> /etc/systemd/system/user@.service.d/override.conf << EOF
+[Service]
+ManagedOOMMemoryPressure=kill
+ManagedOOMMemoryPressureLimit=10%
+EOF
+
+ rlRun "systemctl daemon-reload"
+ rlRun "systemctl restart ${SERVICE_NAME}"
+ rlRun "systemctl status ${SERVICE_NAME}"
+
+ # create a user and run a stress test - it can hang the system for a while
+ USER_NAME="user${RANDOM}"
+ USER_SECRET="S3kr3T${RANDOM}"
+ rlRun "useradd -G systemd-journal ${USER_NAME}"
+ rlRun "echo ${USER_SECRET} | passwd --stdin ${USER_NAME}"
+
+ USER_ID=$(id -u ${USER_NAME})
+ SYSTEM_SERVICE_NAME="user@${USER_ID}.service"
+ USER_SERVICE_NAME="useroomcheck-${RANDOM}.service"
+ rlRun "./ssh-sleep40.exp ${USER_NAME} ${USER_SECRET} localhost systemd-run --user -u ${USER_SERVICE_NAME} tail /dev/zero"
+
+ rlLog "Checking journal for the oom killer string"
+ rlRun "./ssh-nosleep.exp ${USER_NAME} ${USER_SECRET} localhost journalctl -u ${USER_SERVICE_NAME} -g \"A process of this unit has been killed by the OOM killer\""
+ rlRun "./ssh-nosleep.exp ${USER_NAME} ${USER_SECRET} localhost journalctl --user -u ${USER_SERVICE_NAME} -g \"A process of this unit has been killed by the OOM killer\""
+
+ rlRun "systemctl status ${SERVICE_NAME}"
+ if [ "${DEBUG}" = "yes" ]; then
+ rlLog "Displaying list of monitored cgroups and pressure information"
+ rlRun "oomctl dump"
+ rlLog "Displaying journal content for the system ${SYSTEM_SERVICE_NAME} service"
+ rlRun "journalctl -u ${SYSTEM_SERVICE_NAME}"
+ rlLog "Displaying journal content for the user ${USER_SERVICE_NAME} service"
+ rlRun "./ssh-nosleep.exp ${USER_NAME} ${USER_SECRET} localhost journalctl --user -u ${USER_SERVICE_NAME}"
+ fi
+ rlPhaseEnd
+
+ ### cleanup, restoring the previous content
+ rlPhaseStartCleanup
+ rlRun "userdel -rf ${USER_NAME}"
+ rm -f /etc/systemd/system/-.slice.d/override.conf
+ rm -f /etc/systemd/system/user@.service.d/override.conf
+ rlRun "systemctl daemon-reload"
+ rlSECheckAVC
+ rlPhaseEnd
+ rlJournalPrintText
+rlJournalEnd
diff --git a/selinux-policy/systemd-oomd/ssh-nosleep.exp b/selinux-policy/systemd-oomd/ssh-nosleep.exp
new file mode 100755
index 0000000..33e5d4f
--- /dev/null
+++ b/selinux-policy/systemd-oomd/ssh-nosleep.exp
@@ -0,0 +1,20 @@
+#!/usr/bin/expect -f
+# Expect script for SSH logging as $username to $hostname using $password and executing $command.
+# Usage:
+# ./ssh.exp username password hostname command
+set username [lrange $argv 0 0]
+set password [lrange $argv 1 1]
+set hostname [lrange $argv 2 2]
+set command [lrange $argv 3 10]
+set timeout 30
+# connect to remote host and execute given command
+log_user 1
+spawn ssh -t $username@$hostname "$command"
+expect {
+ -nocase "yes/no" { send -- "yes\r" ; exp_continue }
+ -nocase "password" { send -- "$password\r" }
+}
+log_user 1
+# send -- "\r"
+expect eof
+
diff --git a/selinux-policy/systemd-oomd/ssh-sleep40.exp b/selinux-policy/systemd-oomd/ssh-sleep40.exp
new file mode 100755
index 0000000..69563d6
--- /dev/null
+++ b/selinux-policy/systemd-oomd/ssh-sleep40.exp
@@ -0,0 +1,20 @@
+#!/usr/bin/expect -f
+# Expect script for SSH logging as $username to $hostname using $password and executing $command.
+# Usage:
+# ./ssh.exp username password hostname command
+set username [lrange $argv 0 0]
+set password [lrange $argv 1 1]
+set hostname [lrange $argv 2 2]
+set command [lrange $argv 3 10]
+set timeout 30
+# connect to remote host and execute given command
+log_user 1
+spawn ssh -t $username@$hostname "$command ; sleep 40"
+expect {
+ -nocase "yes/no" { send -- "yes\r" ; exp_continue }
+ -nocase "password" { send -- "$password\r" }
+}
+log_user 1
+# send -- "\r"
+expect eof
+
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-09-11 13:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-11 13:23 [tests/selinux] pr775-checkpolicy-revdeps: Add basic test which covers systemd-oomd Zdenek Pytela
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox