Commit dae4ff80 authored by Ravi Bangoria's avatar Ravi Bangoria Committed by Michael Ellerman

powerpc/selftests/ptrace-hwbreak: Add testcases for 2nd DAWR

Message-ID: <20210412112218.128183-2-ravi.bangoria@linux.ibm.com> (raw)

Add selftests to test multiple active DAWRs with ptrace interface.

Sample o/p:
  $ ./ptrace-hwbreak
  ...
  PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW ALIGNED, WO, len: 6: Ok
  PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW UNALIGNED, RO, len: 6: Ok
  PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, WO, len: 6: Ok
  PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, RO, len: 6: Ok
Signed-off-by: default avatarRavi Bangoria <ravi.bangoria@linux.ibm.com>
Reviewed-by: default avatarDaniel Axtens <dja@axtens.net>
[mpe: Fix build on older distros]
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 421a7483
......@@ -30,6 +30,10 @@
#include <linux/hw_breakpoint.h>
#include "utils.h"
#ifndef PPC_DEBUG_FEATURE_DATA_BP_ARCH_31
#define PPC_DEBUG_FEATURE_DATA_BP_ARCH_31 0x20
#endif
#define MAX_LOOPS 10000
#define DAWR_LENGTH_MAX ((0x3f + 1) * 8)
......
......@@ -194,6 +194,18 @@ static void test_workload(void)
big_var[rand() % DAWR_MAX_LEN] = 'a';
else
cvar = big_var[rand() % DAWR_MAX_LEN];
/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW ALIGNED, WO test */
gstruct.a[rand() % A_LEN] = 'a';
/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW UNALIGNED, RO test */
cvar = gstruct.b[rand() % B_LEN];
/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, WO test */
gstruct.a[rand() % A_LEN] = 'a';
/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, RO test */
cvar = gstruct.a[rand() % A_LEN];
}
static void check_success(pid_t child_pid, const char *name, const char *type,
......@@ -417,6 +429,69 @@ static void test_sethwdebug_range_aligned(pid_t child_pid)
ptrace_delhwdebug(child_pid, wh);
}
static void test_multi_sethwdebug_range(pid_t child_pid)
{
struct ppc_hw_breakpoint info1, info2;
unsigned long wp_addr1, wp_addr2;
char *name1 = "PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW ALIGNED";
char *name2 = "PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW UNALIGNED";
int len1, len2;
int wh1, wh2;
wp_addr1 = (unsigned long)&gstruct.a;
wp_addr2 = (unsigned long)&gstruct.b;
len1 = A_LEN;
len2 = B_LEN;
get_ppc_hw_breakpoint(&info1, PPC_BREAKPOINT_TRIGGER_WRITE, wp_addr1, len1);
get_ppc_hw_breakpoint(&info2, PPC_BREAKPOINT_TRIGGER_READ, wp_addr2, len2);
/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW ALIGNED, WO test */
wh1 = ptrace_sethwdebug(child_pid, &info1);
/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DW UNALIGNED, RO test */
wh2 = ptrace_sethwdebug(child_pid, &info2);
ptrace(PTRACE_CONT, child_pid, NULL, 0);
check_success(child_pid, name1, "WO", wp_addr1, len1);
ptrace(PTRACE_CONT, child_pid, NULL, 0);
check_success(child_pid, name2, "RO", wp_addr2, len2);
ptrace_delhwdebug(child_pid, wh1);
ptrace_delhwdebug(child_pid, wh2);
}
static void test_multi_sethwdebug_range_dawr_overlap(pid_t child_pid)
{
struct ppc_hw_breakpoint info1, info2;
unsigned long wp_addr1, wp_addr2;
char *name = "PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap";
int len1, len2;
int wh1, wh2;
wp_addr1 = (unsigned long)&gstruct.a;
wp_addr2 = (unsigned long)&gstruct.a;
len1 = A_LEN;
len2 = A_LEN;
get_ppc_hw_breakpoint(&info1, PPC_BREAKPOINT_TRIGGER_WRITE, wp_addr1, len1);
get_ppc_hw_breakpoint(&info2, PPC_BREAKPOINT_TRIGGER_READ, wp_addr2, len2);
/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, WO test */
wh1 = ptrace_sethwdebug(child_pid, &info1);
/* PPC_PTRACE_SETHWDEBUG 2, MODE_RANGE, DAWR Overlap, RO test */
wh2 = ptrace_sethwdebug(child_pid, &info2);
ptrace(PTRACE_CONT, child_pid, NULL, 0);
check_success(child_pid, name, "WO", wp_addr1, len1);
ptrace(PTRACE_CONT, child_pid, NULL, 0);
check_success(child_pid, name, "RO", wp_addr2, len2);
ptrace_delhwdebug(child_pid, wh1);
ptrace_delhwdebug(child_pid, wh2);
}
static void test_sethwdebug_range_unaligned(pid_t child_pid)
{
struct ppc_hw_breakpoint info;
......@@ -504,6 +579,10 @@ run_tests(pid_t child_pid, struct ppc_debug_info *dbginfo, bool dawr)
test_sethwdebug_range_unaligned(child_pid);
test_sethwdebug_range_unaligned_dar(child_pid);
test_sethwdebug_dawr_max_range(child_pid);
if (dbginfo->num_data_bps > 1) {
test_multi_sethwdebug_range(child_pid);
test_multi_sethwdebug_range_dawr_overlap(child_pid);
}
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment