1 # Copyright 2011 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 set testfile "info-os"
17 set srcfile ${testfile}.c
19 # This test is Linux-only.
20 if ![istarget *-*-linux*] then {
21 unsupported "info-os.exp"
25 # Support for XML-output is needed to run this test.
26 if [gdb_skip_xml_test] then {
27 unsupported "info-os.exp"
31 # Compile test program.
32 if { [prepare_for_testing ${testfile}.exp $testfile $srcfile {debug additional_flags=-lpthread}] } {
33 fail "cannot compile test program"
37 if ![runto_main] then {
38 fail "cannot run to main"
42 # Get PID of test program.
44 set test "get inferior process ID"
45 gdb_test_multiple "call getpid()" $test {
46 -re ".* = ($decimal).*$gdb_prompt $" {
47 set inferior_pid $expect_out(1,string)
52 gdb_breakpoint ${srcfile}:[gdb_get_line_number "Set breakpoint here"]
53 gdb_continue_to_breakpoint "Set breakpoint here"
55 # Get IDs of the IPC object instances.
57 set test "get shared memory ID"
58 gdb_test_multiple "print shmid" $test {
59 -re ".* = ($decimal).*$gdb_prompt $" {
60 set shmid $expect_out(1,string)
66 set test "get semaphore ID"
67 gdb_test_multiple "print semid" $test {
68 -re ".* = ($decimal).*$gdb_prompt $" {
69 set semid $expect_out(1,string)
75 set test "get message queue ID"
76 gdb_test_multiple "print msqid" $test {
77 -re ".* = ($decimal).*$gdb_prompt $" {
78 set msqid $expect_out(1,string)
83 # Get port number of test socket.
85 set test "get socket port number"
86 gdb_test_multiple "print port" $test {
87 -re ".* = ($decimal).*$gdb_prompt $" {
88 set port $expect_out(1,string)
93 # Test output of the 'info os' commands against the expected results.
94 gdb_test "info os processes" ".*pid +user +command +cores.*$inferior_pid +\\S+ +\\S*info-os +\[0-9\]+.*" "get process list"
95 gdb_test "info os procgroups" ".*pgid +leader command +pid +command line.*$inferior_pid +info-os +$inferior_pid +\\S*info-os.*" "get process groups"
96 gdb_test "info os threads" ".*pid +command +tid +core.*$inferior_pid +info-os +\\d+ +\\d+.*" "get threads"
97 gdb_test "info os files" ".*pid +command +file descriptor +name.*$inferior_pid +info-os +\\d+ +/dev/null.*" "get file descriptors"
98 gdb_test "info os sockets" ".*local address +local port +remote address +remote port +state +user +family +protocol.*0\\.0\\.0\\.0 +$port +0\\.0\\.0\\.0 +0 +LISTEN +\\S+ +INET +STREAM.*" "get internet-domain sockets"
99 gdb_test "info os shm" ".*key +shmid +permissions +size +creator command +last op\\. command +num attached +user +group +creator user +creator group +last shmat\\(\\) time +last shmdt\\(\\) time +last shmctl\\(\\) time.*3925 +$shmid +666 +4096 +info-os +.*" "get shared-memory regions"
100 gdb_test "info os semaphores" ".*key +semid +permissions +num semaphores +user +group +creator user +creator group +last semop\\(\\) time +last semctl\\(\\) time.*7428 +$semid +666 +1 +.*" "get semaphores"
101 gdb_test "info os msg" ".*key +msqid +permissions +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.*5294 +$msqid +666 +.*" "get message queues"
103 # The SysV IPC primitives linger on after the creating process is killed
104 # unless they are destroyed explicitly, so allow the test program to tidy
105 # up after itself. Note that the test program attempts to delete and
106 # recreate the shared-memory region if it already exists, in case a
107 # previous run failed before having a chance to clean up. The tests for
108 # semaphores and message queues should still work with primitives from
110 send_gdb "continue\n"