summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Kconfig2
-rw-r--r--test/kconfig/base.cfg1
-rw-r--r--test/kconfig/full.cfg1
-rw-r--r--test/self/Kconfig4
-rw-r--r--test/self/Makefile1
-rw-r--r--test/self/progress-notifier.c79
6 files changed, 87 insertions, 1 deletions
diff --git a/lib/Kconfig b/lib/Kconfig
index 922710e106..ea6de76a22 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -155,7 +155,7 @@ source "lib/logo/Kconfig"
source "lib/bootstrap/Kconfig"
config PROGRESS_NOTIFIER
- bool
+ bool "Progress Notifier" if COMPILE_TEST
help
This is selected by boards that register a notifier to visualize
progress, like blinking a LED during an update.
diff --git a/test/kconfig/base.cfg b/test/kconfig/base.cfg
index 6a9f683498..80b9c68f02 100644
--- a/test/kconfig/base.cfg
+++ b/test/kconfig/base.cfg
@@ -1,3 +1,4 @@
+CONFIG_COMPILE_TEST=y
CONFIG_TEST=y
CONFIG_SELFTEST=y
CONFIG_CMD_SELFTEST=y
diff --git a/test/kconfig/full.cfg b/test/kconfig/full.cfg
index 39275768ea..547100bacc 100644
--- a/test/kconfig/full.cfg
+++ b/test/kconfig/full.cfg
@@ -1,2 +1,3 @@
CONFIG_BTHREAD=y
CONFIG_CMD_BTHREAD=y
+CONFIG_PROGRESS_NOTIFIER=y
diff --git a/test/self/Kconfig b/test/self/Kconfig
index 73dc6c7b4f..dfaa32dda0 100644
--- a/test/self/Kconfig
+++ b/test/self/Kconfig
@@ -28,6 +28,7 @@ config SELFTEST_AUTORUN
config SELFTEST_ENABLE_ALL
bool "Enable all self-tests"
select SELFTEST_PRINTF
+ select SELFTEST_PROGRESS_NOTIFIER
help
Selects all self-tests compatible with current configuration
@@ -36,4 +37,7 @@ config SELFTEST_PRINTF
help
Tests barebox vsnprintf() functionality
+config SELFTEST_PROGRESS_NOTIFIER
+ bool "progress notifier selftest"
+
endif
diff --git a/test/self/Makefile b/test/self/Makefile
index b4aa49d6f8..e78ccc3cfb 100644
--- a/test/self/Makefile
+++ b/test/self/Makefile
@@ -2,3 +2,4 @@
obj-$(CONFIG_SELFTEST) += core.o
obj-$(CONFIG_SELFTEST_PRINTF) += printf.o
+obj-$(CONFIG_SELFTEST_PROGRESS_NOTIFIER) += progress-notifier.o
diff --git a/test/self/progress-notifier.c b/test/self/progress-notifier.c
new file mode 100644
index 0000000000..af65b0900e
--- /dev/null
+++ b/test/self/progress-notifier.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <common.h>
+#include <bselftest.h>
+#include <progress.h>
+
+BSELFTEST_GLOBALS();
+
+static void __ok(bool cond, const char *func, int line)
+{
+ total_tests++;
+ if (!cond) {
+ failed_tests++;
+ printf("%s:%d: assertion failure\n", func, line);
+ }
+}
+
+#define ok(cond) \
+ __ok(cond, __func__, __LINE__)
+
+static unsigned long stage;
+static const void *prefix;
+static int counter;
+
+static int dummy_notifier(struct notifier_block *r, unsigned long _stage, void *_prefix)
+{
+ prefix = _prefix;
+ stage = _stage;
+ counter++;
+ return 0;
+}
+
+static struct notifier_block dummy_nb = {
+ .notifier_call = dummy_notifier
+};
+
+static void test_dummy_notifier(void)
+{
+ const char *arg = "ARGUMENT";
+ int local_counter = 0;
+
+ stage = 0;
+ prefix = NULL;
+ counter = 0;
+
+ progress_register_client(&dummy_nb);
+ ok(stage == 0);
+ ok(prefix == NULL);
+ ok(counter == local_counter);
+ progress_notifier_call_chain(1, arg);
+
+ if (IS_ENABLED(CONFIG_PROGRESS_NOTIFIER)) {
+ ok(stage == 1);
+ ok(prefix == arg);
+ ok(counter == ++local_counter);
+ progress_notifier_call_chain(0, NULL);
+ local_counter++;
+ } else {
+ total_tests += 2;
+ skipped_tests += 2;
+ }
+
+ ok(stage == 0);
+ ok(prefix == NULL || *(const char *)prefix == '\0');
+ ok(counter == local_counter);
+ progress_unregister_client(&dummy_nb);
+
+ ok(stage == 0);
+ ok(prefix == NULL || *(const char *)prefix == '\0');
+ ok(counter == local_counter);
+}
+
+static void test_notifier(void)
+{
+ test_dummy_notifier();
+}
+bselftest(core, test_notifier);