Blame test/dax_kmem_env_var_test.py

Packit Service 724aca
#
Packit Service 724aca
#  Copyright (C) 2019 Intel Corporation.
Packit Service 724aca
#  All rights reserved.
Packit Service 724aca
#
Packit Service 724aca
#  Redistribution and use in source and binary forms, with or without
Packit Service 724aca
#  modification, are permitted provided that the following conditions are met:
Packit Service 724aca
#  1. Redistributions of source code must retain the above copyright notice(s),
Packit Service 724aca
#     this list of conditions and the following disclaimer.
Packit Service 724aca
#  2. Redistributions in binary form must reproduce the above copyright notice(s),
Packit Service 724aca
#     this list of conditions and the following disclaimer in the documentation
Packit Service 724aca
#     and/or other materials provided with the distribution.
Packit Service 724aca
#
Packit Service 724aca
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
Packit Service 724aca
#  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
Packit Service 724aca
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
Packit Service 724aca
#  EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
Packit Service 724aca
#  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit Service 724aca
#  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Packit Service 724aca
#  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Packit Service 724aca
#  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
Packit Service 724aca
#  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
Packit Service 724aca
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service 724aca
#
Packit Service 724aca
from distutils.spawn import find_executable
Packit Service 724aca
from python_framework import CMD_helper
Packit Service 724aca
import os
Packit Service 724aca
Packit Service 724aca
class Test_dax_kmem_env_var(object):
Packit Service 724aca
    os.environ["PATH"] += os.pathsep + os.path.dirname(os.path.dirname(__file__))
Packit Service 724aca
    binary_path = find_executable("memkind-auto-dax-kmem-nodes")
Packit Service 724aca
    environ_err_test = "../environ_err_dax_kmem_malloc_test"
Packit Service 724aca
    environ_err_positive_test = "../environ_err_dax_kmem_malloc_positive_test"
Packit Service 724aca
    expected_libnuma_warning = "libnuma: Warning: node argument -1 is out of range\n\n"
Packit Service 724aca
    fail_msg = "Test failed with:\n {0}"
Packit Service 724aca
    cmd_helper = CMD_helper()
Packit Service 724aca
Packit Service 724aca
    def get_dax_kmem_nodes(self, nodemask=None):
Packit Service 724aca
        """ This function executes memkind function 'get_mbind_nodemask' and returns its output - comma-separated DAX_KMEM nodes """
Packit Service 724aca
        command = self.binary_path
Packit Service 724aca
        if (nodemask):
Packit Service 724aca
            command = "MEMKIND_DAX_KMEM_NODES={}".format(nodemask) + command
Packit Service 724aca
        output, retcode = self.cmd_helper.execute_cmd(command)
Packit Service 724aca
        assert retcode == 0, self.fail_msg.format("\nError: Execution of \'{0}\' returns {1}, \noutput: {2}".format(command, retcode, output))
Packit Service 724aca
        print("\nExecution of {} returns output {}".format(command, output))
Packit Service 724aca
        return output
Packit Service 724aca
Packit Service 724aca
    def test_TC_MEMKIND_dax_kmem_env_var_compare_nodemask_default_and_env_variable(self):
Packit Service 724aca
        """ This test checks whether dax_kmem_nodemask_default and dax_kmem_nodemask_env_variable have the same value """
Packit Service 724aca
        dax_kmem_nodemask_default = self.get_dax_kmem_nodes()
Packit Service 724aca
        dax_kmem_nodemask_env_variable = self.get_dax_kmem_nodes(dax_kmem_nodemask_default)
Packit Service 724aca
        assert dax_kmem_nodemask_default == dax_kmem_nodemask_env_variable, self.fail_msg.format("Error: Nodemask dax_kmem_nodemask_default ({0}) " \
Packit Service 724aca
               "is not the same as nodemask dax_kmem_nodemask_env_variable ({1})".format(dax_kmem_nodemask_default, dax_kmem_nodemask_env_variable))
Packit Service 724aca
Packit Service 724aca
    def test_TC_MEMKIND_dax_kmem_env_var_negative_memkind_malloc(self):
Packit Service 724aca
        """ This test sets usupported value of MEMKIND_DAX_KMEM_NODES, then tries to perform a successful allocation from DRAM using memkind_malloc() """
Packit Service 724aca
        command = "MEMKIND_DAX_KMEM_NODES=-1 " + self.cmd_helper.get_command_path(self.environ_err_test)
Packit Service 724aca
        output, retcode = self.cmd_helper.execute_cmd(command)
Packit Service 724aca
        assert retcode != 0, self.fail_msg.format("\nError: Execution of: \'{0}\' returns: {1} \noutput: {2}".format(command, retcode, output))
Packit Service 724aca
        assert self.expected_libnuma_warning == output, self.fail_msg.format("Error: expected libnuma warning ({0}) " \
Packit Service 724aca
               "was not found (output: {1})").format(self.expected_libnuma_warning, output)
Packit Service 724aca
Packit Service 724aca
    def test_TC_MEMKIND_dax_kmem_env_var_proper_memkind_malloc(self):
Packit Service 724aca
        """ This test checks if allocation is performed on persistent memory correctly """
Packit Service 724aca
        dax_kmem_nodemask_default = self.get_dax_kmem_nodes().strip()
Packit Service 724aca
        command = "MEMKIND_DAX_KMEM_NODES={} ".format(dax_kmem_nodemask_default) + self.cmd_helper.get_command_path(self.environ_err_positive_test)
Packit Service 724aca
        output, retcode = self.cmd_helper.execute_cmd(command)
Packit Service 724aca
        assert retcode == 0, self.fail_msg.format("\nError: Execution of: \'{0}\' returns: {1} \noutput: {2}".format(command, retcode, output))