Automatic Copyright Year update after running gdb/copyright.py
[binutils-gdb.git] / gdb / testsuite / gdb.base / info-os.exp
blob7967e2e43df5ea70dda780e25eb9975f5b307c5e
1 # Copyright 2011-2022 Free Software Foundation, Inc.
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.
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.
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/>.
16 standard_testfile .c
18 # This test is Linux-only.
19 if ![istarget *-*-linux*] then {
20     unsupported "info-os.exp"
21     return -1
24 # Support for XML-output is needed to run this test.
25 if [gdb_skip_xml_test] then {
26     unsupported "info-os.exp"
27     return -1
30 # Compile test program.
31 if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug pthreads}] } {
32     return -1
35 if ![runto_main] then {
36     return -1
39 # Get PID of test program.
40 set inferior_pid ""
41 set test "get inferior process ID"
42 gdb_test_multiple "call (int) getpid()" $test {
43     -re ".* = ($decimal).*$gdb_prompt $" {
44         set inferior_pid $expect_out(1,string)
45         pass $test
46     }
48 if {$inferior_pid == ""} {
49     untested "failed to get pid"
50     return
53 gdb_breakpoint ${srcfile}:[gdb_get_line_number "Set breakpoint here"]
54 gdb_continue_to_breakpoint "Set breakpoint here"
56 # Get keys and IDs of the IPC object instances.
57 set shmkey -1
58 set test "get shared memory key"
59 gdb_test_multiple "print shmkey" $test {
60     -re ".* = ($decimal).*$gdb_prompt $" {
61         set shmkey $expect_out(1,string)
62         pass $test
63     }
65 set shmid -1
66 set test "get shared memory ID"
67 gdb_test_multiple "print shmid" $test {
68     -re ".* = ($decimal).*$gdb_prompt $" {
69         set shmid $expect_out(1,string)
70         pass $test
71     }
74 set semkey -1
75 set test "get semaphore key"
76 gdb_test_multiple "print semkey" $test {
77     -re ".* = ($decimal).*$gdb_prompt $" {
78         set semkey $expect_out(1,string)
79         pass $test
80     }
83 set semid -1
84 set test "get semaphore ID"
85 gdb_test_multiple "print semid" $test {
86     -re ".* = ($decimal).*$gdb_prompt $" {
87         set semid $expect_out(1,string)
88         pass $test
89     }
92 set msgkey -1
93 set test "get message queue key"
94 gdb_test_multiple "print msgkey" $test {
95     -re ".* = ($decimal).*$gdb_prompt $" {
96         set msgkey $expect_out(1,string)
97         pass $test
98     }
101 set msqid -1
102 set test "get message queue ID"
103 gdb_test_multiple "print msqid" $test {
104     -re ".* = ($decimal).*$gdb_prompt $" {
105         set msqid $expect_out(1,string)
106         pass $test
107     }
110 # Get port number of test socket.
111 set port -1
112 set test "get socket port number"
113 gdb_test_multiple "print port" $test {
114     -re ".* = ($decimal).*$gdb_prompt $" {
115         set port $expect_out(1,string)
116         pass $test
117     }
120 # Act like gdb_test but prevent: +ERROR: internal buffer is full.
122 proc expect_multiline { command expect test } {
123     global gdb_prompt
125     # Do not duplicate FAILs from gdb_test_multiple.
126     set found 0
127     set ok 0
128     gdb_test_multiple $command $test {
129         -re "^$expect *\r\n" {
130             set found 1
131             exp_continue
132         }
133         -re "^$gdb_prompt $" {
134             if $found {
135                 set ok 1
136             }
137             # Exit the loop.
138         }
139         -re "\r\n" {
140             # Drop the buffer.
141             exp_continue
142         }
143     }
144     gdb_assert { $ok } $test
147 # Test output of the 'info os' commands against the expected results.
149 #                                     pid            user  command      cores
150 expect_multiline "info os processes" "$inferior_pid +\\S+ +\\S*info-os +\[0-9,\]+" "get process list"
152 #                                      pgid           leader   pid            command line
153 expect_multiline "info os procgroups" "$inferior_pid +info-os +$inferior_pid +\\S*info-os" "get process groups"
155 #                                   pid            command  tid   core
156 expect_multiline "info os threads" "$inferior_pid +info-os +\\d+ +\\d+" "get threads"
158 #                                 pid            command  fd    name
159 expect_multiline "info os files" "$inferior_pid +info-os +\\d+ +/dev/null" "get file descriptors"
161 #                                   local address  l-port remote addr r-port state  user family protocol
162 expect_multiline "info os sockets" "0\\.0\\.0\\.0 +$port +0\\.0\\.0\\.0 +0 +LISTEN +\\S+ +INET +STREAM" "get internet-domain sockets"
164 #                               key   shmid   perm size creator command last op  command  num attached  user  group  creator user  creator group  last shmat() time  last shmdt() time  last shmctl() time
165 expect_multiline "info os shm" "$shmkey +$shmid +666 +4096 +info-os .*" "get shared-memory regions"
167 #                                      key   semid   perm num semaphores  user  group  creator user  creator group  last semop() time  last semctl() time
168 expect_multiline "info os semaphores" "$semkey +$semid +666 +1 .*" "get semaphores"
170 #                               key   msqid   perm  num used bytes  num messages  last msgsnd() command  last msgrcv() command  user  group  creator user  creator group  last msgsnd() time  last msgrcv() time  last msgctl() time
171 expect_multiline "info os msg" "$msgkey +$msqid +666 .*" "get message queues"
173 gdb_test "info os unknown_entry" [multi_line \
174         "warning: Empty data returned by target.  Wrong osdata type\\\?" \
175         "Can not fetch data now."]
177 # The SysV IPC primitives linger on after the creating process is killed
178 # unless they are destroyed explicitly, so allow the test program to tidy
179 # up after itself.
180 gdb_test "continue" "exited.*"