diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2017-07-09 14:25:48 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2017-07-09 14:25:48 -0700 |
commit | 6573fe1f1aa6d87c027d10429ded7e0162e52902 (patch) | |
tree | ddd110af3e987e49bb60ba05c16833c92d6d8901 | |
parent | 6ff9413c5dc624df6a33d7680a6667c27cd9352e (diff) | |
download | mu-6573fe1f1aa6d87c027d10429ded7e0162e52902.tar.gz |
3965 - get rid of the teardown() function
Instead of setup() and teardown() we'll just use a reset() function from now on, which will bring the machine back to a good state before each test or run, and also before exit (to avoid memory leaks).
-rw-r--r-- | 000organization.cc | 8 | ||||
-rw-r--r-- | 001help.cc | 4 | ||||
-rw-r--r-- | 002test.cc | 3 | ||||
-rw-r--r-- | 020run.cc | 3 | ||||
-rw-r--r-- | 034address.cc | 9 | ||||
-rw-r--r-- | 050scenario.cc | 5 | ||||
-rw-r--r-- | 072scheduler.cc | 9 |
7 files changed, 16 insertions, 25 deletions
diff --git a/000organization.cc b/000organization.cc index a29a8813..b1f1dc07 100644 --- a/000organization.cc +++ b/000organization.cc @@ -111,7 +111,7 @@ // End Globals int main(int argc, char* argv[]) { - atexit(teardown); + atexit(reset); // End One-time Setup @@ -131,10 +131,6 @@ int main(int argc, char* argv[]) { //: Without directives or with the :(code) directive, lines get added at the //: end. :(code) -void setup() { +void reset() { // End Setup } - -void teardown() { - // End Teardown -} diff --git a/001help.cc b/001help.cc index 053079f7..7543205e 100644 --- a/001help.cc +++ b/001help.cc @@ -143,7 +143,7 @@ bool starts_with(const string& s, const string& pat) { //: 5. Integer overflow is guarded against at runtime using the -ftrapv flag //: to the compiler, supported by Clang (GCC version only works sometimes: //: http://stackoverflow.com/questions/20851061/how-to-make-gcc-ftrapv-work). -:(before "atexit(teardown)") +:(before "atexit(reset)") initialize_signal_handlers(); // not always necessary, but doesn't hurt //? cerr << INT_MAX+1 << '\n'; // test overflow //? assert(false); // test SIGABRT @@ -179,7 +179,7 @@ void dump_and_exit(int sig, unused siginfo_t* dummy1, unused void* dummy2) { #include <signal.h> //: For good measure we'll also enable SIGFPE. -:(before "atexit(teardown)") +:(before "atexit(reset)") feenableexcept(FE_OVERFLOW | FE_UNDERFLOW); //? assert(sizeof(int) == 4 && sizeof(float) == 4); //? // | exp | mantissa diff --git a/002test.cc b/002test.cc index 1f89b05c..0fa39bf1 100644 --- a/002test.cc +++ b/002test.cc @@ -76,11 +76,10 @@ void run_test(size_t i) { cerr << "no test " << i << '\n'; return; } - setup(); + reset(); // End Test Setup (*Tests[i])(); // End Test Teardown - teardown(); } bool is_integer(const string& s) { diff --git a/020run.cc b/020run.cc index ed364b37..b059224e 100644 --- a/020run.cc +++ b/020run.cc @@ -208,7 +208,7 @@ save_snapshots(); :(before "End Main") if (!Run_tests && contains_key(Recipe_ordinal, "main") && contains_key(Recipe, get(Recipe_ordinal, "main"))) { // Running Main - setup(); + reset(); if (Start_tracing) { Trace_stream = new trace_stream; Save_trace = true; @@ -216,7 +216,6 @@ if (!Run_tests && contains_key(Recipe_ordinal, "main") && contains_key(Recipe, g trace(2, "run") << "=== Starting to run" << end(); assert(Num_calls_to_transform_all == 1); run_main(argc, argv); - teardown(); } :(code) void run_main(int argc, char* argv[]) { diff --git a/034address.cc b/034address.cc index 4b955050..d4c3e4d7 100644 --- a/034address.cc +++ b/034address.cc @@ -358,11 +358,12 @@ int allocate(int size) { //? int Total_free = 0; //? int Num_free = 0; //? :(before "End Setup") +//? if (!Memory.empty()) { +//? cerr << Total_alloc << "/" << Num_alloc +//? << " vs " << Total_free << "/" << Num_free << '\n'; +//? cerr << SIZE(Memory) << '\n'; +//? } //? Total_alloc = Num_alloc = Total_free = Num_free = 0; -//? :(before "End Teardown") -//? cerr << Total_alloc << "/" << Num_alloc -//? << " vs " << Total_free << "/" << Num_free << '\n'; -//? cerr << SIZE(Memory) << '\n'; :(code) void ensure_space(int size) { diff --git a/050scenario.cc b/050scenario.cc index 375da6cb..fb0a0114 100644 --- a/050scenario.cc +++ b/050scenario.cc @@ -217,7 +217,7 @@ void run_mu_scenario(const scenario& s) { //? cerr << s.name << '\n'; if (not_already_inside_test) { Trace_stream = new trace_stream; - setup(); + reset(); } vector<recipe_ordinal> tmp = load("recipe scenario_"+s.name+" [ "+s.to_run+" ]"); mark_autogenerated(tmp.at(0)); @@ -229,7 +229,6 @@ void run_mu_scenario(const scenario& s) { if (!Hide_errors && trace_contains_errors() && !Scenario_testing_scenario) Passed = false; if (not_already_inside_test && Trace_stream) { - teardown(); if (Save_trace) { ofstream fout("last_trace"); fout << Trace_stream->readable_contents(""); @@ -330,7 +329,7 @@ def main [ //: when we eventually build a compiler. //: 'run' is a purely lexical convenience to separate the code actually being -//: tested from any setup or teardown +//: tested from any setup :(scenario run) def main [ diff --git a/072scheduler.cc b/072scheduler.cc index 945e0402..9a914cc5 100644 --- a/072scheduler.cc +++ b/072scheduler.cc @@ -52,7 +52,10 @@ vector<routine*> Routines; int Current_routine_index = 0; :(before "End Setup") Scheduling_interval = 500; +for (int i = 0; i < SIZE(Routines); ++i) + delete Routines.at(i); Routines.clear(); +Current_routine = NULL; :(replace{} "void run(const recipe_ordinal r)") void run(const recipe_ordinal r) { run(new routine(r)); @@ -114,12 +117,6 @@ string routine_label(routine* r) { return result.str(); } -:(before "End Teardown") -for (int i = 0; i < SIZE(Routines); ++i) - delete Routines.at(i); -Routines.clear(); -Current_routine = NULL; - //: special case for the very first routine :(replace{} "void run_main(int argc, char* argv[])") void run_main(int argc, char* argv[]) { |