Skip to content

Commit

Permalink
tests: Update to new API
Browse files Browse the repository at this point in the history
Commit 6814992 ("pi_cond: Update API to support process shared
condvar use cases") introduced an API change in order to address issue
"dvhart#22 Current librtpi API breaks down for process shared condvars"[1].

Make the necessary changes to port all tests to the new API:

  - remove the mutex parameter when initializing the condvar:
    DEFINE_PI_COND(), pi_cond_init().

  - pass a pointer to the associated mutex for pi_cond_wait(),
    pi_cond_timedwait(), pi_cond_signal(), and pi_cond_broadcast()
    calls.

[1] dvhart#22

Signed-off-by: Gratian Crisan <[email protected]>
  • Loading branch information
gratian committed Jan 22, 2020
1 parent 6814992 commit 69c49f4
Show file tree
Hide file tree
Showing 23 changed files with 92 additions and 92 deletions.
4 changes: 2 additions & 2 deletions tests/glibc-tests/tst-cond-except.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void *thr(void *arg)
ret = pi_mutex_init(&mutex, 0);
CHECK_RETURN_VAL_OR_FAIL(ret, "pi_mutex_init");

ret = pi_cond_init(&cond, &mutex, 0);
ret = pi_cond_init(&cond, 0);
CHECK_RETURN_VAL_OR_FAIL(ret, "pi_cond_init");

puts("th: Init done, entering wait...");
Expand All @@ -59,7 +59,7 @@ void *thr(void *arg)
ret = pi_mutex_lock(&mutex);
CHECK_RETURN_VAL_OR_FAIL(ret, "pi_mutex_lock");
while (1) {
ret = pi_cond_wait(&cond);
ret = pi_cond_wait(&cond, &mutex);
CHECK_RETURN_VAL_OR_FAIL(ret, "pi_cond_wait");
}
pthread_cleanup_pop(1);
Expand Down
6 changes: 3 additions & 3 deletions tests/glibc-tests/tst-cond1.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "rtpi.h"

static DEFINE_PI_MUTEX(mut, 0);
static DEFINE_PI_COND(cond, &mut, 0);
static DEFINE_PI_COND(cond, 0);

static void *tf(void *p)
{
Expand All @@ -35,7 +35,7 @@ static void *tf(void *p)

puts("child: got mutex; signalling");

pi_cond_signal(&cond);
pi_cond_signal(&cond, &mut);

puts("child: unlock");

Expand Down Expand Up @@ -72,7 +72,7 @@ static int do_test(void)
/* This test will fail on spurious wake-ups, which are allowed; however,
the current implementation shouldn't produce spurious wake-ups in the
scenario we are testing here. */
err = pi_cond_wait(&cond);
err = pi_cond_wait(&cond, &mut);
if (err != 0)
error(EXIT_FAILURE, err, "parent: cannot wait fir signal");

Expand Down
6 changes: 3 additions & 3 deletions tests/glibc-tests/tst-cond10.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define ROUNDS 100

static DEFINE_PI_MUTEX(mut, 0);
static DEFINE_PI_COND(cond, &mut, 0);
static DEFINE_PI_COND(cond, 0);
static pthread_barrier_t bN1;
static pthread_barrier_t b2;

Expand All @@ -45,7 +45,7 @@ static void *tf(void *p)
exit(1);
}

if (pi_cond_wait(&cond) != 0) {
if (pi_cond_wait(&cond, &mut) != 0) {
puts("child: cond_wait failed");
exit(1);
}
Expand Down Expand Up @@ -114,7 +114,7 @@ static int do_test(void)
puts("parent: mutex_lock failed");
exit(1);
}
if (pi_cond_signal(&cond) != 0) {
if (pi_cond_signal(&cond, &mut) != 0) {
puts("cond_signal failed");
exit(1);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/glibc-tests/tst-cond11.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static int run_test(clockid_t cl)
return 1;
}

if (pi_cond_init(&cond, &mut, flags) != 0) {
if (pi_cond_init(&cond, flags) != 0) {
puts("cond_init failed");
return 1;
}
Expand All @@ -71,7 +71,7 @@ static int run_test(clockid_t cl)
/* Wait one second. */
++ts.tv_sec;

int e = pi_cond_timedwait(&cond, &ts);
int e = pi_cond_timedwait(&cond, &mut, &ts);
if (e == 0) {
puts("cond_timedwait succeeded");
return 1;
Expand Down
8 changes: 4 additions & 4 deletions tests/glibc-tests/tst-cond12.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static int do_test(void)
return 1;
}

if (pi_cond_init(&p->c, &p->m, RTPI_COND_PSHARED) != 0) {
if (pi_cond_init(&p->c, RTPI_COND_PSHARED) != 0) {
puts("mutex_init failed");
return 1;
}
Expand Down Expand Up @@ -107,13 +107,13 @@ static int do_test(void)
p->var = 0;

#ifndef USE_COND_SIGNAL
if (pi_cond_broadcast(&p->c) != 0) {
if (pi_cond_broadcast(&p->c, &p->m) != 0) {
puts("child: cond_broadcast failed");
kill(getppid(), SIGKILL);
exit(1);
}
#else
if (pi_cond_signal(&p->c) != 0) {
if (pi_cond_signal(&p->c, &p->m) != 0) {
puts("child: cond_signal failed");
kill(getppid(), SIGKILL);
exit(1);
Expand All @@ -130,7 +130,7 @@ static int do_test(void)
}

do
pi_cond_wait(&p->c);
pi_cond_wait(&p->c, &p->m);
while (p->var != 0);

if (TEMP_FAILURE_RETRY(waitpid(pid, NULL, 0)) != pid) {
Expand Down
6 changes: 3 additions & 3 deletions tests/glibc-tests/tst-cond16.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "rtpi.h"

DEFINE_PI_MUTEX(lock, 0);
DEFINE_PI_COND(cv, &lock, 0);
DEFINE_PI_COND(cv, 0);
bool n, exiting;
FILE *f;
enum { count = 8 }; /* Number of worker threads. */
Expand All @@ -39,7 +39,7 @@ void *tf(void *dummy)
while (loop) {
pi_mutex_lock(&lock);
while (n && !exiting)
pi_cond_wait(&cv);
pi_cond_wait(&cv, &lock);
n = true;
pi_mutex_unlock(&lock);

Expand All @@ -50,7 +50,7 @@ void *tf(void *dummy)
if (exiting)
loop = false;

pi_cond_broadcast(&cv);
pi_cond_broadcast(&cv, &lock);
pi_mutex_unlock(&lock);
}

Expand Down
10 changes: 5 additions & 5 deletions tests/glibc-tests/tst-cond18.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "rtpi.h"

DEFINE_PI_MUTEX(lock, 0);
DEFINE_PI_COND(cv, &lock, 0);
DEFINE_PI_COND(cv, 0);
bool exiting;
int fd, spins, nn;
enum { count = 8 }; /* Number of worker threads. */
Expand All @@ -47,17 +47,17 @@ void *tf(void *id)
int njobs = rand() % (count + 1);
nn = njobs;
if ((rand() % 30) == 0)
pi_cond_broadcast(&cv);
pi_cond_broadcast(&cv, &lock);
else
while (njobs--)
pi_cond_signal(&cv);
pi_cond_signal(&cv, &lock);
}

pi_cond_broadcast(&cv);
pi_cond_broadcast(&cv, &lock);
} else {
while (!exiting) {
while (!nn && !exiting)
pi_cond_wait(&cv);
pi_cond_wait(&cv, &lock);
--nn;
pi_mutex_unlock(&lock);

Expand Down
6 changes: 3 additions & 3 deletions tests/glibc-tests/tst-cond19.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "rtpi.h"

static DEFINE_PI_MUTEX(mut, 0);
static DEFINE_PI_COND(cond, &mut, 0);
static DEFINE_PI_COND(cond, 0);

static int do_test(void)
{
Expand All @@ -39,7 +39,7 @@ static int do_test(void)

ts.tv_nsec = -1;

int e = pi_cond_timedwait(&cond, &ts);
int e = pi_cond_timedwait(&cond, &mut, &ts);
if (e == 0) {
puts("first cond_timedwait did not fail");
result = 1;
Expand All @@ -50,7 +50,7 @@ static int do_test(void)

ts.tv_nsec = 2000000000;

e = pi_cond_timedwait(&cond, &ts);
e = pi_cond_timedwait(&cond, &mut, &ts);
if (e == 0) {
puts("second cond_timedwait did not fail");
result = 1;
Expand Down
6 changes: 3 additions & 3 deletions tests/glibc-tests/tst-cond2.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "rtpi.h"

static DEFINE_PI_MUTEX(mut, 0);
static DEFINE_PI_COND(cond, &mut, 0);
static DEFINE_PI_COND(cond, 0);
static pthread_barrier_t bar;

static void *tf(void *a)
Expand All @@ -47,7 +47,7 @@ static void *tf(void *a)

printf("child %d: wait\n", i);

err = pi_cond_wait(&cond);
err = pi_cond_wait(&cond, &mut);
if (err != 0)
error(EXIT_FAILURE, err, "child %d: failed to wait", i);

Expand Down Expand Up @@ -121,7 +121,7 @@ static int do_test(void)
puts("broadcast");

/* Wake up all threads. */
err = pi_cond_broadcast(&cond);
err = pi_cond_broadcast(&cond, &mut);
if (err != 0)
error(EXIT_FAILURE, err, "parent: broadcast failed");

Expand Down
22 changes: 11 additions & 11 deletions tests/glibc-tests/tst-cond20.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#define N 10
#define ROUNDS 1000
static DEFINE_PI_MUTEX(mut, 0);
static DEFINE_PI_COND(cond, &mut, 0);
static DEFINE_PI_COND(cond2, &mut, 0);
static DEFINE_PI_COND(cond, 0);
static DEFINE_PI_COND(cond2, 0);
static pthread_barrier_t b;
static int count;

Expand All @@ -41,7 +41,7 @@ static void *tf(void *p)
pi_mutex_lock(&mut);

if (++count == N)
pi_cond_signal(&cond2);
pi_cond_signal(&cond2, &mut);

#ifdef TIMED
struct timespec ts;
Expand All @@ -52,9 +52,9 @@ static void *tf(void *p)
exit(1);
}
ts.tv_sec += 3;
pi_cond_timedwait(&cond, &ts);
pi_cond_timedwait(&cond, &mut, &ts);
#else
pi_cond_wait(&cond);
pi_cond_wait(&cond, &mut);
#endif

pi_mutex_unlock(&mut);
Expand Down Expand Up @@ -96,18 +96,18 @@ static int do_test(void)
for (i = 0; i < ROUNDS; ++i) {
/* Make sure we discard spurious wake-ups. */
do
pi_cond_wait(&cond2);
pi_cond_wait(&cond2, &mut);
while (count != N);

if (i & 2)
pi_cond_broadcast(&cond);
pi_cond_broadcast(&cond, &mut);
else if (i & 4)
for (j = 0; j < N; ++j)
pi_cond_signal(&cond);
pi_cond_signal(&cond, &mut);
else {
for (j = 0; j < (i / 8) % N; ++j)
pi_cond_signal(&cond);
pi_cond_broadcast(&cond);
pi_cond_signal(&cond, &mut);
pi_cond_broadcast(&cond, &mut);
}

pi_mutex_unlock(&mut);
Expand Down Expand Up @@ -138,7 +138,7 @@ static int do_test(void)
}

count = 0;
err = pi_cond_init(&cond, &mut, 0);
err = pi_cond_init(&cond, 0);
if (err) {
printf("pi_cond_init failed: %s\n", strerror(err));
return 1;
Expand Down
8 changes: 4 additions & 4 deletions tests/glibc-tests/tst-cond22.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

static pthread_barrier_t b;
static DEFINE_PI_MUTEX(m, 0);
static DEFINE_PI_COND(c, &m, 0);
static DEFINE_PI_COND(c, 0);

static void cl(void *arg)
{
Expand All @@ -30,7 +30,7 @@ static void *tf(void *arg)
on the mutex. In this case the beginning of the second cond_wait
call will cause the cancellation to happen. */
do
if (pi_cond_wait(&c) != 0) {
if (pi_cond_wait(&c, &m) != 0) {
printf("%s: cond_wait failed\n", __func__);
exit(1);
}
Expand Down Expand Up @@ -66,7 +66,7 @@ static int do_test(void)
puts("1st mutex_lock failed");
return 1;
}
if (pi_cond_signal(&c) != 0) {
if (pi_cond_signal(&c, &m) != 0) {
puts("1st cond_signal failed");
return 1;
}
Expand Down Expand Up @@ -101,7 +101,7 @@ static int do_test(void)
puts("2nd mutex_lock failed");
return 1;
}
if (pi_cond_signal(&c) != 0) {
if (pi_cond_signal(&c, &m) != 0) {
puts("2nd cond_signal failed");
return 1;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/glibc-tests/tst-cond24.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void *thread_fun_timed(void *arg)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
ts.tv_sec += 20;
rv = pi_cond_timedwait(&cond, &ts);
rv = pi_cond_timedwait(&cond, &mutex, &ts);

/* There should be no timeout either. */
if (rv) {
Expand Down Expand Up @@ -103,7 +103,7 @@ void *thread_fun(void *arg)
}

while (!pending) {
rv = pi_cond_wait(&cond);
rv = pi_cond_wait(&cond, &mutex);

if (rv) {
printf("pi_cond_wait: %s(%d)\n",
Expand Down Expand Up @@ -145,7 +145,7 @@ static int do_test_wait(threadfunc f)
return 1;
}

rv = pi_cond_init(&cond, &mutex, 0);
rv = pi_cond_init(&cond, 0);
if (rv) {
printf("pi_cond_init: %s(%d)\n", strerror(rv), rv);
return 1;
Expand All @@ -172,7 +172,7 @@ static int do_test_wait(threadfunc f)
printf("counter: %d\n", counter);
pending += 1;

rv = pi_cond_signal(&cond);
rv = pi_cond_signal(&cond, &mutex);
if (rv) {
printf("pi_cond_signal: %s(%d)\n", strerror(rv),
rv);
Expand Down
Loading

0 comments on commit 69c49f4

Please sign in to comment.