Skip to content

Commit 4604b2e

Browse files
committed
tests: lib: tenstorrent: pgood: test pgood handling
Using emulated GPIOs, test bh_chip PGOOD fault state transitions. The sequence is as follows: - Setup PGOOD GPIO callbacks - Start with PGOOD high - Lower PGOOD and ensure that the callback sets pgood_fall_triggered = 1 - Invoke handle_pgood_event (happens in main loop outside this test) and ensure pgood_fall_triggered is cleared, pgood_last_trip_ms was set, and a severe fault state hasn't been entered - Raise PGOOD and ensure pgood_rise_triggered = 1, then clear it - Lower PGOOD again - Invoke the handler and ensure severe fault state is entered Signed-off-by: Petra Alexson <[email protected]>
1 parent 179068e commit 4604b2e

File tree

5 files changed

+117
-0
lines changed

5 files changed

+117
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(pgood)
6+
7+
FILE(GLOB app_sources src/*.c)
8+
target_sources(app PRIVATE ${app_sources})
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2024 Tenstorrent AI ULC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/gpio/gpio.h>
8+
9+
/ {
10+
asic_reset {
11+
compatible = "zephyr,gpio-line";
12+
label = "Emulated ASIC reset line";
13+
gpios = <&gpio0 0 GPIO_ACTIVE_LOW>;
14+
};
15+
16+
pgood {
17+
compatible = "zephyr,gpio-line";
18+
label = "Emulated power good indicator";
19+
gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>;
20+
};
21+
22+
board_fault_led {
23+
compatible = "zephyr,gpio-line";
24+
label = "Emulated board fault LED";
25+
gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
26+
};
27+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CONFIG_ZTEST=y
2+
3+
CONFIG_TT_BH_CHIP=y
4+
CONFIG_EVENTS=y
5+
CONFIG_TT_EVENT=y
6+
CONFIG_GPIO=y
7+
CONFIG_GPIO_EMUL=y
8+
9+
CONFIG_JTAG=y
10+
CONFIG_TT_JTAG_BOOTROM=y
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 2025 Tenstorrent AI ULC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/drivers/gpio/gpio_emul.h>
8+
#include <zephyr/drivers/gpio.h>
9+
#include <zephyr/ztest.h>
10+
11+
#include <tenstorrent/bh_chip.h>
12+
13+
static struct bh_chip test_chip = {
14+
.config = {
15+
.asic_reset = GPIO_DT_SPEC_GET(DT_PATH(asic_reset), gpios),
16+
.pgood = GPIO_DT_SPEC_GET(DT_PATH(pgood), gpios),
17+
}};
18+
19+
const struct device *gpio_emul = DEVICE_DT_GET(DT_NODELABEL(gpio0));
20+
static const struct gpio_dt_spec board_fault_led =
21+
GPIO_DT_SPEC_GET(DT_PATH(board_fault_led), gpios);
22+
23+
ZTEST(pgood, test_pgood)
24+
{
25+
/* Start with PGOOD high */
26+
gpio_emul_input_set(gpio_emul, 1, 1);
27+
/* Manually clear pgood_rise_triggered */
28+
test_chip.data.pgood_rise_triggered = 0;
29+
30+
/* Wait 1ms so pgood_last_trip_ms will not be set to 0 */
31+
k_msleep(1);
32+
33+
/* Set PGOOD low */
34+
gpio_emul_input_set(gpio_emul, 1, 0);
35+
/* Check that PGOOD fall was triggered */
36+
zassert_true(test_chip.data.pgood_fall_triggered);
37+
38+
handle_pgood_event(&test_chip, board_fault_led);
39+
/* Check that PGOOD fall was handled */
40+
zassert_true(test_chip.data.pgood_last_trip_ms > 0);
41+
zassert_false(test_chip.data.pgood_fall_triggered);
42+
zassert_false(test_chip.data.pgood_severe_fault);
43+
44+
/* Set PGOOD high */
45+
gpio_emul_input_set(gpio_emul, 1, 1);
46+
/* Check that PGOOD rise was triggered */
47+
zassert_true(test_chip.data.pgood_rise_triggered);
48+
/* Manually clear it because bh_chip_reset_chip can't run here */
49+
test_chip.data.pgood_rise_triggered = 0;
50+
51+
/* Set PGOOD low */
52+
gpio_emul_input_set(gpio_emul, 1, 0);
53+
zassert_true(test_chip.data.pgood_fall_triggered);
54+
55+
handle_pgood_event(&test_chip, board_fault_led);
56+
/* Check that PGOOD fall was handled and severe state was entered */
57+
zassert_true(test_chip.data.pgood_last_trip_ms > 0);
58+
zassert_false(test_chip.data.pgood_fall_triggered);
59+
zassert_true(test_chip.data.pgood_severe_fault);
60+
}
61+
62+
static void before(void *arg)
63+
{
64+
ARG_UNUSED(arg);
65+
66+
zassert_ok(pgood_gpio_setup(&test_chip));
67+
}
68+
69+
ZTEST_SUITE(pgood, NULL, NULL, before, NULL, NULL);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tests:
2+
lib.tenstorrent.pgood:
3+
filter: dt_compat_enabled("zephyr,gpio-emul")

0 commit comments

Comments
 (0)