@@ -10,244 +10,15 @@ Organization: Fossil Logic
1010 feel free to contact Michael at [email protected] . 1111==============================================================================
1212*/
13- #ifndef FOSSIL_TEST_INTERNAL_H
14- #define FOSSIL_TEST_INTERNAL_H
13+ #ifndef FOSSIL_TEST_FRAMEWORK_H
14+ #define FOSSIL_TEST_FRAMEWORK_H
1515
1616#include "fossil/_common/common.h"
1717#include "fossil/_common/platform.h"
18+ #include "internal.h"
1819#include "console.h"
1920#include "commands.h"
2021
21- /**
22- * Introspection Data in Fossil Test
23- *
24- * Introspection, in the context of Fossil Test, refers to the process of gathering
25- * detailed information about the testing environment. This information is crucial
26- * for ensuring test stability, reliability, and portability across different
27- * platforms and environments. Fossil Test relies heavily on introspection data to
28- * adapt its behavior dynamically based on the characteristics of the system where
29- * it runs.
30- *
31- * The importance of introspection data can be summarized as follows:
32- *
33- * 1. System Compatibility:
34- * Introspection data allows Fossil Test to identify the underlying architecture,
35- * operating system, CPU count, endianness, and memory size of the test environment.
36- * This information is vital for ensuring that tests execute correctly on diverse
37- * platforms, including ARM, Windows, macOS, and various POSIX-based systems.
38- *
39- * 2. Test Adaptation:
40- * By analyzing introspection data, Fossil Test can adapt its behavior and configuration
41- * to suit the characteristics of the current environment. For example, the console
42- * output may be adjusted based on the console width and height, and color support
43- * may be enabled or disabled depending on the capabilities of the terminal.
44- *
45- * 3. Performance Optimization:
46- * Introspection data helps Fossil Test optimize test execution performance by providing
47- * insights into system resources such as CPU count and memory size. This information
48- * allows Fossil Test to allocate resources efficiently and prioritize test execution
49- * based on available hardware resources.
50- *
51- * 4. Cross-Platform Testing:
52- * With introspection data, Fossil Test can facilitate cross-platform testing by
53- * identifying and handling platform-specific differences transparently. Whether
54- * running on Windows, macOS, Linux, or other operating systems, Fossil Test can
55- * leverage introspection data to ensure consistent test behavior and results.
56- *
57- * In conclusion, introspection data forms the foundation of Fossil Test's ability
58- * to operate effectively in diverse testing environments. By gathering and analyzing
59- * detailed information about the test environment, Fossil Test enhances compatibility,
60- * adaptability, performance, and cross-platform testing capabilities, thereby
61- * empowering developers to write robust and portable test suites.
62- */
63-
64- // Define thread pool size
65- enum {
66- FOSSIL_TEST_MAX_FILTER_LENGTH = 50 ,
67- FOSSIL_TEST_ASSUME_MAX = 5 ,
68- FOSSIL_TEST_EXCEPT_MAX = 5 ,
69- FOSSIL_TEST_MAX_REPEATS = 100 ,
70- FOSSIL_TEST_MIN_REPEATS = 1 ,
71- FOSSIL_TEST_MAX_PRIORITY = 100 ,
72- FOSSIL_TEST_MIN_PRIORITY = 1 ,
73- MAX_EXPECTED_TIME_FAST = 1000 , // Example value: 1000 milliseconds (1 second)
74- MAX_EXPECTED_TIME_SLOW = 2000 , // 2000 milliseconds (2 seconds)
75- FOSSIL_TESTAULT_PRIORITY_THRESHOLD = 50 ,
76- FOSSIL_TEST_ABORT_FAIL = -1 ,
77- };
78-
79- typedef enum {
80- FOSSIL_TEST_IO_AS_HUMAN ,
81- FOSSIL_TEST_IO_AS_CUTBACK ,
82- FOSSIL_TEST_IO_AS_TURBO
83- } fossil_test_mode ;
84-
85- /**
86- * @brief Enumeration representing different types of assertion rules.
87- *
88- * This enum defines various types of assertion rules that can be applied to test cases.
89- * Each value represents a specific type of assertion behavior.
90- */
91- typedef enum {
92- TEST_ASSERT_AS_CLASS_ASSERT , /**< Standard assert, used to enforce conditions that must be true. */
93- TEST_ASSERT_AS_CLASS_EXPECT , /**< Expectation, used to define conditions that are expected but not mandatory. */
94- TEST_ASSERT_AS_CLASS_ASSUME , /**< Assumption, used to specify assumptions that must hold true for the test to proceed. */
95- TEST_ASSERT_AS_CLASS_EXCEPT , /**< Exception, used to handle conditions that are expected to raise exceptions. */
96- TEST_ASSERT_AS_CLASS_SANITY /**< Sanity check, used for basic checks to ensure the test environment is stable. */
97- } xassert_type_t ;
98-
99- /**
100- * @brief Enumeration representing different priority rules for test assertions.
101- *
102- * This enum defines various priority rules for test assertions, indicating the importance
103- * or urgency of the tests. Tests with higher priority values are considered more critical.
104- */
105- typedef enum {
106- TEST_ASSERT_PRIORITY_RULE_LOW , /**< Priority for tests with low importance. */
107- TEST_ASSERT_PRIORITY_RULE_NORMAL , /**< Priority for tests with normal importance. */
108- TEST_ASSERT_PRIORITY_RULE_HIGH , /**< Priority for tests with high importance. */
109- TEST_ASSERT_PRIORITY_RULE_CRITICAL /**< Priority for tests with critical importance. */
110- } xassert_priority_t ;
111-
112- /**
113- * @brief Enumeration representing different mark rules for test assertions.
114- *
115- * This enum defines various marking rules for test assertions, indicating the expected
116- * outcome or behavior of the tests.
117- */
118- typedef enum {
119- TEST_ASSERT_MARK_RULE_SKIP , /**< Mark for tests that should be skipped. */
120- TEST_ASSERT_MARK_RULE_DEFAULT , /**< Default mark for tests with no specific expected outcome. */
121- TEST_ASSERT_MARK_RULE_TIMEOUT , /**< Mark for tests that are expected to timeout. */
122- TEST_ASSERT_MARK_RULE_ERROR , /**< Mark for tests that are expected to throw an error. */
123- TEST_ASSERT_MARK_RULE_NONE , /**< Mark for tests with no specific expected outcome. */
124- TEST_ASSERT_MARK_RULE_ONLY /**< Mark for tests that are the only ones to be run. */
125- } xassert_mark_t ;
126-
127- /**
128- * Structure representing rules or attributes of a test case.
129- * This structure is used to track various states or characteristics of a test case,
130- * such as whether it passed, was skipped, or was categorized as fast or slow.
131- */
132- typedef struct {
133- bool should_pass ; /**< Boolean indicating whether the test case passed. */
134- bool skipped ; /**< Boolean indicating whether the test case was skipped. */
135- bool timeout ; /**< Boolean indicating whether the test case timed out. */
136- bool error ; /**< Boolean indicating whether the test case threw an error. */
137- } fossil_test_rule_t ;
138-
139- /**
140- * @brief Structure to hold timing information for tests.
141- *
142- * This structure stores the timing information for tests, including the start time,
143- * end time, elapsed time, and detailed timing information in different units.
144- * It is used to track the duration of test executions to provide performance metrics.
145- */
146- typedef struct {
147- clock_t start ; /**< Processor time at the start of tests. */
148- clock_t end ; /**< Processor time at the end of tests. */
149- clock_t elapsed ; /**< Elapsed processor time for the tests. */
150- struct {
151- int64_t minutes ; /**< Elapsed time in minutes. */
152- int64_t seconds ; /**< Elapsed time in seconds. */
153- int64_t milliseconds ; /**< Elapsed time in milliseconds. */
154- int64_t microseconds ; /**< Elapsed time in microseconds. */
155- int64_t nanoseconds ; /**< Elapsed time in nanoseconds. */
156- } detail ; /**< Detailed timing information, providing a breakdown of elapsed time in various units. */
157- } fossil_test_timer_t ;
158-
159- /**
160- * Structure representing fixture information with setup and teardown functions.
161- * A fixture is used to set up any necessary environment or state before running a test
162- * and to clean up afterward. This is useful for initializing resources or configurations
163- * that multiple test cases share.
164- */
165- typedef struct {
166- void (* setup )(void ); /**< Function pointer to the setup function for the fixture.
167- This function is called before each test case to set up
168- the test environment. */
169- void (* teardown )(void ); /**< Function pointer to the teardown function for the fixture.
170- This function is called after each test case to clean up
171- the test environment. */
172- } fossil_fixture_t ;
173-
174- /**
175- * Structure representing a test case.
176- * This structure contains all the necessary information for a test case, including its name,
177- * the function implementing the test, priority, tags, and links to setup and teardown functions.
178- */
179- typedef struct fossil_test_t fossil_test_t ;
180- typedef struct fossil_test_t {
181- const char * name ; /**< Name of the test case. */
182- void (* test_function )(void ); /**< Function pointer to the test case's implementation. */
183- char * tags ; /**< Array of tags associated with the test case. */
184- char * marks ; /**< Array of marks associated with the test case. */
185- fossil_test_timer_t timer ; /**< Timer for tracking the duration of the test case. */
186- fossil_fixture_t fixture ; /**< The fixture settings for setup and teardown functions. */
187- int32_t priority ; /**< Priority of the test case (higher value indicates higher priority). */
188- struct fossil_test_t * prev ; /**< Pointer to the previous fossil_test_t node in a linked list. */
189- struct fossil_test_t * next ; /**< Pointer to the next fossil_test_t node in a linked list. */
190- } fossil_test_t ;
191-
192- /**
193- * Structure representing a deque (double-ended queue) for managing test cases.
194- * This structure allows for the addition and removal of test cases from both ends of the queue.
195- */
196- typedef struct {
197- fossil_test_t * front ; /**< Pointer to the front of the deque. */
198- fossil_test_t * rear ; /**< Pointer to the rear of the deque. */
199- } fossil_test_queue_t ;
200-
201- /**
202- * Structure representing statistics for tracking test results.
203- * This structure keeps track of various counts related to the outcomes of test cases,
204- * including passed, failed, skipped, and timed-out tests.
205- */
206- typedef struct {
207- uint16_t expected_passed_count ; /**< Number of expected passed tests. */
208- uint16_t expected_failed_count ; /**< Number of expected failed tests. */
209- uint16_t unexpected_passed_count ; /**< Number of unexpected passed tests. */
210- uint16_t unexpected_failed_count ; /**< Number of unexpected failed tests. */
211- uint16_t expected_skipped_count ; /**< Number of skipped tests. */
212- uint16_t expected_empty_count ; /**< Number of empty tests. */
213- uint16_t expected_timeout_count ; /**< Number of tests that timed out. */
214- uint16_t expected_total_count ; /**< Total number of unit tests that were run. */
215- uint16_t untested_count ; /**< Total number of untested cases when exit or abort is called
216- from an assert. */
217- } fossil_test_score_t ;
218-
219- /**
220- * Structure representing information about an assertion.
221- * This structure contains detailed information about an assertion, including the name of the test case,
222- * the message associated with the assertion, the file name, line number, function name, timestamp, assertion type,
223- * execution time, test case identifier, severity level, custom data, stack trace, and result of the test case.
224- */
225- typedef struct {
226- bool shoudl_timeout ; /**< Flag indicating whether the test case should timeout (1 for true, 0 for false). */
227- bool should_fail ; /**< Flag indicating whether the test case should fail (1 for true, 0 for false). */
228- bool has_assert ; /**< Flag indicating if an assertion occurred (1 for true, 0 for false). */
229- bool same_assert ; /**< Flag indicating if the test case is the same (1 for true, 0 for false). */
230- int32_t num_asserts ; /**< Number of assertions that occurred. */
231- int32_t line ; /**< Line number where the assertion occurred. */
232- char * func ; /**< Function name where the assertion occurred. */
233- char * file ; /**< File name where the assertion occurred. */
234- char * message ; /**< Message associated with the assertion. */
235- } xassert_info ;
236-
237- /**
238- * Structure representing the test environment, holding overall test statistics and timing information.
239- * This structure is used to manage the state of the testing process, including the queue of test cases
240- * and the timer for tracking the duration of the tests.
241- */
242- typedef struct {
243- fossil_test_score_t stats ; /**< Test statistics, including counts of passed, failed, and skipped tests. */
244- fossil_test_timer_t timer ; /**< Timer for tracking the time taken to run the tests. */
245- fossil_test_queue_t * queue ; /**< Queue to hold the test cases, allowing them to be managed and executed in order. */
246- fossil_test_rule_t rule ; /**< Rule for the test case, including whether it should pass, fail, or be skipped. */
247- uint8_t current_except_count ; /**< Counter for the number of exceptions that occurred during testing. */
248- uint8_t current_assume_count ; /**< Counter for the number of assumptions that occurred during testing. */
249- } fossil_env_t ;
250-
25122#ifdef __cplusplus
25223extern "C"
25324{
0 commit comments