xref: /freebsd/usr.bin/posixmqcontrol/posixmqcontroltest8x64.sh (revision 5b56413d04e608379c9a306373554a8e4d321bc0)
1#!/bin/sh
2# exercises create, info, send and recv subcommands.
3
4subject='posixmqcontrol'
5topic='/test123'
6
7${subject} info -q "$topic" 2>/dev/null
8if [ $? == 0 ]; then
9  echo "sorry, $topic exists."
10  exit 1
11fi
12
13# create trivial queue that can hold 8 messages of 64 bytes each.
14${subject} create -q "$topic" -s 64 -d 8
15if [ $? != 0 ]; then
16  exit 1
17fi
18
19info=$(${subject} info -q "$topic")
20if [ $? != 0 ]; then
21  exit 1
22fi
23expected='MSGSIZE: 64'
24actual=$(echo "${info}" | grep 'MSGSIZE: ')
25if [ "$expected" != "$actual" ]; then
26  echo "EXPECTED: $expected"
27  echo "  ACTUAL: $actual"
28  exit 1
29fi
30expected='MAXMSG: 8'
31actual=$(echo "${info}" | grep 'MAXMSG: ')
32if [ "$expected" != "$actual" ]; then
33  echo "EXPECTED: $expected"
34  echo "  ACTUAL: $actual"
35  exit 1
36fi
37expected='CURMSG: 0'
38actual=$(echo "${info}" | grep 'CURMSG: ')
39if [ "$expected" != "$actual" ]; then
40  echo "EXPECTED: $expected"
41  echo "  ACTUAL: $actual"
42  exit 1
43fi
44
45# write eight messages of increasing priority.
46for i in 1 2 3 4 5 6 7 8
47do
48  ${subject} send -q "$topic" -c "message $i" -p "$i"
49  if [ $? != 0 ]; then
50    exit 1
51  fi
52done
53
54info=$(${subject} info -q "$topic")
55if [ $? != 0 ]; then
56  exit
57fi
58expected='CURMSG: 8'
59actual=$(echo "${info}" | grep 'CURMSG: ')
60if [ "$expected" != "$actual" ]; then
61  echo "EXPECTED: $expected"
62  echo "  ACTUAL: $actual"
63  exit 1
64fi
65
66# expect the eight messages to appear in priority order.
67for i in 8 7 6 5 4 3 2 1
68do
69  expected='['"$i"']: message '"$i"
70  actual=$(${subject} recv -q "$topic")
71  if [ $? != 0 ]; then
72    exit
73  fi
74  if [ "$expected" != "$actual" ]; then
75    echo "EXPECTED: $expected"
76    echo "  ACTUAL: $actual"
77    exit 1
78  fi
79done
80
81info=$(${subject} info -q "$topic")
82if [ $? != 0 ]; then
83  exit 1
84fi
85expected='CURMSG: 0'
86actual=$(echo "${info}" | grep 'CURMSG: ')
87if [ "$expected" != "$actual" ]; then
88  echo "EXPECTED: $expected"
89  echo "  ACTUAL: $actual"
90  exit 1
91fi
92
93${subject} rm -q "$topic"
94if [ $? == 0 ]; then
95  echo "Pass!"
96  exit 0
97fi
98
99exit 1
100