[7/7] vcomp/tests: Add tests for vcomp sections.

Sebastian Lackner sebastian at fds-team.de
Thu Jul 16 08:01:45 CDT 2015


The Sleep(1)s are to ensure that the sections are processed by different threads.

---
 dlls/vcomp/tests/vcomp.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/dlls/vcomp/tests/vcomp.c b/dlls/vcomp/tests/vcomp.c
index a9b975d..c433991 100644
--- a/dlls/vcomp/tests/vcomp.c
+++ b/dlls/vcomp/tests/vcomp.c
@@ -33,6 +33,8 @@ static VOID   (WINAPI *pReleaseActCtx)(HANDLE);
 
 static void  (CDECL   *p_vcomp_barrier)(void);
 static void  (WINAPIV *p_vcomp_fork)(BOOL ifval, int nargs, void *wrapper, ...);
+static void  (CDECL   *p_vcomp_sections_init)(int n);
+static int   (CDECL   *p_vcomp_sections_next)(void);
 static void  (CDECL   *p_vcomp_set_num_threads)(int num_threads);
 static int   (CDECL   *pomp_get_max_threads)(void);
 static int   (CDECL   *pomp_get_nested)(void);
@@ -169,6 +171,8 @@ static BOOL init_vcomp(void)
 
     VCOMP_GET_PROC(_vcomp_barrier);
     VCOMP_GET_PROC(_vcomp_fork);
+    VCOMP_GET_PROC(_vcomp_sections_init);
+    VCOMP_GET_PROC(_vcomp_sections_next);
     VCOMP_GET_PROC(_vcomp_set_num_threads);
     VCOMP_GET_PROC(omp_get_max_threads);
     VCOMP_GET_PROC(omp_get_nested);
@@ -342,6 +346,52 @@ static void test_vcomp_fork(void)
     pomp_set_num_threads(max_threads);
 }
 
+static void CDECL section_cb(LONG *a, LONG *b, LONG *c)
+{
+    int i;
+
+    p_vcomp_sections_init(20);
+    while ((i = p_vcomp_sections_next()) != -1)
+    {
+        InterlockedIncrement(a);
+        Sleep(1);
+    }
+
+    p_vcomp_sections_init(30);
+    while ((i = p_vcomp_sections_next()) != -1)
+    {
+        InterlockedIncrement(b);
+        Sleep(1);
+    }
+
+    p_vcomp_sections_init(40);
+    while ((i = p_vcomp_sections_next()) != -1)
+    {
+        InterlockedIncrement(c);
+        Sleep(1);
+    }
+}
+
+static void test_vcomp_sections_init(void)
+{
+    LONG a, b, c;
+    int max_threads = pomp_get_max_threads();
+    int i;
+
+    for (i = 1; i <= 4; i++)
+    {
+        pomp_set_num_threads(i);
+
+        a = b = c = 0;
+        p_vcomp_fork(TRUE, 3, section_cb, &a, &b, &c);
+        ok(a == 20, "expected a = 20, got %d\n", a);
+        ok(b == 30, "expected b = 30, got %d\n", b);
+        ok(c == 40, "expected c = 40, got %d\n", c);
+    }
+
+    pomp_set_num_threads(max_threads);
+}
+
 START_TEST(vcomp)
 {
     if (!init_vcomp())
@@ -350,6 +400,7 @@ START_TEST(vcomp)
     test_omp_get_num_threads(FALSE);
     test_omp_get_num_threads(TRUE);
     test_vcomp_fork();
+    test_vcomp_sections_init();
 
     release_vcomp();
 }
-- 
2.4.5



More information about the wine-patches mailing list