From d1fbbe647224b73495c526c9a79029102610c3de Mon Sep 17 00:00:00 2001
From: mgreiff <marcusgreiff.93@hotmail.com>
Date: Thu, 24 Aug 2017 01:42:21 +0200
Subject: [PATCH] Add unittesting for SysLED and GPIO IO operations

---
 test/BeagleBone/GPIO_test.jl    | 36 +++++++++++++++++++++++++++++++++
 test/BeagleBone/Sys_LED_test.jl | 35 ++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)
 create mode 100644 test/BeagleBone/GPIO_test.jl
 create mode 100644 test/BeagleBone/Sys_LED_test.jl

diff --git a/test/BeagleBone/GPIO_test.jl b/test/BeagleBone/GPIO_test.jl
new file mode 100644
index 0000000..02128f3
--- /dev/null
+++ b/test/BeagleBone/GPIO_test.jl
@@ -0,0 +1,36 @@
+include("../../src/BeagleBone/BeagleBone.jl")
+
+using Base.Test
+
+#Fixture
+device = getdev("gpio")
+gpio_state = true
+
+@testset "GPIO Tests" begin
+    @testset "Error Handling" begin
+        # Attempt to initialize faulty device
+        @test_throws ErrorException  getdev("wrong_device_name")
+
+        # Test that an exception is thrown when a faulty ID is given
+        @test_throws ErrorException write!(device, 100, 1, gpio_state)
+
+        # Test that an exception is thrown when a faulty ID is given
+        @test_throws ErrorException write!(device, 0, 1, gpio_state)
+    end
+    @testset "IO Communication" begin
+        # Instanciate all possible leds and perform 10 read/write commands
+        # with the set high/low operation (1)
+        operation = 1
+        for i = 1:10
+            for index = 1:length(channels)
+                write!(device, index, operation, gpio_state)
+            end
+            sleep(0.01)
+            #for j = 1:4
+                #val = read(device, j)
+                #@test val == gpio_state
+            #end
+            gpio_state = !gpio_state
+        end
+    end
+end
diff --git a/test/BeagleBone/Sys_LED_test.jl b/test/BeagleBone/Sys_LED_test.jl
new file mode 100644
index 0000000..6a8b901
--- /dev/null
+++ b/test/BeagleBone/Sys_LED_test.jl
@@ -0,0 +1,35 @@
+include("../../src/BeagleBone/BeagleBone.jl")
+
+using Base.Test
+
+#Fixture
+device = getdev("sysled")
+ledon = true
+
+@testset "SYS LED Tests" begin
+    @testset "Error Handling" begin
+        # Attempt to initialize faulty device
+        @test_throws ErrorException  getdev("wrong_device_name")
+
+        # Test that an exception is thrown when a faulty ID is given
+        @test_throws ErrorException write!(device, 5, ledon)
+
+        # Test that an exception is thrown when a faulty ID is given
+        @test_throws ErrorException write!(device, 0, ledon)
+    end
+
+    @testset "IO Communication" begin
+        # Instanciate all possible leds and perform 10 read/write commands  
+        for i = 1:10
+            for j = 1:4
+                write!(device, j, ledon)
+            end
+            sleep(0.001)
+            for j = 1:4
+                val = read(device, j)
+                @test val == ledon
+            end
+            ledon = !ledon
+        end
+    end
+end
-- 
GitLab