class Calypso::UnitTest

Unit test model class

Attributes

autorun[R]

@return [Boolean] Whether or not the test should be ran automatically.

exec[R]

@return [String] Unit test build and execution targets.

hardware[R]

@return [Calypso::Hardware] Unit test hardware.

hw[R]

@return [Calypso::Hardware] Unit test hardware.

mode[R]

@return [Symbol] Unit test mode.

name[R]

@return [String] Unit test name.

path[R]

@return [String] Unit test path.

serial[R]

@return [SerialPortData] Information about the serial port used by the test

Public Class Methods

new(conf, serial, hw) click to toggle source

Create a new UnitTest model.

@param conf [Hash] Unit test configuration values. @param serial [Calypso::SerialPortData] Serial port information. @param hw [Calypso::Hardware] Unit test hardware.

# File lib/calypso/unittest.rb, line 49
def initialize(conf, serial, hw)
  @name = conf['name']
  @path = File.expand_path conf['path']
  @mode = conf['mode'] == 'manual' ? :manual : :auto
  @hw = hw
  @hardware = hw
  @exec = conf['execute']
  config = conf['config']
  @conf = "#{@path}/#{config}" unless conf.nil?
  @libdir = File.expand_path conf['libdir'] unless conf['libdir'].nil?
  @serial = serial
  @raw = conf
  @success = false
  @autorun = conf['autorun']
  @compare_file = conf['compare']
end

Public Instance Methods

execute() click to toggle source

Execute the unit test.

@return [Boolean] Whether or not the test executed succesfully.

# File lib/calypso/unittest.rb, line 69
def execute
  kbuild = Kbuild.new(@conf, @path)

  unless Calypso.options.bare
    kbuild.clean
    kbuild.build
    kbuild.install_modules(@libdir)
  end
  
  kbuild.build_test(@exec)
  sp = Calypso::SerialMonitor.new(@serial.port)
  manual_stop = sp.monitor

  if manual_stop or @mode == :manual
    print "Did the test run succesfully? [y/n]: "
    reply = gets.chomp
    @success = true if reply.eql? 'y' or reply.eql? 'Y'
  else
    @success = compare(sp)
  end
end
success?() click to toggle source

Check if the test ran succesfully.

@return [Boolean] Whether or not the test executed succesfully.

# File lib/calypso/unittest.rb, line 103
def success?
  @success
end
update() click to toggle source

Update the unit test configuration file.

@return [nil]

# File lib/calypso/unittest.rb, line 94
def update
  kbuild = Kbuild.new(@conf, @path)
  kbuild.prepare
  kbuild.save_config
end

Private Instance Methods

compare(serial) click to toggle source
# File lib/calypso/unittest.rb, line 108
def compare(serial)
  return if @compare_file.nil?
  path = "#{@path}/#{@compare_file}"
  data = serial.data
  idx = 0

  file = File.open path
  while (line = file.gets) do
    line.chomp!
    return false unless line.eql? data[idx]
    idx += 1
  end

  return true
end