]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/test/testAliHLTTPCDataCheckerComponent.C
Adding first version of data checking component for TPC.
[u/mrichter/AliRoot.git] / HLT / TPCLib / test / testAliHLTTPCDataCheckerComponent.C
CommitLineData
098c0d28 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 testAliHLTTPCDataCheckerComponent.C
19 * @author Artur Szostak <artursz@iafrica.com>
20 * @date 9 Aug 2010
21 *
22 * This macro is used to test the basic functionality of the
23 * AliHLTTPCDataCheckerComponent class.
24 */
25
26#if !defined(__CINT__) || defined(__MAKECINT__)
27#include "Riostream.h"
28#include "TSystem.h"
29#include "TClassTable.h"
30#include "AliLog.h"
31#include "AliHLTSystem.h"
32#include "AliHLTConfiguration.h"
33#include <fstream>
34#include <cstdlib>
35#endif
36
37/**
38 * Creates the input data for the test.
39 * It is just a file of 256 bytes with all zeros.
40 */
41void GenerateInputData(bool debug = false)
42{
43 using namespace std;
44 const char* filename = "dataCheckerInputTestFile.dat";
45 fstream file(filename, ios::trunc | ios::out | ios::binary);
46 if (! file)
47 {
48 if (debug) cerr << "ERROR: Could not create file " << filename << endl;
49 return;
50 }
51
52 char buffer[256];
53 memset(buffer, 0x0, sizeof(buffer));
54 AliHLTUInt32_t* words = reinterpret_cast<AliHLTUInt32_t*>(buffer);
55 words[0] = 0xFFFFFFFF;
56 words[3] = 0x03000000; // RCU version 3 in CDH block attributes field.
57
58 file.write(buffer, sizeof(buffer));
59 if (! file)
60 {
61 if (debug) cerr << "ERROR: I/O error when writing to file " << filename << endl;
62 return;
63 }
64 file.close();
65}
66
67/**
68 * Routine to run a HLT chain with the data checker component to generate output
69 * which we can later check. The chain will only test basic functionality of the
70 * component.
71 */
72void RunChainToCheckComponent(bool debug = false)
73{
74 // Done before to prevent output from AliHLTSystem.
75 if (debug)
76 {
77 AliLog::SetGlobalLogLevel(AliLog::kMaxType);
78 }
79 else
80 {
81 AliLog::SetGlobalLogLevel(AliLog::kFatal);
82 }
83 AliHLTSystem sys;
84 sys.LoadComponentLibraries("libAliHLTUtil.so");
85 sys.LoadComponentLibraries("libAliHLTTPC.so");
86 if (debug)
87 {
88 sys.SetGlobalLoggingLevel(kHLTLogAll);
89 }
90 else
91 {
92 sys.SetGlobalLoggingLevel(kHLTLogNone);
93 }
94
95 AliHLTConfiguration src(
96 "source",
97 "FilePublisher",
98 "",
99 "-datatype 'DDL_RAW ' 'TPC ' -dataspec 0x01010202 -datafile dataCheckerInputTestFile.dat"
100 );
101 AliHLTConfiguration prc(
102 "processor",
103 "TPCDataChecker",
104 "source",
105 "-filter forwardbad -ignoretype"
106 );
107 AliHLTConfiguration snk(
108 "sink",
109 "FileWriter",
110 "processor",
111 "-specfmt -datafile dataCheckerOutputTestFile.dat"
112 );
113
114 sys.BuildTaskList("sink");
115 sys.Run(1); // Run for 1 event.
116}
117
118/**
119 * Checks the output data generated by the chain.
120 * There should be one data block corresponding to the invalid input data block.
121 */
122bool CheckOutput()
123{
124 if (gSystem->Exec("test -f dataCheckerOutputTestFile_0x00000000_0x00_TPC:DDL_RAW_0x01010202.dat") != 0)
125 {
126 cerr << "ERROR: The AliHLTTPCDataCheckerComponent did not generate the expected"
127 " output data block when given a corrupt input data block." << endl;
128 return false;
129 }
130 if (gSystem->Exec("diff dataCheckerInputTestFile.dat dataCheckerOutputTestFile_0x00000000_0x00_TPC:DDL_RAW_0x01010202.dat") != 0)
131 {
132 cerr << "ERROR: The AliHLTTPCDataCheckerComponent forwarded the"
133 " wrong data block when checking for errors." << endl;
134 return false;
135 }
136 return true;
137}
138
139/**
140 * This is the top level testing method which calls individual tests.
141 * \returns true if all tests succeeded and false otherwise.
142 */
143bool testAliHLTTPCDataCheckerComponent(bool debug = false)
144{
145 if (gClassTable->GetID("AliHLTTPCDataCheckerComponent") < 0)
146 {
147 gSystem->Load("libAliHLTUtil.so");
148 }
149 GenerateInputData(debug);
150 RunChainToCheckComponent(debug);
151 if (! CheckOutput()) return false;
152
153 // Cleanup all temporary files generated.
154 gSystem->Exec("rm -f dataCheckerInputTestFile.dat dataCheckerOutputTestFile*.dat");
155 return true;
156}
157
158#ifndef __MAKECINT__
159
160int main(int /*argc*/, const char** /*argv*/)
161{
162 bool resultOk = testAliHLTTPCDataCheckerComponent();
163 if (not resultOk) return 1;
164 return 0;
165}
166
167#endif // __MAKECINT__
168