Blame test/autohbw_test.py

Packit 345191
#
Packit 345191
#  Copyright (C) 2016 - 2019 Intel Corporation.
Packit 345191
#  All rights reserved.
Packit 345191
#
Packit 345191
#  Redistribution and use in source and binary forms, with or without
Packit 345191
#  modification, are permitted provided that the following conditions are met:
Packit 345191
#  1. Redistributions of source code must retain the above copyright notice(s),
Packit 345191
#     this list of conditions and the following disclaimer.
Packit 345191
#  2. Redistributions in binary form must reproduce the above copyright notice(s),
Packit 345191
#     this list of conditions and the following disclaimer in the documentation
Packit 345191
#     and/or other materials provided with the distribution.
Packit 345191
#
Packit 345191
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
Packit 345191
#  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
Packit 345191
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
Packit 345191
#  EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
Packit 345191
#  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit 345191
#  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Packit 345191
#  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Packit 345191
#  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
Packit 345191
#  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
Packit 345191
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 345191
#
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)