testsuite: Disable some tests when logging
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / gdbinit-history.exp
1 # Copyright 2015-2019 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # This file is part of the gdb testsuite.
17
18 # Test the setting of "history size" via $HOME/.gdbinit
19
20 # This test depends on being able to set $HOME and $GDBHISTSIZE.
21 # We cannot expect remote hosts to see environment variables set on the
22 # local machine.
23
24 # Do not run if gdb debug is enabled - it interferes with the command history.
25 if [gdb_debug_enabled] {
26 untested "debug is enabled"
27 return 0
28 }
29
30 if { [is_remote host] } {
31 unsupported "can't set environment variables on remote host"
32 return -1
33 }
34
35 # Check that the history size is properly set to SIZE when reading the .gdbinit
36 # file located in HOME with the environment variable GDBHISTSIZE optionally
37 # set to GDBHISTSIZE_VAL.
38
39 proc test_gdbinit_history_setting { home size { gdbhistsize_val "-" } } {
40 global env
41 global INTERNAL_GDBFLAGS
42 global srcdir
43 global subdir
44
45 save_vars { INTERNAL_GDBFLAGS env(GDBHISTFILE) env(GDBHISTSIZE) env(HOME) } {
46 set env(HOME) "$srcdir/$subdir/$home"
47
48 # These environment variables take precedence over whatever
49 # history size is set in .gdbinit. Make sure the former is not
50 # set.
51 unset -nocomplain env(GDBHISTFILE)
52 unset -nocomplain env(GDBHISTSIZE)
53
54 if { $gdbhistsize_val != "-" } {
55 set env(GDBHISTSIZE) $gdbhistsize_val
56 }
57
58 set INTERNAL_GDBFLAGS [string map {"-nx" ""} $INTERNAL_GDBFLAGS]
59
60 set prefix "home=$home"
61 if { $gdbhistsize_val != "-" } {
62 append prefix " gdbhistsize=$gdbhistsize_val"
63 }
64
65 with_test_prefix $prefix {
66 gdb_exit
67 gdb_start
68
69 gdb_test "show history size" "The size of the command history is $size."
70
71 if { $size == "0" } {
72 gdb_test_no_output "show commands"
73 } elseif { $size != "1" } {
74 gdb_test "show commands" " . show history size\r\n . show commands"
75 }
76 }
77 }
78 }
79
80 # Check that the history file does not get truncated to zero when a gdbinit
81 # file sets the history size to unlimited.
82
83 proc test_no_truncation_of_unlimited_history_file { } {
84 global env
85 global INTERNAL_GDBFLAGS
86
87 save_vars { INTERNAL_GDBFLAGS env(GDBHISTFILE) env(GDBHISTSIZE) } {
88 # These environment variables take precedence over whatever
89 # history size is set in .gdbinit. Make sure the former is not
90 # set.
91 unset -nocomplain env(GDBHISTFILE)
92 unset -nocomplain env(GDBHISTSIZE)
93
94 set temp_gdbinit [standard_output_file "gdbinit-history.gdbinit"]
95 set temp_histfile [standard_output_file "gdbinit-history.gdb_history"]
96 file delete $temp_gdbinit
97 file delete $temp_histfile
98
99 set fd [open $temp_gdbinit "w"]
100 puts $fd "set history size unlimited\n"
101 puts $fd "set history filename $temp_histfile\n"
102 puts $fd "set history save\n"
103 close $fd
104
105 append INTERNAL_GDBFLAGS " -x $temp_gdbinit"
106
107 # We have to start then exit GDB twice: the first time to test the creation
108 # of the initial history file, and the second time to test appending to it.
109 # In either case the initial "print 1" command should persist through the
110 # history file.
111 with_test_prefix "truncation" {
112 gdb_exit
113 gdb_start
114 gdb_test "print 1"
115
116 with_test_prefix "creating" {
117 gdb_exit
118 gdb_start
119 gdb_test "server show commands" " . print 1.*"
120 }
121
122 with_test_prefix "appending" {
123 gdb_exit
124 gdb_start
125 gdb_test "server show commands" " . print 1.*"
126 }
127 }
128 }
129 }
130
131 test_gdbinit_history_setting "gdbinit-history/unlimited" "unlimited"
132 test_gdbinit_history_setting "gdbinit-history/zero" "0"
133
134 test_no_truncation_of_unlimited_history_file
135
136 # A valid GDBHISTSIZE value overrides the setting inside the .gdbinit file; an
137 # invalid GDBHISTSIZE value is ignored, falling back on the setting inside the
138 # .gdbinit file.
139 test_gdbinit_history_setting "gdbinit-history/unlimited" "1000" "1000"
140 test_gdbinit_history_setting "gdbinit-history/unlimited" "unlimited" "foo"
This page took 0.033965 seconds and 4 git commands to generate.