瀏覽代碼

Utest win (#7347)

* [tools] Add `--add-rtconfig` args for scons when you want to add macro definitions build time.

* [utilities][utest] Add VS simulator support.
朱天龙 (Armink) 2 年之前
父節點
當前提交
69e6c3017b
共有 2 個文件被更改,包括 50 次插入1 次删除
  1. 34 0
      components/utilities/utest/utest.c
  2. 16 1
      components/utilities/utest/utest.h

+ 34 - 0
components/utilities/utest/utest.c

@@ -51,6 +51,18 @@ static struct utest local_utest = {UTEST_PASSED, 0, 0};
 
 #if defined(__ICCARM__) || defined(__ICCRX__)         /* for IAR compiler */
 #pragma section="UtestTcTab"
+#elif defined(_MSC_VER)
+#pragma section("UtestTcTab$a", read)
+__declspec(allocate("UtestTcTab$a")) const struct utest_tc_export __tc_export_begin =
+{
+    "__start",
+};
+
+#pragma section("UtestTcTab$z", read)
+__declspec(allocate("UtestTcTab$z")) const struct utest_tc_export __tc_export_end =
+{
+    "__end",
+};
 #endif
 
 #define TC_FAIL_LIST_SIZE                (RT_ALIGN(tc_num, 8) / 8)
@@ -81,6 +93,28 @@ int utest_init(void)
     extern const int __rt_utest_tc_tab_end;
     tc_table = (utest_tc_export_t)&__rt_utest_tc_tab_start;
     tc_num = (utest_tc_export_t) &__rt_utest_tc_tab_end - tc_table;
+#elif defined(_MSC_VER)
+    unsigned int* ptr_begin, * ptr_end;
+
+    ptr_begin = (unsigned int*)&__tc_export_begin;
+    ptr_begin += (sizeof(struct utest_tc_export) / sizeof(unsigned int));
+    while (*ptr_begin == 0) ptr_begin++;
+
+    ptr_end = (unsigned int*)&__tc_export_end;
+    ptr_end--;
+    while (*ptr_end == 0) ptr_end--;
+    /* copy tc_table from rodata section to ram */
+    for (unsigned int *ptr = ptr_begin; ptr < ptr_end;)
+    {
+        if (!tc_table)
+            tc_table = (utest_tc_export_t)rt_malloc(sizeof(struct utest_tc_export));
+        else
+            tc_table = (utest_tc_export_t)rt_realloc(tc_table, (tc_num + 1)* sizeof(struct utest_tc_export));
+        RT_ASSERT(tc_table);
+        tc_table[tc_num++] = *((utest_tc_export_t)ptr);
+        ptr += (sizeof(struct utest_tc_export) / sizeof(unsigned int));
+        while (*ptr == 0) ptr++;
+    }
 #endif
 
     LOG_I("utest is initialize success.");

+ 16 - 1
components/utilities/utest/utest.h

@@ -136,9 +136,23 @@ utest_t utest_handle_get(void);
  * @return None
  *
 */
+#ifdef _MSC_VER
+#pragma section("UtestTcTab$f",read)
+#define UTEST_TC_EXPORT(testcase, name, init, cleanup, timeout)                \
+    __declspec(allocate("UtestTcTab$f"))                                       \
+    static const struct utest_tc_export _utest_testcase =                      \
+    {                                                                          \
+        name,                                                                  \
+        timeout,                                                               \
+        init,                                                                  \
+        testcase,                                                              \
+        cleanup                                                                \
+     }
+#pragma comment(linker, "/merge:UtestTcTab=tctext")
+#else
 #define UTEST_TC_EXPORT(testcase, name, init, cleanup, timeout)                \
     rt_used static const struct utest_tc_export _utest_testcase                \
-    rt_section("UtestTcTab") =                                                    \
+    rt_section("UtestTcTab") =                                                 \
     {                                                                          \
         name,                                                                  \
         timeout,                                                               \
@@ -146,6 +160,7 @@ utest_t utest_handle_get(void);
         testcase,                                                              \
         cleanup                                                                \
     }
+#endif /* _MSC_VER */
 
 /**
  * UTEST_UNIT_RUN