Search in sources :

Example 6 with FogRuntime

use of com.ociweb.iot.maker.FogRuntime in project FogLight-Examples by oci-pronghorn.

the class AppTest method testApp.

@Ignore
public void testApp() {
    FogRuntime runtime = FogRuntime.test(new IoTApp());
    ScriptedNonThreadScheduler scheduler = (ScriptedNonThreadScheduler) runtime.getScheduler();
    scheduler.startup();
    TestHardware hardware = (TestHardware) runtime.getHardware();
    int iterations = 10;
    while (--iterations >= 0) {
        scheduler.run();
    // test application here
    }
}
Also used : ScriptedNonThreadScheduler(com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler) TestHardware(com.ociweb.iot.hardware.impl.test.TestHardware) FogRuntime(com.ociweb.iot.maker.FogRuntime) Ignore(org.junit.Ignore)

Example 7 with FogRuntime

use of com.ociweb.iot.maker.FogRuntime in project FogLight-Examples by oci-pronghorn.

the class AppTest method testApp.

// this test reqires network connectivity of some kind
// HZ  may end up hanging this test if it can not find what it is lookoing for.
@Ignore
public void testApp() {
    FogRuntime runtime = FogRuntime.test(new IoTApp());
    ScriptedNonThreadScheduler scheduler = (ScriptedNonThreadScheduler) runtime.getScheduler();
    scheduler.startup();
    TestHardware hardware = (TestHardware) runtime.getHardware();
    int iterations = 10;
    while (--iterations >= 0) {
        scheduler.run();
    // test application here
    }
}
Also used : ScriptedNonThreadScheduler(com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler) TestHardware(com.ociweb.iot.hardware.impl.test.TestHardware) FogRuntime(com.ociweb.iot.maker.FogRuntime) Ignore(org.junit.Ignore)

Example 8 with FogRuntime

use of com.ociweb.iot.maker.FogRuntime in project FogLight-Examples by oci-pronghorn.

the class AppTest method testApp.

@Test
public void testApp() {
    FogRuntime runtime = FogRuntime.test(new IoTApp());
    TestHardware hardware = (TestHardware) runtime.getHardware();
}
Also used : TestHardware(com.ociweb.iot.hardware.impl.test.TestHardware) FogRuntime(com.ociweb.iot.maker.FogRuntime) Test(org.junit.Test)

Example 9 with FogRuntime

use of com.ociweb.iot.maker.FogRuntime in project FogLight-Examples by oci-pronghorn.

the class AppTest method testApp.

@Test
public void testApp() {
    FogRuntime runtime = FogRuntime.test(new IoTApp());
    ScriptedNonThreadScheduler scheduler = (ScriptedNonThreadScheduler) runtime.getScheduler();
    scheduler.startup();
    TestHardware hardware = (TestHardware) runtime.getHardware();
    hardware.portReader = new BasicTestPortReader();
    int iterations = 4;
    boolean isFirst = true;
    int expected = 0;
    long lastTime = 0;
    while (iterations > 0) {
        scheduler.run();
        long time = hardware.getLastTime(IoTApp.LED_PORT);
        if (0 != time) {
            iterations--;
            assertEquals(expected, 1 & hardware.read(IoTApp.LED_PORT));
            expected = 1 & (expected + 1);
            if (0 != lastTime) {
                long durationMs = (time - lastTime);
                if (!isFirst) {
                    assertTrue(Long.toString(durationMs), // first difference may be short because first transition is later due to startup.
                    durationMs >= 400);
                } else {
                    isFirst = false;
                }
                assertTrue(durationMs <= 750);
            }
            lastTime = time;
            hardware.clearCaputuredLastTimes();
            hardware.clearCaputuredHighs();
        }
    }
}
Also used : ScriptedNonThreadScheduler(com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler) TestHardware(com.ociweb.iot.hardware.impl.test.TestHardware) BasicTestPortReader(com.ociweb.iot.hardware.impl.test.BasicTestPortReader) FogRuntime(com.ociweb.iot.maker.FogRuntime) Test(org.junit.Test)

Example 10 with FogRuntime

use of com.ociweb.iot.maker.FogRuntime in project FogLight-Examples by oci-pronghorn.

the class AppTest method testApp.

@Test
public void testApp() {
    // 1 SEC
    IoTApp.RED_MS = 1000;
    // .8 SEC
    IoTApp.GREEN_MS = 800;
    // .2 SEC
    IoTApp.YELLOW_MS = 200;
    FogRuntime runtime = FogRuntime.test(new IoTApp());
    ScriptedNonThreadScheduler scheduler = (ScriptedNonThreadScheduler) runtime.getScheduler();
    TestHardware hardware = (TestHardware) runtime.getHardware();
    scheduler.startup();
    long next = System.currentTimeMillis() + 5_000;
    while (System.currentTimeMillis() < next) {
        scheduler.run();
        Thread.yield();
    }
    scheduler.shutdown();
}
Also used : ScriptedNonThreadScheduler(com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler) TestHardware(com.ociweb.iot.hardware.impl.test.TestHardware) FogRuntime(com.ociweb.iot.maker.FogRuntime) Test(org.junit.Test)

Aggregations

FogRuntime (com.ociweb.iot.maker.FogRuntime)14 TestHardware (com.ociweb.iot.hardware.impl.test.TestHardware)12 ScriptedNonThreadScheduler (com.ociweb.pronghorn.stage.scheduling.ScriptedNonThreadScheduler)11 Test (org.junit.Test)9 Ignore (org.junit.Ignore)3 GreenCommandChannel (com.ociweb.gl.api.GreenCommandChannel)2 Grove_LCD_RGB (com.ociweb.iot.grove.lcd_rgb.Grove_LCD_RGB)2 LED (com.ociweb.iot.grove.simple_digital.SimpleDigitalTwig.LED)2 BasicTestPortReader (com.ociweb.iot.hardware.impl.test.BasicTestPortReader)2 FogApp (com.ociweb.iot.maker.FogApp)2 FogCommandChannel (com.ociweb.iot.maker.FogCommandChannel)2 Hardware (com.ociweb.iot.maker.Hardware)2 Port (com.ociweb.iot.maker.Port)2 D3 (com.ociweb.iot.maker.Port.D3)2 D5 (com.ociweb.iot.maker.Port.D5)2 D6 (com.ociweb.iot.maker.Port.D6)2 NetGraphBuilder (com.ociweb.pronghorn.network.NetGraphBuilder)2 TestI2CBacking (com.ociweb.iot.hardware.impl.test.TestI2CBacking)1