diff options
Diffstat (limited to 'zephyr/test/i2c')
-rw-r--r-- | zephyr/test/i2c/BUILD.py | 7 | ||||
-rw-r--r-- | zephyr/test/i2c/CMakeLists.txt | 4 | ||||
-rw-r--r-- | zephyr/test/i2c/boards/native_posix.overlay | 37 | ||||
-rw-r--r-- | zephyr/test/i2c/overlay.dts | 22 | ||||
-rw-r--r-- | zephyr/test/i2c/prj.conf | 2 | ||||
-rw-r--r-- | zephyr/test/i2c/src/main.c | 48 | ||||
-rw-r--r-- | zephyr/test/i2c/testcase.yaml | 4 |
7 files changed, 83 insertions, 41 deletions
diff --git a/zephyr/test/i2c/BUILD.py b/zephyr/test/i2c/BUILD.py deleted file mode 100644 index 86d9da537a..0000000000 --- a/zephyr/test/i2c/BUILD.py +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright 2021 The Chromium OS Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -"""Register zmake project for i2c test.""" - -register_host_test("i2c", dts_overlays=["overlay.dts"]) diff --git a/zephyr/test/i2c/CMakeLists.txt b/zephyr/test/i2c/CMakeLists.txt index 214177013f..4b355c4932 100644 --- a/zephyr/test/i2c/CMakeLists.txt +++ b/zephyr/test/i2c/CMakeLists.txt @@ -1,9 +1,9 @@ -# Copyright 2020 The Chromium OS Authors. All rights reserved. +# Copyright 2020 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. cmake_minimum_required(VERSION 3.13.1) -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +find_package(Zephyr REQUIRED HINTS "${ZEPHYR_BASE}") project(i2c) target_sources(app PRIVATE src/main.c) diff --git a/zephyr/test/i2c/boards/native_posix.overlay b/zephyr/test/i2c/boards/native_posix.overlay new file mode 100644 index 0000000000..e78c5d0faa --- /dev/null +++ b/zephyr/test/i2c/boards/native_posix.overlay @@ -0,0 +1,37 @@ +/* Copyright 2020 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <board-overlays/native_posix.dts> + +/ { + i2c1: i2c@400 { + status = "okay"; + compatible = "zephyr,i2c-emul-controller"; + clock-frequency = <I2C_BITRATE_STANDARD>; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x400 4>; + }; + + named-i2c-ports { + compatible = "named-i2c-ports"; + accel-0 { + i2c-port = <&i2c0>; + enum-names = "I2C_PORT_ACCEL", + "I2C_PORT_EEPROM"; + }; + usb-c1 { + i2c-port = <&i2c1>; + enum-names = "I2C_PORT_USB_C1"; + }; + }; +}; + +&i2c0 { + bmi_i2c: bmi@68 { + compatible = "bosch,bmi160"; + reg = <0x68>; + }; +}; diff --git a/zephyr/test/i2c/overlay.dts b/zephyr/test/i2c/overlay.dts deleted file mode 100644 index 1519bb1cb7..0000000000 --- a/zephyr/test/i2c/overlay.dts +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright 2020 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/ { - named-i2c-ports { - compatible = "named-i2c-ports"; - accel-0 { - i2c-port = <&bmi_i2c>; - enum-name = "I2C_PORT_ACCEL"; - }; - }; -}; - -&i2c0 { - bmi_i2c: bmi@68 { - compatible = "bosch,bmi160"; - reg = <0x68>; - label = "accel-i2c"; - }; -}; diff --git a/zephyr/test/i2c/prj.conf b/zephyr/test/i2c/prj.conf index 69c276712e..ee6c43f51a 100644 --- a/zephyr/test/i2c/prj.conf +++ b/zephyr/test/i2c/prj.conf @@ -1,4 +1,4 @@ -# Copyright 2020 The Chromium OS Authors. All rights reserved. +# Copyright 2020 The ChromiumOS Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/zephyr/test/i2c/src/main.c b/zephyr/test/i2c/src/main.c index dbe9878da5..364353f06d 100644 --- a/zephyr/test/i2c/src/main.c +++ b/zephyr/test/i2c/src/main.c @@ -1,13 +1,14 @@ -/* Copyright 2020 The Chromium OS Authors. All rights reserved. +/* Copyright 2020 The ChromiumOS Authors * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include <zephyr/devicetree.h> -#include <ztest.h> +#include <zephyr/ztest.h> #include "common.h" #include "i2c/i2c.h" +#include "i2c.h" /* Unused: required for shimming i2c. */ void watchdog_reload(void) @@ -16,18 +17,47 @@ void watchdog_reload(void) static void test_i2c_port_count(void) { - zassert_equal(NAMED_I2C(accel_0), 0, - "accel_0 expected to be 0 but was %d", - NAMED_I2C(accel_0)); - zassert_equal(I2C_PORT_COUNT, 1, - "I2C_PORT_COUNT expected to be 1 but was %d", + zassert_equal(I2C_PORT_COUNT, 2, + "I2C_PORT_COUNT expected to be 2 but was %d", I2C_PORT_COUNT); } +static void test_i2c_lock(void) +{ + i2c_lock(I2C_PORT_ACCEL, 1); + zassert_equal(i2c_port_is_locked(I2C_PORT_EEPROM), 1, + "I2C_PORT_EEPROM not locked"); + zassert_equal(i2c_port_is_locked(I2C_PORT_ACCEL), 1, + "I2C_PORT_ACCEL not locked"); + + /* Unlock different enum pointing the same i2c device */ + i2c_lock(I2C_PORT_EEPROM, 0); + zassert_equal(i2c_port_is_locked(I2C_PORT_EEPROM), 0, + "I2C_PORT_EEPROM not locked"); + zassert_equal(i2c_port_is_locked(I2C_PORT_ACCEL), 0, + "I2C_PORT_ACCEL not locked"); + + i2c_lock(I2C_PORT_EEPROM, 1); + /* Verify different i2c device */ + zassert_equal(i2c_port_is_locked(I2C_PORT_USB_C1), 0, + "I2C_PORT_USB_C1 locked"); + + i2c_lock(I2C_PORT_USB_C1, 1); + /* Make sure i2c device is locked*/ + zassert_equal(i2c_port_is_locked(I2C_PORT_USB_C1), 1, + "I2C_PORT_USB_C1 locked"); + + /* Another i2c device is still locked */ + i2c_lock(I2C_PORT_USB_C1, 0); + zassert_equal(i2c_port_is_locked(I2C_PORT_EEPROM), 1, + "I2C_PORT_EEPROM not locked"); + i2c_lock(I2C_PORT_EEPROM, 0); +} + /* Test case main entry. */ void test_main(void) { - ztest_test_suite(test_i2c, - ztest_user_unit_test(test_i2c_port_count)); + ztest_test_suite(test_i2c, ztest_user_unit_test(test_i2c_port_count), + ztest_user_unit_test(test_i2c_lock)); ztest_run_test_suite(test_i2c); } diff --git a/zephyr/test/i2c/testcase.yaml b/zephyr/test/i2c/testcase.yaml new file mode 100644 index 0000000000..4e111ea13f --- /dev/null +++ b/zephyr/test/i2c/testcase.yaml @@ -0,0 +1,4 @@ +common: + platform_allow: native_posix +tests: + i2c.default: {} |