diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:12:36 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:12:36 +0000 |
commit | ef5d0b5e97ec8e6fa395d377b09aa7755e345b4f (patch) | |
tree | 27916256fdeeb57d10d2f3d6948be5d71a703215 /tools/intel-features/intel-mpx/test | |
parent | 76e0736e7fcfeb179779e49c05604464b1ccd704 (diff) |
Notes
Diffstat (limited to 'tools/intel-features/intel-mpx/test')
-rw-r--r-- | tools/intel-features/intel-mpx/test/Makefile | 7 | ||||
-rw-r--r-- | tools/intel-features/intel-mpx/test/README.txt | 6 | ||||
-rw-r--r-- | tools/intel-features/intel-mpx/test/TestMPXTable.py | 169 | ||||
-rw-r--r-- | tools/intel-features/intel-mpx/test/main.cpp | 49 |
4 files changed, 231 insertions, 0 deletions
diff --git a/tools/intel-features/intel-mpx/test/Makefile b/tools/intel-features/intel-mpx/test/Makefile new file mode 100644 index 000000000000..b18044407a70 --- /dev/null +++ b/tools/intel-features/intel-mpx/test/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../../../make + +CXX_SOURCES := main.cpp + +CFLAGS_EXTRAS += -mmpx -fcheck-pointer-bounds -lmpxwrappers -lmpx -fuse-ld=bfd + +include $(LEVEL)/Makefile.rules diff --git a/tools/intel-features/intel-mpx/test/README.txt b/tools/intel-features/intel-mpx/test/README.txt new file mode 100644 index 000000000000..6797eff30a79 --- /dev/null +++ b/tools/intel-features/intel-mpx/test/README.txt @@ -0,0 +1,6 @@ +In order to run this test, create the following directory: + + packages/Python/lldbsuite/test/functionalities/plugins/commands/mpxtablecmd + +and copy into it the contents of this directory. + diff --git a/tools/intel-features/intel-mpx/test/TestMPXTable.py b/tools/intel-features/intel-mpx/test/TestMPXTable.py new file mode 100644 index 000000000000..f571252e26f7 --- /dev/null +++ b/tools/intel-features/intel-mpx/test/TestMPXTable.py @@ -0,0 +1,169 @@ +""" +Test mpx-table command. +""" + +from __future__ import print_function + + +import os +import time +import re +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestMPXTable(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + TestBase.setUp(self) + + @skipIf(compiler="clang") + @skipIf(oslist=no_match(['linux'])) + @skipIf(archs=no_match(['i386', 'x86_64'])) + @skipIf(compiler="gcc", compiler_version=["<", "5"]) #GCC version >= 5 supports + #Intel(R) Memory Protection Extensions (Intel(R) MPX). + def test_show_command(self): + """Test 'mpx-table show' command""" + self.build() + + lldb_exec_dir = os.environ["LLDB_IMPLIB_DIR"] + lldb_lib_dir = os.path.join(lldb_exec_dir, os.pardir, "lib") + plugin_file = os.path.join(lldb_lib_dir, "liblldbIntelFeatures.so") + if not os.path.isfile(plugin_file): + self.skipTest("features plugin missing.") + plugin_command = " " + seq = ("plugin", "load", plugin_file) + plugin_command = plugin_command.join(seq) + self.runCmd(plugin_command) + + exe = os.path.join(os.getcwd(), "a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + self.b1 = line_number('main.cpp', '// Break 1.') + self.b2 = line_number('main.cpp', '// Break 2.') + self.b3 = line_number('main.cpp', '// Break 3.') + self.b4 = line_number('main.cpp', '// Break 4.') + lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b1, num_expected_locations=1) + lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b2, num_expected_locations=1) + lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b3, num_expected_locations=1) + lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b4, num_expected_locations=1) + self.runCmd("run", RUN_SUCCEEDED) + + target = self.dbg.GetSelectedTarget() + process = target.GetProcess() + + if (process.GetState() == lldb.eStateExited): + self.skipTest("Intel(R) MPX is not supported.") + else: + self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, + substrs = ["stop reason = breakpoint 1."]) + + self.expect("mpx-table show a", + substrs = ['lbound = 0x', + ', ubound = 0x', + '(pointer value = 0x', + ', metadata = 0x', + ')'], + error = False) + + self.expect("continue", STOPPED_DUE_TO_BREAKPOINT, + substrs = ["stop reason = breakpoint 2."]) + + # Check that out of scope pointer cannot be reached. + # + self.expect("mpx-table show a", + substrs = ['Invalid pointer.'], + error = True) + + self.expect("mpx-table show tmp", + substrs = ['lbound = 0x', + ', ubound = 0x', + '(pointer value = 0x', + ', metadata = 0x', + ')'], + error = False) + + self.expect("continue", STOPPED_DUE_TO_BREAKPOINT, + substrs = ["stop reason = breakpoint 3."]) + + # Check that the pointer value is correctly updated. + # + self.expect("mpx-table show tmp", + substrs = ['lbound = 0x', + ', ubound = 0x', + '(pointer value = 0x2', + ', metadata = 0x', + ')'], + error = False) + + self.expect("continue", STOPPED_DUE_TO_BREAKPOINT, + substrs = ["stop reason = breakpoint 4."]) + + # After going back to main(), check that out of scope pointer cannot be + # reached. + # + self.expect("mpx-table show tmp", + substrs = ['Invalid pointer.'], + error = True) + + self.expect("mpx-table show a", + substrs = ['lbound = 0x', + ', ubound = 0x', + '(pointer value = 0x', + ', metadata = 0x', + ')'], + error = False) + + def test_set_command(self): + """Test 'mpx-table set' command""" + self.build() + + lldb_exec_dir = os.environ["LLDB_IMPLIB_DIR"] + lldb_lib_dir = os.path.join(lldb_exec_dir, os.pardir, "lib") + plugin_file = os.path.join(lldb_lib_dir, "liblldbIntelFeatures.so") + if not os.path.isfile(plugin_file): + self.skipTest("features plugin missing.") + plugin_command = " " + seq = ("plugin", "load", plugin_file) + plugin_command = plugin_command.join(seq) + self.runCmd(plugin_command) + + exe = os.path.join(os.getcwd(), "a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + self.b1 = line_number('main.cpp', '// Break 1.') + lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.b1, num_expected_locations=1) + self.runCmd("run", RUN_SUCCEEDED) + + target = self.dbg.GetSelectedTarget() + process = target.GetProcess() + + if (process.GetState() == lldb.eStateExited): + self.skipTest("Intel(R) MPX is not supported.") + else: + self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, + substrs = ["stop reason = breakpoint 1."]) + + # Check that the BT Entry doesn't already contain the test values. + # + self.expect("mpx-table show a", matching=False, + substrs = ['lbound = 0xcafecafe', + ', ubound = 0xbeefbeef']) + + # Set the test values. + # + self.expect("mpx-table set a 0xcafecafe 0xbeefbeef", error = False) + + # Verify that the test values have been correctly written in the BT + # entry. + # + self.expect("mpx-table show a", + substrs = ['lbound = 0xcafecafe', + ', ubound = 0xbeefbeef'], + error = False) + + diff --git a/tools/intel-features/intel-mpx/test/main.cpp b/tools/intel-features/intel-mpx/test/main.cpp new file mode 100644 index 000000000000..110befb1e250 --- /dev/null +++ b/tools/intel-features/intel-mpx/test/main.cpp @@ -0,0 +1,49 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +//// +//// The LLVM Compiler Infrastructure +//// +//// This file is distributed under the University of Illinois Open Source +//// License. See LICENSE.TXT for details. +//// +////===----------------------------------------------------------------------===// +// + +const int size = 5; + +#include <cstddef> +#include <cstdlib> +#include <sys/prctl.h> + +void func(int *ptr) { + int *tmp; + +#if defined __GNUC__ && !defined __INTEL_COMPILER + __builtin___bnd_store_ptr_bounds ((void**)&ptr, ptr); +#endif + tmp = ptr + size - 1; +#if defined __GNUC__ && !defined __INTEL_COMPILER + __builtin___bnd_store_ptr_bounds ((void**)&tmp, tmp); +#endif + tmp = (int*)0x2; // Break 2. + + return; // Break 3. +} + +int +main(int argc, char const *argv[]) +{ + // This call returns 0 only if the CPU and the kernel support + // Intel(R) Memory Protection Extensions (Intel(R) MPX). + if (prctl(PR_MPX_ENABLE_MANAGEMENT, 0, 0, 0, 0) != 0) + return -1; + + int* a = (int *) calloc(size, sizeof(int)); +#if defined __GNUC__ && !defined __INTEL_COMPILER + __builtin___bnd_store_ptr_bounds ((void**)&a, a); +#endif + func(a); // Break 1. + + free(a); // Break 4. + + return 0; +} |