Thread: [Compbench-devel] CompBenchmarks++/libcompbenchmarks/Benchmark Benchmark-Autotools.cpp, NONE, 1.1 B
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2007-01-22 18:21:57
|
Update of /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/Benchmark In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv19562 Added Files: Benchmark-Autotools.cpp Benchmark-Autotools.h Benchmark.cpp Benchmark-DLLoader.cpp Benchmark-DLLoader.h Benchmark.h Benchmark-xZIP.cpp Benchmark-xZIP.h Makefile.am Package.cpp Package.h Log Message: libcompbenchmarks moved in a separate directory. --- NEW FILE: Benchmark.h --- /* ---------------------------------------------------------------------------- $Id: Benchmark.h,v 1.1 2007/01/22 18:21:47 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBMBENCHMARK #define H_CBMBENCHMARK #include <Compiler/Compiler.h> #include <Compiler/Compiler-Options.h> #include <vector> namespace CBM { class System; /** \brief Defines an abstract benchmark. * * This class can be overloaded in order to get new external benchmarks and packages * supported by CompBenchmarks. Basically it sets up packages (like gzip), prepare, * and run associated benchmarks according to a given context. * * As most of times a distributed package have many benchmarks, it is usual that * a first abstraction defines all methods related to package is then overloaded to * get consistant informations about all related benchmarks. */ class Benchmark { public: class Package *Package(void); private: protected: class Package *package; /** Constructor * Initialise the Benchmark::system variable. */ Benchmark(class Package *_package); /** Give object for underlaying system. Use package pointer. \sa package */ virtual class System *System(void); /** Pure virtual method to run benchmark * \return Benchmark's result (as number). */ virtual std::string bench(void) = 0; public: /** Display informations about benchmark */ void display(void); /** Benchmark name \return a std::string representing current benchmark's identification (e.g. gzip-1c) */ virtual std::string Name(void) = 0; /** Benchmark comments \return a std::string containing comments about current benchmark */ virtual std::string Comments(void) = 0; /** Run benchmark. * Uses bench(). Overloading is unadvised. * This step won't be done and'll return 1 if getStatus()>=Package::Benchmarked. * \return benchmark's result (performance) as a non-null positive number. May changes status. * \sa Make() * \sa status */ virtual std::string Bench(void); /** Virtual destructor */ virtual ~Benchmark(); }; } #define DLdeclare() \ extern "C" CBM::Package *cbmlib_getPackage(void) #define DLPackageWrapper_declare() \ virtual CBM::BenchmarkVector& Benchmarks(void); \ virtual CBM::Benchmark *Benchmark(std::string bid); \ virtual int benchmarkNumber(void) #endif --- NEW FILE: Benchmark-DLLoader.cpp --- #include <Benchmark/Benchmark-DLLoader.h> #include <libcompbenchmarks.h> #include <string> #include <iostream> #include <config.h> using namespace CBM; std::vector<std::string> CBM::cbmlib_paths; std::vector<Package*> CBM::cbmlib_packages; /* cache... */ std::vector<cbmlib_internal*> cbmlib_loaded_libraries; int CBM::PACKAGE_AUTOPURGE=1; cbmlib_internal *cbmlib_check_previousload(char *package_id) { int i; int s = cbmlib_loaded_libraries.size(); cbmlib_internal *l; for(i=0; i<s; i++) { l=cbmlib_loaded_libraries[i]; if (l->PackageGet()->Name()==package_id) return(l); } return(0); } cbmlib_internal *cbmlib_load_internal(const char *lib, char *package_id) { void *library; cbmlib_internal *r; if (UO_verbose) std::cout << "Loading " << lib << "... "; r=cbmlib_check_previousload(package_id); if (r) { if (UO_verbose) std::cout << "found (cached)." << std::endl; return(r); } library=dlopen(lib, RTLD_NOW); if (library) { if (UO_verbose) std::cout << "found." << std::endl; r=new cbmlib_internal; r->library=library; if (UO_verbose) std::cout << " Checking cbmlib_getPackage... "; r->PackageGet=(cbmlib_internal_getPackage_t) (dlsym(r->library, "cbmlib_getPackage")); if (!r->PackageGet) { dlclose(library); if (UO_verbose) std::cout << "Invalid" << std::endl; delete(r); return(0); } else { if (UO_verbose) std::cout << "found." << std::endl; } cbmlib_loaded_libraries.push_back(r); return(r); } else { if (UO_verbose) std::cout << "N.A. (" << dlerror() << ")" << std::endl; } return(0); } cbmlib_internal *CBM::cbmlib_load(char *package_id) { std::string tmp; cbmlib_internal *r = 0; int i; int n = CBM::cbmlib_paths.size(); for(i=0; i<n; i++) { tmp=CBM::cbmlib_paths[i]; tmp+="/libcompbenchmarks-bm-"; tmp+=package_id; tmp+=".so"; r=cbmlib_load_internal(tmp.c_str(), package_id); if (r) { return(r); } } return(0); } void CBM::cbmlib_done(void) { int i; int s; cbmlib_internal *l; s = CBM::cbmlib_packages.size(); CBM::PACKAGE_AUTOPURGE=0; for(i=0; i<s; i++) { delete(CBM::cbmlib_packages[i]); } s = cbmlib_loaded_libraries.size(); for(i=0; i<s; i++) { l=cbmlib_loaded_libraries[i]; dlclose(l->library); delete(l); } } --- NEW FILE: Package.h --- /* ---------------------------------------------------------------------------- $Id: Package.h,v 1.1 2007/01/22 18:21:47 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBMPACKAGE #define H_CBMPACKAGE #include <Compiler/Compiler.h> #include <Compiler/Compiler-Options.h> #include <vector> namespace CBM { class System; /** Defines a vector of benchmarks. Basically owned by CBM::Package instance. */ typedef std::vector<std::string> BenchmarkVector; /** \brief Defines an abstract package. * * This class can be overloaded in order to get new external packages * supported by CompBenchmarks. Basically it sets up packages (like gzip), * and prepares related benchmarks for evaluation. * * \sa Benchmark */ class Package { public: /** Package status * Defines typedef used to code internal status of a given package */ typedef enum Status { Unknown, /*!< Unkown; benchmark/package probably * not yet installed */ Downloaded, /*!< Package has been downloaded and checksum * is Ok. */ Extracted, /*!< Package has been successfuly extracted */ Patched, /*!< Package has been patched (optional step) */ Preconfigured, /*!< Package is now preconfigured. Also * optionnal, but each package goes throught * that step */ Configured, /*!< Package is configured (./configure) */ Made, /*!< Package has been made (make) */ Tested, /*!< Package has been tested */ Benchmarked }; /*!< Benchmarked */ private: /** Package status * \sa Package::Status * \sa storeStatus() * \sa getStatus() * \sa readStatus() */ Status status; /** \sa buildTime() */ std::string lastBuildTime; /** Expected MD5 on downloaded package * \return MD5 expected, as an std::string */ virtual std::string expectedMD5(void) = 0; /** Package's status * Initialise the status from file in the directory defined * by CBM::System::Status. * * \sa Benchmark::Status * \return 1 if ok. */ virtual int readStatus(void); protected: /** \sa Benchmarks() */ BenchmarkVector benchmarks; /** Stores current compiler. */ Compiler *currentCompiler; /** Stores current (compiler) options. */ CompilerOptions *currentOptions; /** System used */ class System *system; /** Constructor * Initialise the Package::system variable. */ Package(class System *_system); /** Pure method to extract package \return 1 if ok \sa Extract() \sa localPackageAbsoluteDirectory() */ virtual int extract(int _force = 0) = 0; /** Method to patch package * Must be overloaded to patch package. * \sa Patch() */ virtual int patch(int _force = 0); /** Method to test package. * Must be overloaded to test package using a method provided by package * maintainers. * \sa Test() */ virtual int test(int _force = 0); /** Pure virtual method to pre-configure package * Pre-configuration creates any needed elements (files or what ever) to benchmark * package. * \return 1 if ok. * \sa PreConfigure() */ virtual int preConfigure(int _force) = 0; /** Pure virtual method to configure package * Broadly speaking, this is ./configure * \sa Configure() * \return 1 if ok */ virtual int configure(Compiler *_currentCompiler, CompilerOptions *_currentOptions) = 0; /** Pure virtual method to build package * This could be a simple make, for instance. * \return 1 if ok * \sa Make() */ virtual int make(void) = 0; /** Pure virtual method to clean-up sources * Useful bettween two Make() to get all sources compiled with same environment. * \sa Release() * \sa Configure() * \sa Make() */ virtual int release(void) = 0; /** Uninstall benchmark * Removes information used by CompBenchmarks as well as any downloaded, extracted * or built element. Default behaviour should be ok in most case. * \return 1 if ok. */ virtual int uninstall(void); /** Gets a context ID * Give an unique ID according to compiler and options used. This can avoid useless * recompilations. * \return ID (MD5) as std::string * \sa Make() * \sa storeContext() * \sa ContextMatches() */ virtual std::string contextID(Compiler *_currentCompiler, CompilerOptions *_currentOptions); /** Stores (compilation) context ID * Stores the context ID for the current benchmark. * \sa contextID() * \sa ContextMatches() * \return 1 if ok */ virtual int storeContext(Compiler *_currentCompiler, CompilerOptions *_currentOptions); public: /** Indicates if the package needs patching * Must be overloaded if so. Returns 0 by default. * \return 0 by default, 1 if patch is needed. * \sa patch() * \sa Patch() */ virtual int hasPatch(void); /** Remove context. * \sa storeContext() */ virtual int resetContext(void); /** Display informations about package */ virtual void display(void); /** Display informations about all supported benchmarks */ virtual void displayBenchmarks(void); /** Get system abstraction object \return CBM::System */ virtual class System *System(void); /** Get all supported benchmarks. \return Array of std::string. */ virtual BenchmarkVector& Benchmarks(void); /** Get supported benchmarks' number \return An integer */ virtual int benchmarkNumber(void); /** Get a benchmark according to its index \sa Benchmarks() \return A pointer to the benchmark instance */ virtual class Benchmark *Benchmark(int i); /** Get a benchmark according to its identifier. \return References to a Benchmark object */ virtual class Benchmark *Benchmark(std::string bid); /** Stores benchmark status * Probably internal usage only. * \return 1 if ok * \sa readStatus() */ virtual int storeStatus(Status _status); /** Package name * \return a std::string like 'gzip', without quotes */ virtual std::string Name(void); /** Package version * \return a std::string like '1.2.4', without quotes */ virtual std::string Version(void) = 0; /** Package size, in bytes * \return an integer coding the size of package's archive (to download) in bytes. */ virtual int Size(void) = 0; /** Package comments * Gives comments about package. Short description, or what ever. * \return comments, as std::string */ virtual std::string Comments(void) = 0; /** Package local filename * \return a relative filename containing the local name of the uncompressed * package (like 'gzip-1.2.4.tar.Z', without quotes) */ virtual std::string localName(void) = 0; /** Benchmark's language * \return std::string (C or C++) */ virtual std::string language(void) = 0; /** Returns package or benchmark license \return a std::string describing license */ virtual std::string license(void) = 0; /** Returns package home page \return URL in std::string */ virtual std::string homePage(void) = 0; /** Author(s) of package \return std::string containing authors. */ virtual std::string author(void) = 0; /** Convenience method * \return local uncompressed absolute archive filename for benchmark. * \sa localPackageName() */ virtual std::string localAbsoluteName(void); /** Convenience method * \return directory used for extracting package * \sa CBM::System::Extract */ virtual std::string localAbsoluteDirectory(void); /** Relative directory to extract package * \return relative directory to use (or used, depending) for package extraction * \sa CBM::System::Extract */ virtual char* extractDirectory(void) = 0; /** Indicates if the package provides a test method. * Must be overloaded if so. Returns 0 by default. * \return 0 by default, 1 if patch is needed. * \sa test() * \sa Test() */ virtual int hasTest(void); /** URL used for downloading package. * \return std::string representing the URL of the package * \sa expectedMD5() */ virtual std::string downloadURL(void) = 0; /** Total size of the package * \return Total size, in bytes, of thepackage. This comprises data used * in pre-configuration step. * \sa preConfigure() * \sa packageSize() */ virtual int totalSize(void); /** Compairs previous compilation context to current one * \return 1 if they match. * \sa contextID() * \sa storeContext() * \sa Make() */ virtual int ContextMatches(Compiler *_currentCompiler, CompilerOptions *_currentOptions); /** Download package. * Gets downloadURL() object from Internet and verify checksum. * Uses download(). Overloading is unadvised. * This step won't be done and'll return 1 if getStatus()>=Package::Downloaded. * \param _force sets to 1 to force operation. May changes status. * \return 1 if ok. * \sa status */ virtual int Download(int _force = 0); /** Extract package. * Extracts downloaded package. * Uses extract(). Overloading is unadvised. * This step won't be done and'll return 1 if getStatus()>=Package::Extracted. * \param _force sets to 1 to force operation. May changes status. * \return 1 if ok. * \sa Download() * \sa status */ virtual int Extract(int _force = 0); /** Patch package. * Patches extracted package. * Overloading is unadvised, 1 is returned without any action, by default. * If hasPatch() returns 1, uses patch(). * This step won't be done and'll return 1 if getStatus()>=Package::Patched. * \param _force sets to 1 to force operation. May changes status. * \return 1 if ok. * \sa Extract() * \sa status */ virtual int Patch(int _force = 0); /** Preconfigure package. * Preconfigure downloaded package. * Uses preConfigure(). Overloading is unadvised. * This step won't be done and'll return 1 if * getStatus()>=Package::PreConfigured. May changes status. * \param _force sets to 1 to force operation. * \return 1 if ok. * \sa Patch() * \sa status */ virtual int PreConfigure(int _force = 0); /** Configure package. * Configure downloaded package. * Uses configure(). Overloading is unadvised. Argument are used to keep * compiler and options used for current bench (context), even * if ./configure script is not present : they'll be used by Make(). * This step won't be done and'll return 1 if getStatus()>=Package::Configured. May changes status. * \return 1 if ok. * \sa Download() * \sa Release() * \sa ContextMatches() * \sa Make(). * \sa status */ virtual int Configure(Compiler *_currentCompiler, CompilerOptions *_currentOptions); /** Build package. * Builds package. * Uses make(). Overloading is unadvised. * This step won't be done and'll return 1 if getStatus()>=Package::Made. * Updates lastBuildTime. * \param _force sets to 1 to force operation. May changes status. * \return 1 if ok. May changes status. * \sa Configure() * \sa Release() * \sa buildTime() * \sa status * \sa ContextMatches() */ virtual int Make(int _force = 0); /** Give build time. * Returns last time (in seconds) of make(). * \return build time in seconds * \sa Make() * \sa make() */ virtual std::string buildTime(void); /** Test a package. * Test a built package. * Overloading is unadvised, 1 is returned without any action, by default. * If hasPatch() returns 1, uses patch(). * This step won't be done and'll return 1 if getStatus()>=Package::Benchmarked. * \param _force sets to 1 to force operation. May changes status. * \return 1 if ok. * \sa Make() * \sa status */ virtual int Test(int _force = 0); /** Clean objects. * Uses release(). Overloading is unadvised. * This step won't be done and'll return 0 if getStatus()<Package::Made. May changes status. * \return 1 if ok. * \sa Bench() */ virtual int Release(void); /** Install package. * Installs package, uses, in that order Download(), Extract(), Patch() (if needed) * and PreConfigure(). Overloading is unadvised. * This step won't be done and'll return 1 if getStatus()>=Package::PreConfigured. * \param _force assign to 1 for forcing operation. * \return 1 if ok. May changes status. * \sa status */ virtual int Install(int _force = 0); /** Copy a local archive. * Copy package to directory defined by CBM::System::Download. It'll be ready * to be extracted using Install(). * \param _source the archive file * \param _force assign to 1 for forcing operation. * \return 1 if ok. May changes status. * \sa status * \sa extract */ virtual int Fetch(char *_source, int _force = 0); /** Uninstall package. * Uses uninstall(). Overloading is unadvised. * This step won't be done and'll return 1 if getStatus()==Package::Unknown. * \return 1 if ok. May changes status. * \sa status */ virtual int Uninstall(void); /** Returns benchmark's status * \return status (enum). * \sa Package::Status */ virtual Status getStatus(void); /** Virtual destructor */ virtual ~Package(); }; } #endif --- NEW FILE: Benchmark-xZIP.cpp --- #include <Benchmark/Benchmark-xZIP.h> #include <System/System.h> #include <fstream> using namespace CBM; PackagexZIP::PackagexZIP(CBM::System *_system) : PackageAutotools(_system) { } int PackagexZIP::preConfigure(int _force) { std::string fileName; std::ofstream OUT; int n = 12 * 1024 * 1024; fileName+=localAbsoluteDirectory(); fileName+="/Compbenchmarks.dat"; OUT.open(fileName.c_str(), std::ios::out); /* !!! */ while (n--) { OUT << std::hex << n; } OUT.close(); return(1); } PackagexZIP::~PackagexZIP() { } BenchmarkxZIP::BenchmarkxZIP(CBM::Package *_package) : Benchmark(_package) { } std::string BenchmarkxZIP::bench(void) { time_t start = System()->Time(); time_t end; std::string cmd; std::string result; std::string sstdout; char dum[16] = { 0 }; cmd="cd "; cmd+=package->localAbsoluteDirectory(); cmd+=" && ./"; cmd+=benchmarkProgram(); cmd+=" -"; cmd+=compressionLevel(); cmd+="c Compbenchmarks.dat > /dev/null"; if (System()->exec(cmd, sstdout)==0) { end=System()->Time(); sprintf(dum, "%0.0f", ((float)package->totalSize())/((int)(end-start))); result=dum; return(result); } else { return("0"); } } BenchmarkxZIP::~BenchmarkxZIP() { } --- NEW FILE: Benchmark.cpp --- #include <Benchmark/Benchmark.h> #include <Benchmark/Package.h> #include <iostream> #include <libcompbenchmarks.h> #include <UI/UI.h> using namespace CBM; Benchmark::Benchmark(CBM::Package *_package) { package=_package; } void Benchmark::display(void) { std::cout << "benchmark::Name=" << Name() << std::endl << "benchmark::Package=" << Package()->Name() << std::endl << "benchmark::Language=" << Package()->language() << std::endl << "benchmark::Size=" << Package()->totalSize() << std::endl << "benchmark::Status=" << Package()->getStatus() << std::endl << "benchmark::Comments=" << Comments() << std::endl << std::endl; } Package *Benchmark::Package(void) { return(package); } System *Benchmark::System(void) { if (package) return(package->System()); else return(0); } std::string Benchmark::Bench(void) { std::string r; std::string info; if (((Package()->getStatus()<Package::Tested) && (Package()->hasTest())) && (UO_enableTestSuite)) { info=Name(); info+=" not tested !"; cbmUI->Information(CBM::UI::BenchTest, info); return("0"); } cbmUI->Information(CBM::UI::BenchBench, Name()); r=bench(); Package()->System()->Chomp(r); if (r!="0") { Package()->storeStatus(Package::Benchmarked); cbmUI->Information(CBM::UI::BenchResult, r); } else { info="Benchmarking failed for "; info+=Package()->Name(); cbmUI->Fatal(info); } return(r); } Benchmark::~Benchmark() { } --- NEW FILE: Makefile.am --- # ----------------------------------------------------------------------------- # $Id: Makefile.am,v 1.1 2007/01/22 18:21:47 xfred Exp $ # $Source: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/Benchmark/Makefile.am,v $ # # This is free software. # For details, see the GNU Public License in the COPYING file, or # Look http://www.fsf.org # ----------------------------------------------------------------------------- noinst_LTLIBRARIES = libBenchmark.la sources = Package.cpp \ Benchmark.cpp \ Benchmark-DLLoader.cpp \ Benchmark-Autotools.cpp \ Benchmark-xZIP.cpp libBenchmark_la_SOURCES = $(sources) libBenchmarkinclude_HEADERS = $(sources:.cpp=.h) libBenchmarkincludedir = $(includedir)/compbenchmarks/Benchmark INCLUDES = -I $(top_srcdir)/libcompbenchmarks --- NEW FILE: Benchmark-xZIP.h --- /* ---------------------------------------------------------------------------- $Id: Benchmark-xZIP.h,v 1.1 2007/01/22 18:21:47 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBMBENCHMARKXZIP #define H_CBMBENCHMARKXZIP #include <Benchmark/Benchmark-Autotools.h> namespace CBM { /** \brief Defines an abstract package based on ZIP utilities. * * This class can be overloaded in order to get new external packages * supported by CompBenchmarks. It provides a 70M (through preConfigure()) * file that can be compressed. * \sa CBM::BenchmarkxZIP */ class PackagexZIP : public PackageAutotools { private: protected: /** Pre-configure package * Creates a ~70M files used for compression benchmarks. * \param _force must be set to 1 to force operation. * \sa CBM::Benchmark::preConfigure() */ virtual int preConfigure(int _force = 0); public: /** Constructor */ PackagexZIP(class System *_system); /** Virtual destructor */ virtual ~PackagexZIP(); }; /** \brief Defines an abstract benchmark based on ZIP utilities. * * This class can be overloaded in order to get new external packages * supported by CompBenchmarks. It provides a 70M (through preConfigure()) * file that can be compressed. * \sa PackagexZIP */ class BenchmarkxZIP : public Benchmark { protected: BenchmarkxZIP(CBM::Package *_package); /** Compression level \return compression level ("0" .. "9") used. */ virtual char* compressionLevel(void) = 0; /** Program name \return std::string like gzip or bzip2. */ virtual std::string benchmarkProgram(void) = 0; /** Runs the benchmark * Gives the amount of compressed bytes per seconds (as CompBenchmarks always apply * "bigger is better" policy to benchmarks' results, we can just rely on time). */ virtual std::string bench(void); virtual ~BenchmarkxZIP(); }; } #endif --- NEW FILE: Benchmark-DLLoader.h --- /* ---------------------------------------------------------------------------- $Id: Benchmark-DLLoader.h,v 1.1 2007/01/22 18:21:47 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBMBENCHMARKDLLOADER #define H_CBMBENCHMARKDLLOADER #include <System/System.h> #include <Benchmark/Benchmark.h> #include <Benchmark/Package.h> #include <dlfcn.h> #include <vector> namespace CBM { /** Paths to libraries */ extern std::vector<std::string> cbmlib_paths; extern std::vector<Package*> cbmlib_packages; extern int PACKAGE_AUTOPURGE; /** Function prototype for accessing a Package object */ typedef Package* (*cbmlib_internal_getPackage_t)(void); /** Low-level internal benchmark's shared library object */ typedef struct cbmlib_internal { void *library; cbmlib_internal_getPackage_t PackageGet; }; /** \brief Low-level library loading according to the benchmark/package's internal name. \param package_id something like gzip, bzip2, nbench and so on. */ cbmlib_internal *cbmlib_load(char *package_id); /** \brief Low-level function to Get a CBMBenchmark instance from a * shared library. * \param bench_id gzip-1c, benchpp-whetstone and so on. * \param _system A system instance. */ Benchmark *cbmlib_bench_load(char *bench_id, System *_system); /** \brief Low-level function for removing any internal existing reference to shared libraries. */ void cbmlib_done(void); } #endif --- NEW FILE: Package.cpp --- #include <Benchmark/Package.h> #include <Benchmark/Benchmark.h> #include <Benchmark/Benchmark-DLLoader.h> #include <System/System.h> #include <UI/UI.h> #include <libcompbenchmarks.h> #include <config.h> #include <fstream> #include <iostream> #include <string> using namespace CBM; Package::Package(CBM::System *_system) { system=_system; status=Unknown; currentCompiler=0; currentOptions=0; } BenchmarkVector& Package::Benchmarks(void) { return(benchmarks); } int Package::benchmarkNumber(void) { Benchmarks(); return(benchmarks.size()); } Benchmark *Package::Benchmark(int i) { Benchmarks(); return(Benchmark(benchmarks[i])); } Benchmark *Package::Benchmark(std::string bid) { std::cerr << "virtual Package::Benchmark() called" << std::endl; return(0); } void Package::display(void) { std::cout << "package::Name=" << Name() << std::endl << "package::Url=" << downloadURL() << std::endl << "package::Size=" << Size() << std::endl << "package::Version=" << Version() << std::endl << "package::Comments=" << Comments() << std::endl << "package::License=" << license() << std::endl << "package::Homepage=" << homePage() << std::endl << "package::Author=" << author() << std::endl << std::endl; } void Package::displayBenchmarks(void) { int i; int n; CBM::Benchmark *B; n=benchmarkNumber(); for(i=0; i<n; i++) { B=Benchmark(i); B->display(); } } System *Package::System(void) { return(system); } std::string Package::Name(void) { return(""); } int Package::readStatus(void) { char s; std::string r; std::string id; id="bm-status-"; id+=Name(); r=system->read((char*) id.c_str()); if (r!="") { s=r.c_str()[0]; status=(Status) ((int) s - (int) '0'); return(1); } else { /* !!! */ return(0); } } int Package::resetContext(void) { std::string contextFile; contextFile=system->temporaryDirectory(System::Status); contextFile+="/"; contextFile+="bm-context-"; contextFile+=Name(); return(system->unlink(contextFile)); } std::string Package::localAbsoluteName(void) { std::string localFile = system->temporaryDirectory(System::Download); localFile+="/"; localFile+=localName(); return(localFile); } std::string Package::localAbsoluteDirectory(void) { std::string cmd; cmd+=system->temporaryDirectory(System::Extract); cmd+="/"; cmd+=extractDirectory(); return(cmd); } int Package::hasPatch(void) { return(0); } int Package::patch(int _force) { return(1); } int Package::totalSize(void) { return(0); } int Package::hasTest(void) { return(0); } int Package::test(int _force) { return(1); } int Package::uninstall(void) { std::string where = localAbsoluteDirectory(); std::string cmd; cmd+=CBM_PROG_RM; cmd+=" -rf "; std::string sstdout; cmd+=where; return(system->exec(cmd, sstdout)==0); } int Package::storeStatus(Status _status) { int r; char c[16] = { 0 }; std::string tmp; std::string id; id="bm-status-"; id+=Name(); sprintf(c, "%d", (int) _status); tmp=c; r=system->store((char*) id.c_str(), tmp); status=_status; return(r); } std::string Package::contextID(CBM::Compiler *_currentCompiler, CBM::CompilerOptions *_currentOptions) { std::string what = _currentCompiler->Binary(); what+="\n"; what+=_currentOptions->Options(); return(what); } int Package::storeContext(CBM::Compiler *_currentCompiler, CBM::CompilerOptions *_currentOptions) { std::string context = contextID(_currentCompiler, _currentOptions); std::string id; int r; id="bm-context-"; id+=Name(); r=system->store((char*) id.c_str(), context); return(r); } int Package::ContextMatches(CBM::Compiler *_currentCompiler, CBM::CompilerOptions *_currentOptions) { std::string previousContext; std::string context; std::string id; id="bm-context-"; id+=Name(); previousContext=system->read((char*) id.c_str()); context=contextID(_currentCompiler, _currentOptions); if (context==previousContext) { currentCompiler=_currentCompiler; currentOptions=_currentOptions; return(1); } else { return(0); } } int Package::Download(int _force) { std::string localFile = localAbsoluteName(); std::string expected_md5; std::string md5; std::string info; if ((!_force) && (getStatus()>=Downloaded)) { return(1); } info=Name(); info+=" "; info+=Version(); cbmUI->Information(CBM::UI::BenchDownload, info); try { system->download(downloadURL(), (char*) localFile.c_str()); } catch (...) { } if (cbmSystem->fileExists(localFile)) { expected_md5=expectedMD5(); md5=system->md5File(localFile); if (expected_md5==md5) { cbmUI->Information(CBM::UI::ChecksumOK, localFile); storeStatus(Downloaded); return(1); } else { cbmUI->Information(CBM::UI::ChecksumFailed, localFile); system->unlink((char*) localFile.c_str()); info="Unsuccesfull download "; info+=downloadURL(); info+=" to "; info+=localFile; cbmUI->Fatal(info); return(0); } } else { info="Can't download "; info+=downloadURL(); info+=" to "; info+=localFile; cbmUI->Fatal(info); system->unlink((char*) localFile.c_str()); } return(0); } int Package::Extract(int _force) { int r; if ((!_force) && (getStatus()>=Extracted)) { return(1); } cbmUI->Information(CBM::UI::BenchExtract, Name()); r=extract(_force); if (r) storeStatus(Extracted); else { std::string info; info="Error extracting "; info+=localAbsoluteName(); info+=" into "; info+=system->temporaryDirectory(System::Extract); cbmUI->Fatal(info); } return(r); } int Package::Patch(int _force) { int r; if (!hasPatch()) return(1); if ((!_force) && (getStatus()>=Patched)) { return(1); } cbmUI->Information(CBM::UI::BenchPatch, Name()); r=patch(_force); if (r) storeStatus(Patched); else { std::string info; info="Error patching "; info+=localAbsoluteName(); cbmUI->Fatal(info); } return(r); } int Package::PreConfigure(int _force) { int r; if ((!_force) && (getStatus()>=Preconfigured)) { return(1); } if ( ((!hasPatch()) && (getStatus()<Extracted)) || ((hasPatch()) && (getStatus()<Patched)) ) { return(0); } cbmUI->Information(CBM::UI::BenchPreconfigure, Name()); r=preConfigure(_force); if (r) storeStatus(Preconfigured); else { std::string info; info="Error in "; info+=Name(); info+="'s pre-configuration"; cbmUI->Fatal(info); } return(r); } int Package::Configure(CBM::Compiler *_currentCompiler, CBM::CompilerOptions *_currentOptions) { int r; std::string info; if (getStatus()>=Configured) { currentCompiler=_currentCompiler; currentOptions=_currentOptions; return(1); } info=Name(); info+=" with compiler "; info+=_currentCompiler->Binary(); if (_currentOptions->Options()=="") { info+=" without options"; } else { info+=" and options "; info+=_currentOptions->Options(); } if (language()!=_currentCompiler->language()) { storeContext(_currentCompiler, _currentOptions); info=_currentCompiler->Binary(); info+=" is a "; info+=_currentCompiler->language(); info+=" compiler, while benchmark is written is "; info+=language(); info+="."; cbmUI->Fatal(info); } cbmUI->Information(CBM::UI::BenchConfigure, info); r=configure(_currentCompiler, _currentOptions); if (r) { storeStatus(Configured); currentCompiler=_currentCompiler; currentOptions=_currentOptions; } else { info="Configure failed for "; info+=Name(); cbmUI->Fatal(info); } return(r); } int Package::Make(int _force) { int r; std::string info; time_t beg; time_t end; char tmp[128]; if ((getStatus()>=Made) && (!_force)) { return(1); } cbmUI->Information(CBM::UI::BenchMake, Name()); beg=system->Time(); r=make(); if (r) { end=system->Time(); sprintf(tmp, "%f", (double) (end-beg)); lastBuildTime=tmp; std::cout << "Build time : " << lastBuildTime << std::endl; storeStatus(Made); storeContext(currentCompiler, currentOptions); } else { info="Make failed for "; info+=Name(); cbmUI->Fatal(info); } return(r); } std::string Package::buildTime(void) { return(lastBuildTime); } int Package::Test(int _force) { int r; std::string dum; if (!hasTest()) return(1); if (getStatus()<Configured) { cbmUI->Fatal("Package is not configured"); } if ((!_force) && (getStatus()>=Benchmarked)) { return(1); } if (getStatus()<Made) { return(0); } if (UO_enableTestSuite) { cbmUI->Information(CBM::UI::BenchTest, Name()); r=test(_force); } else { dum=Name(); dum+=" : passed (disabled by user option)."; cbmUI->Information(CBM::UI::BenchTest, dum); r=1; } if (r) storeStatus(Tested); else { std::string info; info="Error testing "; info+=localAbsoluteName(); cbmUI->Fatal(info); } return(r); } int Package::Release(void) { int r; std::string info; if (getStatus()<Configured) { return(0); } cbmUI->Information(CBM::UI::BenchClean, Name()); r=release(); if (r) { resetContext(); storeStatus(Preconfigured); } else { info="Clean failed for "; info+=Name(); /* cbmUI->Fatal(info); */ } return(r); } int Package::Install(int _force) { int r; if (downloadURL()=="") { cbmUI->Fatal("Package is not known to be hosted anymore on the Internet. Use --fetch option."); } resetContext(); r=Download(_force); if (!r) return(0); r=Extract(_force); if (!r) return(0); if (hasPatch()) { r=Patch(); if (!r) return(0); } r=PreConfigure(_force); return(r); } int Package::Fetch(char *_source, int _force) { std::string dest = localAbsoluteName(); std::string source = _source; std::string expected_md5; std::string md5; if ((getStatus()>=Downloaded) && (!_force)) { return(1); } if (dest!=source) { cbmSystem->copy(source, dest); } if (cbmSystem->fileExists(dest)) { expected_md5=expectedMD5(); md5=system->md5File(dest); if (expected_md5==md5) { cbmUI->Information(CBM::UI::ChecksumOK, dest); storeStatus(Downloaded); return(1); } else { cbmUI->Information(CBM::UI::ChecksumFailed, dest); } } return(0); } int Package::Uninstall(void) { std::string statusFile; int r; cbmUI->Information(CBM::UI::BenchUninstall, Name()); statusFile=system->temporaryDirectory(System::Status); statusFile+="/"; statusFile+="bm-status-"; statusFile+=Name(); if (getStatus()!=Unknown) { system->unlink(localAbsoluteName().c_str()); system->unlink(statusFile.c_str()); resetContext(); r=uninstall(); storeStatus(Unknown); currentCompiler=0; currentOptions=0; return(r); } else return(0); } Package::Status Package::getStatus(void) { // Status result = Unknown; std::string localFile = localAbsoluteName(); if (status==Unknown) readStatus(); return(status); } Package::~Package() { std::vector<Package*>::iterator it; if (PACKAGE_AUTOPURGE) { for(it=cbmlib_packages.begin(); it!=cbmlib_packages.end();) { if (*it == this) { cbmlib_packages.erase(it); break; } } } } --- NEW FILE: Benchmark-Autotools.cpp --- #include <Benchmark/Benchmark-Autotools.h> #include <System/System.h> #include <config.h> #include <fstream> using namespace CBM; PackageAutotools::PackageAutotools(CBM::System *_system) : Package(_system) { } int PackageAutotools::extract(int _force) { std::string localFile = localAbsoluteName(); std::string cmd; std::string sstdout; cmd+="cd "; cmd+=system->temporaryDirectory(CBM::System::Extract); cmd+=" && "; cmd+=CBM_PROG_ZCAT; cmd+=" "; cmd+=localFile; cmd+=" | "; cmd+=CBM_PROG_TAR; cmd+=" xvf -"; return(system->exec(cmd, sstdout)==0); } int PackageAutotools::configure(CBM::Compiler *_currentCompiler, CBM::CompilerOptions *_currentOptions) { std::string cmd; std::string sstdout; cmd="cd "; cmd+=localAbsoluteDirectory(); cmd+=" && "; currentCompiler=_currentCompiler; currentOptions=_currentOptions; if (language()=="C") { cmd+="CC="; } else { if (language()=="C++") { cmd+="CXX="; } else { /* !!! */ } } cmd+=currentCompiler->Binary(); if (language()=="C") { cmd+=" CFLAGS="; } else { if (language()=="C++") { cmd+="CXXFLAGS="; } else { /* !!! */ } } cmd+="'"; cmd+=currentOptions->Options(); cmd+="'"; cmd+=" ./configure"; return(system->exec(cmd, sstdout)==0); } int PackageAutotools::make(void) { std::string cmd; std::string sstdout; cmd="cd "; cmd+=localAbsoluteDirectory(); cmd+=" && "; cmd+=CBM_PROG_MAKE; cmd+=" 2> /dev/null"; return(system->exec(cmd, sstdout)==0); } int PackageAutotools::release(void) { std::string cmd; std::string sstdout; cmd="cd "; cmd+=localAbsoluteDirectory(); cmd+=" && "; cmd+=CBM_PROG_MAKE; cmd+=" clean 2> /dev/null"; return(system->exec(cmd, sstdout)==0); } PackageAutotools::~PackageAutotools() { } --- NEW FILE: Benchmark-Autotools.h --- /* ---------------------------------------------------------------------------- $Id: Benchmark-Autotools.h,v 1.1 2007/01/22 18:21:47 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBMBENCHMARKAUTOTOOLS #define H_CBMBENCHMARKAUTOTOOLS #include <Benchmark/Package.h> #include <Benchmark/Benchmark.h> namespace CBM { /** \brief Defines an abstract package based on autotools. * * This class can be overloaded in order to get new external packages * supported by CompBenchmarks. Basically it sets up packages (like gzip) * using GNU autotools (./configure, make). */ class PackageAutotools : public Package { private: protected: /** Extracts package * Extract a gzipped-tarball. * \return 1 if ok. * \sa CBMBenchmark::packageAbsoluteDirectory() */ virtual int extract(int _force = 0); /** Configure package Use ./configure script and standard options. \sa CBMBenchmark::Configure() \sa CBMBenchmark::language() \return 1 if ok. */ virtual int configure(Compiler *_currentCompiler, CompilerOptions *_currentOptions); /** Build package. Use make. \return 1 if ok. \sa CBMBenchmark::make() */ virtual int make(void); /** Removes object files. Use make clean. \return 1 if ok. \sa CBMBenchmark::release() */ virtual int release(void); /** Constructor */ PackageAutotools(class System *_system); /** Virtual destructor */ virtual ~PackageAutotools(); }; } #endif |