From patchwork Mon Aug 15 19:22:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 12944087 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C89BCC00140 for ; Mon, 15 Aug 2022 21:28:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345968AbiHOV23 (ORCPT ); Mon, 15 Aug 2022 17:28:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348181AbiHOV1B (ORCPT ); Mon, 15 Aug 2022 17:27:01 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54BBCE9A81 for ; Mon, 15 Aug 2022 12:22:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660591379; x=1692127379; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PBfYQPgZSq7q+c20aALR0P51XJsCwD7YzY7SKX4OEDM=; b=CPDxzWS/3uQTfFF1DGgZT/6FjneruLJiRlDxa2g7atmvK4RyBbVS4Wus TYnUz+0e2sLPvml4U2nrVAnbRr9I9ZRQcxK1/5ftkMyS3OMaoqk6Fv4dX QaQtabHMB3elMiZeDt66e0r+fDoxb1KnSZ4Ru05BEoTPJNWAb8RAVhv4T //+As4kztKBB8+siTTpa1VSnoa0fmYlsosf6rdmGz+HQ9LR3hkfryzjV5 0YHjcqxJ9vz8YDAg7npc4qp2Ek3pvq9XORtuqb/H7w3edOWgITRu8jKph 8dxJBTKaN0/BWE4JGZBRW3hYSE/wWP1go/lBOxBjbLUEIAcw/gnQ5yr/F Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10440"; a="293313137" X-IronPort-AV: E=Sophos;i="5.93,239,1654585200"; d="scan'208";a="293313137" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Aug 2022 12:22:22 -0700 X-IronPort-AV: E=Sophos;i="5.93,239,1654585200"; d="scan'208";a="606758268" Received: from smadiset-mobl1.amr.corp.intel.com (HELO vverma7-desk1.intel.com) ([10.209.5.99]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Aug 2022 12:22:21 -0700 From: Vishal Verma To: Cc: , Dan Williams , Alison Schofield , Ira Weiny , Dave Jiang , Vishal Verma Subject: [ndctl PATCH v3 10/11] test: add a cxl-create-region test Date: Mon, 15 Aug 2022 13:22:13 -0600 Message-Id: <20220815192214.545800-11-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220815192214.545800-1-vishal.l.verma@intel.com> References: <20220815192214.545800-1-vishal.l.verma@intel.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4439; h=from:subject; bh=PBfYQPgZSq7q+c20aALR0P51XJsCwD7YzY7SKX4OEDM=; b=owGbwMvMwCXGf25diOft7jLG02pJDEm/5jy7IvjewHTetdgFKT8Y571nd7hy9GPL9bw0kQoxucDN khZrO0pZGMS4GGTFFFn+7vnIeExuez5PYIIjzBxWJpAhDFycAjAR/xxGhq6ltRI3c2PYTh4r7Nk7vU aOp3s+85cVBiviH27SdFtbv5bhn3K021sf8+bGPYfuyIXsYy7sVjilq1ew6nPKXPkTTPl3mAE= X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Add a unit test to exercise the cxl-create-region command with different combinations of memdevs and decoders, using cxl_test based mocked devices. Cc: Dan Williams Reviewed-by: Dan Williams Signed-off-by: Vishal Verma --- test/cxl-create-region.sh | 125 ++++++++++++++++++++++++++++++++++++++ test/meson.build | 2 + 2 files changed, 127 insertions(+) create mode 100644 test/cxl-create-region.sh diff --git a/test/cxl-create-region.sh b/test/cxl-create-region.sh new file mode 100644 index 0000000..66df38f --- /dev/null +++ b/test/cxl-create-region.sh @@ -0,0 +1,125 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2022 Intel Corporation. All rights reserved. + +. $(dirname $0)/common + +rc=1 + +set -ex + +trap 'err $LINENO' ERR + +check_prereq "jq" + +modprobe -r cxl_test +modprobe cxl_test +udevadm settle + +destroy_regions() +{ + if [[ "$*" ]]; then + $CXL destroy-region -f -b cxl_test "$@" + else + $CXL destroy-region -f -b cxl_test all + fi +} + +create_x1_region() +{ + mem="$1" + + # find a pmem capable root decoder for this mem + decoder=$($CXL list -b cxl_test -D -d root -m "$mem" | + jq -r ".[] | + select(.pmem_capable == true) | + select(.nr_targets == 1) | + .decoder") + + if [[ ! $decoder ]]; then + echo "no suitable decoder found for $mem, skipping" + return + fi + + # create region + region=$($CXL create-region -d "$decoder" -m "$mem" | jq -r ".region") + + if [[ ! $region ]]; then + echo "create-region failed for $decoder / $mem" + err "$LINENO" + fi + + # cycle disable/enable + $CXL disable-region --bus=cxl_test "$region" + $CXL enable-region --bus=cxl_test "$region" + + # cycle destroying and creating the same region + destroy_regions "$region" + region=$($CXL create-region -d "$decoder" -m "$mem" | jq -r ".region") + + if [[ ! $region ]]; then + echo "create-region failed for $decoder / $mem" + err "$LINENO" + fi + destroy_regions "$region" +} + +create_subregions() +{ + slice=$((256 << 20)) + mem="$1" + + # find a pmem capable root decoder for this mem + decoder=$($CXL list -b cxl_test -D -d root -m "$mem" | + jq -r ".[] | + select(.pmem_capable == true) | + select(.nr_targets == 1) | + .decoder") + + if [[ ! $decoder ]]; then + echo "no suitable decoder found for $mem, skipping" + return + fi + + size="$($CXL list -m "$mem" | jq -r '.[].pmem_size')" + if [[ ! $size ]]; then + echo "$mem: unable to determine size" + err "$LINENO" + fi + + num_regions=$((size / slice)) + + declare -a regions + for (( i = 0; i < num_regions; i++ )); do + regions[$i]=$($CXL create-region -d "$decoder" -m "$mem" -s "$slice" | jq -r ".region") + if [[ ! ${regions[$i]} ]]; then + echo "create sub-region failed for $decoder / $mem" + err "$LINENO" + fi + udevadm settle + done + + echo "created $num_regions subregions:" + for (( i = 0; i < num_regions; i++ )); do + echo "${regions[$i]}" + done + + for (( i = (num_regions - 1); i >= 0; i-- )); do + destroy_regions "${regions[$i]}" + done +} + +# test reading labels directly through cxl-cli +readarray -t mems < <("$CXL" list -b cxl_test -M | jq -r '.[].memdev') + +for mem in ${mems[@]}; do + create_x1_region "$mem" +done + +# test multiple subregions under the same decoder, using slices of the same memdev +# to test out back-to-back pmem DPA allocations on memdevs +for mem in ${mems[@]}; do + create_subregions "$mem" +done + +modprobe -r cxl_test diff --git a/test/meson.build b/test/meson.build index b382f46..5953c28 100644 --- a/test/meson.build +++ b/test/meson.build @@ -153,6 +153,7 @@ track_uuid = find_program('track-uuid.sh') cxl_topo = find_program('cxl-topology.sh') cxl_sysfs = find_program('cxl-region-sysfs.sh') cxl_labels = find_program('cxl-labels.sh') +cxl_create_region = find_program('cxl-create-region.sh') tests = [ [ 'libndctl', libndctl, 'ndctl' ], @@ -180,6 +181,7 @@ tests = [ [ 'cxl-topology.sh', cxl_topo, 'cxl' ], [ 'cxl-region-sysfs.sh', cxl_sysfs, 'cxl' ], [ 'cxl-labels.sh', cxl_labels, 'cxl' ], + [ 'cxl-create-region.sh', cxl_create_region, 'cxl' ], ] if get_option('destructive').enabled()