From: Laurent MAZET Date: Fri, 19 Dec 2025 17:34:35 +0000 (+0100) Subject: adapt tests for windows X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=2d6433e2baff8c9309413f325dfa7359728b0b7f;p=benchmarks.git adapt tests for windows --- diff --git a/clock.c b/clock.c index fda66bc..98d0d02 100644 --- 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 #include diff --git a/load.c b/load.c index 6ef166a..94f3591 100644 --- a/load.c +++ b/load.c @@ -1,6 +1,7 @@ /* depend: */ /* cflags: */ /* linker: mtime.o -lpthread */ +/* winlnk: mtime.o -lpthread */ #define _GNU_SOURCE #include @@ -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, ¶m) != 0) { +#ifdef _WIN32 /* Windows */ +#else /* Linux */ + if (sched_getparam (0, ¶m) != 0) { fprintf (stderr, "error: sched_getparam\n"); return 1; } +#endif param.sched_priority = sched_rt_prio; int rc = sched_setscheduler (0, SCHED_FIFO, ¶m); /* non-preemptive */ // int rc = sched_setscheduler (0, SCHED_RR, ¶m); /* 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 bb08d9f..2f710f6 100644 --- a/main.c +++ b/main.c @@ -9,7 +9,10 @@ #include #include #include +#ifdef _WIN32 /* Windows */ +#else /* Linux */ #include +#endif #include #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, ¶m) != 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 f40e2ae..5d3d923 100644 --- 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 ef41367..b24af3a 100644 --- 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 #include diff --git a/semaphore.c b/semaphore.c index 5618369..b1d0b2f 100644 --- a/semaphore.c +++ b/semaphore.c @@ -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 #include +#ifdef _WIN32 /* Windows */ +#else /* Linux */ #include +#endif #include #include #include @@ -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; diff --git a/thread_c+j.c b/thread_c+j.c index 0eec36a..2272d68 100644 --- a/thread_c+j.c +++ b/thread_c+j.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 #include diff --git a/thread_c.c b/thread_c.c index ae3be76..a72e461 100644 --- a/thread_c.c +++ b/thread_c.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 #include