2013-04-24 Muhammad Bilal <mbilal@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / info-os.exp
... / ...
CommitLineData
1# Copyright 2011-2013 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
16set testfile "info-os"
17set srcfile ${testfile}.c
18
19# This test is Linux-only.
20if ![istarget *-*-linux*] then {
21 unsupported "info-os.exp"
22 return -1
23}
24
25# Support for XML-output is needed to run this test.
26if [gdb_skip_xml_test] then {
27 unsupported "info-os.exp"
28 return -1
29}
30
31# Compile test program.
32if { [prepare_for_testing ${testfile}.exp $testfile $srcfile {debug additional_flags=-lpthread}] } {
33 fail "cannot compile test program"
34 return -1
35}
36
37if ![runto_main] then {
38 fail "cannot run to main"
39 return -1
40}
41
42# Get PID of test program.
43set inferior_pid -1
44set test "get inferior process ID"
45gdb_test_multiple "call getpid()" $test {
46 -re ".* = ($decimal).*$gdb_prompt $" {
47 set inferior_pid $expect_out(1,string)
48 pass $test
49 }
50}
51
52gdb_breakpoint ${srcfile}:[gdb_get_line_number "Set breakpoint here"]
53gdb_continue_to_breakpoint "Set breakpoint here"
54
55# Get keys and IDs of the IPC object instances.
56set shmkey -1
57set test "get shared memory key"
58gdb_test_multiple "print shmkey" $test {
59 -re ".* = ($decimal).*$gdb_prompt $" {
60 set shmkey $expect_out(1,string)
61 pass $test
62 }
63}
64set shmid -1
65set test "get shared memory ID"
66gdb_test_multiple "print shmid" $test {
67 -re ".* = ($decimal).*$gdb_prompt $" {
68 set shmid $expect_out(1,string)
69 pass $test
70 }
71}
72
73set semkey -1
74set test "get semaphore key"
75gdb_test_multiple "print semkey" $test {
76 -re ".* = ($decimal).*$gdb_prompt $" {
77 set semkey $expect_out(1,string)
78 pass $test
79 }
80}
81
82set semid -1
83set test "get semaphore ID"
84gdb_test_multiple "print semid" $test {
85 -re ".* = ($decimal).*$gdb_prompt $" {
86 set semid $expect_out(1,string)
87 pass $test
88 }
89}
90
91set msgkey -1
92set test "get message queue key"
93gdb_test_multiple "print msgkey" $test {
94 -re ".* = ($decimal).*$gdb_prompt $" {
95 set msgkey $expect_out(1,string)
96 pass $test
97 }
98}
99
100set msqid -1
101set test "get message queue ID"
102gdb_test_multiple "print msqid" $test {
103 -re ".* = ($decimal).*$gdb_prompt $" {
104 set msqid $expect_out(1,string)
105 pass $test
106 }
107}
108
109# Get port number of test socket.
110set port -1
111set test "get socket port number"
112gdb_test_multiple "print port" $test {
113 -re ".* = ($decimal).*$gdb_prompt $" {
114 set port $expect_out(1,string)
115 pass $test
116 }
117}
118
119# Act like gdb_test but prevent: +ERROR: internal buffer is full.
120
121proc expect_multiline { command expect test } {
122 global gdb_prompt
123
124 # Do not duplicate FAILs from gdb_test_multiple.
125 set pass 0
126 set fail 0
127 gdb_test_multiple $command $test {
128 -re "^$expect *\r\n" {
129 pass $test
130 set pass 1
131 exp_continue
132 }
133 -re "^$gdb_prompt $" {
134 if !$pass {
135 set fail 1
136 }
137 # Exit the loop.
138 }
139 -re "\r\n" {
140 # Drop the buffer.
141 exp_continue
142 }
143 }
144 if $fail {
145 fail $test
146 }
147}
148
149# Test output of the 'info os' commands against the expected results.
150
151# pid user command cores
152expect_multiline "info os processes" "$inferior_pid +\\S+ +\\S*info-os +\[0-9,\]+" "get process list"
153
154# pgid leader pid command line
155expect_multiline "info os procgroups" "$inferior_pid +info-os +$inferior_pid +\\S*info-os" "get process groups"
156
157# pid command tid core
158expect_multiline "info os threads" "$inferior_pid +info-os +\\d+ +\\d+" "get threads"
159
160# pid command fd name
161expect_multiline "info os files" "$inferior_pid +info-os +\\d+ +/dev/null" "get file descriptors"
162
163# local address l-port remote addr r-port state user family protocol
164expect_multiline "info os sockets" "0\\.0\\.0\\.0 +$port +0\\.0\\.0\\.0 +0 +LISTEN +\\S+ +INET +STREAM" "get internet-domain sockets"
165
166# 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
167expect_multiline "info os shm" "$shmkey +$shmid +666 +4096 +info-os .*" "get shared-memory regions"
168
169# key semid perm num semaphores user group creator user creator group last semop() time last semctl() time
170expect_multiline "info os semaphores" "$semkey +$semid +666 +1 .*" "get semaphores"
171
172# 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
173expect_multiline "info os msg" "$msgkey +$msqid +666 .*" "get message queues"
174
175
176# The SysV IPC primitives linger on after the creating process is killed
177# unless they are destroyed explicitly, so allow the test program to tidy
178# up after itself.
179gdb_test "continue" "exited.*"
This page took 0.022862 seconds and 4 git commands to generate.