Skip to content

Commit ba3929f

Browse files
committed
tests: p/UnifySDK: Add cmock patch Added-array_as_byte-config-op SiliconLabsSoftware#60
This not an atomic change see next patch in PR Origin: SiliconLabsSoftware#47 Relate-to: SiliconLabsSoftware#60 Relate-to: SiliconLabsSoftware#75 Relate-to: ThrowTheSwitch/CMock#503 Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
1 parent 190ef19 commit ba3929f

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
From b0d6b0ee17f37e57e37bfbeeb08ee6531b8b04f2 Mon Sep 17 00:00:00 2001
2+
From: Philippe Coval <philippe.coval@silabs.com>
3+
Date: Fri, 14 Mar 2025 15:42:31 +0100
4+
Subject: [PATCH] tests: p/cmock: Add
5+
0001-Added-array_as_byte-config-options.patch
6+
7+
This change is needed for testing libs2 which is using anynomous type
8+
(struct S2)
9+
10+
Relate-to: https://github.com/SiliconLabsSoftware/z-wave-protocol-controller/issues/60
11+
Relate-to: https://github.com/SiliconLabsSoftware/z-wave-engine-application-layer/issues/6
12+
Relate-to: https://github.com/SiliconLabsSoftware/z-wave-protocol-controller/issues/75
13+
Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
14+
---
15+
...1-Added-array_as_byte-config-options.patch | 91 +++++++++++++++++++
16+
1 file changed, 91 insertions(+)
17+
create mode 100644 patches/cmock/0001-Added-array_as_byte-config-options.patch
18+
19+
diff --git a/patches/cmock/0001-Added-array_as_byte-config-options.patch b/patches/cmock/0001-Added-array_as_byte-config-options.patch
20+
new file mode 100644
21+
index 0000000000..e4ea529e9a
22+
--- /dev/null
23+
+++ b/patches/cmock/0001-Added-array_as_byte-config-options.patch
24+
@@ -0,0 +1,91 @@
25+
+From 2b089523835cf0ab3c4ac66984ee7b02f21a6d9d Mon Sep 17 00:00:00 2001
26+
+From: Philippe Coval <philippe.coval@silabs.com>
27+
+Date: Fri, 24 Apr 2020 14:05:54 +0200
28+
+Subject: [PATCH] Added array_as_byte config options.
29+
+MIME-Version: 1.0
30+
+Content-Type: text/plain; charset=UTF-8
31+
+Content-Transfer-Encoding: 8bit
32+
+
33+
+[Anders Esbensen]
34+
+
35+
+Option to check arrays by the number of bytes instead of number of elements.
36+
+
37+
+[Philippe Coval]
38+
+
39+
+This change was applied to a fork (ths_cmock) used in a Z-Wave project.
40+
+It was needed to generate mocks from a header that used annonymous structures.
41+
+
42+
+The observed issue was:
43+
+
44+
+(...)_mock.c:486:123: error: invalid application of ‘sizeof’ to incomplete type ‘struct (...)’
45+
+
46+
+Which was just declared in relative header.
47+
+
48+
+The array_as_byte feature prevent this error.
49+
+
50+
+Author: Anders Esbensen <Anders.Esbensen@silabs.com>
51+
+Origin-Upstream: https://github.com/ThrowTheSwitch/CMock/pull/503
52+
+Origin-SiliconLabs: v2.5.1-74-ga078d10
53+
+Relate-to: https://github.com/SiliconLabsSoftware/z-wave-protocol-controller/issues/75
54+
+Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
55+
+---
56+
+ docs/CMock_Summary.md | 4 ++++
57+
+ lib/cmock_config.rb | 1 +
58+
+ lib/cmock_generator_utils.rb | 7 ++++++-
59+
+ 3 files changed, 11 insertions(+), 1 deletion(-)
60+
+
61+
+diff --git a/docs/CMock_Summary.md b/docs/CMock_Summary.md
62+
+index 3183665..5cb201c 100644
63+
+--- a/docs/CMock_Summary.md
64+
++++ b/docs/CMock_Summary.md
65+
+@@ -738,6 +738,10 @@ from the defaults. We've tried to specify what the defaults are below.
66+
+
67+
+ GoBananas_ExpectWithArray(b, 2, 2);
68+
+
69+
++ `:array_as_byte`:
70+
++ When checking arrays, the element size will always be 1, ie depth is the number
71+
++ of bytes to check.
72+
++
73+
+ * `:fail_on_unexpected_calls`:
74+
+ By default, CMock will fail a test if a mock is called without `_Expect` and `_Ignore`
75+
+ called first. While this forces test writers to be more explicit in their expectations,
76+
+diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb
77+
+index ccbf4dc..27cece4 100644
78+
+--- a/lib/cmock_config.rb
79+
++++ b/lib/cmock_config.rb
80+
+@@ -41,6 +41,7 @@ class CMockConfig
81+
+ :orig_header_include_fmt => '#include "%s"',
82+
+ :array_size_type => [],
83+
+ :array_size_name => 'size|len',
84+
++ :array_as_byte => false,
85+
+ :skeleton => false,
86+
+ :exclude_setjmp_h => false,
87+
+
88+
+diff --git a/lib/cmock_generator_utils.rb b/lib/cmock_generator_utils.rb
89+
+index 83e762f..6f0ddc8 100644
90+
+--- a/lib/cmock_generator_utils.rb
91+
++++ b/lib/cmock_generator_utils.rb
92+
+@@ -21,6 +21,7 @@ class CMockGeneratorUtils
93+
+ @ignore_stateless = @config.plugins.include? :ignore_stateless
94+
+ @treat_as = @config.treat_as
95+
+ @helpers = helpers
96+
++ @array_as_byte = @config.array_as_byte
97+
+ end
98+
+
99+
+ def self.arg_type_with_const(arg)
100+
+@@ -230,7 +231,11 @@ class CMockGeneratorUtils
101+
+ lines << " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
102+
+ lines << (depth_name != 1 ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch); }\n" : '')
103+
+ lines << " else\n"
104+
+- lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*', '')}), #{depth_name}, cmock_line, CMockStringMismatch); }\n"
105+
++ if @array_as_byte
106+
++ lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), 1, #{depth_name}, cmock_line, CMockStringMismatch); }\n"
107+
++ else
108+
++ lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*', '')}), #{depth_name}, cmock_line, CMockStringMismatch); }\n"
109+
++ end
110+
+ end
111+
+ when /_ARRAY/
112+
+ if pre == '&'
113+
+--
114+
+2.39.5
115+
+
116+
--
117+
2.39.5
118+

0 commit comments

Comments
 (0)