1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright (c) 2015-2016 Western Digital Corporation or its affiliates.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# Author: Chaitanya Kulkarni <chaitanya.kulkarni@hgst.com>
#
"""
Namespace Format testcase :-
1. Create, attach, detach, delete primary namespace and
extract the supported format information from default namespace:-
- List of the supported format.
- List of Metadata Size per format. Based on this we calculate
data protection parameter at the time of namespace.
- List of LBA Data Size per format.
2. Use the collected information and iterate through each supported
format:-
- Create namespace.
- Attach namespace.
- Run IOs on the namespace under test.
- Detach namespace
- Delete Namespace.
"""
import json
import math
import subprocess
from nvme_test import TestNVMe
class TestNVMeFormatCmd(TestNVMe):
"""
Represents Format testcase.
- Attributes:
- dps : data protection information.
- flabs : LBA format information.
- nsze : namespace size.
- ncap : namespace capacity.
- ctrl_id : controller id.
- lba_format_list : json list of supported format.
- test_log_dir : directory for logs, temp files.
"""
def setUp(self):
""" Pre Section for TestNVMeFormatCmd """
super().setUp()
self.dps = 0
self.flbas = 0
# Assuming run_ns_io with 4KiB * 10 writes.
# Calculating minimum required ncap for this workload
(ds, _) = self.get_lba_format_size()
ncap = int(math.ceil((4096*10)/ds))
self.ncap = ncap
self.nsze = ncap
self.ctrl_id = self.get_ctrl_id()
self.lba_format_list = []
self.test_log_dir = self.log_dir + "/" + self.__class__.__name__
self.setup_log_dir(self.__class__.__name__)
self.delete_all_ns()
def tearDown(self):
"""
Post Section for TestNVMeFormatCmd
- Create primary namespace.
- Attach it to controller.
- Call super class's destructor.
"""
self.assertEqual(self.create_and_validate_ns(self.default_nsid,
self.nsze,
self.ncap,
self.flbas,
self.dps), 0)
self.attach_ns(self.ctrl_id, self.default_nsid)
super().tearDown()
def attach_detach_primary_ns(self):
""" Extract supported format information using default namespace """
self.assertEqual(self.create_and_validate_ns(self.default_nsid,
self.nsze,
self.ncap,
self.flbas,
self.dps), 0)
self.assertEqual(self.attach_ns(self.ctrl_id, self.default_nsid), 0)
# read lbaf information
id_ns_cmd = f"{self.nvme_bin} id-ns {self.ctrl} " + \
f"--namespace-id={self.default_nsid} --output-format=json"
proc = subprocess.Popen(id_ns_cmd,
shell=True,
stdout=subprocess.PIPE,
encoding='utf-8')
err = proc.wait()
self.assertEqual(err, 0, "ERROR : nvme id-ns failed")
json_output = json.loads(proc.stdout.read())
self.lba_format_list = json_output['lbafs']
self.assertTrue(len(self.lba_format_list) > 0,
"ERROR : nvme id-ns could not find any lba formats")
self.assertEqual(self.detach_ns(self.ctrl_id, self.default_nsid), 0)
self.assertEqual(self.delete_and_validate_ns(self.default_nsid), 0)
self.nvme_reset_ctrl()
def test_format_ns(self):
""" Testcase main """
# extract the supported format information.
self.attach_detach_primary_ns()
print("##### Testing lba formats:")
# iterate through all supported format
for flbas, lba_format in enumerate(self.lba_format_list):
ds = lba_format['ds']
ms = lba_format['ms']
print(f"\nlba format {str(flbas)}"
f"\nds {str(ds)}"
f"\nms {str(ms)}")
dps = 1 if str(ms) == '8' else 0
err = self.create_and_validate_ns(self.default_nsid,
self.nsze,
self.ncap,
flbas,
dps)
self.assertEqual(err, 0)
self.assertEqual(self.attach_ns(self.ctrl_id, self.default_nsid), 0)
self.run_ns_io(self.default_nsid, int(ds))
self.assertEqual(self.detach_ns(self.ctrl_id, self.default_nsid), 0)
self.assertEqual(self.delete_and_validate_ns(self.default_nsid), 0)
self.nvme_reset_ctrl()
|