diff --git a/Makefile.am b/Makefile.am index 0a5e538..cce4d0f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -329,10 +329,22 @@ src_testsuite_test_history_LDFLAGS = \ src/backend/libbackend.la \ $(GLIBMM_LIBS) src_testsuite_test_history_SOURCES = \ + src/backend/concrete_environment.cc \ + src/backend/concrete_history.cc \ + src/backend/dynamic_process.cc \ + src/backend/dynamic_request.cc \ + src/backend/dynamic_resource.cc \ + src/backend/dynamic_schedulable.cc \ + src/backend/dynamic_sub_request.cc \ + src/backend/dynamic_thread.cc \ + src/backend/static_process.cc \ + src/backend/static_request.cc \ + src/backend/static_resource.cc \ + src/backend/static_schedulable.cc \ + src/backend/static_sub_request.cc \ + src/backend/static_thread.cc \ src/testsuite/test-history.cc - - #src_testsuite_test_parse_command_CPPFLAGS = \ # -I@top_srcdir@/src \ # -I@top_srcdir@/src/templates \ diff --git a/src/backend/history_observer.hh b/src/backend/history_observer.hh index a9f0df4..39aad74 100644 --- a/src/backend/history_observer.hh +++ b/src/backend/history_observer.hh @@ -31,7 +31,7 @@ namespace sgpem class SG_DLLEXPORT HistoryObserver { public: - virtual void update(History& changed_history) = 0; + virtual void update(const History& changed_history) = 0; virtual ~HistoryObserver(); }; // class HistoryObserver diff --git a/src/testsuite/test-history.cc b/src/testsuite/test-history.cc index 9bf5928..3726512 100644 --- a/src/testsuite/test-history.cc +++ b/src/testsuite/test-history.cc @@ -21,275 +21,44 @@ /* This executable tests for workingness of the whole History services, * and nothing else. */ - - -#include -#include -#include -#include #include "config.h" #include "gettext.h" -#include "glibmm/ustring.h" -#include -#include -#include "backend/history.hh" -#include "backend/static_process.hh" -#include "backend/slice.hh" -#include "backend/observed_subject.hh" -#include "backend/ready_queue.hh" -#include "backend/dynamic_schedulable.hh" -#include "templates/smartp.tcc" +#include + +#include +#include + +#include "backend/concrete_environment.hh" +#include "backend/concrete_history.hh" +#include "backend/history_observer.hh" using namespace sgpem; using namespace std; -/** An HistoryTester object offers a simple interface to test the History class. - * - * - * - */ -class HistoryTester + +// History observer used to see how many times +// it is updated +class DummyObserver : public HistoryObserver { public: - - - HistoryTester(ReadyQueue sl) - : _history_length(-1), _internal_ready_queue(sl) - {} - - /** this method gets a sequence of operations as a parameter and performs them - * checking for anomalies. - * E stands for EnqueueSlice, R for randomize input, T for truncate the last insertion - */ - void - test(std::string commands_sequence) - { - // prints the test sequence - std::cout << commands_sequence << endl; - // executes the test sequence - for (unsigned int i = 0; i < commands_sequence.length() && i < 400; i++) - { - switch(commands_sequence[i]) - { - case 'E': - _insert(_internal_ready_queue); - break; - case 'R': - _randomize(_internal_ready_queue); - break; - case 'T': - _truncate(); - break; - default: - break; - } - _standard_test(); - } - return; - } - + DummyObserver() : _i(0) {} + void update(const History& history) + { + cout << "Observer.update() : " << ++_i << endl; + } private: - - int _history_length; // mirrors the correct length of the history - ReadyQueue* _get_simulation_status_at[400]; // mirrors the correct content of the history - DynamicSchedulable* _get_scheduled_at[400]; // mirrors the correct content of the history - ReadyQueue _internal_ready_queue; - - - // looks for anomalies - void - _standard_test() - { - // checks if the Singleton Pattern has been actually implemented - if (&History::get_instance() != &History::get_instance()) std::cout << "\nget_instance"; - - // checks if the History is long how it should be - if (History::get_instance().get_current_time() != _history_length) std::cout << "\nget_current_time: real: " << History::get_instance().get_current_time() << ", expected " << _history_length << endl; - - // checks if the History contains the right stuff - int min = History::get_instance().get_current_time(); - min = min < _history_length ? min : _history_length; - for (int i = 0; i < min + 1; i++) - { - // watch out here, it's if (NOT ...) operator != was not available. - if - ( - !( - History::get_instance().get_simulation_status_at(i)->has_same_objects( *_get_simulation_status_at[i]) - ) - ) - { - std::cout << "\nget_simulation_status_at"; - } - if (History::get_instance().get_scheduled_at(i) != memory::smart_ptr(NULL) && !(*(History::get_instance().get_scheduled_at(i)) == *(_get_scheduled_at[i]))) - { - std::cout << "\nget_scheduled_at"; - } - } - return; - } - - - // saves the given ReadyQueue into the history, and saves a copy of it into an array - void _insert(sgpem::ReadyQueue& status) - { - History::get_instance().enqueue_slice(status); - - _history_length = _history_length + 1; - _get_simulation_status_at[_history_length] = new ReadyQueue(status); - - if (History::get_instance().get_scheduled_at(_history_length) != memory::smart_ptr(NULL)) - _get_scheduled_at[_history_length] = new DynamicSchedulable(*(History::get_instance().get_scheduled_at(_history_length))); - else - _get_scheduled_at[_history_length] = NULL; - return; - } - - - // modifies the given ReadyQueue object in an arbitrary way. - void _randomize(sgpem::ReadyQueue& status) - { - status.swap(9, 10); - status.swap(1, 16); - status.swap(3, 19); - status.swap(2, 18); - status.swap(5, 16); - status.swap(4, 11); - status.swap(6, 12); - status.swap(7, 14); - status.swap(15, 13); - status.swap(0, 10); - status.swap(9, 4); - status.swap(4, 5); - status.swap(7, 1); - for (unsigned int i = 0; i < status.size(); i++) - { - status.get_item_at(i)->give_cpu_time(i % 2); - status.get_item_at(i)->set_last_scheduled(_history_length % 30); - status.get_item_at(i)->set_state(i % 2 ? DynamicSchedulable::state_running : DynamicSchedulable::state_ready); - } - return; - } - - - // truncates the history by one instant - void _truncate() - { - if (_history_length > -1) - { - if (_get_simulation_status_at[_history_length] != NULL) - { - delete _get_simulation_status_at[_history_length]; - _get_simulation_status_at[_history_length] = NULL; - } - - if (_get_scheduled_at[_history_length] != NULL) - { - delete _get_scheduled_at[_history_length]; - _get_scheduled_at[_history_length] = NULL; - } - - _history_length = _history_length - 1; - History::get_instance().truncate_at(_history_length - 1); - } - return; - } - + unsigned int _i; }; + + int main(int argc, char** argv) { using namespace sgpem; - using Glib::Module; + #warning "Nobody wrote me!" - std::string command("ERERERT"); // the sequence of commands to test - if(argc > 1) - command = argv[1]; - - // sets up the test data - StaticProcess p1("P1", 1, 5, 1); - StaticProcess p2("P2", 5, 55, 2); - StaticProcess p3("P3", 36, 30, 3); - StaticProcess p4("P4", 4, 26, 3); - StaticProcess p5("P5", 15, 200, 3); - StaticProcess p6("P6", 6, 250, 1); - StaticProcess p7("P7", 8, 42, 15); - StaticProcess p8("P8", 8, 56, 1); - StaticProcess p9("P9", 9, 42, 1); - StaticProcess p10("PA", 12, 42, 1); - StaticProcess p11("PB", 106, 42, 1); - StaticProcess p12("PC", 100, 42, 1); - StaticProcess p13("PD", 29, 42, 18); - StaticProcess p14("PE", 0, 42, 1); - StaticProcess p15("PF", 2, 88, 1); - StaticProcess p16("PG", 3666, 9, 1); - StaticProcess p17("PH", 5, 72, 10); - StaticProcess p18("PJ", 6, 26, 1); - StaticProcess p19("PK", 10, 24, 17); - StaticProcess p20("PK2", 11, 34, 67); // not used! - - DynamicSchedulable ss1(p1); - DynamicSchedulable ss2(p2); - DynamicSchedulable ss3(p3); - DynamicSchedulable ss4(p4); - DynamicSchedulable ss5(p5); - DynamicSchedulable ss6(p6); - DynamicSchedulable ss7(p7); - DynamicSchedulable ss8(p8); - DynamicSchedulable ss9(p9); - DynamicSchedulable ss10(p10); - DynamicSchedulable ss11(p11); - DynamicSchedulable ss12(p12); - DynamicSchedulable ss13(p13); - DynamicSchedulable ss14(p14); - DynamicSchedulable ss15(p15); - DynamicSchedulable ss16(p16); - DynamicSchedulable ss17(p17); - DynamicSchedulable ss18(p18); - DynamicSchedulable ss19(p19); // not used! - - ReadyQueue initial; - initial.add_at_bottom(ss1); - initial.add_at_bottom(ss2); - initial.add_at_bottom(ss3); - initial.add_at_bottom(ss4); - initial.add_at_bottom(ss5); - initial.add_at_bottom(ss6); - initial.add_at_bottom(ss7); - initial.add_at_bottom(ss8); - initial.add_at_bottom(ss9); - initial.add_at_bottom(ss10); - initial.add_at_bottom(ss11); - initial.add_at_bottom(ss12); - initial.add_at_bottom(ss13); - initial.add_at_bottom(ss14); - initial.add_at_bottom(ss15); - initial.add_at_bottom(ss16); - initial.add_at_bottom(ss17); - initial.add_at_bottom(ss18); - - HistoryTester HT(initial); - //HT.test("EEEEREREEEERERRREEEEEEEETERRERERTTT"); - HT.test("E"); - HT.test("EE"); - HT.test("EERE"); - HT.test("EEEREE"); - HT.test("EEEREE"); - HT.test("EEER"); - HT.test("EEEERER"); - HT.test("EEER"); - HT.test("EREE"); - HT.test("EEEERERT"); - HT.test("EEEERERTEEEERERT"); - HT.test("EEEERERTEEETRERERT"); - HT.test("EEEERERTEEEERRRERT"); - HT.test("EEEEEEERERTERERT"); - HT.test("EEEEREREEEERERRREEEEEEEETERRERERTTT"); - //HT.test(command); - - cout << std::endl << "\nend of test!\n"; - exit(0); + return 0; }