Blame test/autohbw_test.py

Packit Service 7f3b24
# SPDX-License-Identifier: BSD-2-Clause
Packit Service 7f3b24
# Copyright (C) 2016 - 2020 Intel Corporation.
Packit 345191
Packit 345191
import pytest
Packit 345191
import os
Packit 345191
from python_framework import CMD_helper
Packit 345191
Packit 345191
def _get_lib_path():
Packit 345191
    for p in ["/usr/lib64", "/usr/lib"]:
Packit 345191
        if os.path.isdir(p):
Packit 345191
            return p
Packit 345191
    raise Exception("Cannot find library path in OS")
Packit 345191
Packit 345191
class Test_autohbw(object):
Packit 345191
    binary = "../autohbw_test_helper"
Packit 345191
    fail_msg = "Test failed with:\n {0}"
Packit 345191
    test_prefix = "AUTO_HBW_LOG=2 LD_PRELOAD=%s/libautohbw.so.0 " % _get_lib_path()
Packit 345191
    memkind_malloc_log = "In my memkind malloc"
Packit 345191
    memkind_calloc_log = "In my memkind calloc"
Packit 345191
    memkind_realloc_log = "In my memkind realloc"
Packit 345191
    memkind_posix_memalign_log = "In my memkind align"
Packit 345191
    memkind_free_log = "In my memkind free"
Packit 345191
    cmd_helper = CMD_helper()
Packit 345191
Packit 345191
    def test_TC_MEMKIND_autohbw_malloc_and_free(self):
Packit 345191
        """ This test executes ./autohbw_test_helper with LD_PRELOAD that is overriding malloc() and free() to equivalent autohbw functions"""
Packit 345191
        command = self.test_prefix + self.cmd_helper.get_command_path(self.binary) + " malloc"
Packit 345191
        print "Executing command: {0}".format(command)
Packit 345191
        output, retcode = self.cmd_helper.execute_cmd(command, sudo=False)
Packit 345191
        assert retcode == 0, self.fail_msg.format("\nError: autohbw_test_helper returned {0} \noutput: {1}".format(retcode,output))
Packit 345191
        assert self.memkind_malloc_log in output, self.fail_msg.format("\nError: malloc was not overridden by autohbw equivalent \noutput: {0}").format(output)
Packit 345191
        assert self.memkind_free_log in output, self.fail_msg.format("\nError: free was not overridden by autohbw equivalent \noutput: {0}").format(output)
Packit 345191
Packit 345191
    def test_TC_MEMKIND_autohbw_calloc_and_free(self):
Packit 345191
        """ This test executes ./autohbw_test_helper with LD_PRELOAD that is overriding calloc() and free() to equivalent autohbw functions"""
Packit 345191
        command = self.test_prefix + self.cmd_helper.get_command_path(self.binary) + " calloc"
Packit 345191
        print "Executing command: {0}".format(command)
Packit 345191
        output, retcode = self.cmd_helper.execute_cmd(command, sudo=False)
Packit 345191
        assert retcode == 0, self.fail_msg.format("\nError: autohbw_test_helper returned {0} \noutput: {1}".format(retcode,output))
Packit 345191
        assert self.memkind_calloc_log in output, self.fail_msg.format("\nError: calloc was not overridden by autohbw equivalent \noutput: {0}").format(output)
Packit 345191
        assert self.memkind_free_log in output, self.fail_msg.format("Error: free was not overridden by autohbw equivalent \noutput: {0}").format(output)
Packit 345191
Packit 345191
    def test_TC_MEMKIND_autohbw_realloc_and_free(self):
Packit 345191
        """ This test executes ./autohbw_test_helper with LD_PRELOAD that is overriding realloc() and free() to equivalent autohbw functions"""
Packit 345191
        command = self.test_prefix + self.cmd_helper.get_command_path(self.binary) + " realloc"
Packit 345191
        print "Executing command: {0}".format(command)
Packit 345191
        output, retcode = self.cmd_helper.execute_cmd(command, sudo=False)
Packit 345191
        assert retcode == 0, self.fail_msg.format("\nError: autohbw_test_helper returned {0} \noutput: {1}".format(retcode,output))
Packit 345191
        assert self.memkind_realloc_log in output, self.fail_msg.format("\nError: realloc was not overridden by autohbw equivalent \noutput: {0}").format(output)
Packit 345191
        assert self.memkind_free_log in output, self.fail_msg.format("\nError: free was not overridden by autohbw equivalent \noutput: {0}").format(output)
Packit 345191
Packit 345191
    def test_TC_MEMKIND_autohbw_posix_memalign_and_free(self):
Packit 345191
        """ This test executes ./autohbw_test_helper with LD_PRELOAD that is overriding posix_memalign() and free() to equivalent autohbw functions"""
Packit 345191
        command = self.test_prefix + self.cmd_helper.get_command_path(self.binary) + " posix_memalign"
Packit 345191
        print "Executing command: {0}".format(command)
Packit 345191
        output, retcode = self.cmd_helper.execute_cmd(command, sudo=False)
Packit 345191
        assert retcode == 0, self.fail_msg.format("\nError: autohbw_test_helper returned {0} \noutput: {1}".format(retcode,output))
Packit 345191
        assert self.memkind_posix_memalign_log in output, self.fail_msg.format("\nError: posix_memalign was not overridden by autohbw equivalent \noutput: {0}").format(output)
Packit 345191
        assert self.memkind_free_log in output, self.fail_msg.format("\nError: free was not overridden by autohbw equivalent \noutput: {0}").format(output)