foxygit / fake-08-xbox360 Log in
commit d625ca96dd85a3a76a67f8c33a84400b84a63c04
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sat Jun 18 16:34:21 2022 -0600
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sat Jun 18 16:34:21 2022 -0600

    WIP on cart loading regression test
---
 test/Makefile            |   2 +-
 test/cartloadingtest.cpp | 150 +++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 134 insertions(+), 18 deletions(-)

diff --git a/test/Makefile b/test/Makefile
index 442de1d..966cd1e 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -21,7 +21,7 @@ CFLAGS	:=	-g -Wall -Wno-deprecated -ffunction-sections -std=c++17 \

 CFLAGS	+=	$(INCLUDE) -DVER_STR=\"$(APP_VERSION)\"

-CXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions
+CXXFLAGS	:= $(CFLAGS) -fno-rtti -fexceptions
 #-std=gnu++11 was used before... not sure of difference


diff --git a/test/cartloadingtest.cpp b/test/cartloadingtest.cpp
index c625bab..7ef5092 100644
--- a/test/cartloadingtest.cpp
+++ b/test/cartloadingtest.cpp
@@ -3,6 +3,11 @@
 #include <sstream>
 #include <algorithm>

+#include <chrono>
+#include <thread>
+#include <mutex>
+#include <condition_variable>
+
 #include <stdio.h>
 #include <dirent.h>
 #include <errno.h>
@@ -16,22 +21,132 @@
 #include "../source/nibblehelpers.h"
 #include "../source/filehelpers.h"

-TEST_CASE("Loading and running carts") {
+
+const vector<string> cartsToIgore ({
+    "15666.p8.png",
+    "16069.p8.png",
+    "16355.p8.png",
+    "16507.p8.png",
+    "16677.p8.png",
+    "16965.p8.png",
+    "17616.p8.png",
+    "17853.p8.png",
+    "17888.p8.png",
+    "18124.p8.png",
+    "18199.p8.png",
+    "18560.p8.png",
+    "18813.p8.png",
+    "18987.p8.png",
+    "20797.p8.png",
+    "21114.p8.png", // intermittent
+    "21242.p8.png",
+    "21415.p8.png",
+    "21677.p8.png",
+    "21736.p8.png",
+    "23013.p8.png",
+    "23183.p8.png",
+    "23402.p8.png",
+    "23801.p8.png",
+    "23842.p8.png",
+    "23958.p8.png",
+    "24007.p8.png",
+    "24141.p8.png",
+    "24292.p8.png",
+    "24418.p8.png",
+    "24443.p8.png",
+    "24687.p8.png",
+    "24695.p8.png",
+    "25532.p8.png",
+    "25735.p8.png",
+    "25919.p8.png",
+    "26194.p8.png",
+    "26425.p8.png",
+    "26646.p8.png", //different logs every time
+    "26782.p8.png",
+    "27183.p8.png",
+    "27672.p8.png",
+    "27941.p8.png",
+    "28607.p8.png",
+    "28611.p8.png",
+    "28725.p8.png",
+    "28757.p8.png",
+    "28912.p8.png",
+    "29142.p8.png",
+    "29216.p8.png",
+    "29283.p8.png",
+    "29420.p8.png",
+    "29559.p8.png",
+});
+
+string checkCart(Vm* vm, string cartDirectory, string cart){
+    printf("%s\n", cart.c_str());
+    vm->LoadCart(cartDirectory + "/" + cart, false);
+
+    if (vm->GetBiosError() != "") {
+        return vm->GetBiosError();
+    }
+    else
+    {
+        vm->UpdateAndDraw();
+
+        if (vm->GetBiosError() != "") {
+            vm->GetBiosError();
+        }
+    }
+
+    vm->CloseCart();
+
+    return "";
+}
+/*
+string checkCart_wrapper(string cartDirectory, string cart)
+{
+    std::mutex m;
+    std::condition_variable cv;
+    string retValue;
+
     Host* host = new Host();
     Vm* vm = new Vm(host);
+
+    std::thread t([&cv, &vm, &cartDirectory, &cart, &retValue]()
+    {
+        retValue = checkCart(vm, cartDirectory, cart);
+        cv.notify_one();
+    });
+
+    t.detach();
+
+    {
+        std::unique_lock<std::mutex> l(m);
+        if(cv.wait_for(l, 1s) == std::cv_status::timeout) {
+            retValue = "timeout";
+            //This leaks host and vm. Not sure of alternative?
+            return retValue;
+            //vm->CloseCart();
+        }
+    }

+    delete vm;
+    delete host;
+
+    return retValue;
+}
+*/
+
+TEST_CASE("Loading and running carts") {
     vector<string> carts;
     vector<string> errors;

+
     //TODO: build library of carts to test- set up compiler flag?
-    std::string _cartDirectory = "/Users/jon/p8carts/infinitelooptest";
+    std::string _cartDirectory = "/Users/jon/p8carts/archive/carts";

     DIR *dir;
     struct dirent *ent;
     if ((dir = opendir (_cartDirectory.c_str())) != NULL) {
         /* print all the files and directories within directory */
         while ((ent = readdir (dir)) != NULL) {
-            if (isCartFile(ent->d_name)){
+            if (isCartFile(ent->d_name) && std::find(cartsToIgore.begin(), cartsToIgore.end(), ent->d_name) == cartsToIgore.end()){
                 carts.push_back(ent->d_name);
             }
         }
@@ -43,26 +158,27 @@ TEST_CASE("Loading and running carts") {
     sort(carts.begin(), carts.end());


+    Host* host = new Host();
+    Vm* vm = new Vm(host);
+
+
     for(int i = 0; i < carts.size(); i++) {
-        //printf("%s\n", carts[i].c_str());
-        vm->LoadCart(_cartDirectory + "/" + carts[i], false);
+        try {
+            //string result = checkCart_wrapper(_cartDirectory, carts[i]);

-        if (vm->GetBiosError() != "") {
-            errors.push_back(carts[i] + ": " + vm->GetBiosError());
-        }
-        else
-        {
-            vm->UpdateAndDraw();
+            string result = checkCart(vm, _cartDirectory, carts[i]);

-            if (vm->GetBiosError() != "") {
-                errors.push_back(carts[i] + vm->GetBiosError());
+            if (result.length() > 0) {
+                errors.push_back(carts[i] + ": " + result);
             }
         }
-
-        vm->CloseCart();
+        catch(std::runtime_error& e) {
+            errors.push_back(carts[i] + ": Timeout" + e.what());
+        }
     }

-
     delete vm;
     delete host;
-}
\ No newline at end of file
+
+}
+