1 /*
2  * Copyright (c) 2022 Google LLC
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/ztest.h>
8 #include <zephyr/llext/symbol.h>
9 
10 /**
11  * @brief Try to shorten a filename by removing the current directory
12  *
13  * This helps to reduce the very long filenames in assertion failures. It
14  * removes the current directory from the filename and returns the rest.
15  * This makes assertions a lot more readable, and sometimes they fit on one
16  * line.
17  *
18  * @param file Filename to check
19  * @returns Shortened filename, or @file if it could not be shortened
20  */
ztest_relative_filename(const char * file)21 const char *ztest_relative_filename(const char *file)
22 {
23 	return file;
24 }
25 EXPORT_SYMBOL(ztest_relative_filename);
26 
27 /**
28  * Default entry point for running registered unit tests.
29  *
30  * @param state The current state of the machine as it relates to the test executable.
31  */
z_ztest_run_all(const void * state,bool shuffle,int suite_iter,int case_iter)32 void z_ztest_run_all(const void *state, bool shuffle, int suite_iter, int case_iter)
33 {
34 	ztest_run_test_suites(state, shuffle, suite_iter, case_iter);
35 }
36 
37 /**
38  * @brief Determines if the test suite should run based on test cases listed
39  *	  in the command line argument.
40  *
41  * @param state The current state of the machine as it relates to the test
42  *		executable.
43  * @param suite Pointer to ztest_suite_node
44  * @return true
45  * @return false
46  */
z_ztest_should_suite_run(const void * state,struct ztest_suite_node * suite)47 bool z_ztest_should_suite_run(const void *state, struct ztest_suite_node *suite)
48 {
49 	bool run_suite = true;
50 
51 	if (suite->predicate != NULL) {
52 		run_suite = suite->predicate(state);
53 	}
54 
55 	return run_suite;
56 }
57 
58 /**
59  * @brief Determines if the test case should run based on test cases listed
60  *	  in the command line argument. Run all tests for non-posix builds
61  *
62  * @param suite - name of test suite
63  * @param test  - name of unit test
64  * @return true
65  * @return false
66  */
z_ztest_should_test_run(const char * suite,const char * test)67 bool z_ztest_should_test_run(const char *suite, const char *test)
68 {
69 	return true;
70 }
71 
72 ZTEST_DMEM const struct ztest_arch_api ztest_api = {
73 	.run_all = z_ztest_run_all,
74 	.should_suite_run = z_ztest_should_suite_run,
75 	.should_test_run = z_ztest_should_test_run
76 };
77