#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2023, Intel Corporation

#
# src/test/pmem_is_pmem_posix/TEST0 -- unit test for pmem_is_pmem
#

. ../unittest/unittest.sh

require_test_type medium
set_test_labels fault_injection
require_fs_type none
require_dax_devices 1

setup

# two mm entries
#
# 7fff77423000 2147479552
#	start at first mm entry, extends into second: should produce: 1
# 7fff77423000 2147483648
#	exactly matches sum of both mm entries: should produce: 1
# 7fff77423000 8192
#	start at first mm entry, extends into second: should produce: 1
# 7fff77423000 4096
#	entirely encompassed by first mm entry: should produce: 1
# 7fff77424000 2147479552
#	exactly matches second mm entry, should produce: 1
# 7fff77424000 2147483648
#	extends past second mm entry, should produce: 0
# 7fff77424000 8192
#	entirely encompassed by second mm entry: should produce: 1
# 7fff77428000 10240
#	subset of second mm entry: should produce: 1
# 7fff77423000 0
#	starts at first mm entry: should produce: 1
# 7fff77424000 0
#	starts at second mm entry: should produce: 1
# 7fff77424000 0xffffffffffffffff
#	extends past second mm entry, should produce: 0
# 7fff77423008 1
#	entirely encompassed by first mm entry: should produce: 1
# 7fff77423ff0 32
#	start at first mm entry, extends into second: should produce: 1

expect_normal_exit ./pmem_is_pmem_posix$EXESUFFIX\
	f 0x7fff77423000 4096 MAP_SYNC\
	a 0x7fff77423000 4096 MAP_SYNC\
	a 0x7fff77424000 2147479552 DEV_DAX ${DEVICE_DAX_PATH[0]}\
	\
	t 0x7fff77423000 2147479552\
	t 0x7fff77423000 2147483648\
	t 0x7fff77423000 8192\
	t 0x7fff77423000 4096\
	t 0x7fff77424000 2147479552\
	t 0x7fff77424000 2147483648\
	t 0x7fff77424000 8192\
	t 0x7fff77428000 10240\
	t 0x7fff77423000 0\
	t 0x7fff77424000 0\
	t 0x7fff77424000 0xffffffffffffffff\
	t 0x7fff77423008 1\
	t 0x7fff77423FF0 32

check

pass
