- make sysreg compilable under linux

svn path=/trunk/; revision=27645
This commit is contained in:
Johannes Anderwald 2007-07-14 10:01:09 +00:00
parent 3a4932988f
commit f07d18172d
14 changed files with 70 additions and 104 deletions

View file

@ -11,10 +11,12 @@
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstdio>
namespace Sysreg_
{
using std::ifstream;
extern "C" FILE * open(char * filename, char* filemode);
//---------------------------------------------------------------------------------------
ConfigParser::ConfigParser()
{
@ -34,7 +36,7 @@ namespace Sysreg_
#ifdef UNICODE
file = _tfopen(FileName, _T("rt,ccs=UNICODE"));
#else
file = _tfopen(FileName, _T("rt"));
file = open(FileName, "rt");
#endif
if (!file)
{

View file

@ -28,11 +28,11 @@ public:
virtual ~DataSource()
{}
virtual bool open(const string & opencmd) = 0;
virtual bool openSource(const string & opencmd) = 0;
virtual bool close() = 0;
virtual bool closeSource() = 0;
virtual bool read(std::vector<string> & vect) = 0;
virtual bool readSource(std::vector<string> & vect) = 0;
}; // end of class DataSource

View file

@ -9,9 +9,10 @@
#include "file_reader.h"
#include <assert.h>
#include <cstdio>
namespace System_
{
extern "C" FILE * open(char * filename, char* filemode);
//---------------------------------------------------------------------------------------
FileReader::FileReader() : DataSource(), m_File(NULL)
{
@ -21,12 +22,12 @@ namespace System_
{
}
//---------------------------------------------------------------------------------------
bool FileReader::open(const string & filename)
bool FileReader::openSource(const string & filename)
{
#ifdef UNICODE
m_File = _tfopen(filename.c_str(), _T("rb,ccs=UNICODE"));
m_File = (FILE*)_tfopen(filename.c_str(), _T("rb,ccs=UNICODE"));
#else
m_File = _tfopen(filename.c_str(), _T("rb"));
m_File = open((char*)filename.c_str(), (char*)"rb");
#endif
if (m_File)
@ -39,7 +40,7 @@ namespace System_
}
}
//---------------------------------------------------------------------------------------
bool FileReader::close()
bool FileReader::closeSource()
{
if (!m_File)
{
@ -55,7 +56,7 @@ namespace System_
return false;
}
//---------------------------------------------------------------------------------------
bool FileReader::read(vector<string> & lines)
bool FileReader::readSource(vector<string> & lines)
{
if (!m_File)
{
@ -135,7 +136,7 @@ namespace System_
total_length = 0;
while((ptr = _tcsstr(offset, _T("\x0D\x0A"))) != NULL)
{
long long length = ((long long)ptr - (long long)offset);
long length = ((long )ptr - (long)offset);
length /= sizeof(TCHAR);
offset[length] = _T('\0');

View file

@ -14,7 +14,6 @@
#include "user_types.h"
#include "data_source.h"
#include <vector>
namespace System_
{
using std::vector;
@ -52,8 +51,7 @@ namespace System_
/// @param filename name of the file to open
/// @return bool
virtual bool open(const string & filename);
virtual bool openSource(const string & filename);
//---------------------------------------------------------------------------------------
///
/// closeFile
@ -62,7 +60,7 @@ namespace System_
///
/// @return bool
virtual bool close();
virtual bool closeSource();
//---------------------------------------------------------------------------------------
///
@ -73,7 +71,7 @@ namespace System_
/// Note: returns true on success
///
virtual bool read(vector<string> & lines);
virtual bool readSource(vector<string> & lines);

View file

@ -33,7 +33,7 @@ namespace System_
//---------------------------------------------------------------------------------------
bool NamedPipeReader::open(const string & PipeCmd)
bool NamedPipeReader::openSource(const string & PipeCmd)
{
if (h_Pipe != NULLVAL)
{
@ -68,7 +68,7 @@ namespace System_
//---------------------------------------------------------------------------------------
bool NamedPipeReader::close()
bool NamedPipeReader::closeSource()
{
if (!h_Pipe)
{
@ -171,7 +171,7 @@ namespace System_
//---------------------------------------------------------------------------------------
bool NamedPipeReader::read(vector<string> & vect)
bool NamedPipeReader::readSource(vector<string> & vect)
{
char * localbuf;
DWORD localsize = 100;

View file

@ -74,7 +74,7 @@ namespace System_
///
/// @return bool
virtual bool open(const string & PipeCmd);
virtual bool openSource(const string & PipeCmd);
//---------------------------------------------------------------------------------------
///
@ -84,7 +84,7 @@ namespace System_
///
/// @return bool
virtual bool close();
virtual bool closeSource();
//---------------------------------------------------------------------------------------
///
@ -96,7 +96,7 @@ namespace System_
/// @param Buffer to be written to
/// @return size_t
virtual bool read(std::vector<string> & vect);
virtual bool readSource(std::vector<string> & vect);
//---------------------------------------------------------------------------------------
///

View file

@ -11,7 +11,7 @@
namespace System_
{
#ifdef WIN32
#ifndef __LINUX__
bool OsSupport::terminateProcess(OsSupport::ProcessID pid)
{
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
@ -57,10 +57,10 @@ namespace System_
free(command);
return pid;
}
void OsSupport::sleep(long value)
{
_sleep(value);
}
void OsSupport::sleep(long value)
{
_sleep(value);
}
#else
/********************************************************************************************************************/
OsSupport::ProcessID OsSupport::createProcess(TCHAR *procname, int procargsnum, TCHAR **procargs)
@ -87,10 +87,10 @@ namespace System_
return true;
}
void OsSupport::sleep(long value)
{
sleep(value);
}
void OsSupport::sleep(long value)
{
sleep(value);
}
#endif

View file

@ -14,6 +14,7 @@
namespace System_
{
using std::vector;
//---------------------------------------------------------------------------------------
PipeReader::PipeReader() : m_File(NULL)
{
@ -28,7 +29,7 @@ namespace System_
//---------------------------------------------------------------------------------------
bool PipeReader::openPipe(string const & PipeCmd, string AccessMode)
bool PipeReader::openSource(string const & PipeCmd)
{
if (m_File != NULL)
{
@ -49,7 +50,7 @@ namespace System_
//---------------------------------------------------------------------------------------
bool PipeReader::closePipe()
bool PipeReader::closeSource()
{
if (!m_File)
{
@ -78,34 +79,23 @@ namespace System_
//---------------------------------------------------------------------------------------
string::size_type PipeReader::readPipe(string &Buffer)
bool PipeReader::readSource(vector<string> & lines)
{
TCHAR * buf = (TCHAR *)Buffer.c_str();
string::size_type size = Buffer.capacity();
TCHAR * buf = (TCHAR*)malloc(100 * sizeof(TCHAR));
//#ifdef NDEBUG
memset(buf, 0x0, sizeof(TCHAR) * size);
memset(buf, 0x0, sizeof(TCHAR) * 100);
//#endif
TCHAR * res = _fgetts(buf, size, m_File);
TCHAR * res = _fgetts(buf, 100, m_File);
if (!res)
{
cerr << "Error: PipeReader::readPipe failed" << endl;
return 0;
free(buf);
return false;
}
return _tcslen(buf);
}
//---------------------------------------------------------------------------------------
bool PipeReader::writePipe(const string & Buffer)
{
//TODO
// implement me
cerr << "PipeReader::writePipe is not yet implemented" << endl;
return false;
string line(buf);
lines.push_back(line);
return true;
}
} // end of namespace System_

View file

@ -14,8 +14,8 @@
#include "user_types.h"
#include "data_source.h"
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
//#include <stdlib.h>
namespace System_
{
@ -61,7 +61,7 @@ namespace System_
/// w ... allows writing to the pipe
/// @return bool
bool openPipe(const string & PipeCmd, string AccessMode = _T("rt"));
bool openSource(const string & PipeCmd);
//---------------------------------------------------------------------------------------
///
@ -71,7 +71,7 @@ namespace System_
///
/// @return bool
bool closePipe();
bool closeSource();
//---------------------------------------------------------------------------------------
///
@ -83,17 +83,7 @@ namespace System_
/// @param Buffer to be written to
/// @return string::size_type
string::size_type readPipe(string & Buffer);
//---------------------------------------------------------------------------------------
///
/// writePipe
///
/// Description: attempts to write to the pipe. Returns true on success.
///
/// @param Buffer containing information which is written to the pipe
bool writePipe(const string & Buffer);
bool readSource(std::vector<string> & lines);
//---------------------------------------------------------------------------------------
///

View file

@ -55,7 +55,7 @@ namespace Sysreg_
string RosBootTest::CRITICAL_APP = _T("ROSBOOT_CRITICAL_APP");
//---------------------------------------------------------------------------------------
RosBootTest::RosBootTest() : RegressionTest(RosBootTest::CLASS_NAME), m_Timeout(60.0), m_Delayread(0)
RosBootTest::RosBootTest() : m_Timeout(60.0), m_Delayread(0)
{
}
@ -69,16 +69,16 @@ namespace Sysreg_
void RosBootTest::getPidFromFile()
{
FileReader file;
if (file.open(m_PidFile.c_str ()))
if (file.openSource(m_PidFile.c_str ()))
{
vector<string> lines;
file.read(lines);
file.readSource(lines);
if (lines.size() == 1)
{
string line = lines[0];
m_Pid = _ttoi(line.c_str ());
}
file.close();
file.closeSource();
}
}
//---------------------------------------------------------------------------------------
@ -292,7 +292,7 @@ namespace Sysreg_
src = m_File;
}
if (!m_DataSource->open(src))
if (!m_DataSource->openSource(src))
{
cerr << "Error: failed to open data source with " << src << endl;
return false;
@ -300,7 +300,7 @@ namespace Sysreg_
bool ret = analyzeDebugData();
m_DataSource->close();
m_DataSource->closeSource();
OsSupport::sleep(3 * CLOCKS_PER_SEC);
if (m_Pid)
{
@ -522,7 +522,7 @@ namespace Sysreg_
}
size_t prev_count = vect.size ();
if (!m_DataSource->read (vect))
if (!m_DataSource->readSource (vect))
{
cerr << "No data read" << endl;
continue;
@ -548,7 +548,7 @@ namespace Sysreg_
}
lines += (vect.size() -prev_count); //WTF?
}
m_DataSource->close();
m_DataSource->closeSource();
if (write_log)
{
file.close();

View file

@ -9,19 +9,17 @@
* PURPOSE: ReactOS boot test
* PROGRAMMERS: Johannes Anderwald (johannes.anderwald at sbox tugraz at)
*/
#include "reg_test.h"
#include "data_source.h"
#include "conf_parser.h"
#include <vector>
#ifndef WIN32
#include <unistd.h>
#endif
namespace Sysreg_
{
using std::vector;
using System_::DataSource;
//---------------------------------------------------------------------------------------
///
/// class RosBootTest
@ -29,7 +27,7 @@ namespace Sysreg_
/// Description: this class attempts to boot ReactOS in an emulator with console logging enabled.
/// It
class RosBootTest : public RegressionTest
class RosBootTest
{
public:
static string VARIABLE_NAME;

View file

@ -12,20 +12,16 @@
#include "sysreg.h"
using System_::EnvironmentVariable;
using System_::ComponentFactoryTemplate;
using Sysreg_::ConfigParser;
//regression test classes
using Sysreg_::RegressionTest;
using Sysreg_::RosBootTest;
#if 0
using System_::SymbolFile;
#endif
typedef ComponentFactoryTemplate<RegressionTest, string> ComponentFactory;
static const TCHAR USAGE[] =
_T("sysreg.exe -l | [conf_file] <testname>\n\n-l - list available tests\nconf_file - (optional) path to a configuration file (default: sysreg.cfg)\ntest_name - name of test to execute\n");
@ -35,7 +31,6 @@ _T("sysreg.exe -l | [conf_file] <testname>\n\n-l - list available tes
int _tmain(int argc, TCHAR * argv[])
{
ConfigParser config;
ComponentFactory comp_factory;
TCHAR DefaultConfig[] = _T("sysreg.cfg");
TCHAR *ConfigFile;
TCHAR * TestName;
@ -47,19 +42,6 @@ int _tmain(int argc, TCHAR * argv[])
}
//---------------------------------------------------------------------------------------
/// regression tests should be registered here
comp_factory.registerComponent<RosBootTest>(RosBootTest::CLASS_NAME);
//---------------------------------------------------------------------------------------
if (argc == 2)
{
if (_tcscmp(argv[1], _T("-l")) == 0)
{
comp_factory.listComponentIds();
return -1;
}
}
if (argc == 2)
{
@ -79,7 +61,7 @@ int _tmain(int argc, TCHAR * argv[])
return -1;
}
RegressionTest * regtest = comp_factory.createComponent (TestName);
RosBootTest * regtest = new RosBootTest();
if (!regtest)
{
cerr << "Error: the requested regression test does not exist" << endl;
@ -94,11 +76,11 @@ int _tmain(int argc, TCHAR * argv[])
#endif
if (regtest->execute (config))
{
cout << "The regression test " << regtest->getName () << " completed successfully" << endl;
cout << "The regression test completed successfully" << endl;
}
else
{
cout << "The regression test " << regtest->getName () << " failed" << endl;
cout << "The regression test failed" << endl;
return -2;
}

View file

@ -13,7 +13,6 @@
#include "user_types.h"
#include "env_var.h"
#include "sym_file.h"
#include "comp_factory.h"
#include "conf_parser.h"
// regression test classes

View file

@ -28,11 +28,17 @@
#define _tremove remove
#define _ttoi atoi
#define _T(x) x
#define _tfopen _open
#define _tcsstr strstr
#define _fgetts fgets
#define _tgetenv getenv
#define _tmain main
#endif
typedef std::basic_string<TCHAR> string;
typedef std::basic_istringstream<TCHAR> istringstream;
#ifdef UNICODE
using std::wcout;