Make WDOGCONTROL.INTEN the counter enable of the CMSDK APB Watchdog
PATCH 3/3 tests/qtest/cmsdk-apb-watchdog-test: Test INTEN as counter enable
In reply to Roque Arcudia HernandezThe following tests focus on making sure the counter is not running out of reset and the proper use of INTEN as the counter enable. As described in:
https://developer.arm.com/documentation/ddi0479/d/apb-components/apb-watchdog/programmers-model
The new tests have to target an MPS2 machine because the original machine used by the test (stellaris) has a variation of the cmsdk_apb_watchdog that locks INTEN when it is programmed to 1. The stellaris machine also does not reproduce the problem of the counter running out of cold reset due to the way the clocks are initialized.
--- tests/qtest/cmsdk-apb-watchdog-test.c | 214 ++++++++++++++++++++++++++ 1 file changed, 214 insertions(+)
tests/qtest/cmsdk-apb-watchdog-test.c +214 -0
@@ -68,6 +68,15 @@ static const CMSDKAPBWatchdogTestArgs machine_info[] = { }, }; +static void system_reset (QTestState *qtest) +{ +QDict *resp; + + resp =qtest_qmp (qtest,"{'execute': 'system_reset'}" ); +g_assert (qdict_haskey (resp,"return" )); +qobject_unref (resp); +} +static void test_watchdog (const void *ptr) {const CMSDKAPBWatchdogTestArgs *args = ptr;
@@ -159,6 +168,199 @@ static void test_clock_change(const void *ptr)qtest_end (); } +/* Tests the counter is not running after reset. */ +static void test_watchdog_reset (const void *ptr) +{ +const CMSDKAPBWatchdogTestArgs *args = ptr; +hwaddr wdog_base = args->wdog_base; +int64_t tick = args->tick; + g_autofree gchar *cmdline = g_strdup_printf("-machine %s", args->machine); +qtest_start (cmdline); + g_assert_cmpuint(readl(wdog_base + WDOGRIS), ==, 0); + + g_assert_cmphex(readl(wdog_base + WDOGLOAD), ==, WDOGLOAD_DEFAULT); + g_assert_cmphex(readl(wdog_base + WDOGVALUE), ==, WDOGVALUE_DEFAULT); + + g_assert_cmphex(readl(wdog_base + WDOGCONTROL), ==, 0); + +/* +* The counter should not be running if WDOGCONTROL.INTEN has not been set, +* as it is the case after a cold reset. +*/ +clock_step (15 * tick +1 ); + g_assert_cmphex(readl(wdog_base + WDOGLOAD), ==, WDOGLOAD_DEFAULT); + g_assert_cmphex(readl(wdog_base + WDOGVALUE), ==, WDOGVALUE_DEFAULT); + +/* Let the counter run before reset */ +writel (wdog_base +WDOGLOAD ,3000 ); +writel (wdog_base +WDOGCONTROL ,1 ); + +/* Verify it is running */ +clock_step (1000 * tick +1 ); + g_assert_cmpuint(readl(wdog_base + WDOGLOAD), ==, 3000); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 2000); + +system_reset (global_qtest); + +/* Check defaults after reset */ + g_assert_cmphex(readl(wdog_base + WDOGLOAD), ==, WDOGLOAD_DEFAULT); + g_assert_cmphex(readl(wdog_base + WDOGVALUE), ==, WDOGVALUE_DEFAULT); + +/* The counter should not be running after reset. */ +clock_step (1000 * tick +1 ); + g_assert_cmphex(readl(wdog_base + WDOGLOAD), ==, WDOGLOAD_DEFAULT); + g_assert_cmphex(readl(wdog_base + WDOGVALUE), ==, WDOGVALUE_DEFAULT); + +qtest_end (); +} + +/* +* Tests inten works as the counter enable based on this description: +* +* Enable the interrupt event, WDOGINT. Set HIGH to enable the counter and the +* interrupt, or LOW to disable the counter and interrupt. Reloads the counter +* from the value in WDOGLOAD when the interrupt is enabled, after previously +* being disabled. +*/ +static void test_watchdog_inten (const void *ptr) +{ +const CMSDKAPBWatchdogTestArgs *args = ptr; +hwaddr wdog_base = args->wdog_base; +int64_t tick = args->tick; + g_autofree gchar *cmdline = g_strdup_printf("-machine %s", args->machine); +qtest_start (cmdline); + g_assert_cmpuint(readl(wdog_base + WDOGRIS), ==, 0); + + g_assert_cmphex(readl(wdog_base + WDOGLOAD), ==, WDOGLOAD_DEFAULT); + g_assert_cmphex(readl(wdog_base + WDOGVALUE), ==, WDOGVALUE_DEFAULT); + +/* +* When WDOGLOAD is written to, the count is immediately restarted from the +* new value. +* +* Note: the counter should not be running as long as WDOGCONTROL.INTEN is +* not set +*/ +writel (wdog_base +WDOGLOAD ,4000 ); + g_assert_cmpuint(readl(wdog_base + WDOGLOAD), ==, 4000); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 4000); +clock_step (500 * tick +1 ); + g_assert_cmpuint(readl(wdog_base + WDOGLOAD), ==, 4000); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 4000); + +/* Set HIGH WDOGCONTROL.INTEN to enable the counter and the interrupt */ +writel (wdog_base +WDOGCONTROL ,1 ); +clock_step (500 * tick +1 ); + g_assert_cmpuint(readl(wdog_base + WDOGLOAD), ==, 4000); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 3500); + +/* or LOW to disable the counter and interrupt. */ +writel (wdog_base +WDOGCONTROL ,0 ); +clock_step (100 * tick); + g_assert_cmpuint(readl(wdog_base + WDOGLOAD), ==, 4000); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 3500); + +/* +* Reloads the counter from the value in WDOGLOAD when the interrupt is +* enabled, after previously being disabled. +*/ +writel (wdog_base +WDOGCONTROL ,1 ); + g_assert_cmpuint(readl(wdog_base + WDOGLOAD), ==, 4000); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 4000); + +/* Test counter is still on */ +clock_step (50 * tick +1 ); + g_assert_cmpuint(readl(wdog_base + WDOGLOAD), ==, 4000); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 3950); + +/* +* When WDOGLOAD is written to, the count is immediately restarted from the +* new value. +* +* Note: the counter should be running since WDOGCONTROL.INTEN is set +*/ +writel (wdog_base +WDOGLOAD ,5000 ); + g_assert_cmpuint(readl(wdog_base + WDOGLOAD), ==, 5000); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 5000); +clock_step (4999 * tick +1 ); + g_assert_cmpuint(readl(wdog_base + WDOGLOAD), ==, 5000); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 1); + g_assert_cmpuint(readl(wdog_base + WDOGRIS), ==, 0); + +/* Finally disable and check the conditions don't change */ +writel (wdog_base +WDOGCONTROL ,0 ); +clock_step (10 * tick); + g_assert_cmpuint(readl(wdog_base + WDOGLOAD), ==, 5000); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 1); + g_assert_cmpuint(readl(wdog_base + WDOGRIS), ==, 0); + +qtest_end (); +} + +/* +* Tests the following custom behavior: +* +* The Luminary version of this device ignores writes to this register after the +* guest has enabled interrupts (so they can only be disabled again via reset). +*/ +static void test_watchdog_inten_luminary (const void *ptr) +{ +const CMSDKAPBWatchdogTestArgs *args = ptr; +hwaddr wdog_base = args->wdog_base; +int64_t tick = args->tick; + g_autofree gchar *cmdline = g_strdup_printf("-machine %s", args->machine); +qtest_start (cmdline); + g_assert_cmpuint(readl(wdog_base + WDOGRIS), ==, 0); + + g_assert_cmphex(readl(wdog_base + WDOGLOAD), ==, WDOGLOAD_DEFAULT); + g_assert_cmphex(readl(wdog_base + WDOGVALUE), ==, WDOGVALUE_DEFAULT); + +/* +* When WDOGLOAD is written to, the count is immediately restarted from the +* new value. +* +* Note: the counter should not be running as long as WDOGCONTROL.INTEN is +* not set +*/ +writel (wdog_base +WDOGLOAD ,4000 ); + g_assert_cmpuint(readl(wdog_base + WDOGLOAD), ==, 4000); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 4000); +clock_step (500 * tick +1 ); + g_assert_cmpuint(readl(wdog_base + WDOGLOAD), ==, 4000); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 4000); + +/* Set HIGH WDOGCONTROL.INTEN to enable the counter and the interrupt */ +writel (wdog_base +WDOGCONTROL ,1 ); +clock_step (500 * tick +1 ); + g_assert_cmpuint(readl(wdog_base + WDOGLOAD), ==, 4000); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 3500); + +/* +* The Luminary version of this device ignores writes to this register after +* the guest has enabled interrupts +*/ +writel (wdog_base +WDOGCONTROL ,0 ); +clock_step (100 * tick); + g_assert_cmpuint(readl(wdog_base + WDOGLOAD), ==, 4000); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 3400); + g_assert_cmphex(readl(wdog_base + WDOGCONTROL), ==, 0x1); + +/* They can only be disabled again via reset */ +system_reset (global_qtest); + +/* Check defaults after reset */ + g_assert_cmphex(readl(wdog_base + WDOGLOAD), ==, WDOGLOAD_DEFAULT); + g_assert_cmphex(readl(wdog_base + WDOGVALUE), ==, WDOGVALUE_DEFAULT); + g_assert_cmphex(readl(wdog_base + WDOGCONTROL), ==, 0); + +/* The counter should not be running after reset. */ +clock_step (1000 * tick +1 ); + g_assert_cmphex(readl(wdog_base + WDOGLOAD), ==, WDOGLOAD_DEFAULT); + g_assert_cmphex(readl(wdog_base + WDOGVALUE), ==, WDOGVALUE_DEFAULT); + +qtest_end (); +} +int main (int argc,char **argv) {int r;
@@ -172,10 +374,22 @@ int main(int argc, char **argv)qtest_add_data_func ("/cmsdk-apb-watchdog/watchdog_clock_change" , &machine_info[MACHINE_LM3S811EVB ], test_clock_change); +qtest_add_data_func ("/cmsdk-apb-watchdog/watchdog_reset" , + &machine_info[MACHINE_LM3S811EVB ], + test_watchdog_reset); +qtest_add_data_func ("/cmsdk-apb-watchdog/watchdog_inten_luminary" , + &machine_info[MACHINE_LM3S811EVB ], + test_watchdog_inten_luminary); }if (qtest_has_machine (machine_info[MACHINE_MPS2_AN385 ].machine)) {qtest_add_data_func ("/cmsdk-apb-watchdog/watchdog_mps2" , &machine_info[MACHINE_MPS2_AN385 ], test_watchdog); +qtest_add_data_func ("/cmsdk-apb-watchdog/watchdog_reset_mps2" , + &machine_info[MACHINE_MPS2_AN385 ], + test_watchdog_reset); +qtest_add_data_func ("/cmsdk-apb-watchdog/watchdog_inten" , + &machine_info[MACHINE_MPS2_AN385 ], + test_watchdog_inten); } r =g_test_run ();
Signature · 1 line
2.47.0.277.g8800431eea-goog
PATCH 1/3 hw/watchdog/cmsdk_apb_watchdog: Fix INTEN issues
In reply to Roque Arcudia HernandezCurrent watchdog is free running out of reset, this combined with the fact that current implementation also ensures the counter is running when programing WDOGLOAD creates issues when the firmware defer the programing of WDOGCONTROL.INTEN much later after WDOGLOAD. Arm Programmer's Model documentation states that INTEN is also the counter enable:
Quoted 6 lines
INTEN
Enable the interrupt event, WDOGINT. Set HIGH to enable the counter and the interrupt, or LOW to disable the counter and interrupt. Reloads the counter from the value in WDOGLOAD when the interrupt is enabled, after previously being disabled.
Source of the time of writing:
https://developer.arm.com/documentation/ddi0479/d/apb-components/apb-watchdog/programmers-model
--- hw/watchdog/cmsdk-apb-watchdog.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
hw/watchdog/cmsdk-apb-watchdog.c +26 -3
@@ -202,10 +202,10 @@ static void cmsdk_apb_watchdog_write(void *opaque, hwaddr offset,*/ ptimer_transaction_begin (s->timer);ptimer_set_limit (s->timer, value,1 ); -ptimer_run (s->timer,0 );ptimer_transaction_commit (s->timer);break ; -case A_WDOGCONTROL : +case A_WDOGCONTROL : { +uint32_t prev_control = s->control;if (s->is_luminary &&0 != (R_WDOGCONTROL_INTEN_MASK & s->control)) {/* * The Luminary version of this device ignores writes to
@@ -215,8 +215,25 @@ static void cmsdk_apb_watchdog_write(void *opaque, hwaddr offset,break ; } s->control = value &R_WDOGCONTROL_VALID_MASK ; +if (R_WDOGCONTROL_INTEN_MASK & (s->control ^ prev_control)) { +ptimer_transaction_begin (s->timer); +if (R_WDOGCONTROL_INTEN_MASK & s->control) { +/* +* Set HIGH to enable the counter and the interrupt. Reloads +* the counter from the value in WDOGLOAD when the interrupt +* is enabled, after previously being disabled. +*/ +ptimer_set_count (s->timer,ptimer_get_limit (s->timer)); +ptimer_run (s->timer,0 ); + }else { +/* Or LOW to disable the counter and interrupt. */ +ptimer_stop (s->timer); + } +ptimer_transaction_commit (s->timer); + }cmsdk_apb_watchdog_update (s);break ; + }case A_WDOGINTCLR : s->intstatus =0 ;ptimer_transaction_begin (s->timer);
@@ -305,8 +322,14 @@ static void cmsdk_apb_watchdog_reset(DeviceState *dev) s->resetstatus =0 ;/* Set the limit and the count */ ptimer_transaction_begin (s->timer); +/* +* We need to stop the ptimer before setting its limit reset value. If the +* order is the opposite when the code executes the stop after setting a new +* limit it may want to recalculate the count based on the current time (if +* the timer was currently running) and it won't get the proper reset value. +*/ +ptimer_stop (s->timer);ptimer_set_limit (s->timer,0xffffffff ,1 ); -ptimer_run (s->timer,0 );ptimer_transaction_commit (s->timer); }
Signature · 1 line
2.47.0.277.g8800431eea-goog
cover Make WDOGCONTROL.INTEN the counter enable of the CMSDK APB Watchdog
The following patchset tries to address an issue where the watchdog counter was running as soon as the device is out of reset. This created a few problems with the firmware under test. It was pointed out that the firmware under test was already working on an emulator using the real RTL. Further review showed that the WDOGCONTROL.INTEN is also expected to be the counter enable as it is defined in this page from ARM:
| | Enable the interrupt event, WDOGINT. Set to 1 to
| | enable the counter and the interrupt, or to 0 to
[0] | INTEN | disable the counter and interrupt. Reloads the
| | counter from the value in WDOGLOAD when the interrupt
| | is enabled, after previously being disabled.The second half of the patch is focused on adding tests for this behavior. It was required to modify the test to be able to run some test cases in the MPS2 since the the stellaris machine had 2 issues:
- The stellaris machine did not run the counter out of reset because of the way it is reset. The function ssys_calculate_system_clock is not called until the reset phase stellaris_sys_reset_hold which is after the watchdog executes its reset, so the watchdog would not start the counter due to the clock not being set up at the time of reset.
- The Stellaris machine uses a derived watchdog and not the original CMSDK one which has a special behavior where it cannot be stopped.
The MPS2 machine on the other hand uses the standard CMSDK watchdog and could expose the problems we were dealing with.
Roque Arcudia Hernandez (3):
hw/watchdog/cmsdk_apb_watchdog: Fix INTEN issues tests/qtest/cmsdk-apb-watchdog-test: Parameterize tests tests/qtest/cmsdk-apb-watchdog-test: Test INTEN as counter enable
hw/watchdog/cmsdk-apb-watchdog.c | 29 ++- tests/qtest/cmsdk-apb-watchdog-test.c | 327 +++++++++++++++++++++++--- tests/qtest/meson.build | 3 +- 3 files changed, 325 insertions(+), 34 deletions(-)
Signature · 1 line
2.47.0.277.g8800431eea-goog
PATCH 2/3 tests/qtest/cmsdk-apb-watchdog-test: Parameterize tests
Currently the CMSDK APB watchdog tests target an specialized version of the device (luminaris using the lm3s811evb machine) that prevents the development of tests for the more generic device documented in:
https://developer.arm.com/documentation/ddi0479/d/apb-components/apb-watchdog/programmers-model
This patch allows the execution of the watchdog tests in an MPS2 machine (when applicable) which uses the generic version of the CMSDK APB watchdog.
Finally the rules for compiling the test have to change because it is possible not to have CONFIG_STELLARIS (required for the lm3s811evb machine) while still having CONFIG_CMSDK_APB_WATCHDOG and the test will fail. Due to the addition of the MPS2 machine CONFIG_MPS2 becomes also a dependency for the test compilation.
--- tests/qtest/cmsdk-apb-watchdog-test.c | 115 +++++++++++++++++++------- tests/qtest/meson.build | 3 +- 2 files changed, 86 insertions(+), 32 deletions(-)
tests/qtest/cmsdk-apb-watchdog-test.c +84 -31
@@ -15,14 +15,12 @@*/ #include "qemu/osdep.h" +#include "exec/hwaddr.h" #include "qemu/bitops.h" #include "libqtest-single.h" -/* -* lm3s811evb watchdog; at board startup this runs at 200MHz / 16 == 12.5MHz, -* which is 80ns per tick. -*/ #define WDOG_BASE 0x40000000 +#define WDOG_BASE_MPS2 0x40008000#define WDOGLOAD 0#define WDOGVALUE 4
@@ -37,39 +35,87 @@#define SYSDIV_SHIFT 23#define SYSDIV_LENGTH 4 -static void test_watchdog (void ) +#define WDOGLOAD_DEFAULT 0xFFFFFFFF +#define WDOGVALUE_DEFAULT 0xFFFFFFFF + +typedef struct CMSDKAPBWatchdogTestArgs { +int64_t tick; +hwaddr wdog_base; +const char *machine; +}CMSDKAPBWatchdogTestArgs ; + +enum { +MACHINE_LM3S811EVB , +MACHINE_MPS2_AN385 , +}; + +/* +* lm3s811evb watchdog; at board startup this runs at 200MHz / 16 == 12.5MHz, +* which is 80ns per tick. +* +* IoTKit/ARMSSE dualtimer; driven at 25MHz in mps2-an385, so 40ns per tick +*/ +static const CMSDKAPBWatchdogTestArgs machine_info[] = { + [MACHINE_LM3S811EVB ] = { + .tick =80 , + .wdog_base =WDOG_BASE , + .machine ="lm3s811evb" , + }, + [MACHINE_MPS2_AN385 ] = { + .tick =40 , + .wdog_base =WDOG_BASE_MPS2 , + .machine ="mps2-an385" , + }, +}; + +static void test_watchdog (const void *ptr) { - g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); +const CMSDKAPBWatchdogTestArgs *args = ptr; +hwaddr wdog_base = args->wdog_base; +int64_t tick = args->tick; + g_autofree gchar *cmdline = g_strdup_printf("-machine %s", args->machine); +qtest_start (cmdline); -writel (WDOG_BASE +WDOGCONTROL ,1 ); -writel (WDOG_BASE +WDOGLOAD ,1000 ); + g_assert_cmpuint(readl(wdog_base + WDOGRIS), ==, 0); + +writel (wdog_base +WDOGCONTROL ,1 ); +writel (wdog_base +WDOGLOAD ,1000 );/* Step to just past the 500th tick */ -clock_step (500 *80 +1 ); - g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); - g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); +clock_step (500 * tick +1 ); + g_assert_cmpuint(readl(wdog_base + WDOGRIS), ==, 0); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 500);/* Just past the 1000th tick: timer should have fired */ -clock_step (500 *80 ); - g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); - g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 0); +clock_step (500 * tick); + g_assert_cmpuint(readl(wdog_base + WDOGRIS), ==, 1); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 0);/* VALUE reloads at following tick */ -clock_step (80 ); - g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); +clock_step (tick); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 1000);/* Writing any value to WDOGINTCLR clears the interrupt and reloads */ -clock_step (500 *80 ); - g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 500); - g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 1); -writel (WDOG_BASE +WDOGINTCLR ,0 ); - g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); - g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); +clock_step (500 * tick); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 500); + g_assert_cmpuint(readl(wdog_base + WDOGRIS), ==, 1); +writel (wdog_base +WDOGINTCLR ,0 ); + g_assert_cmpuint(readl(wdog_base + WDOGVALUE), ==, 1000); + g_assert_cmpuint(readl(wdog_base + WDOGRIS), ==, 0); + +qtest_end (); } -static void test_clock_change (void ) +/* +* This test can only be executed in the stellaris board since it relies on a +* component of the board to change the clocking parameters of the watchdog. +*/ +static void test_clock_change (const void *ptr) {uint32_t rcc; +const CMSDKAPBWatchdogTestArgs *args = ptr; + g_autofree gchar *cmdline = g_strdup_printf("-machine %s", args->machine); +qtest_start (cmdline);/* * Test that writing to the stellaris board's RCC register to
@@ -109,6 +155,8 @@ static void test_clock_change(void)writel (WDOG_BASE +WDOGINTCLR ,0 ); g_assert_cmpuint(readl(WDOG_BASE + WDOGVALUE), ==, 1000); g_assert_cmpuint(readl(WDOG_BASE + WDOGRIS), ==, 0); + +qtest_end (); }int main (int argc,char **argv)
@@ -116,16 +164,21 @@ int main(int argc, char **argv)int r;g_test_init (&argc, &argv,NULL ); - -qtest_start ("-machine lm3s811evb" ); - -qtest_add_func ("/cmsdk-apb-watchdog/watchdog" , test_watchdog); -qtest_add_func ("/cmsdk-apb-watchdog/watchdog_clock_change" , - test_clock_change); +g_test_set_nonfatal_assertions (); + +if (qtest_has_machine (machine_info[MACHINE_LM3S811EVB ].machine)) { +qtest_add_data_func ("/cmsdk-apb-watchdog/watchdog" , + &machine_info[MACHINE_LM3S811EVB ], test_watchdog); +qtest_add_data_func ("/cmsdk-apb-watchdog/watchdog_clock_change" , + &machine_info[MACHINE_LM3S811EVB ], + test_clock_change); + } +if (qtest_has_machine (machine_info[MACHINE_MPS2_AN385 ].machine)) { +qtest_add_data_func ("/cmsdk-apb-watchdog/watchdog_mps2" , + &machine_info[MACHINE_MPS2_AN385 ], test_watchdog); + } r =g_test_run (); -qtest_end (); -return r; }
tests/qtest/meson.build +2 -1
@@ -227,7 +227,8 @@ qtests_arm = \ (config_all_devices.has_key('CONFIG_MPS2') ? ['sse-timer-test'] : []) + \ (config_all_devices.has_key('CONFIG_CMSDK_APB_DUALTIMER') ? ['cmsdk-apb-dualtimer-test'] : []) + \ (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \ - (config_all_devices.has_key('CONFIG_CMSDK_APB_WATCHDOG') ? ['cmsdk-apb-watchdog-test'] : []) + \ + (config_all_devices.has_key('CONFIG_STELLARIS') or + config_all_devices.has_key('CONFIG_MPS2') ? ['cmsdk-apb-watchdog-test'] : []) + \ (config_all_devices.has_key('CONFIG_PFLASH_CFI02') and config_all_devices.has_key('CONFIG_MUSICPAL') ? ['pflash-cfi02-test'] : []) + \ (config_all_devices.has_key('CONFIG_ASPEED_SOC') ? qtests_aspeed : []) + \
Signature · 1 line
2.47.0.277.g8800431eea-goog
Re: [PATCH 1/3] hw/watchdog/cmsdk_apb_watchdog: Fix INTEN issues
In reply to Roque Arcudia HernandezQuoted 10 lines · Roque Arcudia Hernandez
Current watchdog is free running out of reset, this combined with the fact that current implementation also ensures the counter is running when programing WDOGLOAD creates issues when the firmware defer the programing of WDOGCONTROL.INTEN much later after WDOGLOAD. Arm Programmer's Model documentation states that INTEN is also the counter enable:
Quoted 2 lines
INTEN
Quoted 8 lines
Quoted 4 lines
Enable the interrupt event, WDOGINT. Set HIGH to enable the counter and the interrupt, or LOW to disable the counter and interrupt. Reloads the counter from the value in WDOGLOAD when the interrupt is enabled, after previously being disabled.
Source of the time of writing:
https://developer.arm.com/documentation/ddi0479/d/apb-components/apb-watchdog/programmers-model
I see that the URL in the current sources
https://developer.arm.com/products/system-design/system-design-kits/cortex-m-system-design-kit
is no longer working -- would you mind including a patch that updates the URL in the comment at the top of the file to the new one
https://developer.arm.com/documentation/ddi0479/
please?
Quoted 12 lines
Signed-off-by Roque Arcudia Hernandez <[email protected]>Reviewed-by Stephen Longfield <[email protected]>Reviewed-by Joe Komlodi <[email protected]>--- hw/watchdog/cmsdk-apb-watchdog.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)hw/watchdog/cmsdk-apb-watchdog.c +0
-0
hw/watchdog/cmsdk-apb-watchdog.c static void cmsdk_apb_watchdog_write(void *opaque, hwaddr offset, · line 206
Quoted 6 lines
hw/watchdog/cmsdk-apb-watchdog.c +0
-1@@ -202,10 +202,10 @@ static void cmsdk_apb_watchdog_write(void *opaque, hwaddr offset,*/ ptimer_transaction_begin (s->timer);ptimer_set_limit (s->timer, value,1 ); -ptimer_run (s->timer,0 );ptimer_transaction_commit (s->timer);break ;
This looks like a correct change, but the comment just above here needs to be updated to match it (it currently says "and make sure we're counting").
Otherwise this change looks good.
-- PMM
Re: [PATCH 2/3] tests/qtest/cmsdk-apb-watchdog-test: Parameterize tests
In reply to Roque Arcudia HernandezQuoted 11 lines · Roque Arcudia Hernandez
Currently the CMSDK APB watchdog tests target an specialized version of the device (luminaris using the lm3s811evb machine) that prevents the development of tests for the more generic device documented in:
https://developer.arm.com/documentation/ddi0479/d/apb-components/apb-watchdog/programmers-model
This patch allows the execution of the watchdog tests in an MPS2 machine (when applicable) which uses the generic version of the CMSDK APB watchdog.
Quoted 8 lines
Finally the rules for compiling the test have to change because it is possible not to have
CONFIG_STELLARIS(required for the lm3s811evb machine) while still havingCONFIG_CMSDK_APB_WATCHDOGand the test will fail. Due to the addition of the MPS2 machineCONFIG_MPS2becomes also a dependency for the test compilation.Signed-off-by Roque Arcudia Hernandez <[email protected]>Reviewed-by Stephen Longfield <[email protected]>
This refactoring mostly looks good.
tests/qtest/cmsdk-apb-watchdog-test.c int main(int argc, char **argv) · line 167
Quoted 11 lines
tests/qtest/cmsdk-apb-watchdog-test.c +1
-6@@ -116,16 +164,21 @@ int main(int argc, char **argv)int r;g_test_init (&argc, &argv,NULL ); - -qtest_start ("-machine lm3s811evb" ); - -qtest_add_func ("/cmsdk-apb-watchdog/watchdog" , test_watchdog); -qtest_add_func ("/cmsdk-apb-watchdog/watchdog_clock_change" , - test_clock_change); +g_test_set_nonfatal_assertions ();
But this addition of g_test_set_nonfatal_assertions() is not related to the refactoring and not mentioned in the commit message.
thanks
-- PMM
Re: [PATCH 3/3] tests/qtest/cmsdk-apb-watchdog-test: Test INTEN as counter enable
In reply to Roque Arcudia HernandezQuoted 25 lines · Roque Arcudia Hernandez
The following tests focus on making sure the counter is not running out of reset and the proper use of INTEN as the counter enable. As described in:
https://developer.arm.com/documentation/ddi0479/d/apb-components/apb-watchdog/programmers-model
The new tests have to target an MPS2 machine because the original machine used by the test (stellaris) has a variation of the
cmsdk_apb_watchdogthat locks INTEN when it is programmed to 1. The stellaris machine also does not reproduce the problem of the counter running out of cold reset due to the way the clocks are initialized.Signed-off-by Roque Arcudia Hernandez <[email protected]>Reviewed-by Stephen Longfield <[email protected]>--- tests/qtest/cmsdk-apb-watchdog-test.c | 214 ++++++++++++++++++++++++++ 1 file changed, 214 insertions(+)tests/qtest/cmsdk-apb-watchdog-test.c +0
-0@@ -68,6 +68,15 @@ static const CMSDKAPBWatchdogTestArgs machine_info[] = { },
tests/qtest/cmsdk-apb-watchdog-test.c static const CMSDKAPBWatchdogTestArgs machine_info[] = { · line 78
Quoted 10 lines
tests/qtest/cmsdk-apb-watchdog-test.c +8
-0}; +static void system_reset (QTestState *qtest) +{ +QDict *resp; + + resp =qtest_qmp (qtest,"{'execute': 'system_reset'}" ); +g_assert (qdict_haskey (resp,"return" )); +qobject_unref (resp); +}
The system_reset QMP command only requests a reset; it does not wait for it to actually happen. For that you need to
qtest_qmp_eventwait(qtest, "RESET");
We seem to already have several implementations of this kind of "reset the system under test" function, several of which have this bug. That suggests to me that we ought to provide it as a utility method qtest_system_reset() in libqtest.
thanks
-- PMM
Re: [PATCH 1/3] hw/watchdog/cmsdk_apb_watchdog: Fix INTEN issues
In reply to Peter MaydellI'll be removing the extra line in the comment and adding a new patch modifying the link in version 2.
Quoted 55 lines · Peter Maydell
Quoted 10 lines · Roque Arcudia Hernandez
Current watchdog is free running out of reset, this combined with the fact that current implementation also ensures the counter is running when programing WDOGLOAD creates issues when the firmware defer the programing of WDOGCONTROL.INTEN much later after WDOGLOAD. Arm Programmer's Model documentation states that INTEN is also the counter enable:
Quoted 2 lines
INTEN
Quoted 8 lines
Quoted 4 lines
Enable the interrupt event, WDOGINT. Set HIGH to enable the counter and the interrupt, or LOW to disable the counter and interrupt. Reloads the counter from the value in WDOGLOAD when the interrupt is enabled, after previously being disabled.
Source of the time of writing:
https://developer.arm.com/documentation/ddi0479/d/apb-components/apb-watchdog/programmers-model
I see that the URL in the current sources
https://developer.arm.com/products/system-design/system-design-kits/cortex-m-system-design-kit
is no longer working -- would you mind including a patch that updates the URL in the comment at the top of the file to the new one
https://developer.arm.com/documentation/ddi0479/please?
Quoted 12 lines
Signed-off-by Roque Arcudia Hernandez <[email protected]>Reviewed-by Stephen Longfield <[email protected]>Reviewed-by Joe Komlodi <[email protected]>--- hw/watchdog/cmsdk-apb-watchdog.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)hw/watchdog/cmsdk-apb-watchdog.c +0
-0hw/watchdog/cmsdk-apb-watchdog.c static void cmsdk_apb_watchdog_write(void *opaque, hwaddr offset, · line 206
Quoted 6 lines
hw/watchdog/cmsdk-apb-watchdog.c +0
-1@@ -202,10 +202,10 @@ static void cmsdk_apb_watchdog_write(void *opaque, hwaddr offset,*/ ptimer_transaction_begin (s->timer);ptimer_set_limit (s->timer, value,1 ); -ptimer_run (s->timer,0 );ptimer_transaction_commit (s->timer);break ;This looks like a correct change, but the comment just above here needs to be updated to match it (it currently says "and make sure we're counting").
Otherwise this change looks good.
-- PMM
Re: [PATCH 2/3] tests/qtest/cmsdk-apb-watchdog-test: Parameterize tests
In reply to Peter MaydellI'll edit the g_test_set_nonfatal_assertions in a separate patch explaining the reasoning behind it in version 2.
Quoted 43 lines · Peter Maydell
Quoted 11 lines · Roque Arcudia Hernandez
Currently the CMSDK APB watchdog tests target an specialized version of the device (luminaris using the lm3s811evb machine) that prevents the development of tests for the more generic device documented in:
https://developer.arm.com/documentation/ddi0479/d/apb-components/apb-watchdog/programmers-model
This patch allows the execution of the watchdog tests in an MPS2 machine (when applicable) which uses the generic version of the CMSDK APB watchdog.
Quoted 8 lines
Finally the rules for compiling the test have to change because it is possible not to have
CONFIG_STELLARIS(required for the lm3s811evb machine) while still havingCONFIG_CMSDK_APB_WATCHDOGand the test will fail. Due to the addition of the MPS2 machineCONFIG_MPS2becomes also a dependency for the test compilation.Signed-off-by Roque Arcudia Hernandez <[email protected]>Reviewed-by Stephen Longfield <[email protected]>This refactoring mostly looks good.
tests/qtest/cmsdk-apb-watchdog-test.c int main(int argc, char **argv) · line 167
Quoted 11 lines
tests/qtest/cmsdk-apb-watchdog-test.c +1
-6@@ -116,16 +164,21 @@ int main(int argc, char **argv)int r;g_test_init (&argc, &argv,NULL ); - -qtest_start ("-machine lm3s811evb" ); - -qtest_add_func ("/cmsdk-apb-watchdog/watchdog" , test_watchdog); -qtest_add_func ("/cmsdk-apb-watchdog/watchdog_clock_change" , - test_clock_change); +g_test_set_nonfatal_assertions ();But this addition of
g_test_set_nonfatal_assertions()is not related to the refactoring and not mentioned in the commit message.thanks
-- PMM
Re: [PATCH 3/3] tests/qtest/cmsdk-apb-watchdog-test: Test INTEN as counter enable
In reply to Peter MaydellThanks for pointing this out. For now I'll be adding the extra line in the version 2 of this patch.
Quoted 50 lines · Peter Maydell
Quoted 25 lines · Roque Arcudia Hernandez
The following tests focus on making sure the counter is not running out of reset and the proper use of INTEN as the counter enable. As described in:
https://developer.arm.com/documentation/ddi0479/d/apb-components/apb-watchdog/programmers-model
The new tests have to target an MPS2 machine because the original machine used by the test (stellaris) has a variation of the
cmsdk_apb_watchdogthat locks INTEN when it is programmed to 1. The stellaris machine also does not reproduce the problem of the counter running out of cold reset due to the way the clocks are initialized.Signed-off-by Roque Arcudia Hernandez <[email protected]>Reviewed-by Stephen Longfield <[email protected]>--- tests/qtest/cmsdk-apb-watchdog-test.c | 214 ++++++++++++++++++++++++++ 1 file changed, 214 insertions(+)tests/qtest/cmsdk-apb-watchdog-test.c +0
-0@@ -68,6 +68,15 @@ static const CMSDKAPBWatchdogTestArgs machine_info[] = { },tests/qtest/cmsdk-apb-watchdog-test.c static const CMSDKAPBWatchdogTestArgs machine_info[] = { · line 78
Quoted 10 lines
tests/qtest/cmsdk-apb-watchdog-test.c +8
-0}; +static void system_reset (QTestState *qtest) +{ +QDict *resp; + + resp =qtest_qmp (qtest,"{'execute': 'system_reset'}" ); +g_assert (qdict_haskey (resp,"return" )); +qobject_unref (resp); +}The
system_resetQMP command only requests a reset; it does not wait for it to actually happen. For that you need to
qtest_qmp_eventwait(qtest, "RESET");We seem to already have several implementations of this kind of "reset the system under test" function, several of which have this bug. That suggests to me that we ought to provide it as a utility method
qtest_system_reset()in libqtest.thanks
-- PMM