2 * Dlt Test Client - Diagnostic Log and Trace
5 * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de>
7 * This program is free software; you can redistribute it and/or modify it under the terms of the
8 * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
11 * Public License, version 2.1, for more details.
13 * You should have received a copy of the GNU Lesser General Public License, version 2.1, along
14 * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
16 * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may
17 * also be applicable to programs even in cases in which the program is not a library in the technical sense.
19 * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may
20 * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to
21 * license your linked modules under the GNU Lesser General Public License, version 2.1, you
22 * may use the program under the following exception.
24 * As a special exception, the copyright holders of DLT give you permission to combine DLT
25 * with software programs or libraries that are released under any license unless such a combination is not
26 * permitted by the license of such a software program or library. You may copy and distribute such a
27 * system following the terms of the GNU Lesser General Public License, version 2.1, including this
28 * special exception, for DLT and the licenses of the other code concerned.
30 * Note that people who make modified versions of DLT are not obligated to grant this special exception
31 * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License,
32 * version 2.1, gives permission to release a modified version without this exception; this exception
33 * also makes it possible to release a modified version which carries forward this exception.
39 /*******************************************************************************
41 ** SRC-MODULE: dlt-test-client.c **
47 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
53 ** PLATFORM DEPENDANT [yes/no]: yes **
55 ** TO BE CHANGED BY USER [yes/no]: no **
57 *******************************************************************************/
59 /*******************************************************************************
61 ********************************************************************************
63 ** Initials Name Company **
64 ** -------- ------------------------- ---------------------------------- **
65 ** aw Alexander Wenzel BMW **
66 *******************************************************************************/
69 #include <dlt_filetransfer.h> /*Needed for transferring files with the dlt protocol*/
70 #include <dlt.h> /*Needed for dlt logging*/
72 //!Declare some context for the main program. It's a must have to do this, when you want to log with dlt.
73 DLT_DECLARE_CONTEXT(mainContext);
75 //!Declare some context for the file transfer. It's not a must have to do this, but later you can set a filter on this context in the dlt viewer.
76 DLT_DECLARE_CONTEXT(fileContext);
78 //!Textfile which will be transferred.
80 //!Image which will be transferred.
82 //!Not existing file which will be transferred.
84 //!Not existing file which will be transferred.
86 //!Not existing file which will be transferred.
88 //!Just some variables
89 int i,countPackages, transferResult, dltResult;
91 //!Prints the test result
92 void printTestResultPositiveExpected(const char *function, int result){
95 printf("%s successful\n",function);
99 printf("%s failed\n",function);
104 //!Prints the test result
105 void printTestResultNegativeExpected(const char *function, int result){
108 printf("%s successful\n",function);
112 printf("%s failed\n",function);
117 //!Test the file transfer with the condition that the transferred file is smaller as the file transfer buffer using dlt_user_log_file_complete.
119 //Just some log to the main context
120 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF1P1 - dlt_user_log_file_complete"),DLT_STRING(file1));
122 //Here's the line where the dlt file transfer is called. The method call needs a context, the absolute file path, will the file be deleted after transfer and the timeout between the packages
123 transferResult = dlt_user_log_file_complete(&fileContext,file1,0,20);
124 if(transferResult < 0 )
126 printf("Error: dlt_user_log_file_complete\n");
127 return transferResult;
129 //Just some log to the main context
130 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF1P1"),DLT_STRING(file1));
132 printTestResultPositiveExpected(__FUNCTION__,transferResult);
134 return transferResult;
137 //!Test the file transfer with the condition that the transferred file is smaller as the file transfer buffer using single package transfer
139 int total_size, used_size;
141 //Get the information how many packages have the file
142 countPackages = dlt_user_log_file_packagesCount(&fileContext,file1);
143 if(countPackages < 0 )
145 printf("Error: dlt_user_log_file_packagesCount\n");
146 printTestResultPositiveExpected(__FUNCTION__,countPackages);
149 //Just some log to the main context
150 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF1P2 - transfer single package"),DLT_STRING(file1));
152 //Logs the header of the file transfer. For more details see Mainpage.c.
153 //The header gives information about the file serial number, filename (with absolute path), filesize, packages of file, buffer size
154 transferResult = dlt_user_log_file_header(&fileContext,file1);
155 if(transferResult >= 0)
157 //Loop to log all packages
158 for(i=1;i<=countPackages;i++)
160 dlt_user_check_buffer(&total_size, &used_size);
161 if((total_size - used_size) < (total_size/2))
163 printf("Error: dlt_user_log_file_data\n");
164 printTestResultPositiveExpected(__FUNCTION__,transferResult);
168 //Logs one single package to the file context
169 transferResult = dlt_user_log_file_data(&fileContext,file1,i,20);
170 if(transferResult < 0)
172 printf("Error: dlt_user_log_file_data\n");
173 printTestResultPositiveExpected(__FUNCTION__,transferResult);
174 return transferResult;
178 //Logs the end of the file transfer. For more details see Mainpage.c
179 //The end gives just information about the file serial number but is needed to signal that the file transfer has correctly finished and needed for the file transfer plugin of the dlt viewer.
180 transferResult = dlt_user_log_file_end(&fileContext,file1,0);
181 if(transferResult < 0)
183 printf("Error: dlt_user_log_file_end\n");
184 printTestResultPositiveExpected(__FUNCTION__,transferResult);
185 return transferResult;
190 printf("Error: dlt_user_log_file_header\n");
191 printTestResultPositiveExpected(__FUNCTION__,transferResult);
192 return transferResult;
195 //Just some log to main context
196 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF1P2 - transfer single package"),DLT_STRING(file1));
197 printTestResultPositiveExpected(__FUNCTION__,transferResult);
200 //!Test the file transfer with the condition that the transferred file is bigger as the file transfer buffer using dlt_user_log_file_complete.
202 //Just some log to main context
203 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF2P1 - dlt_user_log_file_complete"),DLT_STRING(file2));
205 //Here's the line where the dlt file transfer is called. The method call needs a context, the absolute file path, will the file be deleted after transfer and the timeout between the packages
206 transferResult = dlt_user_log_file_complete(&fileContext,file2,0,20);
207 if(transferResult < 0)
209 printf("Error: dlt_user_log_file_complete\n");
210 printTestResultPositiveExpected(__FUNCTION__,transferResult);
211 return transferResult;
213 //Just some log to main context
214 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF2P1"),DLT_STRING(file2));
215 printTestResultPositiveExpected(__FUNCTION__,transferResult);
216 return transferResult;
219 //!Test the file transfer with the condition that the transferred file is bigger as the file transfer buffer using single package transfer
221 int total_size, used_size;
223 //Get the information how many packages have the file
224 countPackages = dlt_user_log_file_packagesCount(&fileContext,file2);
225 if(countPackages < 0 )
227 printf("Error: dlt_user_log_file_packagesCount\n");
228 printTestResultPositiveExpected(__FUNCTION__,countPackages);
232 //Just some log to the main context
233 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF2P2 - transfer single package"),DLT_STRING(file2));
235 //Logs the header of the file transfer. For more details see Mainpage.c.
236 //The header gives information about the file serial number, filename (with absolute path), filesize, packages of file, buffer size
237 transferResult = dlt_user_log_file_header(&fileContext,file2);
238 if( transferResult >= 0){
240 //Loop to log all packages
241 for(i=1;i<=countPackages;i++)
243 dlt_user_check_buffer(&total_size, &used_size);
244 if((total_size - used_size) < (total_size/2))
246 printf("Error: dlt_user_log_file_data\n");
247 printTestResultPositiveExpected(__FUNCTION__,transferResult);
251 //Logs one single package to the file context
252 transferResult = dlt_user_log_file_data(&fileContext,file2,i,20);
253 if(transferResult < 0)
255 printf("Error: dlt_user_log_file_data\n");
256 printTestResultPositiveExpected(__FUNCTION__,transferResult);
257 return transferResult;
261 //Logs the end of the file transfer. For more details see Mainpage.c
262 //The end gives just information about the file serial number but is needed to signal that the file transfer has correctly finished and needed for the file transfer plugin of the dlt viewer.
263 transferResult = dlt_user_log_file_end(&fileContext,file2,0);
264 if(transferResult < 0)
266 printf("Error: dlt_user_log_file_end\n");
267 printTestResultPositiveExpected(__FUNCTION__,transferResult);
268 return transferResult;
273 printf("Error: dlt_user_log_file_header\n");
274 printTestResultPositiveExpected(__FUNCTION__,transferResult);
275 return transferResult;
277 //Just some log to the main context
278 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF2P2"),DLT_STRING(file2));
279 printTestResultPositiveExpected(__FUNCTION__,transferResult);
283 //!Test the file transfer with the condition that the transferred file does not exist using dlt_user_log_file_complete.
286 //Just some log to the main context
287 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF3P1"),DLT_STRING(file3_1));
289 //Here's the line where the dlt file transfer is called. The method call needs a context, the absolute file path, will the file be deleted after transfer and the timeout between the packages
290 transferResult = dlt_user_log_file_complete(&fileContext,file3_1,0,20);
291 if(transferResult < 0)
293 //Error expected because file doesn't exist
294 //printf("Error: dlt_user_log_file_complete\n");
295 //Just some log to the main context
296 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P1"),DLT_STRING(file3_1));
297 printTestResultNegativeExpected(__FUNCTION__,transferResult);
298 return transferResult;
300 printTestResultNegativeExpected(__FUNCTION__,transferResult);
301 return transferResult;
305 //!Test the file transfer with the condition that the transferred file does not exist using single package transfer
308 //Get the information how many packages have the file
309 countPackages = dlt_user_log_file_packagesCount(&fileContext,file3_2);
310 if(countPackages < 0 )
312 //Error expected because file doesn't exist
313 //printf("Error: dlt_user_log_file_packagesCount\n");
314 //Just some log to the main context
315 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P1"),DLT_STRING(file3_2));
316 printTestResultNegativeExpected(__FUNCTION__,countPackages);
319 //Just some log to the main context
320 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF3P1"),DLT_STRING(file3_2));
322 //Logs the header of the file transfer. For more details see Mainpage.c.
323 //The header gives information about the file serial number, filename (with absolute path), filesize, packages of file, buffer size
324 transferResult = dlt_user_log_file_header(&fileContext,file3_2);
325 if( transferResult >= 0){
327 //Loop to log all packages
328 for(i=1;i<=countPackages;i++)
330 //Logs one single package to the file context
331 transferResult = dlt_user_log_file_data(&fileContext,file3_2,i,20);
332 if(transferResult < 0)
334 printf("Error: dlt_user_log_file_data\n");
335 printTestResultNegativeExpected(__FUNCTION__,transferResult);
336 return transferResult;
340 //Logs the end of the file transfer. For more details see Mainpage.c
341 //The end gives just information about the file serial number but is needed to signal that the file transfer has correctly finished and needed for the file transfer plugin of the dlt viewer.
342 transferResult = dlt_user_log_file_end(&fileContext,file3_2,0);
343 if(transferResult < 0)
345 printf("Error: dlt_user_log_file_end\n");
346 printTestResultNegativeExpected(__FUNCTION__,transferResult);
347 return transferResult;
350 printTestResultNegativeExpected(__FUNCTION__,transferResult);
355 //!Logs some information about the file.
358 //Just some log to the main context
359 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Started testF3P2"),DLT_STRING(file3_3));
361 //Here's the line where the dlt file file info is called. The method call logs some information to dlt about the file, filesize, file serial number and number of packages
362 transferResult = dlt_user_log_file_infoAbout(&fileContext,file3_3);
363 if(transferResult < 0)
365 //Error expected because file doesn't exist
366 //printf("Error: dlt_user_log_file_infoAbout\n");
367 //Just some log to the main context
368 DLT_LOG(mainContext,DLT_LOG_INFO,DLT_STRING("Finished testF3P2"),DLT_STRING(file3_3));
369 printTestResultNegativeExpected(__FUNCTION__,transferResult);
370 return transferResult;
372 printTestResultNegativeExpected(__FUNCTION__,transferResult);
376 //!Main program dlt-test-filestransfer starts here
379 //First file contains some text
380 file1 = "/usr/share/dlt-filetransfer/dlt-test-filetransfer-file";
381 //Second file is a picture
382 file2 = "/usr/share/dlt-filetransfer/dlt-test-filetransfer-image.png";
383 //Third file doesn't exist. Just to test the reaction when the file isn't available.
384 file3_1 = "dlt-test-filetransfer-doesntExist_1";
385 //Third file doesn't exist. Just to test the reaction when the file isn't available.
386 file3_2 = "dlt-test-filetransfer-doesntExist_2";
387 //Third file doesn't exist. Just to test the reaction when the file isn't available.
388 file3_3 = "dlt-test-filetransfer-doesntExist_3";
390 //Register the application at the dlt-daemon
391 dltResult = DLT_REGISTER_APP("FLTR","Test Application filetransfer");
392 // if(dltResult < 0){
393 // printf("Error: DLT_REIGSTER_APP: FLTR\n");
396 //Register the context of the main program at the dlt-daemon
397 dltResult = DLT_REGISTER_CONTEXT(mainContext,"MAIN","Main context for filetransfer test");
398 // if(dltResult < 0){
399 // printf("Error: DLT_REGISTER_CONTEXT: MAIN\n");
402 //Register the context in which the file transfer will be logged at the dlt-daemon
403 dltResult = DLT_REGISTER_CONTEXT(fileContext,"FLTR","Test Context for filetransfer");
404 // if(dltResult < 0){
405 // printf("Error: DLT_REGISTER_CONTEXT:FLTR\n");
409 //More details in corresponding methods
418 //Unregister the context in which the file transfer happened from the dlt-daemon
419 DLT_UNREGISTER_CONTEXT(fileContext);
420 //Unregister the context of the main program from the dlt-daemon
421 DLT_UNREGISTER_CONTEXT(mainContext);
422 //Unregister the app from the dlt-daemon
423 DLT_UNREGISTER_APP();