class Calypso::UnitTest
Unit test model class
Attributes
@return [Boolean] Whether or not the test should be ran automatically.
@return [String] Unit test build and execution targets.
@return [Calypso::Hardware] Unit test hardware.
@return [Calypso::Hardware] Unit test hardware.
@return [Symbol] Unit test mode.
@return [String] Unit test name.
@return [String] Unit test path.
@return [SerialPortData] Information about the serial port used by the test
Public Class Methods
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 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
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 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
# 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