Module: Calypso

Defined in:
lib/calypso.rb,
lib/calypso/kbuild.rb,
lib/calypso/iparser.rb,
lib/calypso/version.rb,
lib/calypso/hardware.rb,
lib/calypso/unittest.rb,
lib/calypso/yamlparser.rb,
lib/calypso/parserproxy.rb,
lib/calypso/serialmonitor.rb,
lib/calypso/serialportdata.rb

Overview

Calypso base module

Defined Under Namespace

Classes: Hardware, IParser, Kbuild, ParserProxy, SerialMonitor, SerialPortData, UnitTest, YAMLParser

Constant Summary collapse

VERSION =

Calypso version constant

'0.1.3'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.optionsObject (readonly)

Returns the value of attribute options.



32
33
34
# File 'lib/calypso.rb', line 32

def options
  @options
end

Class Method Details

.run(parser, options) ⇒ nil

Run all unit tests.

Parameters:

  • parser (Calypso::ParserProxy)

    Configuration parser.

  • options (OpenStruct)

    Options passed to Calypso on the cmd line.

Returns:

  • (nil)


225
226
227
228
229
230
231
# File 'lib/calypso.rb', line 225

def run(parser, options)
  hw = parser.hardware

  hw.each do |hwid, hwdata|
    Calypso.run_hardware(parser, options, hwid)
  end
end

.run_hardware(config, options, hwid) ⇒ nil

Run all tests for a specific piece of hardware.

Parameters:

  • config (Calypso::ParserProxy)

    Configuration parser.

  • options (OpenStruct)

    Options passed to Calypso on the cmd line.

  • hwid (String)

    Hardware ID.

Returns:

  • (nil)


196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/calypso.rb', line 196

def run_hardware(config, options, hwid)
  hw = config.hardware[hwid]
  tests = hw.tests
  puts "Running #{hw.name} tests. Press enter to continue..."
  gets

  tests.each do |test|
    next unless test.autorun
    Calypso.tty_fix(test.serial) if options.tty_fix
    test.execute
    success = "successfully" if test.success?
    success = "unsuccessfully" unless test.success?
    puts ""
    puts "#{test.name} ran #{success}!"
    puts ""
  end

  puts "Unit test results:\n"
  tests.each do |test|
    next unless test.autorun
    puts "[#{test.name}]: #{test.success? ? 'OK' : 'FAIL'}"
  end
end

.run_single(parser, options) ⇒ nil

Run a single test.

Parameters:

  • parser (Calypso::ParserProxy)

    Configuration parser.

  • options (OpenStruct)

    Options passed to Calypso on the cmd line.

Returns:

  • (nil)


181
182
183
184
185
186
187
188
# File 'lib/calypso.rb', line 181

def run_single(parser, options)
  test = parser.tests[options.single]
  puts "Running test [#{test.name}]"
  
  Calypso.tty_fix(test.serial) if options.tty_fix
  test.execute
  puts "[#{test.name}]: #{test.success? ? 'OK' : 'FAIL'}"
end

.start(args) ⇒ nil

Start Calypso.

Parameters:

  • args (Array)

    Argument list

Returns:

  • (nil)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/calypso.rb', line 38

def start(args)
  options = OpenStruct.new
  options.parser = nil
  options.config = nil
  options.path = Dir.pwd
  options.single = nil
  options.bare = false
  options.hardware = nil
  options.run_mode = :all
  options.tty_fix = false
  options.tty_fix = true if ENV['TTY_FIX'].eql? 'true'
  options.update = false

  parser = OptionParser.new do |p|
    p.banner = "Usage: calypso [options] -c [config]"
    p.separator ""
    p.separator "Specific options:"

    p.on('-y', '--yaml', "Parse configuration as YAML") do
      options.parser = :yaml
    end

    p.on('-u', '--update', "Update configuration files") do
      options.update = true
    end

    p.on('-b', '--bare', "Do not recompile ETA/OS before running the test") do
      options.bare = true
    end

    p.on('-f', '--tty-fix',
         'Enforce the correct TTY settings before trying to run a test') do
      options.tty_fix = true
    end

    p.on('-t [TESTID]', '--test [TESTID]',
         'Run a specific test') do |id|
      options.single = id
      options.run_mode = :single
    end

    p.on('-c [FILE]', '--config [FILE]',
         'Path to the test configuration') do |conf|
      options.config = conf
    end

    p.on('-H [hardware-id]', '--hardware [hardware-id]',
         'Run all tests configured for a specific MCU') do |hardware|
      options.hardware = hardware
      options.run_mode = :hardware
    end

    p.separator ""
    p.separator "Common options:"

    p.on_tail("-h", "--help", "Show this message") do
      puts p
      exit
    end

    p.on_tail("-v", "--version", "Print the Calypso version") do
      puts "Calypso #{Calypso::VERSION}"
      exit
    end
  end

  parser.parse!

  mandatory = [:config, :parser]
  missing = mandatory.select do |param|
    if options[param].nil? or options[param] == false
      param
    end
  end

  unless missing.empty?
    puts "Missing mandatory options!"
    puts ""
    puts parser
    exit
  end

  unless options.single.nil? or options.hardware.nil?
    puts "The options -t and -H cannot be used together!"
    puts ""
    puts parser
    exit
  end

  @options = options
  config = Calypso::ParserProxy.new(options.parser, options.config)
  config.parse

  if options.update
    Calypso.update(config, options)
    exit
  end

  case options.run_mode
  when :all
    Calypso.run(config, options)
  when :hardware
    Calypso.run_hardware(config, options, options.hardware)
  when :single
    Calypso.run_single(config, options)
  end
end

.tty_fix(serial) ⇒ nil

Fix the serial TTY configuration.

Parameters:

Returns:

  • (nil)


237
238
239
240
# File 'lib/calypso.rb', line 237

def tty_fix(serial)
  fix_cmd = "stty 57600 raw ignbrk hup < #{serial.port}"
  system(fix_cmd)
end

.update(parser, options) ⇒ nil

Update the Kbuild configurations.

Parameters:

Returns:

  • (nil)


168
169
170
171
172
173
174
# File 'lib/calypso.rb', line 168

def update(parser, options)
  hw = parser.hardware

  hw.each do |hwid, hwdata|
    Calypso.update_hw(parser, options, hwid)
  end
end

.update_hw(parser, options, hwid) ⇒ nil

Update the Kbuild configurations.

Parameters:

  • parser (Calypso::ParserProxy)

    Config parser

  • options (OpenStruct)

    Program options

  • hwid (String)

    Harware ID of the tests to update

Returns:

  • (nil)


152
153
154
155
156
157
158
159
160
161
# File 'lib/calypso.rb', line 152

def update_hw(parser, options, hwid)
  hw = parser.hardware[hwid]
  tests = hw.tests

  tests.each do |test|
    puts "Updating #{test.name}"
    puts ""
    test.update
  end
end