summaryrefslogtreecommitdiffstats
path: root/tests/nvme_get_lba_status_test.py
blob: 539c493763a3bc8e2cd9a00cb1e968719ebb057c (plain)
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
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This file is part of nvme-cli
#
# Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved.
#
# Author: Arunpandian J <apj.arun@samsung.com>

"""
NVMe LBA Status Log Testcase :-

    1. Execute get-lba-status on a device.
"""

import subprocess

from nvme_test import TestNVMe


class TestNVMeGetLbaStatusCmd(TestNVMe):

    """
    Represents Get LBA Status test.
    """

    def setUp(self):
        """ Pre Section for TestNVMeGetLbaStatusCmd. """
        super().setUp()
        self.start_lba = 0
        self.block_count = 0
        self.namespace = 1
        self.max_dw = 1
        self.action = 11
        self.range_len = 1
        self.setup_log_dir(self.__class__.__name__)

    def tearDown(self):
        """
        Post Section for TestNVMeGetLbaStatusCmd.

            - Call super class's destructor.
        """
        super().tearDown()

    def get_lba_status(self):
        """ Wrapper for executing nvme get-lba-status.
            - Args:
                - None
            - Returns:
                - 0 on success, error code on failure.
        """
        err = 0
        get_lba_status_cmd = "nvme get-lba-status " + self.ctrl + \
                             " --namespace-id=" + str(self.namespace) + \
                             " --start-lba=" + str(self.start_lba) + \
                             " --max-dw=" + str(self.max_dw) + \
                             " --action=" + str(self.action) + \
                             " --range-len=" + str(self.range_len)
        proc = subprocess.Popen(get_lba_status_cmd,
                                shell=True,
                                stdout=subprocess.PIPE,
                                encoding='utf-8')
        get_lba_status_output = proc.communicate()[0]
        print("\n" + get_lba_status_output + "\n")
        err = proc.wait()
        return err

    def test_get_lba_status(self):
        """ Testcase main """
        self.assertEqual(self.get_lba_status(), 0)