Skip to content

Commit dbea669

Browse files
committed
3.0.4
removed volatile from RingBuf struct, updated Embedded Test 3.0.1 Changed SUTEST macro EXPECT() to VERIFY() 3.0.2 3.0.3 3.0.3 3.0.3 Used ET (Embedded Test) framework for testing 3.0.3
1 parent fc5269e commit dbea669

File tree

12 files changed

+475
-229
lines changed

12 files changed

+475
-229
lines changed

ET/et.c

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*============================================================================
2+
* ET: embedded test (super-simple embedded testing framework)
3+
* GitHub: https://github.com/QuantumLeaps/Embedded-Test
4+
*
5+
* Q u a n t u m L e a P s
6+
* ------------------------
7+
* Modern Embedded Software
8+
*
9+
* Copyright (C) 2005 Quantum Leaps, <state-machine.com>.
10+
*
11+
* SPDX-License-Identifier: MIT
12+
*
13+
* Permission is hereby granted, free of charge, to any person obtaining a
14+
* copy of this software and associated documentation files (the "Software"),
15+
* to deal in the Software without restriction, including without limitation
16+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
17+
* and/or sell copies of the Software, and to permit persons to whom the
18+
* Software is furnished to do so, subject to the following conditions:
19+
*
20+
* The above copyright notice and this permission notice shall be included in
21+
* all copies or substantial portions of the Software.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29+
* DEALINGS IN THE SOFTWARE.
30+
============================================================================*/
31+
#include "et.h" /* ET: embedded test */
32+
33+
/*..........................................................................*/
34+
static void print_str(char const *str);
35+
static void print_dec(unsigned const num);
36+
static void print_summary(unsigned ok);
37+
static void test_end(void);
38+
static int str_cmp(char const *str1, char const *str2);
39+
40+
static unsigned l_test_count;
41+
static unsigned l_skip_count;
42+
static unsigned l_skip_last;
43+
44+
static char const *l_expect_assert_module;
45+
static int l_expect_assert_label;
46+
47+
/*..........................................................................*/
48+
int main(int argc, char *argv[]) {
49+
ET_onInit(argc, argv);
50+
51+
print_str("\nET embedded test " ET_VERSION
52+
", https://github.com/QuantumLeaps/ET\n");
53+
print_str("---------------- group: ");
54+
print_str(ET_group_);
55+
print_str(" -----------------\n");
56+
57+
ET_run_();
58+
59+
test_end();
60+
print_summary(1U);
61+
62+
ET_onExit(0); /* success */
63+
}
64+
65+
/*..........................................................................*/
66+
int ET_test_(char const *title, int skip) {
67+
test_end();
68+
++l_test_count;
69+
ET_onPrintChar('[');
70+
print_dec(l_test_count);
71+
print_str("] \"");
72+
print_str(title);
73+
print_str("\" ");
74+
if (skip) {
75+
++l_skip_count;
76+
}
77+
else {
78+
setup();
79+
ET_onPrintChar('.');
80+
}
81+
l_skip_last = skip;
82+
return skip == 0;
83+
}
84+
/*..........................................................................*/
85+
static void test_end(void) {
86+
if (l_expect_assert_module != (char const *)0) {
87+
ET_fail("Expected Assertion didn't fire",
88+
l_expect_assert_module, l_expect_assert_label);
89+
}
90+
else if (l_test_count > 0) {
91+
if (l_skip_last) {
92+
print_str(" SKIPPED\n");
93+
l_skip_last = 0;
94+
}
95+
else {
96+
teardown();
97+
print_str(". PASSED\n");
98+
}
99+
}
100+
}
101+
/*..........................................................................*/
102+
void ET_fail(char const *cond, char const *group, int line) {
103+
print_str(" FAILED\n--> ");
104+
print_str(group);
105+
ET_onPrintChar(':');
106+
print_dec(line);
107+
ET_onPrintChar(' ');
108+
print_str(cond);
109+
ET_onPrintChar('\n');
110+
print_summary(0U);
111+
112+
ET_onExit(-1); /* failure */
113+
}
114+
/*..........................................................................*/
115+
void ET_expect_assert(char const *module, int label) {
116+
l_expect_assert_module = module;
117+
l_expect_assert_label = label;
118+
}
119+
/*..........................................................................*/
120+
void ET_verify_assert_(char const *module, int label) {
121+
if ((l_expect_assert_label == label)
122+
&& (str_cmp(module, l_expect_assert_module) == 0))
123+
{
124+
l_expect_assert_module = (char const *)0;
125+
test_end();
126+
print_str("Assertion (expected) --> Exiting\n");
127+
print_summary(1U);
128+
129+
ET_onExit(0); /* success */
130+
}
131+
else {
132+
ET_fail("Unexpected assertion", module, label);
133+
}
134+
}
135+
136+
/*..........................................................................*/
137+
static void print_summary(unsigned ok) {
138+
print_str("------------ ");
139+
print_dec(l_test_count);
140+
print_str(" test(s), ");
141+
print_dec(l_skip_count);
142+
print_str(" skipped -------------\n");
143+
print_str(ok ? "OK\n" : "FAILED\n");
144+
}
145+
/*..........................................................................*/
146+
static void print_str(char const *str) {
147+
for (; *str != '\0'; ++str) {
148+
ET_onPrintChar(*str);
149+
}
150+
}
151+
152+
/*..........................................................................*/
153+
static void print_dec(unsigned const num) {
154+
/* find power of 10 of the first decimal digit of the number */
155+
unsigned pwr10 = 1U;
156+
for (; num > (pwr10 * 9U); pwr10 *= 10U) {
157+
}
158+
/* print the decimal digits of the number... */
159+
do {
160+
ET_onPrintChar((char)('0' + ((num / pwr10) % 10U)));
161+
pwr10 /= 10U;
162+
} while (pwr10 != 0U);
163+
}
164+
165+
/*..........................................................................*/
166+
static int str_cmp(char const *str1, char const *str2) {
167+
while (*str1 == *str2++) {
168+
if (*str1++ == '\0') {
169+
return 0;
170+
}
171+
}
172+
--str2;
173+
return *(unsigned char *)str1 - *(unsigned char *)str2;
174+
}

