ReactOS 0.4.15-dev-8138-g1e75ea8
CJournaledTestList.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Automatic Testing Utility
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Class implementing a journaled test list for the Crash Recovery feature
5 * COPYRIGHT: Copyright 2009 Colin Finck (colin@reactos.org)
6 */
7
8#include "precomp.h"
9
10static const char szJournalHeader[] = "RAT_J-V1";
11static const WCHAR szJournalFileName[] = L"rosautotest.journal";
12
21{
22 WCHAR JournalFile[MAX_PATH];
23
25
26 /* Build the path to the journal file */
28 FATAL("SHGetFolderPathW failed\n");
29
30 m_JournalFile = JournalFile;
31 m_JournalFile += L"\\rosautotest\\";
32
33 /* Create the directory if necessary */
36
38
39 /* Check if the journal already exists */
42 else
44}
45
50{
53}
54
64void
66{
68 m_JournalFile.c_str(),
70 0,
71 NULL,
72 (CreateNew ? CREATE_ALWAYS : OPEN_EXISTING),
74 NULL
75 );
76
78 FATAL("CreateFileW failed\n");
79}
80
89void
91{
93 WriteFile(m_hJournal, String.c_str(), (ULONG)String.size() + 1, &BytesWritten, NULL);
95}
96
105void
107{
109 WriteFile(m_hJournal, String.c_str(), ((ULONG)String.size() + 1) * sizeof(WCHAR), &BytesWritten, NULL);
111}
112
123void
125{
126 Output = string(*Buffer);
127 *Buffer += Output.size() + 1;
128}
129
140void
142{
143 Output = wstring((PWSTR)*Buffer);
144 *Buffer += (Output.size() + 1) * sizeof(WCHAR);
145}
146
150void
152{
153 char TerminatingNull = 0;
154 CTestInfo* TestInfo;
156
157 StringOut("Writing initial journal file...\n\n");
158
159 m_ListIterator = 0;
160
161 /* Store all command lines in the m_List vector */
162 while((TestInfo = m_Test->GetNextTestInfo()) != 0)
163 {
164 m_List.push_back(*TestInfo);
165 delete TestInfo;
166 }
167
168 /* Serialize the vector and the iterator into a file */
170
173
174 for(size_t i = 0; i < m_List.size(); i++)
175 {
176 SerializeIntoJournal(m_List[i].CommandLine);
179 }
180
181 WriteFile(m_hJournal, &TerminatingNull, sizeof(TerminatingNull), &BytesWritten, NULL);
183
186
187 /* m_ListIterator will be incremented before its first use */
189}
190
194void
196{
197 char* Buffer;
198 char* pBuffer;
199 char FileHeader[sizeof(szJournalHeader)];
201 DWORD RemainingSize;
202
203 StringOut("Loading journal file...\n\n");
204
206 RemainingSize = GetFileSize(m_hJournal, NULL);
207
208 /* Verify the header of the journal file */
209 ReadFile(m_hJournal, FileHeader, sizeof(szJournalHeader), &BytesRead, NULL);
210 RemainingSize -= BytesRead;
211
212 if(BytesRead != sizeof(szJournalHeader))
213 EXCEPTION("Journal file contains no header!\n");
214
215 if(strcmp(FileHeader, szJournalHeader))
216 EXCEPTION("Journal file has an unsupported header!\n");
217
218 /* Read the iterator */
220 RemainingSize -= BytesRead;
221
222 if(BytesRead != sizeof(m_ListIterator))
223 EXCEPTION("Journal file contains no m_ListIterator member!\n");
224
225 /* Read the rest of the file into a buffer */
226 Buffer = new char[RemainingSize];
227 pBuffer = Buffer;
228 ReadFile(m_hJournal, Buffer, RemainingSize, &BytesRead, NULL);
229
232
233 /* Now recreate the m_List vector out of that information */
234 while(*pBuffer)
235 {
236 CTestInfo TestInfo;
237
241
242 m_List.push_back(TestInfo);
243 }
244
245 delete[] Buffer;
246}
247
251void
253{
255
257
258 /* Skip the header */
260
263
266}
267
277{
278 CTestInfo* TestInfo;
279
280 /* Always jump to the next test here.
281 - If we're at the beginning of a new test list, the iterator will be set to 0.
282 - If we started with a loaded one, we assume that the test m_ListIterator is currently set
283 to crashed, so we move to the next test. */
285
286 /* Check whether the iterator would already exceed the number of stored elements */
287 if(m_ListIterator == m_List.size())
288 {
289 /* Delete the journal and return no pointer */
290 DeleteFileW(m_JournalFile.c_str());
291
292 TestInfo = NULL;
293 }
294 else
295 {
296 /* Update the journal with the current iterator and return the test information */
298
299 TestInfo = new CTestInfo(m_List[m_ListIterator]);
300 }
301
302 return TestInfo;
303}
static const WCHAR szJournalFileName[]
static const char szJournalHeader[]
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
Definition: bufpool.h:45
void UnserializeFromBuffer(char **Buffer, string &Output)
vector< CTestInfo > m_List
CJournaledTestList(CTest *Test)
void OpenJournal(DWORD DesiredAccess, bool CreateNew=false)
CTestInfo * GetNextTestInfo()
void SerializeIntoJournal(const string &String)
wstring CommandLine
Definition: CTestInfo.h:11
string Module
Definition: CTestInfo.h:12
string Test
Definition: CTestInfo.h:13
CTest * m_Test
Definition: CTestList.h:11
Definition: CTest.h:9
virtual CTestInfo * GetNextTestInfo()=0
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define SetFilePointer
Definition: compat.h:743
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:25
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2589
__kernel_size_t size_t
Definition: linux.h:237
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define S_OK
Definition: intsafe.h:52
char string[160]
Definition: util.h:11
#define CREATE_ALWAYS
Definition: disk.h:72
#define FILE_FLAG_WRITE_THROUGH
Definition: disk.h:47
string StringOut(const string &String, bool forcePrint=true)
Definition: tools.cpp:96
#define EXCEPTION(Message)
Definition: precomp.h:56
#define FATAL(Message)
Definition: precomp.h:57
#define GENERIC_WRITE
Definition: nt_native.h:90
#define L(x)
Definition: ntvdm.h:50
PVOID pBuffer
@ Output
Definition: arc.h:85
@ SHGFP_TYPE_CURRENT
Definition: shlobj.h:2142
#define CSIDL_APPDATA
Definition: shlobj.h:2191
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:379
size_type size() const
Definition: _vector.h:192
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870
#define FILE_CURRENT
Definition: winbase.h:113
__wchar_t WCHAR
Definition: xmlstorage.h:180