#!/usr/bin/env -S bats --report-formatter junit --formatter tap -j 2
# -*-sh-*-

load ../common/test_helper_functions
source ../common/functions || exit 1

if [ -s ../TEST_ENV ]; then
	source ../TEST_ENV
fi

setup() {
	if [ -n "$SIMPLE_CI" ]; then
		skip "Not supported in simple CI setup"
	fi

	OUTPUT=$(mktemp)

	check_rms
}

teardown() {
	rm -f "${OUTPUT}"
}

@test "[memlock] check increased soft limit" {
	run_serial_binary -o "${OUTPUT}" prlimit -l -o SOFT

	grep -v SOFT <"${OUTPUT}" | while IFS= read -r limit; do
		if [ "$limit" != "unlimited" ]; then
			flunk "$limit"
		fi
	done
}

@test "[memlock] check increased hard limit" {
	run_serial_binary -o "${OUTPUT}" prlimit -l -o HARD

	grep -v HARD <"${OUTPUT}" | while IFS= read -r limit; do
		if [ "$limit" != "unlimited" ]; then
			flunk "$limit"
		fi
	done
}
