#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2018-2019, Intel Corporation
#
#
# pmempool_create/TEST11 -- test for create command with badblocks
#                           - bad blocks in the regular file
#

. ../unittest/unittest.sh

require_test_type medium
require_build_type debug nondebug

require_badblock_tests_enabled block_device
require_linked_with_ndctl $PMEMPOOL$EXESUFFIX

setup

. ../common_badblock.sh

MOUNT_DIR="$DIR/mnt-pmem"
badblock_test_init block_device $MOUNT_DIR

FILE="$MOUNT_DIR/testfile0"

fallocate -l 10M $FILE
fallocate -l 10M $DIR/testfile1
fallocate -l 10M $DIR/testfile2

LOG=out${UNITTEST_NUM}.log
rm -f $LOG && touch $LOG

POOLSET=$DIR/testset1
create_poolset $POOLSET 10M:$DIR/testfile1:x 10M:$FILE:x 10M:$DIR/testfile2:x

# inject bad block:
SECTOR=$(expect_normal_exit $EXTENTS $FILE -l 100)
ndctl_inject_error $NAMESPACE $SECTOR 1

expect_bad_blocks $NAMESPACE

expect_abnormal_exit "$PMEMPOOL$EXESUFFIX create obj --layout pmempool$SUFFIX $POOLSET &>> $LOG"

ndctl_uninject_error $FULLDEV $NAMESPACE $SECTOR 1
badblock_test_fini $MOUNT_DIR

check

pass
