You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/02/17 15:44:36 UTC
[nuttx-apps] branch master updated: testing/cmocka: update cmocka version and add patch
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 49f88d50b testing/cmocka: update cmocka version and add patch
49f88d50b is described below
commit 49f88d50b2e96c552d476aebdad91da1404e9d73
Author: yintao <yi...@xiaomi.com>
AuthorDate: Fri Feb 17 16:28:11 2023 +0800
testing/cmocka: update cmocka version and add patch
Specify cmocka as the latest version 1.15
add patch to enable cmocka to output with syslog
Signed-off-by: yintao <yi...@xiaomi.com>
---
...duce-the-call-stack-consumption-of-printf.patch | 59 +++++++++++++++++
...ure-to-forwarding-cmocka-log-message-to-c.patch | 74 ++++++++++++++++++++++
testing/cmocka/Makefile | 6 +-
3 files changed, 137 insertions(+), 2 deletions(-)
diff --git a/testing/cmocka/0001-cmocka.c-Reduce-the-call-stack-consumption-of-printf.patch b/testing/cmocka/0001-cmocka.c-Reduce-the-call-stack-consumption-of-printf.patch
new file mode 100644
index 000000000..789779df4
--- /dev/null
+++ b/testing/cmocka/0001-cmocka.c-Reduce-the-call-stack-consumption-of-printf.patch
@@ -0,0 +1,59 @@
+From a5e95907fbf6921668abc4a61641d28a16a88c81 Mon Sep 17 00:00:00 2001
+From: Xiang Xiao <xi...@xiaomi.com>
+Date: Fri, 6 Jan 2023 10:09:20 +0800
+Subject: [PATCH 1/2] cmocka.c: Reduce the call stack consumption of printf
+
+Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
+Change-Id: Idf179ad5eb81bbc63eea4f71980857831668e7a8
+---
+ src/cmocka.c | 14 +++++++-------
+ 1 file changed, 7 insertions(+), 7 deletions(-)
+
+diff --git a/src/cmocka.c cmocka/src/cmocka.c
+index ef8fbd9..ff59b53 100644
+--- a/src/cmocka.c
++++ cmocka/src/cmocka.c
+@@ -2086,7 +2086,7 @@ static void vcmocka_print_error(const char* const format,
+ */
+ static void vcmocka_print_error(const char* const format, va_list args)
+ {
+- char buffer[1024];
++ char buffer[256];
+ size_t msg_len = 0;
+ va_list ap;
+ int len;
+@@ -2427,12 +2427,12 @@ void cmocka_print_error(const char * const format, ...)
+ /* Standard output and error print methods. */
+ void vprint_message(const char* const format, va_list args)
+ {
++ vprintf(format, args);
++ fflush(stdout);
++#ifdef _WIN32
+ char buffer[4096];
+
+ vsnprintf(buffer, sizeof(buffer), format, args);
+- printf("%s", buffer);
+- fflush(stdout);
+-#ifdef _WIN32
+ OutputDebugString(buffer);
+ #endif /* _WIN32 */
+ }
+@@ -2440,12 +2440,12 @@ void vprint_message(const char* const format, va_list args)
+
+ void vprint_error(const char* const format, va_list args)
+ {
++ vfprintf(stderr, format, args);
++ fflush(stderr);
++#ifdef _WIN32
+ char buffer[4096];
+
+ vsnprintf(buffer, sizeof(buffer), format, args);
+- fprintf(stderr, "%s", buffer);
+- fflush(stderr);
+-#ifdef _WIN32
+ OutputDebugString(buffer);
+ #endif /* _WIN32 */
+ }
+--
+2.25.1
+
diff --git a/testing/cmocka/0002-cmocka-feature-to-forwarding-cmocka-log-message-to-c.patch b/testing/cmocka/0002-cmocka-feature-to-forwarding-cmocka-log-message-to-c.patch
new file mode 100644
index 000000000..81d4fbe30
--- /dev/null
+++ b/testing/cmocka/0002-cmocka-feature-to-forwarding-cmocka-log-message-to-c.patch
@@ -0,0 +1,74 @@
+From b4069b535e94c74481bc78ae4363d7741def5e4a Mon Sep 17 00:00:00 2001
+From: chao an <an...@xiaomi.com>
+Date: Mon, 16 Jan 2023 15:19:59 +0800
+Subject: [PATCH 2/2] cmocka: feature to forwarding cmocka log message to
+ custom channel
+
+Add custom log message implementation to support different backend output, such as linux (vsyslog):
+
+https://www.gnu.org/software/libc/manual/html_node/syslog_003b-vsyslog.html
+
+redefine the vprint output function to native implement:
+
+1. Enable platfrom include: -DCMOCKA_PLATFORM_INCLUDE
+2. Add cmocka platform header to forwarding the log message to custom channel
+
+cmocka_platform.h:
+
+| #ifndef CMOCKA_PLATFORM_H_
+| #define CMOCKA_PLATFORM_H_
+|
+| #include <syslog.h>
+|
+| #define cmocka_vprint_message(f,a) vsyslog(LOG_INFO,f,a)
+| #define cmocka_vprint_error(f,a) vsyslog(LOG_ERR,f,a)
+|
+| #endif /* CMOCKA_PLATFORM_H_ */
+
+Change-Id: I0959c3d1fc372de842b63d9e220561d3df62beb2
+Signed-off-by: chao an <an...@xiaomi.com>
+---
+ src/cmocka.c | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/src/cmocka.c cmocka/src/cmocka.c
+index ff59b53..1cc9eac 100644
+--- a/src/cmocka.c
++++ cmocka/src/cmocka.c
+@@ -2427,6 +2427,7 @@ void cmocka_print_error(const char * const format, ...)
+ /* Standard output and error print methods. */
+ void vprint_message(const char* const format, va_list args)
+ {
++#ifndef cmocka_vprint_message
+ vprintf(format, args);
+ fflush(stdout);
+ #ifdef _WIN32
+@@ -2435,11 +2436,15 @@ void vprint_message(const char* const format, va_list args)
+ vsnprintf(buffer, sizeof(buffer), format, args);
+ OutputDebugString(buffer);
+ #endif /* _WIN32 */
++#else
++ cmocka_vprint_message(format, args);
++#endif
+ }
+
+
+ void vprint_error(const char* const format, va_list args)
+ {
++#ifndef cmocka_vprint_error
+ vfprintf(stderr, format, args);
+ fflush(stderr);
+ #ifdef _WIN32
+@@ -2448,6 +2453,9 @@ void vprint_error(const char* const format, va_list args)
+ vsnprintf(buffer, sizeof(buffer), format, args);
+ OutputDebugString(buffer);
+ #endif /* _WIN32 */
++#else
++ cmocka_vprint_error(format, args);
++#endif
+ }
+
+
+--
+2.25.1
+
diff --git a/testing/cmocka/Makefile b/testing/cmocka/Makefile
index 794a31db7..fc852e37f 100644
--- a/testing/cmocka/Makefile
+++ b/testing/cmocka/Makefile
@@ -36,9 +36,11 @@ MAINSRC = $(CURDIR)/cmocka_main.c
ifeq ($(wildcard cmocka/.git),)
VERSION ?= 1.1.5
cmocka.zip:
- $(Q) curl -L https://github.com/clibs/cmocka/archive/cmocka-$(VERSION).zip -o cmocka.zip
+ $(Q) curl -L https://github.com/clibs/cmocka/archive/$(VERSION).zip -o cmocka.zip
$(Q) unzip -o cmocka.zip
- $(Q) mv cmocka-cmocka-$(VERSION) cmocka
+ $(Q) mv cmocka-$(VERSION) cmocka
+ $(Q) patch -p0 < 0001-cmocka.c-Reduce-the-call-stack-consumption-of-printf.patch
+ $(Q) patch -p0 < 0002-cmocka-feature-to-forwarding-cmocka-log-message-to-c.patch
context:: cmocka.zip