mock: added mraa mock platform infra and GPIO implementation
Mock platform allows one to use mraa without having any real HW. This commit makes necessary foundational changes and implements GPIO functionality as well as adds respective tests. 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
593fd0be54
commit
bcb6adc551
@@ -14,12 +14,16 @@ if (BUILDSWIGPYTHON)
|
||||
elseif (PYTHON3INTERP_FOUND)
|
||||
set (PYTHON_DEFAULT_PYTHONPATH "${CMAKE_BINARY_DIR}/src/python/python3")
|
||||
endif ()
|
||||
add_test (NAME py_general COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/general_checks.py)
|
||||
set_tests_properties(py_general PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
|
||||
if (MOCKPLAT)
|
||||
add_subdirectory (mock)
|
||||
else()
|
||||
add_test (NAME py_general COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/general_checks.py)
|
||||
set_tests_properties(py_general PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
|
||||
|
||||
add_test (NAME py_platform COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/platform_checks.py)
|
||||
set_tests_properties(py_platform PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
|
||||
add_test (NAME py_platform COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/platform_checks.py)
|
||||
set_tests_properties(py_platform PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
|
||||
|
||||
add_test (NAME py_gpio COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks.py)
|
||||
set_tests_properties(py_gpio PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
|
||||
add_test (NAME py_gpio COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks.py)
|
||||
set_tests_properties(py_gpio PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
19
tests/mock/CMakeLists.txt
Normal file
19
tests/mock/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
# Mock platform tests
|
||||
add_test (NAME py_general COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/general_checks.py)
|
||||
add_test (NAME py_platform COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/platform_checks.py)
|
||||
add_test (NAME py_gpio_basic COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks_basic.py)
|
||||
add_test (NAME py_gpio_dir COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks_dir.py)
|
||||
add_test (NAME py_gpio_write_read COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks_write_read.py)
|
||||
add_test (NAME py_gpio_edge COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gpio_checks_edge.py)
|
||||
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)
|
||||
|
||||
set_tests_properties(py_general
|
||||
py_platform
|
||||
py_gpio_basic
|
||||
py_gpio_dir
|
||||
py_gpio_write_read
|
||||
py_gpio_edge
|
||||
py_gpio_isr
|
||||
py_gpio_mode
|
||||
PROPERTIES ENVIRONMENT "PYTHONPATH=${PYTHON_DEFAULT_PYTHONPATH}")
|
||||
38
tests/mock/general_checks.py
Executable file
38
tests/mock/general_checks.py
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Costin Constantin <costin.c.constantin@intel.com>
|
||||
# Copyright (c) 2015 Intel Corporation.
|
||||
#
|
||||
# Contributors: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
#
|
||||
# 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
|
||||
|
||||
class GeneralChecks(u.TestCase):
|
||||
def test_mraa_version(self):
|
||||
version = m.getVersion()
|
||||
print("Version is: " + version)
|
||||
self.assertIsNotNone(version)
|
||||
self.assertNotEqual(version, "", "MRAA version is an empty string")
|
||||
|
||||
if __name__ == "__main__":
|
||||
u.main()
|
||||
49
tests/mock/gpio_checks_basic.py
Executable file
49
tests/mock/gpio_checks_basic.py
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
#
|
||||
# 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_TEST_PIN = 0
|
||||
|
||||
class GpioChecksBasic(u.TestCase):
|
||||
def setUp(self):
|
||||
self.pin = m.Gpio(MRAA_TEST_PIN)
|
||||
|
||||
def tearDown(self):
|
||||
del self.pin
|
||||
|
||||
def test_gpio_state_after_init(self):
|
||||
# After GPIO init it should be in INPUT and LOW state
|
||||
self.assertEqual(self.pin.read(), 0, "GPIO is in a wrong state after init")
|
||||
|
||||
def test_gpio_dir_after_init(self):
|
||||
# After GPIO init it should be in INPUT and LOW state
|
||||
self.assertEqual(self.pin.readDir(), m.DIR_IN, "GPIO has wrong direction after init")
|
||||
|
||||
def test_get_pin_num(self):
|
||||
self.assertEqual(self.pin.getPin(), MRAA_TEST_PIN, "Returned GPIO pin number is incorrect")
|
||||
|
||||
if __name__ == '__main__':
|
||||
u.main()
|
||||
67
tests/mock/gpio_checks_dir.py
Executable file
67
tests/mock/gpio_checks_dir.py
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
#
|
||||
# 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_TEST_PIN = 0
|
||||
|
||||
class GpioChecksDir(u.TestCase):
|
||||
def setUp(self):
|
||||
self.pin = m.Gpio(MRAA_TEST_PIN)
|
||||
|
||||
def tearDown(self):
|
||||
del self.pin
|
||||
|
||||
def test_set_dir_output(self):
|
||||
direction = m.DIR_OUT
|
||||
res = self.pin.dir(direction)
|
||||
self.assertEqual(res, m.SUCCESS, "Setting GPIO to output failed")
|
||||
self.assertEqual(self.pin.readDir(), direction, "GPIO has incorrect direction after dir(DIR_OUT)")
|
||||
|
||||
def test_set_dir_output_HIGH(self):
|
||||
res = self.pin.dir(m.DIR_OUT_HIGH)
|
||||
self.assertEqual(res, m.SUCCESS, "Setting GPIO to output HIGH failed")
|
||||
self.assertEqual(self.pin.readDir(), m.DIR_OUT, "GPIO has incorrect direction after dir(DIR_OUT_HIGH)")
|
||||
self.assertEqual(self.pin.read(), 1, "GPIO has incorrect state after dir(DIR_OUT_HIGH)")
|
||||
|
||||
def test_set_dir_output_LOW(self):
|
||||
res = self.pin.dir(m.DIR_OUT_LOW)
|
||||
self.assertEqual(res, m.SUCCESS, "Setting GPIO to output LOW failed")
|
||||
self.assertEqual(self.pin.readDir(), m.DIR_OUT, "GPIO has incorrect direction after dir(DIR_OUT_LOW)")
|
||||
self.assertEqual(self.pin.read(), 0, "GPIO has incorrect state after dir(DIR_OUT_LOW)")
|
||||
|
||||
def test_set_dir_input(self):
|
||||
direction = m.DIR_IN
|
||||
res = self.pin.dir(direction)
|
||||
self.assertEqual(res, m.SUCCESS, "Setting GPIO to input failed")
|
||||
self.assertEqual(self.pin.readDir(), direction, "GPIO has incorrect direction after dir(DIR_IN)")
|
||||
|
||||
def test_set_dir_invalid(self):
|
||||
direction = 99
|
||||
res = self.pin.dir(direction)
|
||||
self.assertNotEqual(res, m.SUCCESS, "Setting direction to " + str(direction) + " should have failed")
|
||||
|
||||
if __name__ == '__main__':
|
||||
u.main()
|
||||
54
tests/mock/gpio_checks_edge.py
Executable file
54
tests/mock/gpio_checks_edge.py
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
#
|
||||
# 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_TEST_PIN = 0
|
||||
|
||||
class GpioChecksEdge(u.TestCase):
|
||||
def setUp(self):
|
||||
self.pin = m.Gpio(MRAA_TEST_PIN)
|
||||
|
||||
def tearDown(self):
|
||||
del self.pin
|
||||
|
||||
def test_set_edge_mode_NONE(self):
|
||||
res = self.pin.edge(m.EDGE_NONE)
|
||||
self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting edge mode to EDGE_NONE did not return unimplemented")
|
||||
|
||||
def test_set_edge_mode_BOTH(self):
|
||||
res = self.pin.edge(m.EDGE_BOTH)
|
||||
self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting edge mode to EDGE_BOTH did not return unimplemented")
|
||||
|
||||
def test_set_edge_mode_RISING(self):
|
||||
res = self.pin.edge(m.EDGE_RISING)
|
||||
self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting edge mode to EDGE_RISING did not return unimplemented")
|
||||
|
||||
def test_set_edge_mode_FALLING(self):
|
||||
res = self.pin.edge(m.EDGE_FALLING)
|
||||
self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting edge mode to EDGE_FALLING did not return unimplemented")
|
||||
|
||||
if __name__ == '__main__':
|
||||
u.main()
|
||||
52
tests/mock/gpio_checks_isr.py
Normal file
52
tests/mock/gpio_checks_isr.py
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
#
|
||||
# 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_TEST_PIN = 0
|
||||
|
||||
def test_isr():
|
||||
print("In the ISR")
|
||||
|
||||
class GpioChecksIsr(u.TestCase):
|
||||
def setUp(self):
|
||||
self.pin = m.Gpio(MRAA_TEST_PIN)
|
||||
|
||||
def tearDown(self):
|
||||
del self.pin
|
||||
|
||||
def test_set_isr(self):
|
||||
self.pin.dir(m.DIR_IN)
|
||||
res = self.pin.isr(m.EDGE_BOTH, test_isr, None)
|
||||
self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Enabling ISR did not return unimplemented")
|
||||
|
||||
def test_isr_exit(self):
|
||||
self.pin.dir(m.DIR_IN)
|
||||
self.pin.isr(m.EDGE_BOTH, test_isr, None)
|
||||
res = self.pin.isrExit()
|
||||
self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Calling isrExit() did not return unimplemented")
|
||||
|
||||
if __name__ == '__main__':
|
||||
u.main()
|
||||
54
tests/mock/gpio_checks_mode.py
Normal file
54
tests/mock/gpio_checks_mode.py
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
#
|
||||
# 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_TEST_PIN = 0
|
||||
|
||||
class GpioChecksMode(u.TestCase):
|
||||
def setUp(self):
|
||||
self.pin = m.Gpio(MRAA_TEST_PIN)
|
||||
|
||||
def tearDown(self):
|
||||
del self.pin
|
||||
|
||||
def test_set_mode_STRONG(self):
|
||||
res = self.pin.mode(m.MODE_STRONG)
|
||||
self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting GPIO mode to MODE_STRONG did not return unimplemented")
|
||||
|
||||
def test_set_mode_PULLUP(self):
|
||||
res = self.pin.mode(m.MODE_PULLUP)
|
||||
self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting GPIO mode to MODE_PULLUP did not return unimplemented")
|
||||
|
||||
def test_set_mode_PULLDOWN(self):
|
||||
res = self.pin.mode(m.MODE_PULLDOWN)
|
||||
self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting GPIO mode to MODE_PULLDOWN did not return unimplemented")
|
||||
|
||||
def test_set_mode_HIZ(self):
|
||||
res = self.pin.mode(m.MODE_HIZ)
|
||||
self.assertEqual(res, m.ERROR_FEATURE_NOT_IMPLEMENTED, "Setting GPIO mode to MODE_HIZ did not return unimplemented")
|
||||
|
||||
if __name__ == '__main__':
|
||||
u.main()
|
||||
70
tests/mock/gpio_checks_write_read.py
Executable file
70
tests/mock/gpio_checks_write_read.py
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
# Copyright (c) 2016 Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
#
|
||||
# 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_TEST_PIN = 0
|
||||
|
||||
class GpioChecksWriteRead(u.TestCase):
|
||||
def setUp(self):
|
||||
self.pin = m.Gpio(MRAA_TEST_PIN)
|
||||
|
||||
def tearDown(self):
|
||||
del self.pin
|
||||
|
||||
def test_gpio_as_output_write_HIGH(self):
|
||||
self.pin.dir(m.DIR_OUT)
|
||||
res = self.pin.write(1)
|
||||
self.assertEqual(res, m.SUCCESS, "Setting GPIO to HIGH failed")
|
||||
res = self.pin.read()
|
||||
self.assertEqual(res, 1, "GPIO is not HIGH after write(1)")
|
||||
|
||||
def test_gpio_as_output_write_LOW(self):
|
||||
self.pin.dir(m.DIR_OUT)
|
||||
res = self.pin.write(0)
|
||||
self.assertEqual(res, m.SUCCESS, "Setting GPIO to LOW failed")
|
||||
res = self.pin.read()
|
||||
self.assertEqual(res, 0, "GPIO is not LOW after write(0)")
|
||||
|
||||
def test_gpio_as_output_write_invalid(self):
|
||||
self.pin.dir(m.DIR_OUT)
|
||||
value = 10
|
||||
res = self.pin.write(value)
|
||||
self.assertNotEqual(res, m.SUCCESS, "Writing " + str(value) + " to GPIO should have failed")
|
||||
res = self.pin.read()
|
||||
self.assertNotEqual(res, value, "Writing " + str(value) + " to GPIO should not have set it to " + str(value))
|
||||
|
||||
def test_gpio_as_input_write_HIGH(self):
|
||||
self.pin.dir(m.DIR_IN)
|
||||
res = self.pin.write(1)
|
||||
self.assertNotEqual(res, m.SUCCESS, "Setting GPIO in INPUT to HIGH should have failed")
|
||||
|
||||
def test_gpio_as_input_write_LOW(self):
|
||||
self.pin.dir(m.DIR_IN)
|
||||
res = self.pin.write(0)
|
||||
self.assertNotEqual(res, m.SUCCESS, "Setting GPIO in INPUT to LOW should have failed")
|
||||
|
||||
if __name__ == '__main__':
|
||||
u.main()
|
||||
49
tests/mock/platform_checks.py
Executable file
49
tests/mock/platform_checks.py
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Author: Costin Constantin <costin.c.constantin@intel.com>
|
||||
# Copyright (c) 2015 Intel Corporation.
|
||||
#
|
||||
# Contributors: Alex Tereschenko <alext.mkrs@gmail.com>
|
||||
#
|
||||
# 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
|
||||
|
||||
PLATFORM_PINCOUNT = 1
|
||||
PLATFORM_STD_ADC_RES_BITS = 10
|
||||
PLATFORM_MAX_ADC_RES_BITS = 12
|
||||
|
||||
class PlatformChecks(u.TestCase):
|
||||
def test_platform_pin_count(self):
|
||||
self.assertEqual(m.getPinCount(), PLATFORM_PINCOUNT, "Wrong number of pins reported by platform")
|
||||
|
||||
def test_adc_std_res(self):
|
||||
adc_std_res = m.adcSupportedBits()
|
||||
print("Platform ADC standard resolution is: " + str(adc_std_res) + " bits")
|
||||
self.assertEqual(adc_std_res, PLATFORM_STD_ADC_RES_BITS, "Wrong ADC standard resolution")
|
||||
|
||||
def test_adc_max_res(self):
|
||||
adc_max_res = m.adcRawBits()
|
||||
print("Platform ADC max. resolution is: " + str(adc_max_res) + " bits")
|
||||
self.assertEqual(adc_max_res, PLATFORM_MAX_ADC_RES_BITS, "Wrong ADC max. resolution")
|
||||
|
||||
if __name__ == "__main__":
|
||||
u.main()
|
||||
Reference in New Issue
Block a user