adapt tests for windows origin/master
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Fri, 19 Dec 2025 17:34:35 +0000 (18:34 +0100)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Fri, 19 Dec 2025 17:34:35 +0000 (18:34 +0100)
clock.c
load.c
main.c
main.h
mutex.c
semaphore.c
thread_c+j.c
thread_c.c

diff --git a/clock.c b/clock.c
index fda66bc000b61b76de45a150466541a46c3a26a1..98d0d02707eae3154a1e80740ec4a99dde12b004 100644 (file)
--- a/clock.c
+++ b/clock.c
@@ -1,6 +1,7 @@
 /* depend: */
 /* cflags: */
 /* linker: main.o mtime.o stat.o -lm -lpthread -lrt */
+/* winlnk: main.o mtime.o stat.o -lm -lpthread */
 
 #include <pthread.h>
 #include <stdio.h>
diff --git a/load.c b/load.c
index 6ef166a1417366ca6352630415e97e4bbba60ecd..94f3591b28ceb989f62c103d25a7406254a408c8 100644 (file)
--- a/load.c
+++ b/load.c
@@ -1,6 +1,7 @@
 /* depend: */
 /* cflags: */
 /* linker: mtime.o -lpthread */
+/* winlnk: mtime.o -lpthread */
 
 #define _GNU_SOURCE
 #include <assert.h>
