MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / utest_init

Function utest_init

components/utilities/utest/utest.c:104–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104int utest_init(void)
105{
106 /* initialize the utest commands table.*/
107#if defined(__ARMCC_VERSION) /* ARM C Compiler */
108 extern const int UtestTcTab$$Base;
109 extern const int UtestTcTab$$Limit;
110 tc_table = (utest_tc_export_t)&UtestTcTab$$Base;
111 tc_num = (utest_tc_export_t)&UtestTcTab$$Limit - tc_table;
112#elif defined (__ICCARM__) || defined(__ICCRX__) /* for IAR Compiler */
113 tc_table = (utest_tc_export_t)__section_begin("UtestTcTab");
114 tc_num = (utest_tc_export_t)__section_end("UtestTcTab") - tc_table;
115#else
116 unsigned int *ptr_begin, *ptr_end;
117#if defined(__GNUC__)
118 extern const int __rt_utest_tc_tab_start;
119 extern const int __rt_utest_tc_tab_end;
120 ptr_begin = (unsigned int *)&__rt_utest_tc_tab_start;
121 ptr_end = (unsigned int *)&__rt_utest_tc_tab_end;
122#elif defined(_MSC_VER)
123 ptr_begin = (unsigned int *)&__tc_export_begin;
124 ptr_end = (unsigned int *)&__tc_export_end;
125 ptr_begin += (sizeof(struct utest_tc_export) / sizeof(unsigned int));
126#endif
127 while (*ptr_begin == 0) ptr_begin++;
128 ptr_end--;
129 while (*ptr_end == 0) ptr_end--;
130 /* copy tc_table from rodata section to ram */
131 for (unsigned int *ptr = ptr_begin; ptr < ptr_end;)
132 {
133 if (!tc_table)
134 tc_table = (utest_tc_export_t)rt_malloc(sizeof(struct utest_tc_export));
135 else
136 tc_table = (utest_tc_export_t)rt_realloc(tc_table, (tc_num + 1)* sizeof(struct utest_tc_export));
137 RT_ASSERT(tc_table);
138 tc_table[tc_num++] = *((utest_tc_export_t)ptr);
139 ptr += (sizeof(struct utest_tc_export) / sizeof(unsigned int));
140 while (*ptr == 0) ptr++;
141 }
142#endif
143
144 LOG_I("utest is initialize success.");
145 LOG_I("total utest testcase num: (%d)", tc_num);
146 if (tc_num > 0)
147 {
148 tc_fail_list = rt_malloc(TC_FAIL_LIST_SIZE);
149 if(!tc_fail_list)
150 {
151 LOG_E("no memory, tc_fail_list init failed!");
152 }
153 }
154
155 utest_build_options();
156
157 return tc_num;
158}
159INIT_COMPONENT_EXPORT(utest_init);
160
161static long utest_tc_list(void)

Callers

nothing calls this directly

Calls 3

rt_mallocFunction · 0.85
rt_reallocFunction · 0.85
utest_build_optionsFunction · 0.85

Tested by

no test coverage detected