pauldick 01/05/09 13:28:14
Modified: c/Tests/Performance perf.cpp
Log:
Updated handling of command line args.
Revision Changes Path
1.19 +124 -108 xml-xalan/c/Tests/Performance/perf.cpp
Index: perf.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/Tests/Performance/perf.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- perf.cpp 2001/05/03 15:07:03 1.18
+++ perf.cpp 2001/05/09 20:28:10 1.19
@@ -57,7 +57,11 @@
#include <iostream>
#include <strstream>
+#include <stdio.h>
+#include <direct.h>
+//#include <stdlib.h>
+
#if !defined(NDEBUG) && defined(_MSC_VER)
#include <crtdbg.h>
#endif
@@ -87,6 +91,7 @@
#include <XMLFileReporter.hpp>
#include <FileUtility.hpp>
+#include <HarnessInit.hpp>
#if !defined(XALAN_NO_NAMESPACES)
using std::cerr;
@@ -128,6 +133,8 @@
//"large-cem10k.xsl",
0
};
+const XalanDOMString pathSep(XalanDOMString("\\"));
+
inline bool
checkForExclusion(XalanDOMString currentFile)
@@ -269,146 +276,143 @@
printArgOptions()
{
cerr << endl
- << "Perf options (options are not case-sensitive)"
- << endl
+ << "Perf dirname [-out -category -i -iter]"
<< endl
- << "-base dirname (base directory for testcases)"
<< endl
+ << "dirname (base directory for testcases)"
<< endl
- << "[-out dirname (base directory for output) ]"
+ << "-out dirname (base directory for output)"
<< endl
- << "[-category dirname (run files only from a specific
directory) ]"
+ << "-category dirname (run files only from a specific
directory)"
<< endl
- << "[-i (include all testcases) ]"
+ << "-i (include all testcases)"
<< endl
- << "[-iter n (specifies number of iterations; must
be > 0) ]"
+ << "-iter n (specifies number of iterations; must be
> 0)"
<< endl;
}
-bool
-getParams(int argc,
- const char* argv[],
- long& iterCount,
- bool& skip,
- bool& cat,
- XalanDOMString& category,
- XalanDOMString& basedir)
+void
+checkAndCreateDir(XalanDOMString directory )
{
- if (argc = 1 )
- {
- printArgOptions();
- return false;
- }
+char buffer[_MAX_PATH]; // buffer2[_MAX_PATH], buffer3[_MAX_PATH];
+const char* buf;
- if (argc >= 2)
- {
- iterCount = atol(argv[1]);
- if (iterCount <= 0)
- {
- cerr << "Usage: perf <count, -i(nclude)>" << endl <<
endl;
- return false;
- }
- else if (argc >= 3 && !stricmp(argv[2], "-i"))
- {
- skip = false;
- }
- }
+ _getcwd( buffer, _MAX_PATH );
- if (argc >= 4 && !stricmp(argv[3], "-category"))
- {
- cout << argv[4] << endl;
- cat = true;
- assign(category, XalanDOMString(argv[4]));
- }
- if (argc >= 5 && !stricmp(argv[5], "-basedir"))
+ if ( (_chdir(c_str(TranscodeToLocalCodePage(directory)))) )
+ {
+ //cout << "Couldn't change to " << directory << ", will create
it." << endl;
+ if ( !(_mkdir(c_str(TranscodeToLocalCodePage(directory)))))
{
- cout << argv[6] << endl;
- assign(basedir, XalanDOMString(argv[6]));
+ cout << directory << " created." << endl;
}
+ }
- return true;
+ _chdir(buffer);
}
+
bool
-getParamsNEW(int argc,
- const char* argv[],
- long& iterCount,
- bool& skip,
- XalanDOMString& category,
+getParams(int argc,
+ const char* argv[],
XalanDOMString& basedir,
- XalanDOMString& outdir)
+ XalanDOMString& outdir,
+ XalanDOMString& category,
+ bool& skip,
+ long& iterCount)
{
- bool fSuccess = true;
+bool fSuccess = true; // Used to continue argument loop
+bool fSetOut = true; // Set default output directory
- if (argc == 1 )
+
+ // Insure that required "-base" argument is there.
+ if (argc == 1 || argv[1][0] == '-')
{
printArgOptions();
return false;
}
- for (int i = 1; i < argc && fSuccess == true; ++i)
+ else
{
+ assign(basedir, XalanDOMString(argv[1]));
+ insert(basedir, 0, pathSep);
+ }
- if(!stricmp("-base", argv[i]))
+ // Get the rest of the arguments in any order.
+ for (int i = 2; i < argc && fSuccess == true; ++i)
{
- ++i;
- if(i < argc && argv[i][0] != '-')
+ if(!stricmp("-out", argv[i]))
{
- assign(basedir, XalanDOMString(argv[i]));
- }
- else
- {
- fSuccess = false;
+ ++i;
+ if(i < argc && argv[i][0] != '-')
+ {
+ assign(outdir, XalanDOMString(argv[i]));
+ insert(outdir, 0, XalanDOMString("\\"));
+ append(outdir, XalanDOMString("\\"));
+ checkAndCreateDir(outdir);
+ fSetOut = false;
+ }
+ else
+ {
+ printArgOptions();
+ fSuccess = false;
+ }
}
- }
- else if(!stricmp("-out", argv[i]))
- {
- ++i;
- if(i < argc && argv[i][0] != '-')
+ else if(!stricmp("-category", argv[i]))
{
- assign(outdir, XalanDOMString(argv[i]));
+ ++i;
+ if(i < argc && argv[i][0] != '-')
+ {
+ assign(category, XalanDOMString(argv[i]));
+ }
+ else
+ {
+ printArgOptions();
+ fSuccess = false;
+ }
}
- else
+ else if(!stricmp("-i", argv[i]))
{
- fSuccess = false;
+ skip = false;
}
- }
- else if(!stricmp("-category", argv[i]))
- {
- ++i;
- if(i < argc && argv[i][0] != '-')
+ else if(!stricmp("-iter", argv[i]))
{
- assign(category, XalanDOMString(argv[i]));
+ ++i;
+
+ // Make sure number is there and is greater then zero
+ if(i < argc && atol(argv[i]) > 0)
+ {
+ iterCount = atol(argv[i]);
+ }
+ else
+ {
+ printArgOptions();
+ fSuccess = false;
+ }
}
else
{
- fSuccess = false;
- }
- }
- else if(!stricmp("-i", argv[i]))
- {
- skip = false;
- }
- else if(!stricmp("-iter", argv[i]))
- {
- ++i;
- iterCount = atol(argv[i]);
- if (iterCount <= 0)
- {
printArgOptions();
fSuccess = false;
}
- }
} // End of for-loop
+
+ // Do we need to set the default output directory??
+ if (fSetOut)
+ {
+ unsigned int ii = lastIndexOf(basedir,charAt(pathSep,0));
+ outdir = substring(basedir, 0, ii+1);
+ append(outdir,XalanDOMString("PERF-RESULTS\\"));
+ checkAndCreateDir(outdir);
+ }
+
+ // Add the path seperator to the end of the base directory
+ append(basedir,pathSep);
return fSuccess;
}
-
-
-
-
int
main(
int argc,
@@ -424,15 +428,14 @@
Hashtable runAttrs;
long iterCount = 5; // Default number of iterations
bool skip = true; // Default will skip long tests
- bool cat = false; // run tests from single directory
-
- XalanDOMString category(XalanDOMString("")); // Default perf/dir to
test
- XalanDOMString
baseDir(XALAN_STATIC_UCODE_STRING("d:\\xslt\\xsl-test\\perf\\"));
- XalanDOMString
outputRoot(XALAN_STATIC_UCODE_STRING("d:\\xslt\\cperf-results\\"));
- XalanDOMString
resultsRoot(XALAN_STATIC_UCODE_STRING("d:\\xslt\\xsl-test\\perf-dataxml\\"));
+ XalanDOMString category; // Test all of base dir by default
+ XalanDOMString baseDir;
//(XALAN_STATIC_UCODE_STRING("\\xslt\\xsl-test\\perf\\"));
+ XalanDOMString outputRoot; //(XALAN_STATIC_UCODE_STRING(""));
+ XalanDOMString
resultsRoot(XALAN_STATIC_UCODE_STRING("\\xslt\\xsl-test\\perf-dataxml\\"));
+ //const XalanDOMString pathSep(XALAN_STATIC_UCODE_STRING("\\"));
- if (getParamsNEW(argc, argv, iterCount, skip, category, baseDir,
outputRoot) == true)
+ if (getParams(argc, argv, baseDir, outputRoot, category, skip,
iterCount) == true)
{
FileUtility f;
@@ -449,8 +452,8 @@
const XalanDOMString resultFilePrefix(XalanDOMString("cpp"));
const XalanDOMString resultsFile(resultsRoot +
resultFilePrefix + UniqRunid + XMLSuffix);
- const XalanDOMString pathSep(XALAN_STATIC_UCODE_STRING("\\"));
+
// Get the list of Directories that are below perf
const FileNameVectorType dirs = f.getDirectoryNames(baseDir);
@@ -466,17 +469,28 @@
try
{
// Call the static initializers... and define file
suffixes
- XMLPlatformUtils::Initialize();
+ // Having xmlplatformutils in it's own class like this
means that if there are
+ // exceptions then terminate() is sure to run because
it will automatically get
+ // cleaned up when this instance goes out of scope.
+ HarnessInit xmlPlatformUtils;
+
{
XSLTInit theInit;
for(FileNameVectorType::size_type j = 0;
j < dirs.size(); j++)
{
+ // Run specific category of files from
given directory
if (length(category) > 0 &&
!equals(dirs[j], category))
{
continue;
}
+ cout << "Processing files in Directory:
" << dirs[j] << endl;
+
+ // Check that output directory is there.
+ const XalanDOMString theOutputDir =
outputRoot + dirs[j];
+ checkAndCreateDir(theOutputDir);
+
logFile.logTestCaseInit(XalanDOMString("Performance Directory: ") + dirs[j] );
const FileNameVectorType files =
f.getTestFileNames(baseDir, dirs[j], false);
for(FileNameVectorType::size_type i =
0; i < files.size(); i++)
@@ -498,6 +512,7 @@
const XalanDOMString
theXSLFile= baseDir + dirs[j] + pathSep + files[i];
const XalanDOMString
theXMLFile = f.GenerateFileName(theXSLFile,"xml");
+
const XalanDOMString theOutput
= outputRoot + dirs[j] + pathSep + files[i];
const XalanDOMString
theOutputFile = f.GenerateFileName(theOutput, "out");
@@ -692,23 +707,24 @@
}//xsltinit
+ logFile.logTestFileClose("Performance", "Done");
+ logFile.close();
- logFile.logTestFileClose("Performance", "Done");
- logFile.close();
-
- XMLPlatformUtils::Terminate();
-
}//try
- catch(const
XalanFileOutputStream::XalanFileOutputStreamOpenException&)
+ catch(const
XalanFileOutputStream::XalanFileOutputStreamOpenException& ex)
{
- cerr << "Could not open output file" << endl << endl;
+ cerr << ex.getMessage() << endl << endl;
}
catch(...)
{
cerr << "Exception caught!!!" << endl << endl;
}
+
+
+
+ //XMLPlatformUtils::Terminate();
} //if getParams
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]