@@ -164,7 +165,7 @@ double determinant (matrix_t *matrix)
 
 void generate_matrix (matrix_t *matrix)
 {
-    double base = 10 * drand48 () - 5;
+    double base = 10 * rand () / (double)RAND_MAX - 5;
     for (int i = 0; i < matrix->n; i++) {
         for (int j = 0; j < matrix->n; j++) {
             double val = base * (rand () - RAND_MAX / 2) / (double)RAND_MAX;
@@ -327,10 +328,13 @@ int main (int argc, char *argv[])
         /* real-time process */
 
         struct sched_param param = {0};
-        if (sched_getparam (0, &param) != 0) {
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
+       if (sched_getparam (0, &param) != 0) {
             fprintf (stderr, "error: sched_getparam\n");
             return 1;
         }
+#endif
         param.sched_priority = sched_rt_prio;
         int rc = sched_setscheduler (0, SCHED_FIFO, &param); /* non-preemptive */
         // int rc = sched_setscheduler (0, SCHED_RR, &param); /* preemptive */
@@ -343,7 +347,9 @@ int main (int argc, char *argv[])
 
     /* main process */
 
-    if (do_clock)  {
+    if (do_clock) {
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
         cpu_set_t cpu_mask;
         CPU_ZERO (&cpu_mask);
         CPU_SET (0, &cpu_mask);
@@ -351,6 +357,7 @@ int main (int argc, char *argv[])
             fprintf (stderr, "error: sched_setaffinity\n");
             return 1;
         }
+#endif
         while (do_clock--) {
             printf ("\r");
             printf ("Tics clock: %.0fMHz", estimate_tics_clock () / 1e6);
diff --git a/main.c b/main.c
index bb08d9f4123953cc4e123308a778e2de92365fca..2f710f638e00cae9887284e180db4a4b5bf7cafd 100644 (file)
--- a/main.c
+++ b/main.c
@@ -9,7 +9,10 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
+#ifdef _WIN32 /* Windows */
+#else /* Linux */ 
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
 
 #include "stat.h"
@@ -82,6 +85,8 @@ typedef struct {
 void *launch (void *arg)
 {
     launch_param_t *param = (launch_param_t *)arg;
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
     cpu_set_t cpu_mask;
     if (sched_getaffinity (0, sizeof (cpu_set_t), &cpu_mask) != 0) {
         fprintf (stderr, "error: sched_getaffinity\n");
@@ -98,6 +103,7 @@ void *launch (void *arg)
             RETURN (mode, 1);
         }
     }
+#endif
     if (param->synchro) {
         switch (param->target) {
         case 0:
@@ -227,6 +233,9 @@ int main (int argc, char *argv[])
 
     /* real-time process */
 
+#ifdef _WIN32 /* Windows */
+    fprintf (stderr, "No RT scheduling on Windows\n");
+#else /* Linux */
     struct sched_param param = {0};
     if (sched_getparam (0, &param) != 0) {
         fprintf (stderr, "error: sched_getparam\n");
@@ -239,6 +248,7 @@ int main (int argc, char *argv[])
         fprintf (stderr, "error: sched_setscheduler\n");
         return 1;
     }
+#endif
 
     /* main process */
 
@@ -287,6 +297,10 @@ int main (int argc, char *argv[])
         }
         break;
     case 1:
+#ifdef _WIN32 /* Windows */
+        fprintf (stderr, "process mode not supported on Windows\n");
+       return 1;
+#else /* Linux */
         printf ("process mode\n");
         sem_sig = sem_open (SEMSIG, O_CREAT, S_IRUSR|S_IWUSR, 0);
         sem_act = sem_open (SEMACT, O_CREAT, S_IRUSR|S_IWUSR, 0);
@@ -317,6 +331,7 @@ int main (int argc, char *argv[])
                 }
             }
         }
+#endif
         break;
     case 2:
         printf ("ping mode\n");
diff --git a/main.h b/main.h
index f40e2ae2d14d7ab3b30251d31249ed85543ae479..5d3d92385790a5aaec055d076065d7656d5d3827 100644 (file)
--- a/main.h
+++ b/main.h
@@ -4,7 +4,7 @@
 #include "mtime.h"
 
 static int rc = 0;
-#define RETURN(m, v) do { rc = (v); if ((m) == 0) pthread_exit (NULL); else return NULL; } while (0)
+#define RETURN(m, v) rc = (v); if ((m) == 0) pthread_exit (NULL); return NULL;
 
 int init (dts_t *buffer, int nb, int mode);
 
diff --git a/mutex.c b/mutex.c
index ef41367efa192cba1b759147e2c8bd3cbddf50bd..b24af3a8de07a8973681726799c06da0a63fd108 100644 (file)
--- a/mutex.c
+++ b/mutex.c
@@ -1,6 +1,7 @@
 /* depend: */
 /* cflags: */
 /* linker: main.o mtime.o stat.o -lm -lpthread -lrt */
+/* winlnk: main.o mtime.o stat.o -lm -lpthread */
 
 #include <pthread.h>
 #include <semaphore.h>
index 561836942e4b65bd3b3f523d69e4858b2aa0eedf..b1d0b2fb8cd7efcbfc45709748b5591a8c57b05d 100644 (file)
@@ -1,10 +1,14 @@
 /* depend: */
 /* cflags: */
 /* linker: main.o mtime.o stat.o -lm -lpthread -lrt */
+/* winlnk: main.o mtime.o stat.o -lm -lpthread */
 
 #include <errno.h>
 #include <fcntl.h>
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
 #include <mqueue.h>
+#endif
 #include <pthread.h>
 #include <semaphore.h>
 #include <stdio.h>
@@ -62,6 +66,10 @@ int init (dts_t *buffer, int nb, int mode)
     /* communication through mq */
 
     if (current_mode == 1) {
+#ifdef _WIN32 /* Windows */
+       fprintf (stderr, "process mode not supported on Windows\n");
+        return 1;
+#else /* Linux */
         struct mq_attr mq_attr = { 0 };
         mq_attr.mq_flags = 0;
         mq_attr.mq_maxmsg = 1;
@@ -78,6 +86,7 @@ int init (dts_t *buffer, int nb, int mode)
             return 1;
         }
         mq_close (mq);
+#endif
     }
 
     return 0;
@@ -87,11 +96,14 @@ void *ping (__attribute__((unused)) void *arg)
 {
 
     /* open mq for communication betwen process */
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
     mqd_t mq = (current_mode == 1) ? mq_open (MQCOM, O_RDONLY) : -2;
     if (mq == -1) {
         fprintf (stderr, "ping error: mq_open\n");
         RETURN (current_mode, 1);
     }
+#endif
 
     /* main loop */
 
@@ -108,11 +120,14 @@ void *ping (__attribute__((unused)) void *arg)
             /* done by thread pong */
             break;
         case 1:
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
             if (mq_receive (mq, (char *)&ts2, sizeof (ts2), NULL) == -1) {
                 fprintf (stderr, "pong error: mq_receive (%d)\n", i);
                 RETURN (current_mode, 1);
             }
             if (i != -1) deltas[i] = diff_timestamp (&ts2, &ts1);
+#endif
             break;
         case 2:
             /* to do */
@@ -128,7 +143,10 @@ void *ping (__attribute__((unused)) void *arg)
     /* close communication between process */
 
     if (current_mode == 1) {
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
         mq_close (mq);
+#endif
     }
 
     RETURN (current_mode, 0);
@@ -138,12 +156,14 @@ void *pong (__attribute__((unused)) void *arg)
 {
 
     /* open mq for communication betwen process */
-
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
     mqd_t mq = (current_mode == 1) ? mq_open (MQCOM, O_WRONLY) : -2;
     if (mq == -1) {
         fprintf (stderr, "pong error: mq_open\n");
         RETURN (current_mode, 1);
     }
+#endif
 
     /* main loop */
 
@@ -159,10 +179,13 @@ void *pong (__attribute__((unused)) void *arg)
             if (i != -1) deltas[i] = diff_timestamp (&ts2, &ts1);
             break;
         case 1:
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
             if (mq_send (mq, (char *)&ts2, sizeof (ts2), 0) == -1) {
                 fprintf (stderr, "ping error: mq_send (%d)\n", i);
                 RETURN (current_mode, 1);
             }
+#endif
             break;
         case 2:
             /* can't append */
@@ -176,7 +199,10 @@ void *pong (__attribute__((unused)) void *arg)
     /* close communication between process */
 
     if (current_mode == 1) {
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
         mq_close (mq);
+#endif
     }
 
     RETURN (current_mode, 0);
@@ -197,9 +223,12 @@ int finish ()
     /* close queue */
 
     if (current_mode == 1) {
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
         if ((mq_unlink (MQCOM) != 0) && errno != ENOENT) {
             fprintf (stderr, "error: mq_unlink\n");
         }
+#endif
     }
 
     return rc;
index 0eec36a98ffb47d2506816e0c5a235613016e426..2272d68222d9495de3b575604c1f3e7c4075c310 100644 (file)
@@ -1,6 +1,7 @@
 /* depend: */
 /* cflags: */
 /* linker: main.o mtime.o stat.o -lm -lpthread -lrt */
+/* winlnk: main.o mtime.o stat.o -lm -lpthread */
 
 #include <pthread.h>
 #include <semaphore.h>
index ae3be76308b8ece712719a256f689030d912d85a..a72e4611dd70ae12e877f4cbcc0fe0f8a32f49a7 100644 (file)
@@ -1,6 +1,7 @@
 /* depend: */
 /* cflags: */
 /* linker: main.o mtime.o stat.o -lm -lpthread -lrt */
+/* winlnk: main.o mtime.o stat.o -lm -lpthread */
 
 #include <pthread.h>
 #include <semaphore.h>