From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 75217 invoked by alias); 3 Oct 2016 04:22:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 75074 invoked by uid 89); 3 Oct 2016 04:22:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=2.7.4, H*r:4.86_1, ui_file, observers X-HELO: gproxy1.mail.unifiedlayer.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO gproxy1.mail.unifiedlayer.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 03 Oct 2016 04:22:35 +0000 Received: from cmgw3 (cmgw4 [10.0.90.84]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 33895175A2A for ; Sun, 2 Oct 2016 22:22:34 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id qsNW1t00k2f2jeq01sNZHy; Sun, 02 Oct 2016 22:22:34 -0600 X-Authority-Analysis: v=2.1 cv=M7redUAs c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=CH0kA5CcgfcA:10 a=zstS-IiYAAAA:8 a=VnNF1IyMAAAA:8 a=mDV3o1hIAAAA:8 a=544D_HGdAAAA:8 a=djLt3F2fxkaLCUW4kzEA:9 a=fUWHpEvPm8BxwYnX:21 a=_FPJhIuH_NDbS_ap:21 a=4G6NA9xxw8l3yy4pmD5M:22 a=skCgnbhlp52w9zbo2JeP:22 a=_FVE-zBwftR9WsbkzFJk:22 a=m6Qi5owKsdZQ2eb-sZEm:22 Received: from 71-218-192-86.hlrn.qwest.net ([71.218.192.86]:60644 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1bqulq-0001Vt-Pg; Sun, 02 Oct 2016 22:22:30 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 4/4] Change observer tests to use selftest framework Date: Mon, 03 Oct 2016 04:22:00 -0000 Message-Id: <1475468542-11446-5-git-send-email-tom@tromey.com> In-Reply-To: <1475468542-11446-1-git-send-email-tom@tromey.com> References: <1475468542-11446-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1bqulq-0001Vt-Pg X-Source-Sender: 71-218-192-86.hlrn.qwest.net (bapiya.Home) [71.218.192.86]:60644 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-SW-Source: 2016-10/txt/msg00013.txt.bz2 This changes the observer tests in observer.exp to be written in C++ and use the self-test framework. This was a bit simpler than trying to make the .exp test work again. 2016-10-02 Tom Tromey * observer.h (gdb_observers) : Remove. * observer.c: Include selftest.h. (test_notification): Now static. (test_first_observer, test_second_observer, test_third_observer) (test_first_notification_function) (test_second_notification_function) (test_third_notification_function): Renamed. Now static. (check_counters, observer_self_tests): New function. (_initialize_observer): Register observer_self_tests. 2016-10-02 Tom Tromey * gdb.gdb/observer.exp: Remove. --- gdb/ChangeLog | 10 +++ gdb/observer.c | 137 ++++++++++++++++++++++++++--------- gdb/observer.h | 4 -- gdb/testsuite/ChangeLog | 4 ++ gdb/testsuite/gdb.gdb/observer.exp | 143 ------------------------------------- 5 files changed, 119 insertions(+), 179 deletions(-) delete mode 100644 gdb/testsuite/gdb.gdb/observer.exp diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fb84728..ec56801 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2016-10-02 Tom Tromey + * observer.h (gdb_observers) : Remove. + * observer.c: Include selftest.h. + (test_notification): Now static. + (test_first_observer, test_second_observer, test_third_observer) + (test_first_notification_function) + (test_second_notification_function) + (test_third_notification_function): Renamed. Now static. + (check_counters, observer_self_tests): New function. + (_initialize_observer): Register observer_self_tests. + * ada-lang.c, ada-tasks.c, agent.c, aix-thread.c, annotate.c, arm-tdep.c, auto-load.c, auxv.c, break-catch-syscall.c, breakpoint.c, bsd-uthread.c, cli/cli-interp.c, cli/cli-setshow.c, diff --git a/gdb/observer.c b/gdb/observer.c index ae7b725..f105556 100644 --- a/gdb/observer.c +++ b/gdb/observer.c @@ -21,6 +21,7 @@ #include "observer.h" #include "command.h" #include "gdbcmd.h" +#include "selftest.h" namespace gdb_observers { @@ -109,8 +110,106 @@ namespace gdb_observers inferior_call_post ("inferior_call_post"); observer2 register_changed ("register_changed"); - observer1 - test_notification ("test_notification"); + +#ifdef GDB_SELF_TEST + + // This observer is used for internal testing. + static observer1 test_notification ("test_notification"); + + static int test_first_observer = 0; + static int test_second_observer = 0; + static int test_third_observer = 0; + + static void + test_first_notification_function (int arg) + { + test_first_observer++; + } + + static void + test_second_notification_function (int arg) + { + test_second_observer++; + } + + static void + test_third_notification_function (int arg) + { + test_third_observer++; + } + + static void + notify_check_counters (int one, int two, int three) + { + // Reset. + test_first_observer = 0; + test_second_observer = 0; + test_third_observer = 0; + // Notify. + test_notification.notify (0); + // Check. + SELF_CHECK (one == test_first_observer); + SELF_CHECK (two == test_second_observer); + SELF_CHECK (three == test_third_observer); + } + + static void + observer_self_tests () + { + // First, try sending a notification without any observer attached. + notify_check_counters (0, 0, 0); + + // Now, attach one observer, and send a notification. + test_notification.attach (&test_second_notification_function); + notify_check_counters (0, 1, 0); + + // Remove the observer, and send a notification. + test_notification.detach (&test_second_notification_function); + notify_check_counters (0, 0, 0); + + // With a new observer. + test_notification.attach (&test_first_notification_function); + notify_check_counters (1, 0, 0); + + // With 2 observers. + test_notification.attach (&test_second_notification_function); + notify_check_counters (1, 1, 0); + + // With 3 observers. + test_notification.attach (&test_third_notification_function); + notify_check_counters (1, 1, 1); + + // Remove middle observer. + test_notification.detach (&test_second_notification_function); + notify_check_counters (1, 0, 1); + + // Remove first observer. + test_notification.detach (&test_first_notification_function); + notify_check_counters (0, 0, 1); + + // Remove last observer. + test_notification.detach (&test_third_notification_function); + notify_check_counters (0, 0, 0); + + // Go back to 3 observers, and remove them in a different order... + test_notification.attach (&test_first_notification_function); + test_notification.attach (&test_second_notification_function); + test_notification.attach (&test_third_notification_function); + notify_check_counters (1, 1, 1); + + // Remove the third observer. + test_notification.detach (&test_third_notification_function); + notify_check_counters (1, 1, 0); + + // Remove the second observer. + test_notification.detach (&test_second_notification_function); + notify_check_counters (1, 0, 0); + + // Remove first observer, no more observers. + test_notification.detach (&test_first_notification_function); + notify_check_counters (0, 0, 0); + } +#endif } static void @@ -124,36 +223,6 @@ show_observer_debug (struct ui_file *file, int from_tty, testsuite. DO NOT USE IT within observer.c (or anywhere else for that matter)! */ -/* If we define these variables and functions as `static', the - compiler will optimize them out. */ - -int observer_test_first_observer = 0; -int observer_test_second_observer = 0; -int observer_test_third_observer = 0; - -/* Provide prototypes to silence -Wmissing-prototypes. */ -extern void observer_test_first_notification_function (int arg); -extern void observer_test_second_notification_function (int arg); -extern void observer_test_third_notification_function (int arg); - -void -observer_test_first_notification_function (int arg) -{ - observer_test_first_observer++; -} - -void -observer_test_second_notification_function (int arg) -{ - observer_test_second_observer++; -} - -void -observer_test_third_notification_function (int arg) -{ - observer_test_third_observer++; -} - extern initialize_file_ftype _initialize_observer; /* -Wmissing-prototypes */ void @@ -167,4 +236,8 @@ When non-zero, observer debugging is enabled."), NULL, show_observer_debug, &setdebuglist, &showdebuglist); + +#if GDB_SELF_TEST + register_self_test (gdb_observers::observer_self_tests); +#endif } diff --git a/gdb/observer.h b/gdb/observer.h index 0fa5ab6..83e751e 100644 --- a/gdb/observer.h +++ b/gdb/observer.h @@ -385,10 +385,6 @@ namespace gdb_observers // A register in the inferior has been modified by the gdb user. extern observer2 register_changed; - - // This observer is used for internal testing. Do not use. - // See testsuite/gdb.gdb/observer.exp. - extern observer1 test_notification; } #endif /* GDB_OBSERVER_H */ diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index d7cdf74..8c6dba3 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-10-02 Tom Tromey + + * gdb.gdb/observer.exp: Remove. + 2016-09-29 Peter Bergner * gdb.arch/powerpc-power.exp : Update tests to account for diff --git a/gdb/testsuite/gdb.gdb/observer.exp b/gdb/testsuite/gdb.gdb/observer.exp deleted file mode 100644 index 2e70dfb..0000000 --- a/gdb/testsuite/gdb.gdb/observer.exp +++ /dev/null @@ -1,143 +0,0 @@ -# Copyright 2003-2016 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 was written by Joel Brobecker (brobecker@gnat.com), derived -# from xfullpath.exp. - -load_lib selftest-support.exp - -proc attach_first_observer { message } { - gdb_test_no_output "set \$first_obs = observer_attach_test_notification (&observer_test_first_notification_function)" \ - "$message; attach first observer" -} - -proc attach_second_observer { message } { - gdb_test_no_output "set \$second_obs = observer_attach_test_notification (&observer_test_second_notification_function)" \ - "$message; attach second observer" -} - -proc attach_third_observer { message } { - gdb_test_no_output "set \$third_obs = observer_attach_test_notification (&observer_test_third_notification_function)" \ - "$message; attach third observer" -} - -proc detach_first_observer { message } { - gdb_test_no_output "call observer_detach_test_notification (\$first_obs)" \ - "$message; detach first observer" -} - -proc detach_second_observer { message } { - gdb_test_no_output "call observer_detach_test_notification (\$second_obs)" \ - "$message; detach second observer" -} - -proc detach_third_observer { message } { - gdb_test_no_output "call observer_detach_test_notification (\$third_obs)" \ - "$message; detach third observer" -} - -proc check_counters { first second third message } { - gdb_test "print observer_test_first_observer" \ - ".\[0-9\]+ =.*$first" \ - "$message; check first observer counter value" - gdb_test "print observer_test_second_observer" \ - ".\[0-9\]+ =.*$second" \ - "$message; check second observer counter value" - gdb_test "print observer_test_third_observer" \ - ".\[0-9\]+ =.*$third" \ - "$message; check third observer counter value" -} - -proc reset_counters { message } { - gdb_test_no_output "set variable observer_test_first_observer = 0" \ - "$message; reset first observer counter" - gdb_test_no_output "set variable observer_test_second_observer = 0" \ - "$message; reset second observer counter" - gdb_test_no_output "set variable observer_test_third_observer = 0" \ - "$message; reset third observer counter" -} - -proc test_notifications { first second third message args } { - # Do any initialization - for {set i 0} {$i < [llength $args]} {incr i} { - [lindex $args $i] $message - } - reset_counters $message - # Call observer_notify_test_notification. Note that this procedure - # takes one argument, but this argument is ignored by the observer - # callbacks we have installed. So we just pass an arbitrary value. - gdb_test_no_output "call observer_notify_test_notification (0)" \ - "$message; sending notification" - check_counters $first $second $third $message -} - -proc test_observer {} { - # First, try sending a notification without any observer attached. - test_notifications 0 0 0 "no observer attached" - - # Now, attach one observer, and send a notification. - test_notifications 0 1 0 "second observer attached" \ - attach_second_observer - - # Remove the observer, and send a notification. - test_notifications 0 0 0 "second observer detached" \ - detach_second_observer - - # With a new observer. - test_notifications 1 0 0 "1st observer added" \ - attach_first_observer - - # With 2 observers. - test_notifications 1 1 0 "2nd observer added" \ - attach_second_observer - - # With 3 observers. - test_notifications 1 1 1 "3rd observer added" \ - attach_third_observer - - # Remove middle observer. - test_notifications 1 0 1 "2nd observer removed" \ - detach_second_observer - - # Remove first observer. - test_notifications 0 0 1 "1st observer removed" \ - detach_first_observer - - # Remove last observer. - test_notifications 0 0 0 "3rd observer removed" \ - detach_third_observer - - # Go back to 3 observers, and remove them in a different order... - test_notifications 1 1 1 "three observers added" \ - attach_first_observer \ - attach_second_observer \ - attach_third_observer - - # Remove the third observer. - test_notifications 1 1 0 "third observer removed" \ - detach_third_observer - - # Remove the second observer. - test_notifications 1 0 0 "second observer removed" \ - detach_second_observer - - # Remove the first observer, no more observers. - test_notifications 0 0 0 "first observer removed" \ - detach_first_observer - - return 0 -} - -do_self_tests captured_main test_observer -- 2.7.4