From patchwork Wed Sep 27 15:33:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Buettner X-Patchwork-Id: 23177 Received: (qmail 42367 invoked by alias); 27 Sep 2017 15:33:41 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 42358 invoked by uid 89); 27 Sep 2017 15:33:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1160, referred X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 27 Sep 2017 15:33:39 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E983E3E2B9 for ; Wed, 27 Sep 2017 15:33:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E983E3E2B9 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=kevinb@redhat.com Received: from pinnacle.lan (ovpn-117-96.phx2.redhat.com [10.3.117.96]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B5A555F6E6 for ; Wed, 27 Sep 2017 15:33:37 +0000 (UTC) Date: Wed, 27 Sep 2017 08:33:36 -0700 From: Kevin Buettner To: gdb-patches@sourceware.org Subject: [PATCH 2/2] OpenMP parallel region scope tests Message-ID: <20170927083336.1c70d48c@pinnacle.lan> In-Reply-To: <20170927082748.5b379d06@pinnacle.lan> References: <20170927082748.5b379d06@pinnacle.lan> MIME-Version: 1.0 X-IsSubscribed: yes Add tests which check for accessibility of variables from within various OpenMP parallel regions. Variables in question are within various scopes and may be declared (via #pragma omp parallel directives) to be private or shared. gdb/testsuite/ChangeLog: * gdb.threads/omp-par-scope.c: New file. * gdb/threads/omp-par-scope.exp: New file. --- gdb/testsuite/gdb.threads/omp-par-scope.c | 160 ++++++++++++++ gdb/testsuite/gdb.threads/omp-par-scope.exp | 317 ++++++++++++++++++++++++++++ 2 files changed, 477 insertions(+) diff --git a/gdb/testsuite/gdb.threads/omp-par-scope.c b/gdb/testsuite/gdb.threads/omp-par-scope.c new file mode 100644 index 0000000..dc3c470 --- /dev/null +++ b/gdb/testsuite/gdb.threads/omp-par-scope.c @@ -0,0 +1,160 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2017 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include +#include + +/* Testcase for checking access to variables in a single / outer scope. + Make sure that variables not referred to in the parallel section are + accessible from the debugger. */ + +void +single_scope (void) +{ + static int s1 = -41, s2 = -42, s3 = -43; + int i1 = 11, i2 = 12, i3 = 13; + +#pragma omp parallel num_threads (2) shared (s1, i1) private (s2, i2) + { + int thread_num = omp_get_thread_num (); + + s2 = 100 * (thread_num + 1) + 2; + i2 = s2 + 10; + + #pragma omp critical + printf ("single_scope: thread_num=%d, s1=%d, i1=%d, s2=%d, i2=%d\n", + thread_num, s1, i1, s2, i2); + } + + printf ("single_scope: s1=%d, s2=%d, s3=%d, i1=%d, i2=%d, i3=%d\n", + s1, s2, s3, i1, i2, i3); +} + +static int file_scope_var = 9876; + +/* Testcase for checking access to variables from parallel region + nested within more than one lexical scope. Of particular interest + are variables which are not referenced in the parallel section. */ + +void +multi_scope (void) +{ + int i01 = 1, i02 = 2; + + { + int i11 = 11, i12 = 12; + + { + int i21 = -21, i22 = 22; + +#pragma omp parallel num_threads (2) \ + firstprivate (i01) \ + shared (i11) \ + private (i21) + { + i21 = 100 * (omp_get_thread_num () + 1) + 21; + + #pragma omp critical + printf ("multi_scope: thread_num=%d, i01=%d, i11=%d, i21\n", + omp_get_thread_num (), i01, i11, i21); + } + + printf ("multi_scope: i01=%d, i02=%d, i11=%d, " + "i12=%d, i21=%d, i22=%d\n", + i01, i02, i11, i12, i21, i22); + } + } +} + +/* Nested functions in C is a GNU extension. */ +#ifdef __GNUC__ + +/* Testcase for checking access of variables from within parallel + region in a lexically nested function. */ + +void +nested_func (void) +{ + static int s1 = -42; + int i = 1, j = 2, k = 3; + + void + foo (int p, int q, int r) + { + int x = 4; + + { + int y = 5, z = 6; +#pragma omp parallel num_threads (2) shared (i, p, x) private (j, q, y) + { + int tn = omp_get_thread_num (); + + j = 1000 * (omp_get_thread_num () + 1); + q = j + 1; + y = q + 1; + #pragma omp critical + printf ("nested_func: tn=%d: i=%d, p=%d, x=%d, j=%d, q=%d, y=%d\n", + omp_get_thread_num (), i, p, x, j, q, y); + } + } + } + + foo (10, 11, 12); + + i = 101; j = 102; k = 103; + foo (20, 21, 22); +} +#endif + +/* Testcase for checking access to variables from with a nested parallel + region. */ + +void +nested_parallel (void) +{ + int i = 1, j = 2; + int l = -1; + + omp_set_nested (1); + omp_set_dynamic (0); +#pragma omp parallel num_threads (2) private (l) + { + int num = omp_get_thread_num (); + int nthr = omp_get_num_threads (); + int off = num * nthr; + int k = off + 101; + l = off + 102; +#pragma omp parallel num_threads (2) shared (num) + { + #pragma omp critical + printf ("nested_parallel (inner threads): outer thread num = %d, thread num = %d\n", num, omp_get_thread_num ()); + } + #pragma omp critical + printf ("nested_parallel (outer threads) %d: k = %d, l = %d\n", num, k, l); + } +} + +int +main (int argc, char **argv) +{ + single_scope (); + multi_scope (); + nested_func (); + nested_parallel (); + return 0; +} + diff --git a/gdb/testsuite/gdb.threads/omp-par-scope.exp b/gdb/testsuite/gdb.threads/omp-par-scope.exp new file mode 100644 index 0000000..f806c50 --- /dev/null +++ b/gdb/testsuite/gdb.threads/omp-par-scope.exp @@ -0,0 +1,317 @@ +# Copyright 2017 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This file is part of the gdb testsuite. + +standard_testfile + +if {[gdb_compile_openmp "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != ""} { + untested "failed to compile OpenMP program" + return -1 +} + +clean_restart ${binfile} + +if {[openmp_setup $binfile] != ""} { + return -1 +} + +if {![runto_main]} { + untested "could not run to main" + return -1 +} + +with_test_prefix "single_scope" { + + gdb_breakpoint [gdb_get_line_number "single_scope: thread_num="] + gdb_breakpoint [gdb_get_line_number "single_scope: s1="] + + with_test_prefix "first thread" { + gdb_continue_to_breakpoint "at printf" + + setup_xfail *-*-* + gdb_test "print thread_num" "= \[01\]" + setup_kfail "gdb/22214" *-*-* + gdb_test "print s1" "= -41" + gdb_test "print s2" "= \[12\]02" + setup_kfail "gdb/22214" *-*-* + gdb_test "print s3" "= -43" + gdb_test "print i1" "= 11" + gdb_test "print i2" "= \[12]12" + setup_kfail "gdb/22214" *-*-* + gdb_test "print i3" "= 13" + } + + with_test_prefix "second thread" { + gdb_continue_to_breakpoint "at printf" + + setup_xfail *-*-* + gdb_test "print thread_num" "= \[01\]" + setup_kfail "gdb/22214" *-*-* + gdb_test "print s1" "= -41" + gdb_test "print s2" "= \[12\]02" + setup_kfail "gdb/22214" *-*-* + gdb_test "print s3" "= -43" + gdb_test "print i1" "= 11" + gdb_test "print i2" "= \[12]12" + setup_kfail "gdb/22214" *-*-* + gdb_test "print i3" "= 13" + } + + with_test_prefix "after parallel region" { + gdb_continue_to_breakpoint "at printf" + + gdb_test "print s1" "= -41" + gdb_test "print s2" "= -42" + gdb_test "print s3" "= -43" + gdb_test "print i1" "= 11" + gdb_test "print i2" "= 12" + gdb_test "print i3" "= 13" + } + +} + +with_test_prefix "multi_scope" { + gdb_breakpoint [gdb_get_line_number "multi_scope: thread_num="] + gdb_breakpoint [gdb_get_line_number "multi_scope: i01="] + + with_test_prefix "first thread" { + gdb_continue_to_breakpoint "at printf" + + gdb_test "print i01" "= 1" + setup_kfail "gdb/22214" *-*-* + gdb_test "print i02" "= 2" + gdb_test "print i11" "= 11" + setup_kfail "gdb/22214" *-*-* + gdb_test "print i12" "= 12" + gdb_test "print i21" "= \[12\]21" + setup_kfail "gdb/22214" *-*-* + gdb_test "print i22" "= 22" + gdb_test "print file_scope_var" "= 9876" + } + + with_test_prefix "second thread" { + gdb_continue_to_breakpoint "at printf" + + gdb_test "print i01" "= 1" + setup_kfail "gdb/22214" *-*-* + gdb_test "print i02" "= 2" + gdb_test "print i11" "= 11" + setup_kfail "gdb/22214" *-*-* + gdb_test "print i12" "= 12" + gdb_test "print i21" "= \[12\]21" + setup_kfail "gdb/22214" *-*-* + gdb_test "print i22" "= 22" + gdb_test "print file_scope_var" "= 9876" + } + + with_test_prefix "after parallel" { + gdb_continue_to_breakpoint "at printf" + + gdb_test "print i01" "= 1" + gdb_test "print i02" "= 2" + gdb_test "print i11" "= 11" + gdb_test "print i12" "= 12" + gdb_test "print i21" "= -21" + gdb_test "print i22" "= 22" + gdb_test "print file_scope_var" "= 9876" + } +} + +# Nested functions in C are a GNU extension, so don't do the following +# tests unless the compiler is GCC. + +if [test_compiler_info gcc*] { + with_test_prefix "nested_func" { + gdb_breakpoint [gdb_get_line_number "nested_func: tn="] + + with_test_prefix "1st call" { + with_test_prefix "1st thread" { + gdb_continue_to_breakpoint "at printf" + + gdb_test "print file_scope_var" "= 9876" + setup_kfail "gdb/22214" *-*-* + gdb_test "print s1" "= -42" + gdb_test "print i" "= 1" + gdb_test "print j" "= \[12\]000" + setup_kfail "gdb/22214" *-*-* + gdb_test "print k" "= 3" + gdb_test "print p" "= 10" + gdb_test "print q" "= \[12\]001" + setup_kfail "gdb/22214" *-*-* + gdb_test "print r" "= 12" + gdb_test "print x" "= 4" + gdb_test "print y" "= \[12\]002" + setup_kfail "gdb/22214" *-*-* + gdb_test "print z" "= 6" + setup_xfail *-*-* + gdb_test "print tn" "= \[01\]" + } + + with_test_prefix "2nd thread" { + gdb_continue_to_breakpoint "at printf" + + gdb_test "print file_scope_var" "= 9876" + setup_kfail "gdb/22214" *-*-* + gdb_test "print s1" "= -42" + gdb_test "print i" "= 1" + gdb_test "print j" "= \[12\]000" + setup_kfail "gdb/22214" *-*-* + gdb_test "print k" "= 3" + gdb_test "print p" "= 10" + gdb_test "print q" "= \[12\]001" + setup_kfail "gdb/22214" *-*-* + gdb_test "print r" "= 12" + gdb_test "print x" "= 4" + gdb_test "print y" "= \[12\]002" + setup_kfail "gdb/22214" *-*-* + gdb_test "print z" "= 6" + setup_xfail *-*-* + gdb_test "print tn" "= \[01\]" + } + } + + with_test_prefix "2nd call" { + with_test_prefix "1st thread" { + gdb_continue_to_breakpoint "at printf" + + gdb_test "print file_scope_var" "= 9876" + setup_kfail "gdb/22214" *-*-* + gdb_test "print s1" "= -42" + gdb_test "print i" "= 101" + gdb_test "print j" "= \[12\]000" + setup_kfail "gdb/22214" *-*-* + gdb_test "print k" "= 103" + gdb_test "print p" "= 20" + gdb_test "print q" "= \[12\]001" + setup_kfail "gdb/22214" *-*-* + gdb_test "print r" "= 22" + gdb_test "print x" "= 4" + gdb_test "print y" "= \[12\]002" + setup_kfail "gdb/22214" *-*-* + gdb_test "print z" "= 6" + setup_xfail *-*-* + gdb_test "print tn" "= \[01\]" + } + + with_test_prefix "2nd thread" { + gdb_continue_to_breakpoint "at printf" + + gdb_test "print file_scope_var" "= 9876" + setup_kfail "gdb/22214" *-*-* + gdb_test "print s1" "= -42" + gdb_test "print i" "= 101" + gdb_test "print j" "= \[12\]000" + setup_kfail "gdb/22214" *-*-* + gdb_test "print k" "= 103" + gdb_test "print p" "= 20" + gdb_test "print q" "= \[12\]001" + setup_kfail "gdb/22214" *-*-* + gdb_test "print r" "= 22" + gdb_test "print x" "= 4" + gdb_test "print y" "= \[12\]002" + setup_kfail "gdb/22214" *-*-* + gdb_test "print z" "= 6" + setup_xfail *-*-* + gdb_test "print tn" "= \[01\]" + } + } + } +} + +with_test_prefix "nested_parallel" { + gdb_breakpoint [gdb_get_line_number "nested_parallel (inner threads)"] + + with_test_prefix "inner_threads" { + with_test_prefix "1st stop" { + gdb_continue_to_breakpoint "at printf" + + gdb_test "print file_scope_var" "= 9876" + gdb_test "print num" "= \[01\]" + setup_kfail "gdb/22214" *-*-* + gdb_test "print i" "= 1" + setup_kfail "gdb/22214" *-*-* + gdb_test "print j" "= 2" + setup_xfail *-*-* + gdb_test "print l" "= 10\[24\]" + setup_xfail *-*-* + gdb_test "print k" "= 10\[13\]" + } + + with_test_prefix "2nd stop" { + gdb_continue_to_breakpoint "at printf" + + gdb_test "print file_scope_var" "= 9876" + gdb_test "print num" "= \[01\]" + setup_kfail "gdb/22214" *-*-* + gdb_test "print i" "= 1" + setup_kfail "gdb/22214" *-*-* + gdb_test "print j" "= 2" + setup_xfail *-*-* + gdb_test "print l" "= 10\[24\]" + setup_xfail *-*-* + gdb_test "print k" "= 10\[13\]" + } + + with_test_prefix "3rd stop" { + gdb_continue_to_breakpoint "at printf" + + gdb_test "print file_scope_var" "= 9876" + gdb_test "print num" "= \[01\]" + setup_kfail "gdb/22214" *-*-* + gdb_test "print i" "= 1" + setup_kfail "gdb/22214" *-*-* + gdb_test "print j" "= 2" + setup_xfail *-*-* + gdb_test "print l" "= 10\[24\]" + setup_xfail *-*-* + gdb_test "print k" "= 10\[13\]" + } + + with_test_prefix "4th stop" { + gdb_continue_to_breakpoint "at printf" + + gdb_test "print file_scope_var" "= 9876" + gdb_test "print num" "= \[01\]" + setup_kfail "gdb/22214" *-*-* + gdb_test "print i" "= 1" + setup_kfail "gdb/22214" *-*-* + gdb_test "print j" "= 2" + setup_xfail *-*-* + gdb_test "print l" "= 10\[24\]" + setup_xfail *-*-* + gdb_test "print k" "= 10\[13\]" + } + } + + with_test_prefix "outer_threads" { + gdb_breakpoint [gdb_get_line_number "nested_parallel (outer threads)"] + + with_test_prefix "outer stop" { + gdb_continue_to_breakpoint "at printf" + + gdb_test "print file_scope_var" "= 9876" + setup_xfail *-*-* + gdb_test "print num" "= \[01\]" + setup_kfail "gdb/22214" *-*-* + gdb_test "print i" "= 1" + setup_kfail "gdb/22214" *-*-* + gdb_test "print j" "= 2" + gdb_test "print l" "= 10\[24\]" + setup_xfail *-*-* + gdb_test "print k" "= 10\[13\]" + } + } +}