From c96351699e7613fd8bf35a2c91d23410cd122319 Mon Sep 17 00:00:00 2001 From: "Fred T. Hamster" Date: Sun, 15 Feb 2026 00:50:24 -0500 Subject: [PATCH] automated the cromp tests now the cromp tests actually are called, with both the server and client. this test reveals some issues (bugs) with the cromp code though, where the client loses contact with the server. also the runtime is way too long for a unit test. --- octopi/library/tests_cromp/crompish_pax.h | 23 ++++- .../tests_cromp/example_cromp_data.txt | 4 + octopi/library/tests_cromp/makefile | 9 +- octopi/library/tests_cromp/makefile.decoder | 6 +- .../library/tests_cromp/test_cromp_client.cpp | 8 +- .../library/tests_cromp/test_cromp_server.cpp | 19 ++-- .../library/tests_cromp/test_many_cromp.cpp | 87 ++++++++++++------- 7 files changed, 105 insertions(+), 51 deletions(-) create mode 100644 octopi/library/tests_cromp/example_cromp_data.txt diff --git a/octopi/library/tests_cromp/crompish_pax.h b/octopi/library/tests_cromp/crompish_pax.h index 03b35fa5..709e233a 100644 --- a/octopi/library/tests_cromp/crompish_pax.h +++ b/octopi/library/tests_cromp/crompish_pax.h @@ -20,11 +20,16 @@ \*****************************************************************************/ #include +#include #include #include #include #include +// uncomment to cause more checking that verifies the packed_size method +// is reporting accurately. +//#define CHECK_CROMPISH_PACKED_SIZE + class bubble : public octopi::infoton { public: @@ -51,7 +56,7 @@ public: int data_length() const { return _data.length(); } - clonable *clone() const { return octopi::cloner(*this); } + virtual clonable *clone() const { return octopi::cloner(*this); } basis::byte_array &data() { return _data; } @@ -64,15 +69,27 @@ public: } virtual void pack(basis::byte_array &packed_form) const { + FUNCDEF("pack") +#ifdef CHECK_CROMPISH_PACKED_SIZE + int prior_len = packed_form.length(); +#endif structures::attach(packed_form, _color); _bounds.pack(packed_form); structures::attach(packed_form, _data); +#ifdef CHECK_CROMPISH_PACKED_SIZE + int predicted_size = packed_size(); + int new_len = packed_form.length(); + if (prior_len + predicted_size != new_len) { + loggers::deadly_error(class_name(), func, basis::a_sprintf("size predicted=%d but actually was %d", predicted_size, new_len - prior_len)); + } +#endif } int packed_size() const { - return _data.length() + 2 * sizeof(int) // packed byte array. + return _data.length() + 2 * sizeof(int) // packed byte array. + sizeof(int) // packed color. - + 4 * sizeof(int); // packed screen rectangle. + + _bounds.packed_size(); // packed string array. +///no, old. 4 * sizeof(int); } virtual bool unpack(basis::byte_array &packed_form) { diff --git a/octopi/library/tests_cromp/example_cromp_data.txt b/octopi/library/tests_cromp/example_cromp_data.txt new file mode 100644 index 00000000..fd40910d --- /dev/null +++ b/octopi/library/tests_cromp/example_cromp_data.txt @@ -0,0 +1,4 @@ + + + + diff --git a/octopi/library/tests_cromp/makefile b/octopi/library/tests_cromp/makefile index 48a19848..a7ab6d68 100644 --- a/octopi/library/tests_cromp/makefile +++ b/octopi/library/tests_cromp/makefile @@ -5,15 +5,20 @@ include cpp/variables.def PROJECT = test_cromp TYPE = test TARGETS = test_cromp_client.exe test_cromp_server.exe test_many_cromp.exe -LAST_TARGETS = create_decoder_ring LOCAL_LIBS_USED = unit_test crypto application configuration filesystem loggers \ mathematics nodes processes sockets structures textual timely octopus cromp \ tentacles structures basis USE_SSL = t -#RUN_TARGETS = $(ACTUAL_TARGETS) +LAST_TARGETS = create_decoder_ring run_client_server_test include cpp/rules.def create_decoder_ring: $(MAKE) -f makefile.decoder +run_client_server_test: + # launch the server into the background first. we have to hope it completes, eventually. + ($(FEISTY_MEOW_BINARIES)/test_cromp_server &) + $(FEISTY_MEOW_BINARIES)/test_cromp_client + # zap the server now, since it won't quit otherwise. + killall test_cromp_server diff --git a/octopi/library/tests_cromp/makefile.decoder b/octopi/library/tests_cromp/makefile.decoder index 82d48d01..89451ff4 100644 --- a/octopi/library/tests_cromp/makefile.decoder +++ b/octopi/library/tests_cromp/makefile.decoder @@ -9,7 +9,11 @@ LOCAL_LIBS_USED = unit_test octopus cromp crypto application configuration files mathematics nodes processes sockets structures textual timely \ tentacles structures basis USE_SSL = t -RUN_TARGETS = $(ACTUAL_TARGETS) +LAST_TARGETS = decoder_ring include cpp/rules.def +decoder_ring: + $(FEISTY_MEOW_BINARIES)/cromp_decoder < example_cromp_data.txt + + diff --git a/octopi/library/tests_cromp/test_cromp_client.cpp b/octopi/library/tests_cromp/test_cromp_client.cpp index b0bc262e..8d99e39c 100644 --- a/octopi/library/tests_cromp/test_cromp_client.cpp +++ b/octopi/library/tests_cromp/test_cromp_client.cpp @@ -57,8 +57,8 @@ using namespace unit_test; #undef LOG #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), astring(s)) -#undef BASE_LOG -#define BASE_LOG(s) EMERGENCY_LOG(program_wide_logger::get(), astring(s)) +///#undef BASE_LOG +///#define BASE_LOG(s) EMERGENCY_LOG(program_wide_logger::get(), astring(s)) #define DEBUG_TESTER @@ -677,7 +677,7 @@ void cromp_client_tester::report(const time_stamp &start_time, packed_transa.length() - payload_portion)); #endif - BASE_LOG(a_sprintf("sent %.0f items, %.0f bytes, %.0f bytes per item,%s" + LOG(a_sprintf("sent %.0f items, %.0f bytes, %.0f bytes per item,%s" "payload %.0f bytes, overhead %.0f bytes, percent overhead %.1f%%,%s" "in %.2f seconds is %f ms/item%s" "at %.2f %cb/sec & %.2f items/sec.", @@ -809,7 +809,7 @@ int cromp_client_tester::execute() /// int char_read = fgetc(stdin); #endif - BASE_LOG("cromp_client:: works for those functions tested."); + LOG("works for those functions tested."); return 0; } diff --git a/octopi/library/tests_cromp/test_cromp_server.cpp b/octopi/library/tests_cromp/test_cromp_server.cpp index be3db71b..e036d8c6 100644 --- a/octopi/library/tests_cromp/test_cromp_server.cpp +++ b/octopi/library/tests_cromp/test_cromp_server.cpp @@ -14,20 +14,23 @@ #include "crompish_pax.h" +#include +#include +#include +#include #include #include -#include #include -#include -#include -#include -#include #include #include -#include +#include +#include #include #include #include +#include +#include +#include #include using namespace application; @@ -119,7 +122,7 @@ public: bubble *inf = dynamic_cast(&to_chow); if (!inf) return NO_HANDLER; //LOG("caching product! success getting unpacked etc."); - bubble *junk = (bubble *)inf->clone(); + bubble *junk = dynamic_cast(inf->clone()); store_product(junk, item_id); return OKAY; } @@ -139,7 +142,7 @@ cromp_server_tester::cromp_server_tester() _encryption(false) { FUNCDEF("constructor"); - SET_DEFAULT_COMBO_LOGGER; +/// SET_DEFAULT_COMBO_LOGGER; LOG(""); LOG(""); diff --git a/octopi/library/tests_cromp/test_many_cromp.cpp b/octopi/library/tests_cromp/test_many_cromp.cpp index bd64ff71..c3acb5a5 100644 --- a/octopi/library/tests_cromp/test_many_cromp.cpp +++ b/octopi/library/tests_cromp/test_many_cromp.cpp @@ -18,32 +18,52 @@ #include "crompish_pax.h" -#include -#include -#include -#include +#include +#include + +#include +#include +#include +#include #include #include #include -#include -#include #include +#include #include -#include -#include +#include +#include +#include +#include +#include #include +using namespace application; +using namespace basis; +using namespace configuration; +using namespace cromp; +using namespace mathematics; +using namespace filesystem; +using namespace loggers; +using namespace octopi; +using namespace processes; +using namespace sockets; +using namespace structures; +using namespace textual; +using namespace timely; +using namespace unit_test; + #define DEBUG_TESTER // uncomment for noisier version. const int REPORTING_INTERVAL = 20 * SECOND_ms; // how frequently we tell about bad crompers. -#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger(), s) -#define BASE_LOG(s) EMERGENCY_LOG(program_wide_logger(), s) +#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), astring(s)) +#define BASE_LOG(s) EMERGENCY_LOG(program_wide_logger::get(), astring(s)) -class many_cromp_tester : public application_shell +class many_cromp_tester : virtual public unit_base, virtual public application_shell { public: many_cromp_tester(); @@ -51,7 +71,7 @@ public: virtual int execute(); - IMPLEMENT_CLASS_NAME("many_cromp_tester"); + DEFINE_CLASS_NAME("many_cromp_tester"); private: amorph _uplinks; // a list of cromp clients. @@ -59,10 +79,11 @@ private: int _count; // number of cromps. }; -//////////////////////////////////////////////////////////////////////////// +////////////// many_cromp_tester::many_cromp_tester() -: application_shell("many_cromp_tester"), +: application_shell(), +///"many_cromp_tester"), _uplinks(), _encryption(false), _count(1) @@ -73,21 +94,21 @@ many_cromp_tester::many_cromp_tester() internet_address server_loc; - command_line args(__argc, __argv); -//LOG(isprintf("argc is %d and first is %s", __argc, __argv[0])); + command_line args(application::_global_argc, application::_global_argv); +//LOG(a_sprintf("argc is %d and first is %s", application::_global_argc, application::_global_argv[0])); // check for a port on the command line. - istring port_text; + astring port_text; int port = 5678; if (args.get_value("port", port_text, false)) { - LOG(istring("using port: ") + port_text); + LOG(astring("using port: ") + port_text); port = port_text.convert(5678); } server_loc.port = port; - istring count_text; + astring count_text; if (args.get_value("count", count_text, false)) { - LOG(istring("using count: ") + count_text); + LOG(astring("using count: ") + count_text); _count = count_text.convert(_count); } @@ -101,25 +122,25 @@ many_cromp_tester::many_cromp_tester() } // check for a hostname on the command line. - istring hostname("local"); - istring host_temp; + astring hostname("local"); + astring host_temp; if (args.get_value("host", host_temp, false)) { - LOG(istring("using host: ") + host_temp); + LOG(astring("using host: ") + host_temp); hostname = host_temp; } -LOG(istring("using host: ") + hostname); +LOG(astring("using host: ") + hostname); strcpy(server_loc.hostname, hostname.s()); -LOG(istring("opening at ") + server_loc.text_form()); +LOG(astring("opening at ") + server_loc.text_form()); -LOG(isprintf("count of %d cromps will be created.", _count)); +LOG(a_sprintf("count of %d cromps will be created.", _count)); for (int i = 0; i < _count; i++) { -LOG(isprintf("%d. A", i)); +LOG(a_sprintf("%d. A", i)); cromp_client *uplink = new cromp_client(server_loc); -LOG(isprintf("%d. B", i)); +LOG(a_sprintf("%d. B", i)); uplink->add_tentacle(new bubbles_tentacle(false)); -LOG(isprintf("%d. C", i)); +LOG(a_sprintf("%d. C", i)); _uplinks.append(uplink); } @@ -142,7 +163,7 @@ int many_cromp_tester::execute() for (int i = 0; i < _uplinks.elements(); i++) { outcome ret = _uplinks.borrow(i)->connect(); if (ret != cromp_client::OKAY) { - deadly_error(class_name(), func, istring("connection failed with error: ") + deadly_error(class_name(), func, astring("connection failed with error: ") + cromp_client::outcome_name(ret)); } } @@ -160,13 +181,13 @@ time_stamp when_to_leave(10 * HOUR_ms); if (time_stamp() > next_report) { int connected = _uplinks.elements() - unconnected; - LOG(isprintf("[ %d connected and %d did not ]", connected, unconnected)); + LOG(a_sprintf("[ %d connected and %d did not ]", connected, unconnected)); next_report.reset(REPORTING_INTERVAL); } //do something with uplinks. - portable::sleep_ms(100); + time_control::sleep_ms(100); } @@ -175,7 +196,7 @@ time_stamp when_to_leave(10 * HOUR_ms); return 0; } -//////////////////////////////////////////////////////////////////////////// +////////////// HOOPLE_MAIN(many_cromp_tester, ) -- 2.43.0