Author: cwittich
Date: Wed Oct 25 20:02:47 2006
New Revision: 24649
URL:
http://svn.reactos.org/svn/reactos?rev=24649&view=rev
Log:
-debug info can now be read from a pipe
-fixed a typo
-terminate the qemu process on linux
Added:
trunk/reactos/tools/sysreg/namedpipe_reader.cpp
trunk/reactos/tools/sysreg/namedpipe_reader.h
Modified:
trunk/reactos/tools/sysreg/rosboot_test.cpp
trunk/reactos/tools/sysreg/sysreg.mak
Added: trunk/reactos/tools/sysreg/namedpipe_reader.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/namedpipe_rea…
==============================================================================
--- trunk/reactos/tools/sysreg/namedpipe_reader.cpp (added)
+++ trunk/reactos/tools/sysreg/namedpipe_reader.cpp Wed Oct 25 20:02:47 2006
@@ -1,0 +1,131 @@
+/* $Id: pipe_reader.cpp 24643 2006-10-24 11:45:21Z janderwald $
+ *
+ * PROJECT: System regression tool for ReactOS
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: tools/sysreg/namedpipe_reader.cpp
+ * PURPOSE: pipe reader support
+ * PROGRAMMERS: Johannes Anderwald (johannes.anderwald at sbox tugraz at)
+ * Christoph von Wittich (Christoph(a)ApiViewer.de)
+ */
+
+#include "namedpipe_reader.h"
+
+#include <iostream>
+#include <assert.h>
+
+namespace System_
+{
+//---------------------------------------------------------------------------------------
+ NamedPipeReader::NamedPipeReader() : h_Pipe(NULL)
+ {
+
+ }
+
+//---------------------------------------------------------------------------------------
+ NamedPipeReader::~NamedPipeReader()
+ {
+
+ }
+
+//---------------------------------------------------------------------------------------
+
+ bool NamedPipeReader::openPipe(string const & PipeCmd)
+ {
+ if (h_Pipe != NULL)
+ {
+ cerr << "NamedPipeReader::openPipe> pipe already open" <<
endl;
+ return false;
+ }
+
+#ifdef __LINUX__
+
+#else
+ h_Pipe = CreateFile(PipeCmd.c_str(),
+ GENERIC_WRITE | GENERIC_READ,
+ 0,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ (HANDLE)
+ NULL);
+
+ if(INVALID_HANDLE_VALUE == h_Pipe) {
+ cerr << "NamedPipeReader::openPipe> failed to open pipe " <<
PipeCmd << GetLastError() << endl;
+ return false;
+ }
+ else
+ {
+ cout << "NamedPipeReader::openPipe> successfully opened pipe"
<< endl;
+ return true;
+ }
+
+ ConnectNamedPipe(
+ h_Pipe,
+ 0);
+
+#endif
+
+ }
+
+//---------------------------------------------------------------------------------------
+
+ bool NamedPipeReader::closePipe()
+ {
+ if (!h_Pipe)
+ {
+ cerr << "NamedPipeReader::closePipe> pipe is not open" <<
endl;
+ return false;
+ }
+
+
+#ifdef __LINUX__
+
+#else
+ DisconnectNamedPipe(h_Pipe);
+ CloseHandle(h_Pipe);
+#endif
+
+ h_Pipe = NULL;
+ return true;
+ }
+
+//---------------------------------------------------------------------------------------
+
+ string::size_type NamedPipeReader::readPipe(string &Buffer)
+ {
+ TCHAR * buf = (TCHAR *)Buffer.c_str();
+ string::size_type size = Buffer.capacity();
+ DWORD cbRead;
+ BOOL fSuccess;
+
+//#ifdef NDEBUG
+ memset(buf, 0x0, sizeof(TCHAR) * size);
+//#endif
+
+#ifdef __LINUX__
+
+#else
+ do
+ {
+ fSuccess = ReadFile(
+ h_Pipe,
+ buf,
+ size,
+ &cbRead,
+ NULL);
+
+ if (! fSuccess && GetLastError() != ERROR_MORE_DATA)
+ break;
+
+ _tprintf( TEXT("%s\n"), buf );
+ } while (!fSuccess); // repeat loop if ERROR_MORE_DATA
+
+ if (!fSuccess)
+ return 0;
+#endif
+
+ return _tcslen(buf);
+ }
+
+
+} // end of namespace System_
Added: trunk/reactos/tools/sysreg/namedpipe_reader.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/namedpipe_rea…
==============================================================================
--- trunk/reactos/tools/sysreg/namedpipe_reader.h (added)
+++ trunk/reactos/tools/sysreg/namedpipe_reader.h Wed Oct 25 20:02:47 2006
@@ -1,0 +1,107 @@
+#ifndef NAMEDPIPE_READER_H__
+#define NAMEDPIPE_READER_H__
+
+/* $Id: namedpipe_reader.h 24643 2006-10-24 11:45:21Z janderwald $
+ *
+ * PROJECT: System regression tool for ReactOS
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: tools/sysreg/namedpipe_reader.h
+ * PURPOSE: file reading support
+ * PROGRAMMERS: Johannes Anderwald (johannes.anderwald at sbox tugraz at)
+ * Christoph von Wittich (Christoph(a)ApiViewer.de)
+ */
+
+
+
+#include "user_types.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef __LINUX__
+
+#else
+ #include <windows.h>
+#endif
+
+namespace System_
+{
+//---------------------------------------------------------------------------------------
+///
+/// class NamedPipeReader
+///
+/// Description: this class implements a named pipe reader.
+
+ class NamedPipeReader
+ {
+ public:
+
+//---------------------------------------------------------------------------------------
+///
+/// NamedPipeReader
+///
+/// Description: constructor of class PipeReader
+
+ NamedPipeReader();
+
+//---------------------------------------------------------------------------------------
+///
+/// virtual ~NamedPipeReader
+///
+/// Description: destructor of class PipeReader
+
+ virtual ~NamedPipeReader();
+
+//---------------------------------------------------------------------------------------
+///
+/// openPipe
+///
+/// Description: this function attempts to open a pipe. If an pipe is already open or
+/// it fails to open a pipe, the function returns false
+///
+/// @param PipeCmd command of the pipe to open
+///
+/// @return bool
+
+ bool openPipe(const string & PipeCmd);
+
+//---------------------------------------------------------------------------------------
+///
+/// closePipe
+///
+/// Description: closes a pipe. Returns true on success
+///
+/// @return bool
+
+ bool closePipe();
+
+//---------------------------------------------------------------------------------------
+///
+/// readPipe
+///
+/// Description: attempts to read from the pipe. Returns true on success. If it returns
+/// false, call PipeReader::isEoF() to determine if the pipe should be closed
+///
+/// @param Buffer to be written to
+/// @return string::size_type
+
+ string::size_type readPipe(string & Buffer);
+
+//---------------------------------------------------------------------------------------
+///
+/// isEof
+///
+/// Description: returns true if the pipe has reached end of file. The caller should
call
+/// closePipe if this function returns true
+
+ bool isEof();
+
+protected:
+ HANDLE h_Pipe;
+
+ }; // end of class NamedPipeReader
+
+} // end of namespace System_
+
+
+
+#endif /* end of NAMEDPIPE_READER_H__ */
Modified: trunk/reactos/tools/sysreg/rosboot_test.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/rosboot_test.…
==============================================================================
--- trunk/reactos/tools/sysreg/rosboot_test.cpp (original)
+++ trunk/reactos/tools/sysreg/rosboot_test.cpp Wed Oct 25 20:02:47 2006
@@ -11,6 +11,7 @@
#include "rosboot_test.h"
#include "pipe_reader.h"
+#include "namedpipe_reader.h"
#include "sym_file.h"
#include "file_reader.h"
@@ -32,6 +33,7 @@
{
using std::vector;
using System_::PipeReader;
+ using System_::NamedPipeReader;
using System_::SymbolFile;
using System_::FileReader;
@@ -314,18 +316,42 @@
//---------------------------------------------------------------------------------------
bool RosBootTest::fetchDebugByPipe(string boot_cmd)
{
- PipeReader pipe_reader;
-
- if (!pipe_reader.openPipe(boot_cmd, string(_T("rt"))))
- {
- cerr << "Error: failed to open pipe with cmd: " << boot_cmd
<<endl;
- return false;
- }
- string Buffer;
- Buffer.reserve (500);
-
- bool ret = true;
- vector<string> vect;
+ NamedPipeReader namedpipe_reader;
+ string pipecmd = _T("");
+
+#ifdef __LINUX__
+
+#else
+ STARTUPINFO siStartInfo;
+ PROCESS_INFORMATION piProcInfo;
+
+ ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
+ ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
+
+ siStartInfo.cb = sizeof(STARTUPINFO);
+ siStartInfo.wShowWindow = SW_SHOWNORMAL;
+ siStartInfo.dwFlags = STARTF_USESHOWWINDOW;
+
+ LPTSTR command = _tcsdup(boot_cmd.c_str());
+
+ if (!CreateProcess(NULL, command, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL,
&siStartInfo, &piProcInfo))
+ {
+ cerr << "Error: CreateProcess failed " << boot_cmd
<<endl;
+ return false;
+ }
+#endif
+
+ string::size_type pipe_pos = boot_cmd.find (_T("serial pipe:"));
+ pipe_pos += 12;
+ string::size_type pipe_pos_end = boot_cmd.find (_T(" "), pipe_pos);
+ if (pipe_pos != string::npos && pipe_pos > 0 && pipe_pos <
boot_cmd.size())
+ {
+ pipecmd = "\\\\.\\pipe\\" + boot_cmd.substr (pipe_pos, pipe_pos_end -
pipe_pos);
+ }
+ else
+ {
+ return false;
+ }
if (m_Delayread)
{
@@ -336,14 +362,26 @@
_sleep( (clock_t)m_Delayread * CLOCKS_PER_SEC );
}
- while(!pipe_reader.isEof ())
+ if (!namedpipe_reader.openPipe(pipecmd))
+ {
+ cerr << "Error: failed to open pipe with cmd: " << boot_cmd
<<endl;
+ return false;
+ }
+ string Buffer;
+ Buffer.reserve (500);
+
+ bool ret = true;
+ vector<string> vect;
+
+ while(1)
{
if (isTimeout(m_Timeout))
{
break;
}
- pipe_reader.readPipe (Buffer);
+ namedpipe_reader.readPipe (Buffer);
+ cout << Buffer.c_str() << endl;
vect.push_back (Buffer);
DebugState state = checkDebugData(vect);
@@ -358,14 +396,13 @@
break;
}
}
- pipe_reader.closePipe ();
+ namedpipe_reader.closePipe ();
return ret;
}
//---------------------------------------------------------------------------------------
bool RosBootTest::fetchDebugByFile(string boot_cmd, string debug_log)
{
PipeReader pipe_reader;
-
_tremove(debug_log.c_str ());
_tremove(m_PidFile.c_str ());
if (!pipe_reader.openPipe(boot_cmd, string(_T("rt"))))
@@ -377,7 +414,7 @@
if (m_Delayread)
{
///
- /// delay reading untill emulator is ready
+ /// delay reading until emulator is ready
///
_sleep( (clock_t)m_Delayread * CLOCKS_PER_SEC );
@@ -449,7 +486,7 @@
if (pid)
{
#ifdef __LINUX__
-
+ kill(pid, SIGTERM);
#else
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
if (hProcess)
Modified: trunk/reactos/tools/sysreg/sysreg.mak
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/sysreg.mak?re…
==============================================================================
--- trunk/reactos/tools/sysreg/sysreg.mak (original)
+++ trunk/reactos/tools/sysreg/sysreg.mak Wed Oct 25 20:02:47 2006
@@ -22,6 +22,7 @@
conf_parser.cpp \
env_var.cpp \
pipe_reader.cpp \
+ namedpipe_reader.cpp \
rosboot_test.cpp \
sym_file.cpp \
sysreg.cpp \
@@ -55,6 +56,10 @@
$(ECHO_CC)
${host_gpp} $(SYSREGBUILD_HOST_CFLAGS) -c $< -o $@
+$(SYSREGBUILD_INT_)namedpipe_reader.o: $(SYSREGBUILD_BASE_)namedpipe_reader.cpp |
$(SYSREGBUILD_INT)
+ $(ECHO_CC)
+ ${host_gpp} $(SYSREGBUILD_HOST_CFLAGS) -c $< -o $@
+
$(SYSREGBUILD_INT_)rosboot_test.o: $(SYSREGBUILD_BASE_)rosboot_test.cpp |
$(SYSREGBUILD_INT)
$(ECHO_CC)
${host_gpp} $(SYSREGBUILD_HOST_CFLAGS) -c $< -o $@