calypso 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18c02c94d3be06550f507b2e2318c3f5e7dea130
4
- data.tar.gz: 531ef2d2eb7dcaacfbd3eee8c02053e3fa9d18d4
3
+ metadata.gz: 170ce85369fbbdf51b9ef207fbb371e51167b870
4
+ data.tar.gz: 0cb0131ed1eecc82b9567a93a819eaf7bbbeb6a4
5
5
  SHA512:
6
- metadata.gz: ed43a49b4a8acbd8b8ebc1aefb31efd589de49f4e8d9aebb61a0d697285f1b6889723c9920119fe14146902a119c15e7169abc00b44df8e9c17aa64fb0b38bf0
7
- data.tar.gz: 7eb5682cfd6d3a12eddce97027f7efa095ce5237f9f7447cefe24cab306230c0f784e67d4f7585b808a2b79fbf4aa2d82b1bed9bffc680776acf37903ef5d2dd
6
+ metadata.gz: 7186a005c6c8d6582e99ebb87e16088760370c32160f99e5f374d692821a6cd230888ced193e8bc387debad0302d20ea38c5dd24a9ee673d9af1fa6a89b46e31
7
+ data.tar.gz: e54e457cfc00701dc1bb8e4fcb0e97b18b7fc8895c6593f11f9a1e233596029d38c87c7f71d3e2acd505f95fc4ad8e08991b35cbe3b714ff07bb17e2f4af2193
@@ -0,0 +1,53 @@
1
+ #
2
+ # Calypso module - Unit test hardware
3
+ # Copyright (C) 2016 Michel Megens <dev@bietje.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ #
20
+ module Calypso
21
+ # Calypso hardware model.
22
+ class Hardware
23
+ # @return [String] Hardware ID.
24
+ attr_reader :id
25
+ # @return [String] Hardware name.
26
+ attr_reader :name
27
+ # @return [String] CPU name.
28
+ attr_reader :cpu
29
+ # @return [Array] An array of Calypso::UnitTest
30
+ attr_reader :tests
31
+
32
+ # Create a new Calypso::Hardware object.
33
+ #
34
+ # @param id [String] Hardware ID.
35
+ # @param name [String] Hardware name.
36
+ # @param cpu [String] CPU name (or MCU for the matter of it).
37
+ def initialize(id, name, cpu)
38
+ @id = id
39
+ @name = name
40
+ @cpu = cpu
41
+ @tests = []
42
+ end
43
+
44
+ # Add a new test.
45
+ #
46
+ # @param test [Calypso::UnitTest] Test to add.
47
+ # @return [Array] The new array of [Calypso::UnitTest].
48
+ def add_test(test)
49
+ @tests.push test
50
+ end
51
+ end
52
+ end
53
+
@@ -0,0 +1,61 @@
1
+ #
2
+ # Calypso parser interface
3
+ # Copyright (C) 2016 Michel Megens <dev@bietje.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ #
20
+ module Calypso
21
+ # Parser interface.
22
+ class IParser
23
+ # @return [Hash] Hash of unit tests.
24
+ attr_reader :tests
25
+ # @return [Hash] Hash of available hardware.
26
+ attr_reader :hardware
27
+
28
+ # Create a new Parser.
29
+ #
30
+ # @param file [String] Path to the configuration file.
31
+ def initialize(file)
32
+ @tests = {}
33
+ @hardware = {}
34
+ @file = file
35
+ end
36
+
37
+ # Cruch data.
38
+ #
39
+ # @return [nil]
40
+ def parse
41
+ end
42
+
43
+ protected
44
+ # Set the hardware hash.
45
+ #
46
+ # @param hw [Hash] Hash of available hardware.
47
+ # @return [nil]
48
+ def set_hardware(hw)
49
+ @hardware = hw
50
+ end
51
+
52
+ # Set the tests hash.
53
+ #
54
+ # @param tests [Hash] Hash of available tests.
55
+ # @return [nil]
56
+ def set_tests(tests)
57
+ @tests = tests
58
+ end
59
+ end
60
+ end
61
+
@@ -0,0 +1,83 @@
1
+ #
2
+ # Calypso module - Kbuild representation
3
+ # Copyright (C) 2016 Michel Megens <dev@bietje.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'fileutils'
20
+
21
+ #
22
+ module Calypso
23
+ # Kbuild model.
24
+ class Kbuild
25
+ # @return [String] Absolute path to an ETA/OS configuration file.
26
+ attr_reader :conf
27
+
28
+ # Build targets.
29
+ ETAOS_BUILD_TARGETS = "all".freeze
30
+ # Prebuild targets.
31
+ ETAOS_PREBUILD_TARGETS = "prepare".freeze
32
+ # Clean targets.
33
+ ETAOS_CLEAN_TARGETS = "clean".freeze
34
+ # Module install targets.
35
+ ETAOS_INSTALL_TARGETS = "modules_install".freeze
36
+
37
+ # Create a new Kconfig controller.
38
+ #
39
+ # @param conf [String] ETA/OS configuration file.
40
+ # @param test_path [String] Unit test path.
41
+ def initialize(conf, test_path)
42
+ @conf = conf
43
+ @path = test_path
44
+ FileUtils.copy(@conf, "#{Dir.pwd}/.config")
45
+ end
46
+
47
+ # Run the clean target on ETA/OS.
48
+ def clean
49
+ system("make #{ETAOS_CLEAN_TARGETS}")
50
+ end
51
+
52
+ # Build ETA/OS.
53
+ def build
54
+ system("make #{ETAOS_PREBUILD_TARGETS}")
55
+ system("make #{ETAOS_BUILD_TARGETS}")
56
+ end
57
+
58
+ # Install the ETA/OS modules.
59
+ #
60
+ # @param libdir [String] Library directory.
61
+ def install_modules(libdir)
62
+ system("make #{ETAOS_INSTALL_TARGETS} INSTALL_MOD_PATH=#{libdir}")
63
+ end
64
+
65
+ # Build the test.
66
+ #
67
+ # @param targets [String] Build targets.
68
+ def build_test(targets)
69
+ system("make -f scripts/Makefile.calypso TARGETS=\"#{targets}\" TEST=#{@path}")
70
+ end
71
+
72
+ # Build all targets.
73
+ # @deprecated
74
+ def build_all
75
+ clean
76
+ build
77
+ install_modules
78
+ build_app
79
+ nil
80
+ end
81
+ end
82
+ end
83
+
@@ -0,0 +1,60 @@
1
+ #
2
+ # Calypso parser proxy
3
+ # Copyright (C) 2016 Michel Megens <dev@bietje.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'calypso/iparser'
20
+ require 'calypso/yamlparser'
21
+
22
+ #
23
+ module Calypso
24
+ # Proxy class for the Calypso configuration parser.
25
+ class ParserProxy
26
+ # Create a new parser proxy instance.
27
+ #
28
+ # @param type [Symbol] Parser type.
29
+ # @param file [String] Path to configuration file.
30
+ def initialize(type, file)
31
+ @file = File.expand_path(file)
32
+ @parser = case type
33
+ when :yaml
34
+ YAMLParser.new(@file)
35
+ else
36
+ nil
37
+ end
38
+ end
39
+
40
+ # Parse the config file.
41
+ def parse
42
+ @parser.parse
43
+ end
44
+
45
+ # Get the available hardware.
46
+ #
47
+ # @return [Hash] Hash of the available hardware.
48
+ def hardware
49
+ @parser.hardware
50
+ end
51
+
52
+ # Get a hash containing all tests.
53
+ #
54
+ # @return [Hash] All available unit tests.
55
+ def tests
56
+ @parser.tests
57
+ end
58
+ end
59
+ end
60
+
@@ -0,0 +1,109 @@
1
+ #
2
+ # Calypso module - Unit test
3
+ # Copyright (C) 2016 Michel Megens <dev@bietje.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'serialport'
20
+ require 'thread'
21
+
22
+ #
23
+ module Calypso
24
+ # Calypso's serial controller
25
+ class SerialMonitor
26
+ # @return [String] Path to the serial device.
27
+ attr_reader :portname
28
+ # @return [Fixnum] Serial baud rate.
29
+ attr_reader :baud
30
+ # @return [Fixnum] Number of data bits per byte.
31
+ attr_reader :databits
32
+ # @return [Fixnum] Number of stop bits.
33
+ attr_reader :stopbits
34
+ # @return [Symbol] Connection parity.
35
+ attr_reader :parity
36
+ # @return [Array<String>] Array of data read from the serial port.
37
+ attr_reader :data
38
+
39
+ # Calypso application exit token.
40
+ CALYPSO_EXIT = "calypso_exit".freeze
41
+
42
+ # Create a new serial port controller.
43
+ #
44
+ # @param port [String] Path to the serial device.
45
+ # @param baud [Fixnum] Serial baud rate.
46
+ # @param databits [Fixnum] Number of data bits per byte.
47
+ # @param stopbits [Fixnum] Number of stop bits.
48
+ # @param parity [Symbol] Connection parity.
49
+ def initialize(port, baud = 9600, databits = 8, stopbits = 1, parity = SerialPort::NONE)
50
+ @port = SerialPort.new(port, baud, databits, stopbits, parity)
51
+ @portname = port
52
+ @baud = baud
53
+ @databits = databits
54
+ @stopbits = stopbits
55
+ @parity = parity
56
+ @data = nil
57
+ @mutex = Mutex.new
58
+ end
59
+
60
+ # Monitor the serial port.
61
+ #
62
+ # @return [Boolean] Whether or not the application was manually stopped.
63
+ def monitor
64
+ running = true
65
+ ary = []
66
+ manual_stop = false
67
+
68
+ thread = Thread.new do
69
+ while running do
70
+ begin
71
+ input = gets
72
+ puts input
73
+ if input.nil?
74
+ @mutex.synchronize {running = false}
75
+ manual_stop = true
76
+ Thread.stop
77
+ break
78
+ end
79
+
80
+ input.chomp!
81
+ @port.write input
82
+ @port.flush
83
+ rescue Exception => e
84
+ puts e.message
85
+ exit
86
+ end
87
+ end
88
+ end
89
+
90
+ while (data = @port.gets.chomp) do
91
+ if data.eql? CALYPSO_EXIT then
92
+ Thread.kill thread
93
+ ary.push data
94
+ break
95
+ end
96
+
97
+ puts data
98
+ ary.push data
99
+ break unless running
100
+ end
101
+
102
+ thread.join unless manual_stop
103
+ @port.close
104
+ @data = ary
105
+ manual_stop
106
+ end
107
+ end
108
+ end
109
+
@@ -0,0 +1,50 @@
1
+ #
2
+ # Calypso module - SerialPort wrapper
3
+ # Copyright (C) 2016 Michel Megens <dev@bietje.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ #
20
+ module Calypso
21
+ # Serial port information wrapper.
22
+ class SerialPortData
23
+ # @return [String] Path to the serial device.
24
+ attr_reader :port
25
+ # @return [Fixnum] Serial baud rate.
26
+ attr_reader :baud
27
+ # @return [Fixnum] Number of data bits per byte.
28
+ attr_reader :databits
29
+ # @return [Fixnum] Number of stop bits.
30
+ attr_reader :stopbits
31
+ # @return [Symbol] Connection parity.
32
+ attr_reader :parity
33
+
34
+ # Create a new serial port controller.
35
+ #
36
+ # @param port [String] Path to the serial device.
37
+ # @param baud [Fixnum] Serial baud rate.
38
+ # @param databits [Fixnum] Number of data bits per byte.
39
+ # @param stopbits [Fixnum] Number of stop bits.
40
+ # @param parity [Symbol] Connection parity.
41
+ def initialize(port, baud = 9600, databits = 8, stopbits = 1, parity = SerialPort::NONE)
42
+ @port = port
43
+ @baud = baud
44
+ @databits = databits
45
+ @stopbits = stopbits
46
+ @parity = parity
47
+ end
48
+ end
49
+ end
50
+
@@ -0,0 +1,114 @@
1
+ #
2
+ # Calypso module - Unit test
3
+ # Copyright (C) 2016 Michel Megens <dev@bietje.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'calypso/serialmonitor'
20
+ require 'calypso/serialportdata'
21
+ require 'calypso/kbuild'
22
+
23
+ #
24
+ module Calypso
25
+ # Unit test model class
26
+ class UnitTest
27
+ # @return [String] Unit test name.
28
+ attr_reader :name
29
+ # @return [String] Unit test path.
30
+ attr_reader :path
31
+ # @return [Symbol] Unit test mode.
32
+ attr_reader :mode
33
+ # @return [Calypso::Hardware] Unit test hardware.
34
+ attr_reader :hw
35
+ # @return [Calypso::Hardware] Unit test hardware.
36
+ attr_reader :hardware
37
+ # @return [String] Unit test build and execution targets.
38
+ attr_reader :exec
39
+ # @return [Boolean] Whether or not the test should be ran automatically.
40
+ attr_reader :autorun
41
+
42
+ # Create a new UnitTest model.
43
+ #
44
+ # @param conf [Hash] Unit test configuration values.
45
+ # @param serial [Calypso::SerialPortData] Serial port information.
46
+ # @param hw [Calypso::Hardware] Unit test hardware.
47
+ def initialize(conf, serial, hw)
48
+ @name = conf['name']
49
+ @path = File.expand_path conf['path']
50
+ @mode = conf['mode'] == 'manual' ? :manual : :auto
51
+ @hw = hw
52
+ @hardware = hw
53
+ @exec = conf['execute']
54
+ config = conf['config']
55
+ @conf = "#{@path}/#{config}" unless conf.nil?
56
+ @libdir = File.expand_path conf['libdir'] unless conf['libdir'].nil?
57
+ @serial = serial
58
+ @raw = conf
59
+ @success = false
60
+ @autorun = conf['autorun']
61
+ @compare_file = conf['compare']
62
+ end
63
+
64
+ # Execute the unit test.
65
+ #
66
+ # @return [Boolean] Whether or not the test executed succesfully.
67
+ def execute
68
+ kbuild = Kbuild.new(@conf, @path)
69
+
70
+ unless Calypso.options.bare
71
+ kbuild.clean
72
+ kbuild.build
73
+ kbuild.install_modules(@libdir)
74
+ end
75
+
76
+ kbuild.build_test(@exec)
77
+ sp = Calypso::SerialMonitor.new(@serial.port)
78
+ manual_stop = sp.monitor
79
+
80
+ if manual_stop or @mode == :manual
81
+ print "Did the test run succesfully? [y/n]: "
82
+ reply = gets.chomp
83
+ @success = true if reply.eql? 'y' or reply.eql? 'Y'
84
+ else
85
+ @success = compare(sp)
86
+ end
87
+ end
88
+
89
+ # Check if the test ran succesfully.
90
+ #
91
+ # @return [Boolean] Whether or not the test executed succesfully.
92
+ def success?
93
+ @success
94
+ end
95
+
96
+ private
97
+ def compare(serial)
98
+ return if @compare_file.nil?
99
+ path = "#{@path}/#{@compare_file}"
100
+ data = serial.data
101
+ idx = 0
102
+
103
+ file = File.open path
104
+ while (line = file.gets) do
105
+ line.chomp!
106
+ return false unless line.eql? data[idx]
107
+ idx += 1
108
+ end
109
+
110
+ return true
111
+ end
112
+ end
113
+ end
114
+
@@ -19,5 +19,5 @@
19
19
  #