ET/et.h

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*============================================================================
2+
* ET: embedded test (super-simple embedded testing framework)
3+
* GitHub: https://github.com/QuantumLeaps/Embedded-Test
4+
*
5+
* Q u a n t u m L e a P s
6+
* ------------------------
7+
* Modern Embedded Software
8+
*
9+
* Copyright (C) 2005 Quantum Leaps, <state-machine.com>.
10+
*
11+
* SPDX-License-Identifier: MIT
12+
*
13+
* Permission is hereby granted, free of charge, to any person obtaining a
14+
* copy of this software and associated documentation files (the "Software"),
15+
* to deal in the Software without restriction, including without limitation
16+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
17+
* and/or sell copies of the Software, and to permit persons to whom the
18+
* Software is furnished to do so, subject to the following conditions:
19+
*
20+
* The above copyright notice and this permission notice shall be included in
21+
* all copies or substantial portions of the Software.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29+
* DEALINGS IN THE SOFTWARE.
30+
============================================================================*/
31+
#ifndef ET_H_
32+
#define ET_H_
33+
34+
/* Embedded Test (ET) version */
35+
#define ET_VERSION "1.0.0"
36+
37+
/*! macro to define a test group */
38+
#define TEST_GROUP(name_) \
39+
char const ET_group_[] = name_; \
40+
void ET_run_(void)
41+
42+
/* macro to start a new test */
43+
#define TEST(title_) \
44+
if (ET_test_(title_, 0))
45+
46+
/* macro to skip a test */
47+
#define SKIP_TEST(title_) \
48+
if (ET_test_(title_, 1))
49+
50+
/*! macro to verify a test expectation */
51+
#define VERIFY(cond_) \
52+
((cond_) ? (void)0 : ET_fail(#cond_, &ET_group_[0], __LINE__))
53+
54+
#define VERIFY_ASSERT(module_, label_) \
55+
ET_verify_assert_((module_), (label_))
56+
57+
/*! macro to force a failure of a test */
58+
#define FAIL(note_) \
59+
(ET_fail(note_, &ET_group_[0], __LINE__))
60+
61+
#ifndef ARRAY_NELEM
62+
/*! convenience macro to provide the number of elements in the array a_ */
63+
#define ARRAY_NELEM(a_) (sizeof(a_) / sizeof((a_)[0]))
64+
#endif /* ARRAY_NELEM */
65+
66+
#ifdef __cplusplus
67+
extern "C" {
68+
#endif
69+
70+
void setup(void); /*!< called right before each test */
71+
void teardown(void); /*!< called right after each test */
72+
73+
/* callback functions to be implemented in the ET board support packages */
74+
void ET_onInit(int argc, char *argv[]);
75+
void ET_onPrintChar(char const ch);
76+
void ET_onExit(int err);
77+
78+
/* public helpers */
79+
void ET_fail(char const *cond, char const *group, int line);
80+
void ET_expect_assert(char const *module, int label);
81+
void ET_verify_assert_(char const *module, int label);
82+
83+
/* private helpers */
84+
void ET_run_(void);
85+
int ET_test_(char const *title, int skip);
86+
extern char const ET_group_[];
87+
88+
#ifdef __cplusplus
89+
}
90+
#endif
91+
92+
#endif /* ET_H_ */

LICENSE

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
Copyright (c) 2021 Quantum Leaps (https:://www.state-machine.com)
1+
MIT License
22

3-
SPDX-License-Identifier: MIT
3+
Copyright (c) 2023 Quantum Leaps
44

5-
Permission is hereby granted, free of charge, to any person
6-
obtaining a copy of this software and associated documentation
7-
files (the "Software"), to deal in the Software without
8-
restriction, including without limitation the rights to use,
9-
copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
copies of the Software, and to permit persons to whom the
11-
Software is furnished to do so, subject to the following
12-
conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
1311

14-
The above copyright notice and this permission notice shall be
15-
included in all copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
1614

17-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24-
OTHER DEALINGS IN THE SOFTWARE.
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
## Brought to you by:
2-
[![Quantum Leaps](https://www.state-machine.com/attachments/logo_ql_400.png)](https://www.state-machine.co)
2+
[![Quantum Leaps](https://www.state-machine.com/attachments/logo_ql_400.png)](https://www.state-machine.com)
3+
<hr>
4+
5+
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/QuantumLeaps/lock-free-ring-buffer)](https://github.com/QuantumLeaps/lock-free-ring-buffer/releases/latest)
6+
[![GitHub](https://img.shields.io/github/license/QuantumLeaps/lock-free-ring-buffer)](https://github.com/QuantumLeaps/lock-free-ring-buffer/blob/master/LICENSE)
37

4-
---------------------------------------------------------------------
58
# What is it?
69
"Lock-Free Ring Buffer" (LFRB) is a minimal, customizable implementation
710
of a ring buffer (a.k.a. circular buffer) in C, specifically suitable
@@ -31,19 +34,20 @@ src directory:
3134
- [ring_buf.c](src/ring_buf.c) - contains the implementation
3235

3336
The ring buffer holds elements of they type RingBufElement, which
34-
can be customized (typically `uint8_t`, `uint16_t`, `uint32_t`, `float`,
37+
can be customized (typically `uint8_t`, `uint16_t`, `uint32_t`, `float`,
3538
`void*` (pointers), etc.)
3639

3740

3841
# Test/Example of Use
39-
The directory `test` contains a very "Simple Unit Testing (SUTEST)" framework
40-
for unit testing, consisting of the files:
42+
The directory `ET` contains the
43+
[<b>Embedded Test (ET)</b>](https://github.com/QuantumLeaps/Embedded-Test)
44+
super-simple testing framework. ET is used to test the LFRB.
4145

42-
- [sutest.h](test/sutest.h) - SUTEST interface
43-
- [sutest.c](test/sutest.c) - SUTEST implementation
46+
<p align="center">
47+
<a title="ET on GitHub" href="https://github.com/QuantumLeaps/Embedded-Test"><img src="img/logo_et-chip.png"/></a>
48+
</p>
4449

45-
The SUTEST framework is used to test the LFRB. Specifically, the tests
46-
and examples of use of LFRB are located in the file:
50+
Specifically, the ET tests and examples of use of LFRB are located in the file:
4751

4852
- [test_ring_buf.c](test/test_ring_buf.c) - example of use and tests the LFRB.
4953

@@ -57,5 +61,9 @@ If you'd like to discuss LFRB or related subjects, plese use the
5761
["Issues" tab](https://github.com/QuantumLeaps/lock-free-ring-buffer/issues).
5862

5963

60-
# Contact Information
61-
[state-machine.com](https://www.state-machine.com)
64+
# How to Help this Project?
65+
Please feel free to clone, fork, and make pull requests to improve LFRB.
66+
If you like this project, please give it a star
67+
(in the upper-right corner of your browser window):
68+
69+
<p align="center"><img src="img/github-star.jpg"/></p>

0 commit comments

Comments
 (0)