#!/bin/bash
# SPDX-License-Identifier: GPL-3.0+
# Copyright (C) 2018 Omar Sandoval
#
# Test the LOOP_GET_STATUS{,64} error case where the passed argument is NULL.
# Regression test for commit bdac616db9bb ("loop: fix LOOP_GET_STATUS lock
# imbalance").

. tests/loop/rc

DESCRIPTION="call LOOP_GET_STATUS{,64} with a NULL arg"
QUICK=1

requires() {
	_have_src_program loop_get_status_null
}

test() {
	local loop_dev

	echo "Running ${TEST_NAME}"

	truncate -s 1M "$TMPDIR/file"
	if ! loop_dev="$(losetup -f --show "$TMPDIR/file")"; then
		return 1
	fi

	"$SRCDIR/loop_get_status_null" "$loop_dev"
	"$SRCDIR/loop_get_status_null" "$loop_dev" 64

	losetup -d "$loop_dev"

	echo "Test complete"
}
