4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
5 * PROPRIETARY/CONFIDENTIAL
7 * Contact: JuHak Park <juhaki.park@samsung.com>,
8 * JuneHyuk Lee <junhyuk7.lee@samsung.com>,
9 * SunBong Ha <sunbong.ha@samsung.com>
11 * This software is the confidential and proprietary information of
12 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not disclose
13 * such Confidential Information and shall use it only in accordance with the
14 * terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
15 * SAMSUNG make no representations or warranties about the suitability of the
16 * software, either express or implied, including but not limited to the
17 * implied warranties of merchantability, fitness for a particular purpose, or
18 * non-infringement. SAMSUNG shall not be liable for any damages suffered by
19 * licensee as a result of using, modifying or distributing this software or
24 * For any sort of issue you concern as to this software,
25 * you may use following point of contact.
26 * All resources contributed on this software
27 * are orinigally written by S-Core Inc., a member of Samsung Group.
29 * SeongWon Shim <seongwon.shim@samsung.com>
35 * Created on: 2011. 3. 29.
39 #include "unit_test_common.h"
40 #include "unit_test_run.h"
41 #include "unit_test_suites.h"
43 #include <sys/types.h>
47 /* introduction to unit test using check by yangsuh
48 * SRunner : runner of all test which belong to added suites
49 * Suite : container of test cases(TCase)
50 * TCase : container of tests
51 * test : container of many asserts
53 * SRunner has fork_status option. I will set this option to CK_FORK which means
54 * not stopping until all test finished.
55 * (Of course, when error like SIGSEGV occurs or test failed, current test will be stopped
56 * and goes to next test)
59 typedef enum fork_status fork_status_t;
60 int unit_test_main(fork_status_t fork_status)
64 /* srunner build up by defined test suites */
65 int suite_count = sizeof(suiteFunctions)/sizeof(SUITE_FUNCTION);
66 fprintf(stderr, "total test suites number = %d\n", suite_count);
68 if (suite_count == 0) {
69 return 0; /* nothing to do */
70 } else { /* suite_count > 0 */
71 SUITE_FUNCTION suite_func = NULL;
74 for (i = 0; i < suite_count; i++) {
75 suite_func = suiteFunctions[i];
76 Suite *s = suite_func();
79 sr = srunner_create(s);
80 } else if (i > 0 && i < suite_count) {
81 srunner_add_suite(sr, s);
84 fprintf(stderr, "invalid suite function\n");
90 srunner_set_log(sr, "/tmp/test.log"); /* set log file */
91 srunner_set_fork_status(sr, fork_status); /* set fork status of Runner */
93 srunner_run_all(sr, CK_VERBOSE); /* set print mode to verbose */
99 /* TODO : return handling */
100 static inline int unit_test_run_fork_mode()
108 fprintf(stderr, "Error in call to fork\n");
110 /* child process : run unit_test_main */
111 unit_test_main(CK_FORK);
115 fprintf(stderr, "test process pid = %d", pid);
116 pid_w = waitpid(pid, &status, 0);
119 fprintf(stderr, "test finished successfully\n");
120 return 1; /* test finished */
122 fprintf(stderr, "test failed\n");
123 return 0; /* test error */
130 /* running as main function will be need during debugging */
131 /* TODO : return handling */
132 static inline int unit_test_run_function_mode()
134 return unit_test_main(CK_NOFORK);
137 int unit_test_run(run_unit_test_mode_t mode)
139 int success = 1; /* success */
143 success = unit_test_run_fork_mode();
146 success = unit_test_run_function_mode();