mock: added AIO pin and logic
Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Brendan Le Foll
parent
917a1bd371
commit
63b244cfc3
@@ -8,6 +8,8 @@ add_test (NAME py_gpio_edge COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT
|
||||
add_test (NAME py_gpio_isr COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks_isr.py)
|
||||
add_test (NAME py_gpio_mode COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks_mode.py)
|
||||
|
||||
add_test (NAME py_aio COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/aio_checks.py)
|
||||
|
||||
set_tests_properties(py_general
|
||||
py_platform
|
||||
py_gpio_basic
|
||||
@@ -16,4 +18,5 @@ set_tests_properties(py_general
|
||||
py_gpio_edge
|
||||
py_gpio_isr
|
||||
py_gpio_mode
|
||||
py_aio
|
||||
PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
|
||||
|
||||
58
tests/mock/aio_checks.py
Normal file
58
tests/mock/aio_checks.py
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import mraa as m
|
||||
import unittest as u
|
||||
|
||||
MRAA_AIO_TEST_PIN = 0
|
||||
PLATFORM_STD_ADC_RES_BITS = 10
|
||||
PLATFORM_MAX_ADC_RES_BITS = 12
|
||||
|
||||
class AioChecks(u.TestCase):
|
||||
def setUp(self):
|
||||
self.pin = m.Aio(MRAA_AIO_TEST_PIN)
|
||||
|
||||
def tearDown(self):
|
||||
del self.pin
|
||||
|
||||
def test_aio_get_bit(self):
|
||||
self.assertEqual(self.pin.getBit(), PLATFORM_STD_ADC_RES_BITS, "Wrong ADC resolution reported")
|
||||
|
||||
def test_aio_set_bit(self):
|
||||
self.pin.setBit(PLATFORM_MAX_ADC_RES_BITS)
|
||||
self.assertEqual(self.pin.getBit(), PLATFORM_MAX_ADC_RES_BITS, "Wrong ADC resolution reported after setBit()")
|
||||
|
||||
def test_aio_read(self):
|
||||
self.assertNotEqual(self.pin.read(), -1, "Error returned when reading ADC value")
|
||||
|
||||
def test_aio_read_float_std_res(self):
|
||||
self.pin.setBit(PLATFORM_STD_ADC_RES_BITS)
|
||||
self.assertNotEqual(self.pin.readFloat(), -1, "Error returned when reading float ADC value at standard resolution")
|
||||
|
||||
def test_aio_read_float_max_res(self):
|
||||
self.pin.setBit(PLATFORM_MAX_ADC_RES_BITS)
|
||||
self.assertNotEqual(self.pin.readFloat(), -1, "Error returned when reading float ADC value at maximum resolution")
|
||||
|
||||
if __name__ == "__main__":
|
||||
u.main()
|
||||
@@ -27,7 +27,7 @@
|
||||
import mraa as m
|
||||
import unittest as u
|
||||
|
||||
PLATFORM_PINCOUNT = 1
|
||||
PLATFORM_PINCOUNT = 2
|
||||
PLATFORM_STD_ADC_RES_BITS = 10
|
||||
PLATFORM_MAX_ADC_RES_BITS = 12
|
||||
|
||||
|
||||
Reference in New Issue
Block a user