20
20
  module Calypso
21
21
  # Calypso version constant
22
- VERSION = '0.1.0'
22
+ VERSION = '0.1.1'
23
23
  end
@@ -0,0 +1,65 @@
1
+ #
2
+ # Calypso YAML parser
3
+ # Copyright (C) 2016 Michel Megens <dev@bietje.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'yaml'
20
+
21
+ require 'calypso/iparser'
22
+ require 'calypso/hardware'
23
+ require 'calypso/unittest'
24
+ require 'calypso/serialportdata'
25
+
26
+ #
27
+ module Calypso
28
+ # YAML parser library
29
+ class YAMLParser < IParser
30
+ # Create a new YAML parser.
31
+ #
32
+ # @param file [String] Path to the configuration file.
33
+ def initialize(file)
34
+ super
35
+ end
36
+
37
+ # Parse the configuration file.
38
+ #
39
+ # @return [nil]
40
+ def parse
41
+ obj = YAML.load_file(@file)
42
+ hardware = Hash.new
43
+ tests = Hash.new
44
+
45
+ obj['hardware'].each do |key, value|
46
+ hw = Calypso::Hardware.new(key, value['name'], value['cpu'])
47
+ hardware[key] = hw
48
+ end
49
+
50
+ obj['unit-tests'].each do |key, value|
51
+ hw = hardware[value['hardware']]
52
+ port = value['port']
53
+ baud = value['baud']
54
+ serial = Calypso::SerialPortData.new(port, baud)
55
+ tst = Calypso::UnitTest.new(value, serial, hw)
56
+ tests[key] = tst
57
+ hw.add_test tst
58
+ end
59
+
60
+ set_hardware(hardware)
61
+ set_tests(tests)
62
+ end
63
+ end
64
+ end
65
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calypso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Megens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-13 00:00:00.000000000 Z
11
+ date: 2016-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,7 +76,15 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - bin/calypso
78
78
  - lib/calypso.rb
79
+ - lib/calypso/hardware.rb
80
+ - lib/calypso/iparser.rb
81
+ - lib/calypso/kbuild.rb
82
+ - lib/calypso/parserproxy.rb
83
+ - lib/calypso/serialmonitor.rb
84
+ - lib/calypso/serialportdata.rb
85
+ - lib/calypso/unittest.rb
79
86
  - lib/calypso/version.rb
87
+ - lib/calypso/yamlparser.rb
80
88
  homepage: http://etaos.bietje.net/calypso
81
89
  licenses:
82
90
  - GPLv3