]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/util/test/testAliHLTCorruptorComponent.C
Fixing in/out tags in documentation
[u/mrichter/AliRoot.git] / HLT / BASE / util / test / testAliHLTCorruptorComponent.C
CommitLineData
1e5db830 1/**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Primary Authors: Artur Szostak <artursz@iafrica.com> *
6 * for The ALICE HLT Project. *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
17/**
18 * @file testCorruptorComponent.C
19 * @author Artur Szostak <artursz@iafrica.com>
20 * @date 5 Aug 2010
21 *
22 * This macro is used to test the basic functionality of the AliHLTCorruptorComponent
23 * class.
24 */
25
26#if !defined(__CINT__) || defined(__MAKECINT__)
27#include "Riostream.h"
28#include "TSystem.h"
29#include "TClassTable.h"
30#include "TBits.h"
31#include "AliLog.h"
32#include "AliHLTSystem.h"
33#include "AliHLTConfiguration.h"
34#include <fstream>
35#include <cstdlib>
36#endif
37
38/**
39 * Creates the input data for the test.
40 * It is just a file of 256 bytes with all zeros.
41 */
42void GenerateInputData(bool debug = false)
43{
44 using namespace std;
45 const char* filename = "corruptorInputTestFile.dat";
46 fstream file(filename, ios::trunc | ios::out | ios::binary);
47 if (! file)
48 {
49 if (debug) cerr << "ERROR: Could not create file " << filename << endl;
50 return;
51 }
52 char buffer[256];
53 memset(buffer, 0x0, sizeof(buffer));
54 file.write(buffer, sizeof(buffer));
55 if (! file)
56 {
57 if (debug) cerr << "ERROR: I/O error when writing to file " << filename << endl;
58 return;
59 }
60 file.close();
61}
62
63/**
64 * Routine to check that the filtering of the data blocks works with the corruptor
65 * component. Only filtered blocks should be modified.
66 */
67void RunChainToCheckFiltering(bool debug = false)
68{
69 AliHLTSystem sys;
70 sys.LoadComponentLibraries("libAliHLTUtil.so");
71 if (debug)
72 {
73 sys.SetGlobalLoggingLevel(kHLTLogAll);
74 }
75 else
76 {
77 sys.SetGlobalLoggingLevel(kHLTLogError);
78 }
79
80 const int numSources = 4;
81 const char* fileTypeNames[numSources] = {
82 "-datatype SOMEDATA HLT -dataspec 0x0",
83 "-datatype MOREDATA HLT -dataspec 0x0",
84 "-datatype SOMEDATA TPC -dataspec 0x0",
85 "-datatype SOMEDATA HLT -dataspec 0xFF"
86 };
87 TString allSources = "";
88 for (int i = 0; i < numSources; ++i)
89 {
90 TString sourceName = Form("source%d", i+1);
91 if (allSources.Length() > 0) allSources += " ";
92 allSources += sourceName;
93 AliHLTConfiguration src(
94 sourceName.Data(),
95 "FilePublisher",
96 "",
97 Form("%s -datafile corruptorInputTestFile.dat", fileTypeNames[i])
98 );
99 }
100
101 const int numProcessors = 4;
102 const char* commandLine[numProcessors] = {
103 "-datatype MOREDATA HLT -dataspec 0x0",
104 "-datatype SOMEDATA TPC -dataspec 0x0",
105 "-datatype SOMEDATA HLT -dataspec 0xFF",
106 "-dataspec 0xFF -typeid '*******' -typeid MOREDATA -dataspec 0x0"
107 };
108 for (int i = 0; i < numProcessors; ++i)
109 {
110 TString processorName = Form("processor%d", i+1);
111 AliHLTConfiguration prc(
112 processorName.Data(),
113 "CorruptorComponent",
114 allSources.Data(),
115 commandLine[i]
116 );
117 TString sinkName = Form("sink%d", i+1);
118 AliHLTConfiguration snk(
119 sinkName.Data(),
120 "FileWriter",
121 processorName.Data(),
122 Form("-specfmt -datafile corruptorOutputTestFile_sink%d.dat", i+1)
123 );
124 sys.BuildTaskList(sinkName.Data());
125 }
126
127 sys.Run(1); // Run for 1 event.
128}
129
130/**
131 * Reads a file into a buffer.
9bb806cd 132 * \param [in] filename The name of the file to read.
133 * \param [out] buffer The buffer which is created to store the contents.
1e5db830 134 * Must be deleted with 'delete [] buffer' by caller if not NULL.
9bb806cd 135 * \param [out] size The size of the buffer created in bytes.
136 * \param [in] debug Indicates if debug messages should be printed.
1e5db830 137 * \returns true if the file was read, the buffer created and filled; false otherwise.
138 * \note The caller becomes the owner of the allocated buffer.
139 */
140bool ReadFile(const char* filename, char*& buffer, size_t& size, bool debug = false)
141{
142 buffer = NULL;
143 size = 0;
144 using namespace std;
145 fstream file(filename, ios::in | ios::binary);
146 if (! file)
147 {
148 if (debug) cerr << "ERROR: Could not open file " << filename << endl;
149 return false;
150 }
151 file.seekg(0, std::ios::end);
152 size_t filesize = file.tellg();
153 file.seekg(0, std::ios::beg);
154 if (! file)
155 {
156 if (debug) cerr << "ERROR: Could not get file size for " << filename << endl;
157 return false;
158 }
159 buffer = new char[filesize];
160 if (buffer == NULL)
161 {
162 if (debug) cerr << "ERROR: Cannot allocate more memory for buffers." << endl;
163 return false;
164 }
165 size = filesize;
166 file.read(buffer, size);
167 if (! file)
168 {
169 if (debug) cerr << "ERROR: I/O error when reading from file " << filename << endl;
170 return false;
171 }
172 return true;
173}
174
175/**
176 * Checks if the output data is as expected for the filtering.
177 * Only the output data blocks that were filtered should be modified.
178 */
179bool CheckFilteringOutput(bool debug = false)
180{
181 const int numBuffers = 5;
182 int sinknum[numBuffers] = {1, 2, 3, 4, 4};
183 const char* blocknum[numBuffers] = {
184 "0x00",
185 "0x00",
186 "0x00",
187 "0x00",
188 "0x01"
189 };
190 const char* blocktype[numBuffers] = {
191 "HLT:MOREDATA",
192 "TPC:SOMEDATA",
193 "HLT:SOMEDATA",
194 "HLT:SOMEDATA",
195 "HLT:MOREDATA"
196 };
197 const char* blockspec[numBuffers] = {
198 "0x00000000",
199 "0x00000000",
200 "0x000000ff",
201 "0x000000ff",
202 "0x00000000"
203 };
204 char* buffer[numBuffers];
205 size_t size[numBuffers];
206 for (int i = 0; i < numBuffers; ++i)
207 {
208 const char* filename = Form("corruptorOutputTestFile_sink%d_0x00000000_%s_%s_%s.dat",
209 sinknum[i], blocknum[i], blocktype[i], blockspec[i]
210 );
211 if (! ReadFile(filename, buffer[i], size[i], debug))
212 {
213 if (! debug)
214 {
215 cerr << "ERROR: Filtering chain test did not generate correct output files."
216 << " Run with 'debug = true' for more details." << endl;
217 }
218 return false;
219 }
220 delete [] buffer[i];
221 }
222
223 return true;
224}
225
226/**
227 * Routine to check the single bit flip option.
228 */
229void RunChainToCheckSingleFlips(bool debug = false)
230{
231 AliHLTSystem sys;
232 sys.LoadComponentLibraries("libAliHLTUtil.so");
233 if (debug)
234 {
235 sys.SetGlobalLoggingLevel(kHLTLogAll);
236 }
237 else
238 {
239 sys.SetGlobalLoggingLevel(kHLTLogError);
240 }
241
242 AliHLTConfiguration src(
243 "source",
244 "FilePublisher",
245 "",
246 "-datatype SOMEDATA HLT -dataspec 0x0 -datafile corruptorInputTestFile.dat"
247 );
248 AliHLTConfiguration prc(
249 "processor",
250 "CorruptorComponent",
251 "source",
252 "-seed 123 -datatype SOMEDATA HLT -range 128 max -alignment 4 -errorcount 5 5 -singleflips"
253 );
254 AliHLTConfiguration snk(
255 "sink",
256 "FileWriter",
257 "processor",
258 "-datafile corruptorOutputTestFile_single.dat"
259 );
260
261 sys.BuildTaskList("sink");
262 sys.Run(1); // Run for 1 event.
263}
264
265/**
266 * Checks if the output data is as expected for the single bit flip option.
267 */
268bool CheckSingleFlipOutput(bool debug = false)
269{
270 char* buffer = NULL;
271 size_t size = 0;
272 if (! ReadFile("corruptorOutputTestFile_single_0x00000000_0x00_HLT:SOMEDATA.dat", buffer, size, debug))
273 {
274 if (! debug)
275 {
276 cerr << "ERROR: Single flips chain test did not generate correct"
277 << " output files. Run with 'debug = true' for more details."
278 << endl;
279 }
280 return false;
281 }
282 if (size != 256)
283 {
284 cerr << "ERROR: The output file is not the expected 256 bytes in size"
285 << " when testing the -singleflips option." << endl;
286 delete [] buffer;
287 return false;
288 }
289 // Check that the first 128 bytes are zero.
290 for (int i = 0; i < 128; ++i)
291 {
292 if (buffer[i] != 0x0)
293 {
294 cerr << "ERROR: The first 128 bytes were not left as zeros when testing"
295 << " the -singleflips option." << endl;
296 delete [] buffer;
297 return false;
298 }
299 }
300 // Check that the correct number of bit flips happened in the last 128 bytes.
301 TBits bits(128*8);
302 bits.Set(128*8, buffer+128);
303 UInt_t bitcount = bits.CountBits();
304 if (bitcount != 5)
305 {
306 cerr << "ERROR: When testing the -singleflips option,"
307 << " the number of bits flipped in the output buffer was "
308 << bitcount << ", but we expect exactly 5 bit flips."
309 << endl;
310 delete [] buffer;
311 return false;
312 }
313 // Check that the bit flips are only on 4 bit aligned addresses.
314 for (UInt_t j = 128*8; j < 256*8; ++j)
315 {
316 if (bits[j] && (j & 0x7) != 0)
317 {
318 cerr << "ERROR: When testing the -singleflips option, bit " << j
319 << " was flipped in the output buffer,"
320 << " but it is not aligned to a 4 bit word boundary."
321 << endl;
322 delete [] buffer;
323 return false;
324 }
325 }
326
327 delete [] buffer;
328 return true;
329}
330
331/**
332 * Routine to check the burst error option.
333 */
334void RunChainToCheckBurstErrors(bool debug = false)
335{
336 AliHLTSystem sys;
337 sys.LoadComponentLibraries("libAliHLTUtil.so");
338 if (debug)
339 {
340 sys.SetGlobalLoggingLevel(kHLTLogAll);
341 }
342 else
343 {
344 sys.SetGlobalLoggingLevel(kHLTLogError);
345 }
346
347 AliHLTConfiguration src(
348 "source",
349 "FilePublisher",
350 "",
351 "-datatype SOMEDATA HLT -dataspec 0x0 -datafile corruptorInputTestFile.dat"
352 );
353 AliHLTConfiguration prc(
354 "processor",
355 "CorruptorComponent",
356 "source",
357 "-seed 123 -datatype SOMEDATA HLT -range 0 256 -alignment 32 -errorcount 3 3 -bursterrors 16 8"
358 );
359 AliHLTConfiguration snk(
360 "sink",
361 "FileWriter",
362 "processor",
363 "-datafile corruptorOutputTestFile_burst.dat"
364 );
365
366 sys.BuildTaskList("sink");
367 sys.Run(1); // Run for 1 event.
368}
369
370/**
371 * Checks if the output data is as expected for the burst errors.
372 */
373bool CheckBurstErrorOutput(bool debug = false)
374{
375 char* buffer = NULL;
376 size_t size = 0;
377 if (! ReadFile("corruptorOutputTestFile_burst_0x00000000_0x00_HLT:SOMEDATA.dat", buffer, size, debug))
378 {
379 if (! debug)
380 {
381 cerr << "ERROR: Burst error chain test did not generate correct"
382 << " output files. Run with 'debug = true' for more details."
383 << endl;
384 }
385 return false;
386 }
387 if (size != 256)
388 {
389 cerr << "ERROR: The output file is not the expected 256 bytes in size"
390 << " when testing the -bursterrors option." << endl;
391 delete [] buffer;
392 return false;
393 }
394 TBits bits(256*8);
395 bits.Set(256*8, buffer);
396 // Check that the bit flips are only on the lower part of the 32 bit words.
397 for (UInt_t j = 0; j < 256*8; ++j)
398 {
399 if (bits[j] && (j % 32) >= 16)
400 {
401 cerr << "ERROR: When testing the -bursterrors option, bit " << j
402 << " was flipped in the output buffer, but only the lower"
403 << " part of any 32 bit word is supposed to be corrupted."
404 << endl;
405 delete [] buffer;
406 return false;
407 }
408 }
409
410 delete [] buffer;
411 return true;
412}
413
414/**
415 * Routine to check the replacement options.
416 */
417void RunChainToCheckReplaceErrors(bool debug = false)
418{
419 AliHLTSystem sys;
420 sys.LoadComponentLibraries("libAliHLTUtil.so");
421 if (debug)
422 {
423 sys.SetGlobalLoggingLevel(kHLTLogAll);
424 }
425 else
426 {
427 sys.SetGlobalLoggingLevel(kHLTLogError);
428 }
429
430 AliHLTConfiguration src1(
431 "source1",
432 "FilePublisher",
433 "",
434 "-datatype DATAAAAA HLT -dataspec 0x0 -datafile corruptorInputTestFile.dat"
435 );
436 AliHLTConfiguration prc1(
437 "processor1",
438 "CorruptorComponent",
439 "source1",
440 "-datatype DATAAAAA HLT -range 128:4 128:4 -replace 0x1/1 0xF 0xF/3 -seed 1"
441 );
442 AliHLTConfiguration src2(
443 "source2",
444 "FilePublisher",
445 "",
446 "-datatype DATABBBB HLT -dataspec 0x0 -datafile corruptorInputTestFile.dat"
447 );
448 AliHLTConfiguration prc2(
449 "processor2",
450 "CorruptorComponent",
451 "source2",
452 "-datatype DATABBBB HLT -seed 123 -range 8 8 -errorcount 1 1 -replace-random 64 64"
453 );
454 AliHLTConfiguration snk(
455 "sink",
456 "FileWriter",
457 "processor1 processor2",
458 "-datafile corruptorOutputTestFile_replace.dat"
459 );
460
461 sys.BuildTaskList("sink");
462 sys.Run(1); // Run for 1 event.
463}
464
465/**
466 * Checks if the output data is as expected for the replacement commands.
467 */
468bool CheckReplaceErrorsOutput(bool debug = false)
469{
470 char* buffer = NULL;
471 size_t size = 0;
472 if (! ReadFile("corruptorOutputTestFile_replace_0x00000000_0x01_HLT:DATAAAAA.dat", buffer, size, debug))
473 {
474 if (! debug)
475 {
476 cerr << "ERROR: Replace errors chain test did not generate correct"
477 << " output files. Run with 'debug = true' for more details."
478 << endl;
479 }
480 return false;
481 }
482 if (size != 256)
483 {
484 cerr << "ERROR: The output file is not the expected 256 bytes in size"
485 << " when testing the -replace option." << endl;
486 delete [] buffer;
487 return false;
488 }
489 // Check that the correct bits were set. All bits zero except 128:4 to 129:4
490 for (UInt_t j = 0; j < 128; ++j)
491 {
492 if (buffer[j] != 0)
493 {
494 cerr << "ERROR: When testing the -replace option we found bits set in byte"
495 << j << " but the byte should be zero."
496 << endl;
497 delete [] buffer;
498 return false;
499 }
500 }
501 if (AliHLTUInt8_t(buffer[128]) != 0xF0 || AliHLTUInt8_t(buffer[129]) != 0x0F)
502 {
503 cerr << "ERROR: When testing the -replace option we found a value of "
504 << Form("0x%2.2X", int(AliHLTUInt8_t(buffer[128]))) << " for byte 128 and "
505 << Form("0x%2.2X", int(AliHLTUInt8_t(buffer[129]))) << " for byte 129,"
506 << " but we expected values of 0xF0 and 0x0F respectively."
507 << endl;
508 delete [] buffer;
509 return false;
510 }
511 for (UInt_t j = 130; j < 256; ++j)
512 {
513 if (buffer[j] != 0)
514 {
515 cerr << "ERROR: When testing the -replace option we found bits set in byte"
516 << j << " but the byte should be zero."
517 << endl;
518 delete [] buffer;
519 return false;
520 }
521 }
522 delete [] buffer;
523 buffer = NULL;
524 size = 0;
525 // Now test the next buffer...
526 if (! ReadFile("corruptorOutputTestFile_replace_0x00000000_0x00_HLT:DATABBBB.dat", buffer, size, debug))
527 {
528 if (! debug)
529 {
530 cerr << "ERROR: Replace errors chain test did not generate correct"
531 << " output files. Run with 'debug = true' for more details."
532 << endl;
533 }
534 return false;
535 }
536 if (size != 256)
537 {
538 cerr << "ERROR: The output file is not the expected 256 bytes in size"
539 << " when testing the -replace-random option." << endl;
540 delete [] buffer;
541 return false;
542 }
543 // Check that only bits in the second 64 bit word were set.
544 for (UInt_t j = 0; j < 8; ++j)
545 {
546 if (buffer[j] != 0x0)
547 {
548 cerr << "ERROR: When testing the -replace-random option we found bits set in byte"
549 << j << " but the byte should be zero."
550 << endl;
551 delete [] buffer;
552 return false;
553 }
554 }
555 if ((reinterpret_cast<AliHLTUInt64_t*>(buffer))[1] == 0x0)
556 {
557 cerr << "ERROR: When testing the -replace-random option we found no bits set in bytes 8 to 15." << endl;
558 delete [] buffer;
559 return false;
560 }
561 for (UInt_t j = 16; j < 256; ++j)
562 {
563 if (buffer[j] != 0x0)
564 {
565 cerr << "ERROR: When testing the -replace-random option we found bits set in byte"
566 << j << " but the byte should be zero."
567 << endl;
568 delete [] buffer;
569 return false;
570 }
571 }
572 delete [] buffer;
573 return true;
574}
575
576/**
577 * Routine to check the insertion options.
578 */
579void RunChainToCheckInsertErrors(bool debug = false)
580{
581 AliHLTSystem sys;
582 sys.LoadComponentLibraries("libAliHLTUtil.so");
583 if (debug)
584 {
585 sys.SetGlobalLoggingLevel(kHLTLogAll);
586 }
587 else
588 {
589 sys.SetGlobalLoggingLevel(kHLTLogError);
590 }
591
592 AliHLTConfiguration src1(
593 "source1",
594 "FilePublisher",
595 "",
596 "-datatype DATAAAAA HLT -dataspec 0x0 -datafile corruptorInputTestFile.dat"
597 );
598 AliHLTConfiguration prc1(
599 "processor1",
600 "CorruptorComponent",
601 "source1",
602 "-datatype DATAAAAA HLT -range 128 128 -errorcount 1 1 -insert 0xCBA/12"
603 );
604 AliHLTConfiguration src2(
605 "source2",
606 "FilePublisher",
607 "",
608 "-datatype DATABBBB HLT -dataspec 0x0 -datafile corruptorInputTestFile.dat"
609 );
610 AliHLTConfiguration prc2(
611 "processor2",
612 "CorruptorComponent",
613 "source2",
614 "-datatype DATABBBB HLT -seed 123 -range max max -errorcount 1 1 -insert-random 64 64"
615 );
616 AliHLTConfiguration snk(
617 "sink",
618 "FileWriter",
619 "processor1 processor2",
620 "-datafile corruptorOutputTestFile_insert.dat"
621 );
622
623 sys.BuildTaskList("sink");
624 sys.Run(1); // Run for 1 event.
625}
626
627/**
628 * Checks if the output data is as expected for the insertion commands.
629 */
630bool CheckInsertErrorsOutput(bool debug = false)
631{
632 char* buffer = NULL;
633 size_t size = 0;
634 if (! ReadFile("corruptorOutputTestFile_insert_0x00000000_0x01_HLT:DATAAAAA.dat", buffer, size, debug))
635 {
636 if (! debug)
637 {
638 cerr << "ERROR: Insert errors chain test did not generate correct"
639 << " output files. Run with 'debug = true' for more details."
640 << endl;
641 }
642 return false;
643 }
644 if (size != 258)
645 {
646 cerr << "ERROR: The output file is not the expected 258 bytes in size"
647 << " when testing the -insert option." << endl;
648 delete [] buffer;
649 return false;
650 }
651 // Check that the correct bits were set. All bits zero except 128 to 129
652 for (UInt_t j = 0; j < 128; ++j)
653 {
654 if (buffer[j] != 0)
655 {
656 cerr << "ERROR: When testing the -insert option we found bits set in byte"
657 << j << " but the byte should be zero."
658 << endl;
659 delete [] buffer;
660 return false;
661 }
662 }
663 if (AliHLTUInt8_t(buffer[128]) != 0xBA || AliHLTUInt8_t(buffer[129]) != 0x0C)
664 {
665 cerr << "ERROR: When testing the -insert option we found a value of "
666 << Form("0x%2.2X", int(AliHLTUInt8_t(buffer[128]))) << " for byte 128 and "
667 << Form("0x%2.2X", int(AliHLTUInt8_t(buffer[129]))) << " for byte 129,"
668 << " but we expected values of 0xBA and 0x0C respectively."
669 << endl;
670 delete [] buffer;
671 return false;
672 }
673 for (UInt_t j = 130; j < 258; ++j)
674 {
675 if (buffer[j] != 0)
676 {
677 cerr << "ERROR: When testing the -insert option we found bits set in byte"
678 << j << " but the byte should be zero."
679 << endl;
680 delete [] buffer;
681 return false;
682 }
683 }
684 delete [] buffer;
685 buffer = NULL;
686 size = 0;
687 // Now test the next buffer...
688 if (! ReadFile("corruptorOutputTestFile_insert_0x00000000_0x00_HLT:DATABBBB.dat", buffer, size, debug))
689 {
690 if (! debug)
691 {
692 cerr << "ERROR: Insert errors chain test did not generate correct"
693 << " output files. Run with 'debug = true' for more details."
694 << endl;
695 }
696 return false;
697 }
698 if (size != 264)
699 {
700 cerr << "ERROR: The output file is not the expected 264 bytes in size"
701 << " when testing the -insert-random option." << endl;
702 delete [] buffer;
703 return false;
704 }
705 // Check that only bits in the last 64 bit word were set.
706 for (UInt_t j = 0; j < 256; ++j)
707 {
708 if (buffer[j] != 0x0)
709 {
710 cerr << "ERROR: When testing the -insert-random option we found bits set in byte"
711 << j << " but the byte should be zero."
712 << endl;
713 delete [] buffer;
714 return false;
715 }
716 }
717 if ((reinterpret_cast<AliHLTUInt64_t*>(buffer))[32] == 0x0)
718 {
719 cerr << "ERROR: When testing the -insert-random option we found no bits set in bytes 256 to 263." << endl;
720 delete [] buffer;
721 return false;
722 }
723 delete [] buffer;
724 return true;
725}
726
727/**
728 * Routine to check the remove option.
729 */
730void RunChainToCheckRemoveErrors(bool debug = false)
731{
732 AliHLTSystem sys;
733 sys.LoadComponentLibraries("libAliHLTUtil.so");
734 if (debug)
735 {
736 sys.SetGlobalLoggingLevel(kHLTLogAll);
737 }
738 else
739 {
740 sys.SetGlobalLoggingLevel(kHLTLogError);
741 }
742
743 AliHLTConfiguration src(
744 "source",
745 "FilePublisher",
746 "",
747 "-datatype SOMEDATA HLT -dataspec 0x0 -datafile corruptorInputTestFile.dat"
748 );
749 AliHLTConfiguration prc(
750 "processor",
751 "CorruptorComponent",
752 "source",
753 "-datatype SOMEDATA HLT -range 128 128 -errorcount 1 1 -replace 0x78563412/32 -remove 16 16 -range max max -insert removed"
754 );
755 AliHLTConfiguration snk(
756 "sink",
757 "FileWriter",
758 "processor",
759 "-datafile corruptorOutputTestFile_remove.dat"
760 );
761
762 sys.BuildTaskList("sink");
763 sys.Run(1); // Run for 1 event.
764}
765
766/**
767 * Checks if the output data is as expected for the remove command.
768 */
769bool CheckRemoveErrorsOutput(bool debug = false)
770{
771 char* buffer = NULL;
772 size_t size = 0;
773 if (! ReadFile("corruptorOutputTestFile_remove_0x00000000_0x00_HLT:SOMEDATA.dat", buffer, size, debug))
774 {
775 if (! debug)
776 {
777 cerr << "ERROR: Remove errors chain test did not generate correct"
778 << " output file. Run with 'debug = true' for more details."
779 << endl;
780 }
781 return false;
782 }
783 if (size != 256)
784 {
785 cerr << "ERROR: The output file is not the expected 256 bytes in size"
786 << " when testing the -remove option." << endl;
787 delete [] buffer;
788 return false;
789 }
790 // Check that the correct bits were removed and set.
791 for (UInt_t j = 0; j < 128; ++j)
792 {
793 if (buffer[j] != 0)
794 {
795 cerr << "ERROR: When testing the -remove option we found bits set in byte"
796 << j << " but the byte should be zero."
797 << endl;
798 delete [] buffer;
799 return false;
800 }
801 }
802 if (AliHLTUInt8_t(buffer[128]) != 0x56 || AliHLTUInt8_t(buffer[129]) != 0x78)
803 {
804 cerr << "ERROR: When testing the -remove option we found a value of "
805 << Form("0x%2.2X", int(AliHLTUInt8_t(buffer[128]))) << " for byte 128 and "
806 << Form("0x%2.2X", int(AliHLTUInt8_t(buffer[129]))) << " for byte 129,"
807 << " but we expected values of 0x56 and 0x78 respectively."
808 << endl;
809 delete [] buffer;
810 return false;
811 }
812 for (UInt_t j = 130; j < 254; ++j)
813 {
814 if (buffer[j] != 0)
815 {
816 cerr << "ERROR: When testing the -remove option we found bits set in byte"
817 << j << " but the byte should be zero."
818 << endl;
819 delete [] buffer;
820 return false;
821 }
822 }
823 if (AliHLTUInt8_t(buffer[254]) != 0x12 || AliHLTUInt8_t(buffer[255]) != 0x34)
824 {
825 cerr << "ERROR: When testing the -remove option we found a value of "
826 << Form("0x%2.2X", int(AliHLTUInt8_t(buffer[254]))) << " for byte 128 and "
827 << Form("0x%2.2X", int(AliHLTUInt8_t(buffer[255]))) << " for byte 129,"
828 << " but we expected values of 0x12 and 0x34 respectively."
829 << endl;
830 delete [] buffer;
831 return false;
832 }
833 delete [] buffer;
834 return true;
835}
836
837/**
838 * Routine to check the relative address option for "-range".
839 */
840void RunChainToCheckRelativeAddress(bool debug = false)
841{
842 AliHLTSystem sys;
843 sys.LoadComponentLibraries("libAliHLTUtil.so");
844 if (debug)
845 {
846 sys.SetGlobalLoggingLevel(kHLTLogAll);
847 }
848 else
849 {
850 sys.SetGlobalLoggingLevel(kHLTLogError);
851 }
852
853 AliHLTConfiguration src(
854 "source",
855 "FilePublisher",
856 "",
857 "-datatype SOMEDATA HLT -dataspec 0x0 -datafile corruptorInputTestFile.dat"
858 );
859 AliHLTConfiguration prc(
860 "processor",
861 "CorruptorComponent",
862 "source",
863 "-datatype SOMEDATA HLT -errorcount 1 1 -range max-4 max-4 -replace 0xFF/8 -range min+0:4 min+0:4 -replace 0xBA/8"
864 );
865 AliHLTConfiguration snk(
866 "sink",
867 "FileWriter",
868 "processor",
869 "-datafile corruptorOutputTestFile_reladdr.dat"
870 );
871
872 sys.BuildTaskList("sink");
873 sys.Run(1); // Run for 1 event.
874}
875
876/**
877 * Checks if the output data is as expected for the remove command.
878 */
879bool CheckRelativeAddressOutput(bool debug = false)
880{
881 char* buffer = NULL;
882 size_t size = 0;
883 if (! ReadFile("corruptorOutputTestFile_reladdr_0x00000000_0x00_HLT:SOMEDATA.dat", buffer, size, debug))
884 {
885 if (! debug)
886 {
887 cerr << "ERROR: Relative address chain test did not generate correct"
888 << " output file. Run with 'debug = true' for more details."
889 << endl;
890 }
891 return false;
892 }
893 if (size != 256)
894 {
895 cerr << "ERROR: The output file is not the expected 256 bytes in size"
896 << " when testing the relative address option." << endl;
897 delete [] buffer;
898 return false;
899 }
900 // Check that the correct bits were set.
901 char refBuf[256];
902 memset(refBuf, 0x0, sizeof(refBuf));
903 refBuf[0] = 0xA0;
904 refBuf[1] = 0x0B;
905 refBuf[252] = 0xFF;
906 for (UInt_t j = 0; j < 256; ++j)
907 {
908 if (buffer[j] != refBuf[j])
909 {
910 cerr << "ERROR: When testing the relative address option we find byte "
911 << j << " has a value of "
912 << Form("0x%2.2X", int(AliHLTUInt8_t(buffer[j])))
913 << ", but we expected a value of "
914 << Form("0x%2.2X", int(AliHLTUInt8_t(refBuf[j])))
915 << "." << endl;
916 delete [] buffer;
917 return false;
918 }
919 }
920 delete [] buffer;
921 return true;
922}
923
924/**
925 * This is the top level testing method which calls individual tests.
926 * \returns true if all tests succeeded and false otherwise.
927 */
928bool testAliHLTCorruptorComponent(bool debug = false)
929{
930 if (debug)
931 {
932 AliLog::SetGlobalLogLevel(AliLog::kMaxType);
933 }
934 else
935 {
936 // Done here to prevent output from AliHLTSystem.
937 AliLog::SetGlobalLogLevel(AliLog::kError);
938 }
939
940 if (gClassTable->GetID("AliHLTCorruptorComponent") < 0)
941 {
942 gSystem->Load("libAliHLTUtil.so");
943 }
944
945 GenerateInputData(debug);
946 RunChainToCheckFiltering(debug);
947 if (! CheckFilteringOutput(debug)) return false;
948 RunChainToCheckSingleFlips(debug);
949 if (! CheckSingleFlipOutput(debug)) return false;
950 RunChainToCheckBurstErrors(debug);
951 if (! CheckBurstErrorOutput(debug)) return false;
952 RunChainToCheckReplaceErrors(debug);
953 if (! CheckReplaceErrorsOutput(debug)) return false;
954 RunChainToCheckInsertErrors(debug);
955 if (! CheckInsertErrorsOutput(debug)) return false;
956 RunChainToCheckRemoveErrors(debug);
957 if (! CheckRemoveErrorsOutput(debug)) return false;
958 RunChainToCheckRelativeAddress(debug);
959 if (! CheckRelativeAddressOutput(debug)) return false;
960
961 // Cleanup all temporary files generated.
962 gSystem->Exec("rm -f corruptorInputTestFile.dat corruptorOutputTestFile*.dat");
963 return true;
964}
965
966#ifndef __MAKECINT__
967
968int main(int /*argc*/, const char** /*argv*/)
969{
970 bool resultOk = testAliHLTCorruptorComponent();
971 if (not resultOk) return 1;
972 return 0;
973}
974
975#endif // __MAKECINT__
976