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 scripted_test_process.c
22 : * @version 0.1
23 : * @brief This file contains implementation of Scripted Test Process.
24 : */
25 :
26 : /* ------------------------------------------------------------------------- */
27 : /* INCLUDE FILES */
28 : #include "scripted_test_process.h"
29 :
30 : /* ------------------------------------------------------------------------- */
31 : /* EXTERNAL DATA STRUCTURES */
32 : /* None */
33 :
34 : /* ------------------------------------------------------------------------- */
35 : /* EXTERNAL GLOBAL VARIABLES */
36 : /* ------------------------------------------------------------------------- */
37 : extern TMC_t *ptmc;
38 : extern DLList *tp_handlers;
39 : extern TSBool stprun;
40 : /* ------------------------------------------------------------------------- */
41 : /* EXTERNAL FUNCTION PROTOTYPES */
42 : /* None */
43 :
44 : /* ------------------------------------------------------------------------- */
45 : /* GLOBAL VARIABLES */
46 : /* None */
47 :
48 : /* ------------------------------------------------------------------------- */
49 : /* CONSTANTS */
50 : /* None */
51 :
52 : /* ------------------------------------------------------------------------- */
53 : /* MACROS */
54 : /* None */
55 :
56 : /* ------------------------------------------------------------------------- */
57 : /* LOCAL GLOBAL VARIABLES */
58 : /* None */
59 :
60 : /* ------------------------------------------------------------------------- */
61 : /* LOCAL CONSTANTS AND MACROS */
62 : /* None */
63 :
64 : /* ------------------------------------------------------------------------- */
65 : /* MODULE DATA STRUCTURES */
66 : /* None */
67 :
68 : /* ------------------------------------------------------------------------- */
69 : /* LOCAL FUNCTION PROTOTYPES */
70 : /* ------------------------------------------------------------------------- */
71 : /** Used for looking for specified class name on the list of them. */
72 : LOCAL int _look4class (const void *a, const void *b);
73 : /* ------------------------------------------------------------------------- */
74 : /** Handles MSG_RUN command.
75 : * @param msg [in] message that comes through IPC.
76 : *
77 : * This function runs a test function provided by the end user. The return
78 : * value of that function is picked as a test result and is send through
79 : * IPC in MSG_RET message.
80 : */
81 : LOCAL void stp_handle_run (const MsgBuffer * msg);
82 : /* ------------------------------------------------------------------------- */
83 : /* FORWARD DECLARATIONS */
84 : /* None */
85 :
86 : /* ------------------------------------------------------------------------- */
87 : /* ==================== LOCAL FUNCTIONS ==================================== */
88 : /* ------------------------------------------------------------------------- */
89 : LOCAL int _look4class (const void *a, const void *b)
90 27 : {
91 27 : TestClassDetails *tcd = (TestClassDetails *) a;
92 27 : MIN_DEBUG ("%s classname %s", __FUNCTION__, tcd->classname_);
93 27 : return strcmp (tcd->classname_, (char *)b);
94 : }
95 :
96 : /* ------------------------------------------------------------------------- */
97 : LOCAL void stp_handle_run (const MsgBuffer * msg)
98 27 : {
99 27 : DLListIterator it = DLListNULLIterator;
100 27 : TestClassDetails *tcd = INITPTR;
101 : MinItemParser mip;
102 27 : int ret = 0;
103 27 : int mq = mq_open_queue ('a');
104 : MsgBuffer result;
105 :
106 : /* 1) look-up for the class on the list */
107 27 : it = dl_list_find (dl_list_head (tp_handlers)
108 : , dl_list_tail (tp_handlers)
109 : , _look4class, msg->message_);
110 :
111 27 : if (it == DLListNULLIterator) {
112 0 : MIN_ERROR("No class [%s] on list.List has %d elements",
113 : msg->message_, dl_list_size (tp_handlers));
114 0 : goto EXIT;
115 : }
116 :
117 : /* 2) extract data from found item */
118 27 : tcd = (TestClassDetails *) dl_list_data (it);
119 :
120 : /* 3) extract data from IPC communicate */
121 27 : mip.item_line_section_ = NEW2 (char, strlen (msg->desc_) + 1);
122 27 : STRCPY (mip.item_line_section_, msg->desc_, strlen (msg->desc_) + 1);
123 27 : mip.item_skip_and_mark_pos_ = &mip.item_line_section_[0];
124 27 : mip.parsing_type_ = ENormalParsing;
125 27 : mip.get_methods_indicator_ = ESTrue;
126 27 : if (mip.item_line_section_ == INITPTR) {
127 0 : MIN_WARN ("MinItemParser is INITPTR");
128 0 : goto EXIT;
129 : }
130 :
131 : /* 4) call test function */
132 27 : ret = tcd->runtc_ (&mip);
133 :
134 : /* 5) when the test is finished we have to do something... */
135 : /* sending result back via IPC looks like a good idea. */
136 27 : result.receiver_ = getppid ();
137 27 : result.sender_ = getpid ();
138 27 : result.type_ = MSG_RET;
139 27 : result.param_ = ret;
140 27 : STRCPY (result.desc_, msg->desc_, MaxDescSize);
141 27 : STRCPY (result.message_, msg->desc_, MaxMsgSize);
142 27 : result.special_ = 0;
143 27 : mq_send_message (mq, &result);
144 27 : DELETE (mip.item_line_section_);
145 27 : EXIT:
146 : return;
147 : }
148 :
149 : /* ------------------------------------------------------------------------- */
150 : /* ======================== FUNCTIONS ====================================== */
151 : /* ------------------------------------------------------------------------- */
152 : void stp_handle_message (const MsgBuffer * msg)
153 27 : {
154 27 : switch (msg->type_) {
155 : case MSG_RUN:
156 27 : MIN_DEBUG ("Recieved message MSG_RUN from: %d, with"
157 : " param: %d [%s] [%s]",
158 : msg->sender_, msg->param_, msg->desc_,
159 : msg->message_);
160 27 : stp_handle_run (msg);
161 27 : break;
162 : default:
163 0 : MIN_WARN ("Unhandled message from %d: to %d, type: %d",
164 : msg->sender_, msg->receiver_, msg->type_);
165 : }
166 : return;
167 : }
168 :
169 : /* ------------------------------------------------------------------------- */
170 : void stp_handle_sigusr2 (int signum)
171 6 : {
172 6 : stprun = ESFalse;
173 6 : }
174 :
175 : /* ------------------------------------------------------------------------- */
176 : void stp_exit ()
177 6 : {
178 6 : DLListIterator it = DLListNULLIterator;
179 6 : TestClassDetails *tcd = INITPTR;
180 :
181 : /* 1) We need to clean the list with pointers to run function. */
182 6 : it = dl_list_tail (tp_handlers);
183 :
184 18 : while (it != DLListNULLIterator) {
185 6 : tcd = (TestClassDetails *) dl_list_data (it);
186 6 : if (tcd != INITPTR) {
187 6 : dlclose (tcd->dllhandle_);
188 6 : DELETE (tcd->classname_);
189 6 : DELETE (tcd);
190 6 : it->data_ = INITPTR;
191 : } else {
192 0 : MIN_ERROR ("Unable to obtain TCD");
193 : }
194 6 : dl_list_remove_it (it);
195 6 : it = dl_list_tail (tp_handlers);
196 : }
197 :
198 : /* resend msgs from buffer, flush the mq buffer. */
199 6 : mq_resend_buffered ();
200 6 : mq_flush_msg_buffer ();
201 :
202 6 : MIN_TRACE ("Exiting");
203 : /* 2) At the end exit gracefully. */
204 6 : exit (TP_EXIT_SUCCESS);
205 : return;
206 : }
207 : /* ------------------------------------------------------------------------- */
208 : /* ================= OTHER EXPORTED FUNCTIONS ============================== */
209 : /* None */
210 :
211 : /* ------------------------------------------------------------------------- */
212 : /* ================= TESTS FOR LOCAL FUNCTIONS ============================= */
213 : #ifdef MIN_UNIT_TEST
214 :
215 : #endif /* MIN_UNIT_TEST */
216 : /* End of file */
|