1 : /*
2 : * This file is part of MIN Test Framework. Copyright © 2008 Nokia Corporation
3 : * and/or its subsidiary(-ies).
4 : * Contact: Konrad Marek Zapalowicz
5 : * Contact e-mail: DG.MIN-Support@nokia.com
6 : *
7 : * This program is free software: you can redistribute it and/or modify it
8 : * under the terms of the GNU General Public License as published by the Free
9 : * Software Foundation, version 2 of the License.
10 : *
11 : * This program is distributed in the hope that it will be useful, but WITHOUT
12 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 : * more details. You should have received a copy of the GNU General Public
15 : * License along with this program. If not, see
16 : * <http://www.gnu.org/licenses/>.
17 : */
18 :
19 :
20 : /**
21 : * @file min_ipc_mechanism.test
22 : * @version 0.1
23 : * @brief This file contains test for MIN IPC Mechanism
24 : */
25 :
26 : /* ------------------------------------------------------------------------- */
27 : /* INCLUDES */
28 : #include <check.h>
29 : #include <stdio.h>
30 : #include "min_ipc_mechanism.h"
31 :
32 : /* ------------------------------------------------------------------------- */
33 : /* CONSTANTS */
34 : /* None */
35 :
36 : /* ------------------------------------------------------------------------- */
37 : /* MACROS */
38 : /* None */
39 :
40 : /* ------------------------------------------------------------------------- */
41 : /* DATA TYPES */
42 : /* None */
43 :
44 : /* ------------------------------------------------------------------------- */
45 : /* LOCAL FUNCTION PROTOTYPES */
46 : /* None */
47 :
48 : /* ------------------------------------------------------------------------- */
49 : /* FORWARD DECLARATIONS */
50 : /* None */
51 :
52 : /* ------------------------------------------------------------------------- */
53 : /* STRUCTURES */
54 : /* None */
55 :
56 : /* ------------------------------------------------------------------------- */
57 : /* ==================== LOCAL FUNCTIONS ==================================== */
58 : /* None */
59 :
60 : /* ------------------------------------------------------------------------- */
61 : /* ============================= TESTS ===================================== */
62 : /* ------------------------------------------------------------------------- */
63 1 : START_TEST(test_ipc_open)
64 : {
65 : char buf[512];
66 : char command[256];
67 1 : int mqid = 0;
68 1 : FILE *fp = NULL;
69 1 : buf[0] = '\0';
70 :
71 1 : mqid = mq_open_queue('a');
72 1 : sprintf(command,"ipcs -q | grep %d",mqid);
73 1 : fp = popen(command, "r");
74 1 : fail_unless(fp != NULL,"Error executing ipcs command");
75 3 : while( fgets(buf, 512, fp) != NULL )
76 1 : fail_unless(strlen(buf) > 0,"Queue not opened.");
77 1 : pclose(fp);
78 :
79 1 : mqid = mq_open_queue('a');
80 1 : sprintf(command,"ipcs -q | grep %d",mqid);
81 1 : fp = popen(command, "r");
82 1 : fail_unless(fp != NULL,"Error executing ipcs command");
83 3 : while( fgets(buf, 512, fp) != NULL )
84 1 : fail_unless(strlen(buf) > 0,"Queue not opened.");
85 1 : pclose(fp);
86 :
87 1 : mqid = mq_open_queue('a');
88 1 : sprintf(command,"ipcs -q | grep %d",mqid);
89 1 : fp = popen(command, "r");
90 1 : fail_unless(fp != NULL,"Error executing ipcs command");
91 3 : while( fgets(buf, 512, fp) != NULL )
92 1 : fail_unless(strlen(buf) > 0,"Queue not opened.");
93 1 : pclose(fp);
94 1 : mq_close_queue(mqid);
95 : }
96 1 : END_TEST
97 : /* ------------------------------------------------------------------------- */
98 1 : START_TEST(test_ipc_close)
99 : {
100 : char buf[512];
101 : char command[256];
102 1 : int mqid = 0;
103 1 : FILE *fp = NULL;
104 1 : buf[0] = '\0';
105 :
106 1 : mqid = mq_open_queue('a');
107 1 : sprintf(command,"ipcs -q | grep %d",mqid);
108 1 : fp = popen(command, "r");
109 1 : fail_unless(fp != NULL,"Error executing ipcs command");
110 3 : while( fgets(buf, 512, fp) != NULL )
111 1 : fail_unless(strlen(buf) > 0,"Queue not opened.");
112 1 : pclose(fp);
113 1 : mq_close_queue(mqid);
114 1 : fp = popen(command, "r");
115 1 : fail_unless(fp != NULL,"Error executing ipcs command");
116 2 : while( fgets(buf, 512, fp) != NULL )
117 0 : fail_unless(strlen(buf) == 0,"Queue not closed.");
118 1 : pclose(fp);
119 : }
120 1 : END_TEST
121 : /* ------------------------------------------------------------------------- */
122 1 : START_TEST(test_ipc_peek)
123 : {
124 1 : int mqid = 0;
125 1 : int peek = 0;
126 1 : mqid = mq_open_queue('a');
127 1 : fail_unless( mqid != -1, "Open queue error" );
128 1 : peek = mq_peek_message(mqid,0);
129 1 : fail_unless( peek == 0, "Peek queue error" );
130 1 : mq_send_message2(mqid,1,1,1,"");
131 1 : peek = mq_peek_message(mqid,0);
132 1 : fail_unless( peek == 1, "Peek queue error" );
133 1 : mq_close_queue(mqid);
134 : }
135 1 : END_TEST
136 : /* ------------------------------------------------------------------------- */
137 1 : START_TEST(test_ipc_send)
138 : {
139 1 : int mqid = mq_open_queue('a');
140 1 : int peek = 0;
141 1 : int retval = 0;
142 1 : fail_unless( mqid != -1, "Open queue error" );
143 1 : retval = mq_send_message2(mqid,1,1,1,"");
144 1 : fail_unless(retval != -1, "Problem with sending message");
145 1 : peek = mq_peek_message(mqid,0);
146 1 : fail_unless( peek == 1, "Peek queue error" );
147 1 : mq_close_queue(mqid);
148 : }
149 1 : END_TEST
150 : /* ------------------------------------------------------------------------- */
151 0 : START_TEST(test_ipc_recieve)
152 : {
153 0 : int mqid = mq_open_queue('a');
154 0 : int retval = 0;
155 : MsgBuffer msg;
156 0 : fail_unless( mqid != -1, "Open queue error" );
157 0 : retval = mq_read_message(0,0,&msg);
158 0 : fail_unless( retval == -1, "Read queue error" );
159 0 : retval = mq_send_message2(mqid,1,1,1,"ala ma kota");
160 0 : fail_unless(retval != -1, "Problem with sending message");
161 0 : retval = mq_read_message(mqid,0,&msg);
162 0 : fail_unless( retval != -1, "Read queue error" );
163 0 : fail_unless( msg.receiver_ == 1, "Reciever field bad value" );
164 0 : fail_unless( msg.sender_ == getpid(), "Sender field bad value" );
165 0 : fail_unless( msg.type_ == 1, "Type field bad value" );
166 0 : fail_unless( msg.param_ == 1, "Param field bad value" );
167 0 : fail_unless( strcmp(msg.message_,"ala ma kota")==0
168 : , "Message field bad value" );
169 0 : mq_close_queue(mqid);
170 : }
171 0 : END_TEST
172 : /* ------------------------------------------------------------------------- */
173 : /* ========================== FUNCTIONS ==================================== */
174 : /* ------------------------------------------------------------------------- */
175 : Suite* ipc_suite()
176 5 : {
177 5 : Suite * s = suite_create ("ipc");
178 :
179 : /* Core test case */
180 5 : TCase *tc_core = tcase_create ("Core");
181 5 : tcase_add_test (tc_core, test_ipc_open);
182 5 : tcase_add_test (tc_core, test_ipc_close);
183 5 : tcase_add_test (tc_core, test_ipc_peek);
184 5 : tcase_add_test (tc_core, test_ipc_send);
185 : // tcase_add_test (tc_core, test_ipc_recieve);
186 5 : suite_add_tcase (s, tc_core);
187 :
188 5 : return s;
189 : }
190 : /* ------------------------------------------------------------------------- */
191 : int ipc_tests()
192 5 : {
193 5 : int number_failed = 0;
194 5 : Suite * s = ipc_suite ();
195 5 : SRunner * sr = srunner_create (s);
196 5 : srunner_run_all(sr, CK_NORMAL);
197 1 : number_failed = srunner_ntests_failed(sr);
198 1 : srunner_free(sr);
199 1 : return number_failed;
200 : }
201 : /* ------------------------------------------------------------------------- */
202 : /* End of file */
|