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

#
# src/test/obj_reorder_basic/TEST0 -- unit test for the reordering script
#

. ../unittest/unittest.sh

# it doesn't make sense to run in local directory
require_fs_type pmem non-pmem
require_build_type debug
require_test_type medium
require_pmemcheck_version_ge 1 0
require_pmemcheck_version_lt 2 0
require_pmreorder

setup

export PMEMOBJ_LOG_LEVEL=10

POOL_SIZE=$((32*1024*1024))
expect_normal_exit $PMEMPOOL$EXESUFFIX create --layout intro_1 obj $DIR/testfile -s $POOL_SIZE

BIN="./obj_reorder_basic$EXESUFFIX"
PMEMCHECK_CMD="$BIN w $DIR/testfile"
PMREORDER_CMD="$BIN c"

pmreorder_create_store_log $DIR/testfile "$PMEMCHECK_CMD"
pmreorder_expect_success ReorderFull "PMREORDER_MARKER_WRITE=ReorderPartial" "$PMREORDER_CMD"

$GREP -c "pmemobj_open.BEGIN" store_log$UNITTEST_NUM.log > grep$UNITTEST_NUM.log || true
$GREP -c "pmemobj_open.END" store_log$UNITTEST_NUM.log >> grep$UNITTEST_NUM.log || true
$GREP -c "pmemobj_root_construct.BEGIN" store_log$UNITTEST_NUM.log >> grep$UNITTEST_NUM.log || true
$GREP -c "pmemobj_root_construct.END" store_log$UNITTEST_NUM.log >> grep$UNITTEST_NUM.log || true

check

pass
