Commit 5fabbf80 authored by Mathieu Faverge's avatar Mathieu Faverge

svn merge -r 881:1096...

svn merge -r 881:1096 svn+ssh://faverge@scm.gforge.inria.fr/svn/vite/branches/new_parser/tests . / Add generator tests done by kevin in an old branch
parent 539cb985
#include "Generator.hpp"
#include <iostream>
#include <math.h>
Generator::Generator (QString name,
int depth, int procNbr, int nbrOfState, int nbrOfLine,
int countNbr, int eventNbr, int linkNbr,
int eventTypeNbr, int linkTypeNbr,
bool paje, bool otf, bool tau){
_name = name ;
_depth = depth ;
_procNbr = procNbr ;
_numberOfState = nbrOfState ;
_numberOfLine = nbrOfLine ;
_counterNbr = countNbr ;
_eventNbr = eventNbr ;
_linkNbr = linkNbr ;
_eventTypeNbr = eventTypeNbr;
_linkTypeNbr = linkTypeNbr ;
_paje = paje ;
_otf = otf ;
_tau = tau ;
_arrayOfValues = new int[TYPEACTION];
int pos = 0;
_arrayOfValues[pos] = CHANGESTATE;
pos ++;
if (linkNbr){
_arrayOfValues[pos] = STARTLINK;
pos ++;
_arrayOfValues[pos] = ENDLINK;
pos ++;
}
if (countNbr){
_arrayOfValues[pos] = INCCPT;
pos ++;
_arrayOfValues[pos] = DECCPT;
pos ++;
}
if (eventNbr){
_arrayOfValues[pos] = EVENT;
pos ++;
}
_numberAction = pos;
fprintf (stderr, "Valeur de nb action = %d \n", _numberAction);
if (paje)
_pajeGen = new PajeGenerator ();
if (otf)
_otfGen = new OTFGenerator ();
if (tau)
_tauGen = new TauGenerator ();
}
Generator::~Generator (){
if (_pajeGen)
delete _pajeGen;
_pajeGen = NULL;
if (_tauGen)
delete _tauGen;
_tauGen = NULL;
if (_otfGen)
delete _otfGen;
_otfGen = NULL;
}
void Generator::initTrace (QString name, int depth, int procNbr, int stateTypeNbr, int eventTypeNbr, int linkTypeNbr, int varNbr){
if (_paje)
_pajeGen->initTrace (name, depth, procNbr, stateTypeNbr, eventTypeNbr, linkTypeNbr, varNbr);
if (_tau)
_tauGen->initTrace (name, depth, procNbr, stateTypeNbr, eventTypeNbr, linkTypeNbr, varNbr);
if (_otf)
_otfGen->initTrace (name, depth, procNbr, stateTypeNbr, eventTypeNbr, linkTypeNbr, varNbr);
time_t t;
t = time(NULL);
srand ((int)t);
}
void Generator::endTrace (){
int i;
my_link lnk;
fpritnf (stderr, "Ending the trace, nettoyage des liens morts\n");
for (i=0; i<_size ; i++){
lnk = getLink (1);
// Ending the link
endLink (lnk.proc, lnk.type, lnk.time);
}
fprintf (stderr, "Nettoyee \n");
if (_paje)
_pajeGen->endTrace ();
if (_tau)
_tauGen->endTrace ();
if (_otf)
_otfGen->endTrace ();
}
void Generator::addState (int proc, int state, double time){
if (_paje)
_pajeGen->addState (proc, state, time);
if (_tau)
_tauGen->addState (proc, state, time);
if (_otf)
_otfGen->addState (proc, state, time);
}
void Generator::startLink (int proc, int type, double time){
if (_paje)
_pajeGen->startLink (proc, type, time);
if (_tau)
_tauGen->startLink (proc, type, time);
if (_otf)
_otfGen->startLink (proc, type, time);
}
void Generator::endLink (int proc, int type, double time){
if (_paje)
_pajeGen->endLink (proc, type, time);
if (_tau)
_tauGen->endLink (proc, type, time);
if (_otf)
_otfGen->endLink (proc, type, time);
}
void Generator::addEvent (int proc, int type, double time){
if (_paje)
_pajeGen->addEvent (proc, type, time);
if (_tau)
_tauGen->addEvent (proc, type, time);
if (_otf)
_otfGen->addEvent (proc, type, time);
}
void Generator::incCpt (int proc, int var, double time){
if (_paje)
_pajeGen->incCpt (proc, var, time);
if (_tau)
_tauGen->incCpt (proc, var, time);
if (_otf)
_otfGen->incCpt (proc, var, time);
}
void Generator::decCpt (int proc, int var, double time){
if (_paje)
_pajeGen->decCpt (proc, var, time);
if (_tau)
_tauGen->decCpt (proc,var, time);
if (_otf)
_otfGen->decCpt (proc, var, time);
}
void Generator::generate (){
int i;
int val = 0;
initTrace (_name, _depth, _procNbr, _numberOfState, _eventTypeNbr, _linkTypeNbr, _counterNbr);
for (i=0; i<_numberOfLine ; i++){
do{
val = getRand (_numberAction);
if (_arrayOfValues[val]==STARTLINK)
_size ++;
}
while (_arrayOfValues[val]==ENDLINK && _size<1);
launchAction (_arrayOfValues[val], i);
}
endTrace ();
}
void Generator::launchAction (int val, int time){
int newVal ;
int newVal2;
my_link lnk ;
switch (val){
case CHANGESTATE :
// Getting the corresponding proc
newVal = getRand (_procNbr);
// Getting the corresponding state
newVal2 = getRand (_numberOfState);
addState (newVal, newVal2, time);
break;
case STARTLINK :
// Getting the corresponding proc
newVal = getRand (_linkNbr);
// Getting the corresponding link type
newVal2 = getRand (_linkTypeNbr);
lnk.time = time;
lnk.proc = newVal;
lnk.type = newVal2;
// Ajouter un lien a la liste
_startedLink.append (lnk);
startLink (newVal, newVal2, time);
break;
case ENDLINK :
// Choosing the link to end
newVal = getRand (_size);
_size--;
lnk = getLink (newVal);
// Ending the link
endLink (lnk.proc, lnk.type, time);
break;
case EVENT :
// Getting the proc to add the event
newVal = getRand (_eventNbr);
// Getting the type of the event
newVal2 = getRand (_eventTypeNbr);
addEvent (newVal, newVal2, time);
break;
case INCCPT :
newVal = getRand (_counterNbr);
// Always generate 1 counter per proc
incCpt (newVal, 1, time);
break;
case DECCPT :
newVal = getRand (_counterNbr);
// Always generate 1 counter per proc
decCpt (newVal, 1, time);
break;
default :
break;
}
}
my_link Generator::getLink (int pos){
my_link ret;
QList<my_link>::iterator it = _startedLink.begin ();
it += pos;
ret = *it;
_startedLink.erase (it);
return ret;
}
int Generator::getRand (int max){
int ret = 10.0 * rand () / (RAND_MAX + 1.0);
return ret%max;
}
#ifndef _VITE_GENERATOR_
#define _VITE_GENERATOR_
#include <QMainWindow>
#include "PajeGenerator.hpp"
#include "TauGenerator.hpp"
#include "OTFGenerator.hpp"
typedef struct _my_link{
int time;
int proc;
int type;
int value;
int key;
}my_link;
class Generator : public Writer{
private :
PajeGenerator* _pajeGen;
TauGenerator * _tauGen ;
OTFGenerator * _otfGen ;
bool _paje;
bool _tau;
bool _otf;
// Values
QString _name ; // Name of the file to create
int _depth ; // Depth of the container tree
int _procNbr ; // Number of procs
int _numberOfState ; // Number of different states
int _numberOfLine ; // Number of line generated
bool _counter ; // If counter are enabled
bool _event ; // If events are enabled
bool _link ; // If link are enabled
int _linkNbr ; // Number of proc with links
int _linkTypeNbr ; // Number of type of link
int _eventNbr ; // Number of proc with events
int _eventTypeNbr ; // Number of event type
int _counterNbr ; // Number of proc with counters
int _numberAction ; // Number of action available
// List of started links
QList<my_link> _startedLink ;
int _size ; // Number of link started
int* _arrayOfValues;
// Action = changeState, startLink, endLink, event, incCpt, decCpt
static const int TYPEACTION = 6;
static const int CHANGESTATE = 0;
static const int STARTLINK = 1;
static const int ENDLINK = 2;
static const int EVENT = 3;
static const int INCCPT = 4;
static const int DECCPT = 5;
int getRand (int maxVal);
void launchAction (int val, int time);
my_link getLink (int pos);
public :
// Constructor
Generator (QString name,
int depth, int procNbr, int nbrOfState, int nbrOfLine,
int countNbr, int eventNbr, int linkNbr,
int eventTypeNbr, int linkTypeNbr,
bool paje, bool otf, bool tau);
// Destructor
virtual ~Generator ();
// Main function that launch the creation of the traces
void generate ();
void initTrace (QString name, int depth, int procNbr, int stateTypeNbr, int eventTypeNbr, int linkTypeNbr, int varNbr);
void addState (int proc , int state, double time);
void startLink (int proc , int type , double time);
void endLink (int proc , int type , double time);
void addEvent (int proc , int type , double time);
void incCpt (int proc , int var , double time);
void decCpt (int proc , int var , double time);
void endTrace ();
};
#endif
#include "GeneratorWindow.hpp"
#include <iostream>
GeneratorWindow::GeneratorWindow (QWidget* parent, QApplication* app):QMainWindow (parent){
_app = app;
setupUi(this);
_gene = NULL;
_ui_name = qFindChild<QLineEdit*>(this, "fileNameEdit") ;
if (_ui_name == NULL)
fprintf (stderr, "Cannot find the name box in the .ui file") ;
_ui_depth = qFindChild<QLineEdit*>(this, "depthEdit") ;
if (_ui_depth == NULL)
fprintf (stderr, "Cannot find the depth box in the .ui file") ;
_ui_procNbr = qFindChild<QLineEdit*>(this, "procNumberEdit") ;
if (_ui_procNbr == NULL)
fprintf (stderr, "Cannot find the proc number box in the .ui file") ;
_ui_numberOfState = qFindChild<QLineEdit*>(this, "stateNumberEdit") ;
if (_ui_numberOfState == NULL)
fprintf (stderr, "Cannot find the number of state box in the .ui file");
_ui_linkNbr = qFindChild<QLineEdit*>(this, "linkEdit") ;
if (_ui_linkNbr == NULL)
fprintf (stderr, "Cannot find the link box in the .ui file") ;
_ui_counterNbr = qFindChild<QLineEdit*>(this, "counterEdit") ;
if (_ui_counterNbr == NULL)
fprintf (stderr, "Cannot find the counter box in the .ui file") ;
_ui_linkTypeNbr = qFindChild<QLineEdit*>(this, "linkType") ;
if (_ui_linkTypeNbr == NULL)
fprintf (stderr, "Cannot find the link type in the .ui file") ;
_ui_eventTypeNbr= qFindChild<QLineEdit*>(this, "eventType") ;
if (_ui_eventTypeNbr == NULL)
fprintf (stderr, "Cannot find the event type in the .ui file") ;
_ui_eventNbr = qFindChild<QLineEdit*>(this, "eventEdit") ;
if (_ui_eventNbr == NULL)
fprintf (stderr, "Cannot find the event box in the .ui file") ;
_ui_event = qFindChild<QCheckBox*>(this, "eventCheck") ;
if (_ui_event == NULL)
fprintf (stderr, "Cannot find the event checkbox in the .ui file") ;
_ui_counter = qFindChild<QCheckBox*>(this, "counterCheck") ;
if (_ui_counter == NULL)
fprintf (stderr, "Cannot find the counter checkbox in the .ui file") ;
_ui_link = qFindChild<QCheckBox*>(this, "linkCheck") ;
if (_ui_link == NULL)
fprintf (stderr, "Cannot find the link checkbox in the .ui file") ;
_ui_eventLabel = qFindChild<QLabel*>(this, "eventLabel") ;
if (_ui_event == NULL)
fprintf (stderr, "Cannot find the event label in the .ui file") ;
_ui_counterLabel = qFindChild<QLabel*>(this, "counterLabel") ;
if (_ui_counter == NULL)
fprintf (stderr, "Cannot find the counter label in the .ui file") ;
_ui_linkLabel = qFindChild<QLabel*>(this, "linkLabel") ;
if (_ui_link == NULL)
fprintf (stderr, "Cannot find the link label in the .ui file") ;
_ui_paje = qFindChild<QCheckBox*>(this, "paje") ;
if (_ui_paje == NULL)
fprintf (stderr, "Cannot find the paje checkbox in the .ui file") ;
_ui_tau = qFindChild<QCheckBox*>(this, "tau") ;
if (_ui_counter == NULL)
fprintf (stderr, "Cannot find the tau checkbox in the .ui file") ;
_ui_otf = qFindChild<QCheckBox*>(this, "otf") ;
if (_ui_link == NULL)
fprintf (stderr, "Cannot find the otf checkbox in the .ui file") ;
generateButton = qFindChild<QPushButton*>(this, "generateButton");
if (generateButton == NULL)
fprintf (stderr, "Cannot find the generate button in the .ui file");
resetButton = qFindChild<QPushButton*>(this, "resetButton");
if (resetButton == NULL)
fprintf (stderr, "Cannot find the reset button in the .ui file");
_ui_numberOfLine = qFindChild<QLineEdit*>(this, "lineNumberEdit") ;
if ( _ui_numberOfLine == NULL)
fprintf (stderr, "Cannot find the number of line in the .ui file");
// QMetaObject::connectSlotsByName (parent);
QObject::connect (generateButton, SIGNAL (clicked ()), this, SLOT (generateButton_clicked ()));
QObject::connect (resetButton, SIGNAL (clicked ()), this, SLOT (resetButton_clicked ()));
this->show ();
}
GeneratorWindow::~GeneratorWindow (){
}
void GeneratorWindow::generate (){
_gene->generate ();
}
void GeneratorWindow::setParam (){
QString nb;
_name = (_ui_name->text () == "")?NAME:_ui_name->text () ;
_depth = (_ui_depth->text () == "")?DEPTH:_ui_depth->text ().toInt () ;
_procNbr = (_ui_procNbr->text () == "")?PROCNBR:_ui_procNbr->text ().toInt () ;
_numberOfState = (_ui_numberOfState->text () == "")?NUMBEROFSTATE:_ui_numberOfState->text ().toInt ();
_numberOfLine = (_ui_numberOfLine->text () == "")?NUMBEROFLINE:_ui_numberOfLine->text ().toInt () ;
_paje = _ui_paje->isChecked ();
_otf = _ui_otf->isChecked ();
_tau = _ui_tau->isChecked ();
nb = _ui_counterNbr->text ();
if (_ui_counter->isChecked () && (nb != ""))
_counterNbr = (nb.toInt ()<_procNbr)?nb.toInt ():_procNbr;
else
_counterNbr = COUNTERNBR;
nb = _ui_linkNbr->text ();
if (_ui_link->isChecked () && (nb != "")){
_linkNbr = (nb.toInt ()<_procNbr)?nb.toInt ():_procNbr;
_linkTypeNbr = _ui_linkTypeNbr->text ().toInt ();
}
else{
_linkNbr = LINKNBR;
_linkTypeNbr = LINKTYPENBR;
}
nb = _ui_linkTypeNbr->text ();
if (_ui_link->isChecked () && (nb != ""))
_linkTypeNbr = nb.toInt ();
else
_linkTypeNbr = LINKTYPENBR;
nb = _ui_eventNbr->text ();
if (_ui_event->isChecked () && (nb != ""))
_eventNbr = (nb.toInt ()<_procNbr)?nb.toInt ():_procNbr;
else
_eventNbr = EVENTNBR;
nb = _ui_eventTypeNbr->text ();
if (_ui_event->isChecked () && (nb != ""))
_eventTypeNbr = nb.toInt ();
else
_eventTypeNbr = EVENTTYPENBR;
std::cout << " Valeurs rentrees : " << std::endl << " nom : " << _name.toStdString () << std::endl << " depth " << _depth << std::endl << " proc nbr " << _procNbr << std::endl << "nb of state " << _numberOfState << std::endl << "nbr line " << _numberOfLine << std::endl << "count nbr " << _counterNbr << std::endl << "event nbr " << _eventNbr << std::endl << "link nbr " << _linkNbr << std::endl << "event type nbr " << _eventTypeNbr << std::endl << "link type nbr " << _linkTypeNbr << std::endl;
if (_gene)
delete (_gene);
_gene = new Generator (_name,
_depth, _procNbr, _numberOfState, _numberOfLine,
_counterNbr, _eventNbr, _linkNbr,
_eventTypeNbr, _linkTypeNbr,
_paje, _otf, _tau);
}
void GeneratorWindow::hideCounter (){
_ui_counterLabel->hide ();
_ui_counterNbr->hide ();
}
void GeneratorWindow::hideLink (){
_ui_linkLabel->hide ();
_ui_linkNbr->hide ();
}
void GeneratorWindow::hideEvent (){
_ui_eventLabel->hide ();
_ui_eventNbr->hide ();
}
void GeneratorWindow::showCounter (){
_ui_counterLabel->show ();
_ui_counterNbr->show ();
}
void GeneratorWindow::showLink (){
_ui_linkLabel->show ();
_ui_linkNbr->show ();
}
void GeneratorWindow::showEvent (){
_ui_eventLabel->show ();
_ui_eventNbr->show ();
}
void GeneratorWindow::finishGeneration (){
cleanParam () ;
if (_gene)
delete _gene;
_gene = NULL;
}
void GeneratorWindow::cleanParam (){
// Class param
_name = NAME ;
_depth = DEPTH ;
_procNbr = PROCNBR ;
_numberOfLine = NUMBEROFLINE ;
_numberOfState = NUMBEROFSTATE;
_linkNbr = LINKNBR ;
_eventNbr = EVENTNBR ;
_counterNbr = COUNTERNBR ;
// UI edit param
_ui_name->setText ("");
_ui_depth->setText ("");
_ui_procNbr->setText ("");
_ui_numberOfLine->setText ("");
_ui_numberOfState->setText ("");
_ui_linkNbr->setText ("");
_ui_eventNbr->setText ("");
_ui_counterNbr->setText ("");
_ui_eventTypeNbr->setText ("");
// UI checkbox
_ui_link->setChecked (true);
_ui_event->setChecked (true);
_ui_counter->setChecked (true);
// Ensure fields are visible
showEvent ();
showLink ();
showCounter ();
}
void GeneratorWindow::resetButton_clicked (){
fprintf (stderr, "Reset ..... \n\n\n");
finishGeneration ();
}
void GeneratorWindow::generateButton_clicked (){
fprintf (stderr, "Generation ..... \n\n\n");
setParam ();
generate ();
cleanParam ();
}
int GeneratorWindow::run (){
return _app->exec ();
}
#ifndef _VITE_GENERATORWINDOW_
#define _VITE_GENERATORWINDOW_
#include <QMainWindow>
#include <QtGui/QApplication>
#include "ui_mainWindowGenerate.h"
#include "Generator.hpp"
// Default values
static const QString NAME = "trace";
static const int DEPTH = 2;
static const int PROCNBR = 16;
static const int NUMBEROFSTATE = 10;
static const int NUMBEROFLINE = 10000;
static const bool COUNTER = true;
static const bool EVENT = true;
static const bool LINK = true;
static const int LINKNBR = 8;
static const int EVENTNBR = 8;
static const int COUNTERNBR = 8;
static const int LINKTYPENBR = 5;
static const int EVENTTYPENBR = 5;
class GeneratorWindow : public QMainWindow, protected Ui_generatorBody{
Q_OBJECT