From 197f45368ba110bb16d11cf7fb255a7bb0cc770c Mon Sep 17 00:00:00 2001 From: Chinmay Pendharkar Date: Tue, 16 Jan 2024 15:31:04 +0800 Subject: [PATCH] test(*): fixing broken tests --- gateways/c/tests/test_fjage.c | 9 +++++ .../groovy/org/arl/fjage/test/BasicTests.py | 0 .../org/arl/fjage/test/fjagecTest.groovy | 37 ++++++++++++++---- .../org/arl/fjage/test/fjagepyTest.groovy | 2 +- .../java/org/arl/fjage/test/BasicTests.java | 38 +++++++++---------- 5 files changed, 59 insertions(+), 27 deletions(-) mode change 100644 => 100755 src/test/groovy/org/arl/fjage/test/BasicTests.py diff --git a/gateways/c/tests/test_fjage.c b/gateways/c/tests/test_fjage.c index 17452e5f..8005c68e 100644 --- a/gateways/c/tests/test_fjage.c +++ b/gateways/c/tests/test_fjage.c @@ -53,6 +53,14 @@ static void test_assert(const char* name, int pass) { static void test_summary(void) { printf("\n*** %d test(s) PASSED, %d test(s) FAILED ***\n\n", passed, failed); + +} + +static void send_report(fjage_gw_t gw){ + fjage_msg_t msg = fjage_msg_create("org.arl.fjage.test.TestCompleteNtf", FJAGE_INFORM); + fjage_msg_set_recipient(msg, fjage_aid_create("test")); + fjage_msg_add_bool(msg, "status", failed == 0); + fjage_send(gw, msg); } static int error(const char* msg) { @@ -251,6 +259,7 @@ int main(int argc, char* argv[]) { aid = fjage_aid_topic("mytopic"); test_assert("set param (-string)", fjage_param_set_string(gw, aid, "dummy", "dummy", -1) < 0); fjage_aid_destroy(aid); + send_report(gw); test_assert("close", fjage_close(gw) == 0); test_summary(); return failed; diff --git a/src/test/groovy/org/arl/fjage/test/BasicTests.py b/src/test/groovy/org/arl/fjage/test/BasicTests.py old mode 100644 new mode 100755 diff --git a/src/test/groovy/org/arl/fjage/test/fjagecTest.groovy b/src/test/groovy/org/arl/fjage/test/fjagecTest.groovy index b409be3a..beb51149 100644 --- a/src/test/groovy/org/arl/fjage/test/fjagecTest.groovy +++ b/src/test/groovy/org/arl/fjage/test/fjagecTest.groovy @@ -13,6 +13,8 @@ class fjagecTest { @Test void fjageCTest() { if (System.getProperty("os.name").startsWith("Windows")) return // skip on Windows + def testResult = false + def testPending = true def platform = new RealTimePlatform() def container = new MasterContainer(platform, 5081) WebServer.getInstance(8080).add("/", "/org/arl/fjage/web") @@ -20,16 +22,37 @@ class fjagecTest { def shell = new ShellAgent(new ConsoleShell(conn), new GroovyScriptEngine()) container.addConnector(new WebSocketConnector(8080, "/ws", true)) container.add 'shell', shell + container.add('test', new Agent(){ + @Override + protected void init() { + add(new MessageBehavior(){ + @Override + void onReceive(Message msg) { + println("Received: " + msg.performative + ',' + msg.recipient + ',' + msg.sender) + testResult = msg.performative == Performative.AGREE + testPending = false + } + }) + } + }) platform.start() Thread.sleep(5) def ret = 0 - println "Running automated tests." - def proc = "make -C gateways/c clean test runtest".execute() - def sout = new StringBuilder(), serr = new StringBuilder() - proc.consumeProcessOutput(sout, serr) - proc.waitFor() - ret = proc.exitValue() - println "C : out = $sout \n err = $serr \n ret = $ret" + if (System.getProperty('manualCTest') == null){ + println "Running automated tests." + def proc = "make -C gateways/c clean test runtest".execute() + def sout = new StringBuilder(), serr = new StringBuilder() + proc.consumeProcessOutput(sout, serr) + proc.waitFor() + ret = proc.exitValue() + println "C : out = $sout \n err = $serr \n ret = $ret" + }else{ + println "waiting for user to run manual tests" + while (testPending){ + platform.delay(1000) + } + println "test complete " + testPending + " : " + testResult + } container.shutdown() platform.shutdown() assertEquals(ret,0) diff --git a/src/test/groovy/org/arl/fjage/test/fjagepyTest.groovy b/src/test/groovy/org/arl/fjage/test/fjagepyTest.groovy index 3eb0f6b4..fca50c4b 100644 --- a/src/test/groovy/org/arl/fjage/test/fjagepyTest.groovy +++ b/src/test/groovy/org/arl/fjage/test/fjagepyTest.groovy @@ -34,7 +34,7 @@ class fjagepyTest { def st = platform.currentTimeMillis(); if (System.getProperty('manualPyTest') == null){ println "Running automated tests." - def proc = "python src/test/groovy/org/arl/fjage/test/BasicTests.py".execute() + def proc = "src/test/groovy/org/arl/fjage/test/BasicTests.py".execute() def sout = new StringBuilder(), serr = new StringBuilder() proc.consumeProcessOutput(sout, serr) proc.waitFor() diff --git a/src/test/java/org/arl/fjage/test/BasicTests.java b/src/test/java/org/arl/fjage/test/BasicTests.java index 7bf63ba9..a5e1010c 100644 --- a/src/test/java/org/arl/fjage/test/BasicTests.java +++ b/src/test/java/org/arl/fjage/test/BasicTests.java @@ -365,14 +365,14 @@ public void testListener() { assertFalse(container.removeListener(listener)); int n1 = listener.n; assertTrue(n1 > 0); - assertTrue(n1 == server.nuisance); - assertTrue(n1 == client.nuisance); + assertEquals(n1, server.nuisance); + assertEquals(n1, client.nuisance); server.nuisance = 0; client.nuisance = 0; platform.delay(1000); platform.shutdown(); - assertTrue(n1 == listener.n); - assertTrue(server.nuisance == client.nuisance); + assertEquals(n1, listener.n); + assertEquals(server.nuisance, client.nuisance); } @Test @@ -393,13 +393,13 @@ public void testListener2() { assertFalse(container.removeListener(listener)); int n1 = listener.n; assertTrue(n1 > 0); - assertTrue(n1 == client.nuisance); - assertTrue(server.nuisance == 0); + assertEquals(n1,client.nuisance); + assertEquals(server.nuisance,0); server.nuisance = 0; client.nuisance = 0; platform.delay(1000); platform.shutdown(); - assertTrue(n1 == listener.n); + assertEquals(n1,listener.n); assertTrue(server.nuisance > 0); } @@ -423,10 +423,10 @@ public void testParam1() { log.info("Successful: "+(client1.count + client2.count + client3.count)); log.info("Warnings: "+(client1.warnings + client2.warnings + client3.warnings)); log.info("Errors: "+(server.errors + client1.errors + client2.errors + client3.errors)); - assertTrue(server.errors == 0); - assertTrue(client1.errors == 0); - assertTrue(client2.errors == 0); - assertTrue(client3.errors == 0); + assertEquals(server.errors, 0); + assertEquals(client1.errors, 0); + assertEquals(client2.errors, 0); + assertEquals(client3.errors, 0); assertTrue(client1.warnings < 3); assertTrue(client2.warnings < 3); assertTrue(client3.warnings < 3); @@ -453,10 +453,10 @@ public void testParam2() { log.info("Successful: "+(client1.count + client2.count + client3.count)); log.info("Warnings: "+(client1.warnings + client2.warnings + client3.warnings)); log.info("Errors: "+(server.errors + client1.errors + client2.errors + client3.errors)); - assertTrue(server.errors == 0); - assertTrue(client1.errors == 0); - assertTrue(client2.errors == 0); - assertTrue(client3.errors == 0); + assertEquals(server.errors, 0); + assertEquals(client1.errors, 0); + assertEquals(client2.errors, 0); + assertEquals(client3.errors, 0); assertTrue(client1.warnings < 3); assertTrue(client2.warnings < 3); assertTrue(client3.warnings < 3); @@ -483,10 +483,10 @@ public void testAIDParam() { log.info("Successful: "+(client1.count + client2.count + client3.count)); log.info("Warnings: "+(client1.warnings + client2.warnings + client3.warnings)); log.info("Errors: "+(server.errors + client1.errors + client2.errors + client3.errors)); - assertTrue(server.errors == 0); - assertTrue(client1.errors == 0); - assertTrue(client2.errors == 0); - assertTrue(client3.errors == 0); + assertEquals(server.errors, 0); + assertEquals(client1.errors, 0); + assertEquals(client2.errors, 0); + assertEquals(client3.errors, 0); assertTrue(client1.warnings < 3); assertTrue(client2.warnings < 3); assertTrue(client3.warnings < 3);