Hi,
This Patch fixes the pi-tests to use librttest infrastructure.
Also Addresses the issues Sebastien has Brought out.
Thanks Sebastien.
Signed-Off-By: Chirag <[EMAIL PROTECTED]>
---
testcases/realtime/func/pi-tests/sbrk_mutex.c | 22 +---
testcases/realtime/func/pi-tests/testpi-1.c | 135 ++---------------------
testcases/realtime/func/pi-tests/testpi-2.c | 141 +++---------------------
testcases/realtime/func/pi-tests/testpi-4.c | 147 ++++---------------------
testcases/realtime/func/pi-tests/testpi-5.c | 8 +
testcases/realtime/func/pi-tests/testpi-6.c | 7 +
6 files changed, 61 insertions(+), 399 deletions(-)
diff --git a/testcases/realtime/func/pi-tests/sbrk_mutex.c
b/testcases/realtime/func/pi-tests/sbrk_mutex.c
index 5d6aeb5..64f8e3d 100644
--- a/testcases/realtime/func/pi-tests/sbrk_mutex.c
+++ b/testcases/realtime/func/pi-tests/sbrk_mutex.c
@@ -55,7 +55,6 @@
#define DELAY 1000 /* how long to sleep in the worker thread in us */
static pthread_mutex_t *mutexes[NUM_MUTEXES];
-static pthread_t threads[NUM_THREADS];
static int run_jvmsim=0;
@@ -100,7 +99,7 @@ void *worker_thread(void *arg)
usleep(DELAY);
- if (_dbg_lvl)
+ //if (_dbg_lvl)
printf("thread %ld @ %d\n", (long)arg, i);
}
return NULL;
@@ -149,28 +148,13 @@ int main(int argc, char* argv[])
/* start children threads to walk the array, grabbing the locks */
for (t = 0; t < NUM_THREADS; t++) {
- pthread_attr_t attr;
- struct sched_param param;
-
- param.sched_priority = sched_get_priority_min(SCHED_FIFO);
- pthread_attr_init(&attr);
- pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED);
- pthread_attr_setschedparam(&attr, ¶m);
- pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
-
- if (pthread_create(&threads[t], &attr, worker_thread,
(void*)t)) {
- perror("pthread_create failed");
+ if (create_fifo_thread(worker_thread, (void*)t,
sched_get_priority_min(SCHED_FIFO))) {
}
-
- pthread_attr_destroy(&attr);
}
/* wait for the children to complete */
printf("joining threads\n");
- for (t = 0; t < NUM_THREADS; t++) {
- pthread_join(threads[t], NULL);
- }
-
+ join_threads();
/* destroy all the mutexes */
for (m = 0; m < NUM_MUTEXES; m++) {
if (mutexes[m]) {
diff --git a/testcases/realtime/func/pi-tests/testpi-1.c
b/testcases/realtime/func/pi-tests/testpi-1.c
index 0c0b62a..75a7879 100644
--- a/testcases/realtime/func/pi-tests/testpi-1.c
+++ b/testcases/realtime/func/pi-tests/testpi-1.c
@@ -88,29 +88,10 @@ typedef void* (*entrypoint_t)(void*);
pthread_mutex_t glob_mutex;
-/*typedef struct thread {
- int priority;
- int policy;
- entrypoint_t func;
- pthread_attr_t attr;
- pthread_t handle;
- pthread_mutex_t mutex;
- pthread_cond_t cond;
- int flags;
- int count;
-} Thread;*/
-
-typedef struct thread Thread;
-
-Thread arg1, arg2, arg3, arg4, arg5;
-
-int strartThread(Thread* thr);
-void stopThread(Thread* thr);
-void joinThread(Thread* thr);
void* func_nonrt(void* arg)
{
- Thread* pthr = (Thread*)arg;
+ struct thread* pthr = (struct thread*)arg;
int rc, i, j, policy, tid = gettid();
struct sched_param schedp;
// unsigned long mask = 1;
@@ -127,7 +108,7 @@ void* func_nonrt(void* arg)
printf("Thread started %d on CPU %ld\n", pthr->priority, (long)mask.__bits);
pthread_getschedparam(pthr->pthread, &policy, &schedp);
- printf("Thread running %d\n", pthr->priority);
+ printf("Thread running %d\n", schedp.sched_priority);
pthread_mutex_lock(&glob_mutex);
printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",
pthr->priority,
@@ -149,7 +130,7 @@ void* func_nonrt(void* arg)
pthread_mutex_unlock(&(pthr->mutex));
}
if ((pthr->flags & THREAD_STOP) != 0 ) {
- printf("Stopping thread %d\n", pthr->priority);
+ printf("Stopping thread %d\n", schedp.sched_priority);
break;
}
}
@@ -159,7 +140,7 @@ void* func_nonrt(void* arg)
void* func_rt(void* arg)
{
- Thread* pthr = (Thread*)arg;
+ struct thread* pthr = (struct thread* )arg;
int rc, i, j, policy, tid = gettid();
struct sched_param schedp;
cpu_set_t mask;
@@ -178,7 +159,7 @@ void* func_rt(void* arg)
pthread_barrier_wait(&barrier);
- printf("Thread running %d\n", pthr->priority);
+ printf("Thread running %d\n", schedp.sched_priority);
pthread_mutex_lock(&glob_mutex);
printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",
pthr->priority,
policy, schedp.sched_priority);
@@ -202,7 +183,7 @@ void* func_rt(void* arg)
pthread_mutex_unlock(&(pthr->mutex));
}
if ((pthr->flags & THREAD_STOP) != 0 ) {
- printf("Stopping thread %d\n", pthr->priority);
+ printf("Stopping thread %d\n", schedp.sched_priority);
break;
}
}
@@ -212,7 +193,7 @@ void* func_rt(void* arg)
void* func_noise(void* arg)
{
- Thread* pthr = (Thread*)arg;
+ struct thread* pthr = (struct thread* )arg;
int rc, i, j, policy, tid = gettid();
struct sched_param schedp;
cpu_set_t mask;
@@ -231,7 +212,7 @@ void* func_noise(void* arg)
pthread_barrier_wait(&barrier);
- printf("Noise Thread running %d\n", pthr->priority);
+ printf("Noise Thread running %d\n", schedp.sched_priority);
for (i=0;i<10000;i++) {
if (i%100 == 0) {
@@ -246,83 +227,10 @@ void* func_noise(void* arg)
pthread_mutex_lock(&(pthr->mutex));
pthread_mutex_unlock(&(pthr->mutex));
}
- if ((pthr->flags & THREAD_STOP) != 0 ) {
- printf("Stopping Noise thread %d\n", pthr->priority);
- break;
- }
}
return NULL;
}
-int startThread(Thread* thrd)
-{
- struct sched_param schedp;
- pthread_condattr_t condattr;
- int retc, policy, inherit;
-
- printf("Start thread priority %d\n", thrd->priority);
- if (pthread_attr_init(&(thrd->attr)) != 0) {
- printf("Attr init failed");
- exit(2);
- }
- thrd->flags = 0;
- memset(&schedp, 0, sizeof(schedp));
- schedp.sched_priority = thrd->priority;
- policy = thrd->policy;
-
- if (pthread_attr_setschedpolicy(&(thrd->attr), policy) != 0) {
- printf("Can't set policy %d\n", policy);
- }
- if (pthread_attr_getschedpolicy(&(thrd->attr), &policy) != 0) {
- printf("Can't get policy\n");
- } else {
- printf("Policy in attribs is %d\n", policy);
- }
- if (pthread_attr_setschedparam(&(thrd->attr), &schedp) != 0) {
- printf("Can't set params");
- }
- if (pthread_attr_getschedparam(&(thrd->attr), &schedp) != 0) {
- printf("Can't get params");
- } else {
- printf("Priority in attribs is %d\n", schedp.sched_priority);
- }
- if (pthread_attr_setinheritsched(&(thrd->attr), PTHREAD_EXPLICIT_SCHED) !=
0) {
- printf("Can't set inheritsched\n");
- }
- if (pthread_attr_getinheritsched(&(thrd->attr), &inherit) != 0) {
- printf("Can't get inheritsched\n");
- } else {
- printf("inherit sched in attribs is %d\n", inherit);
- }
- if ((retc = pthread_mutex_init(&(thrd->mutex), NULL)) != 0) {
- printf("Failed to init mutex: %d\n", retc);
- }
- if (pthread_condattr_init(&condattr) != 0) {
- printf("Failed to init condattr\n");
- }
- if (pthread_cond_init(&(thrd->cond), &condattr) != 0) {
- printf("Failed to init cond\n");
- }
- retc = pthread_create(&(thrd->pthread),&(thrd->attr), thrd->func, thrd);
- printf("Create returns %d\n\n", retc);
- return retc;
-}
-
-void stopThread(Thread* thr)
-{
- thr->flags += THREAD_STOP;
- joinThread(thr);
-}
-
-void joinThread(Thread* thr)
-{
- void* ret = NULL;
- if (pthread_join(thr->pthread, &ret) != 0) {
- printf("Join failed\n");
- }
- printf("Join gave %p\n", ret);
-}
-
/*
* Test pthread creation at different thread priorities.
*/
@@ -354,13 +262,6 @@ int main(int argc, char* argv[]) {
exit(-1);
}
retc = sched_getaffinity(0, sizeof(mask), &mask);
-
- arg1.policy = SCHED_OTHER; arg1.priority = 0; arg1.func = func_nonrt;
- arg2.policy = SCHED_RR; arg2.priority = 20; arg2.func = func_rt;
- arg3.policy = SCHED_RR; arg3.priority = 30; arg3.func = func_rt;
- arg4.policy = SCHED_RR; arg4.priority = 40; arg4.func = func_rt;
- arg5.policy = SCHED_RR; arg5.priority = 40; arg5.func = func_noise;
-
for (i=0;i<argc;i++) {
if (strcmp(argv[i],"nopi") == 0) nopi = 1;
}
@@ -384,23 +285,15 @@ int main(int argc, char* argv[]) {
}
}
- startThread(&arg1);
- startThread(&arg2);
- startThread(&arg3);
- startThread(&arg4);
- startThread(&arg5);
+ create_other_thread(func_nonrt,NULL);
+ create_rr_thread(func_rt, NULL, 20);
+ create_rr_thread(func_rt, NULL, 30);
+ create_rr_thread(func_rt, NULL, 40);
+ create_rr_thread(func_noise, NULL, 40);
sleep(10);
-
+ join_threads();
printf("Stopping threads\n");
- stopThread(&arg1);
- stopThread(&arg2);
- stopThread(&arg3);
- stopThread(&arg4);
- stopThread(&arg5);
-
- printf("Thread counts %d %d %d %d %d\n",arg1.id, arg2.id,
- arg3.id, arg4.id, arg5.id);
printf("Done\n");
printf("Criteria:Low Priority Thread should Preempt Higher Priority Noise
Thread\n");
diff --git a/testcases/realtime/func/pi-tests/testpi-2.c
b/testcases/realtime/func/pi-tests/testpi-2.c
index 9c60e68..ebd3363 100644
--- a/testcases/realtime/func/pi-tests/testpi-2.c
+++ b/testcases/realtime/func/pi-tests/testpi-2.c
@@ -87,29 +87,9 @@ typedef void* (*entrypoint_t)(void*);
pthread_mutex_t glob_mutex;
-/*typedef struct thread {
- int priority;
- int policy;
- entrypoint_t func;
- pthread_attr_t attr;
- pthread_t handle;
- pthread_mutex_t mutex;
- pthread_cond_t cond;
- int flags;
- int count;
-} Thread;*/
-
-typedef struct thread Thread;
-
-Thread arg1, arg2, arg3, arg4, arg5;
-
-int strartThread(Thread* thr);
-void stopThread(Thread* thr);
-void joinThread(Thread* thr);
-
void* func_lowrt(void* arg)
{
- Thread* pthr = (Thread*)arg;
+ struct thread* pthr = (struct thread* )arg ;
int rc, i, j, policy, tid = gettid();
struct sched_param schedp;
cpu_set_t mask;
@@ -125,7 +105,7 @@ void* func_lowrt(void* arg)
printf("Thread started %d on CPU %ld\n", pthr->priority, (long)mask.__bits);
pthread_getschedparam(pthr->pthread, &policy, &schedp);
- printf("Thread running %d\n", pthr->priority);
+ printf("Thread running %d\n", schedp.sched_priority);
pthread_mutex_lock(&glob_mutex);
printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",
pthr->priority,
@@ -147,7 +127,7 @@ void* func_lowrt(void* arg)
pthread_mutex_unlock(&(pthr->mutex));
}
if ((pthr->flags & THREAD_STOP) != 0 ) {
- printf("Stopping thread %d\n", pthr->priority);
+ printf("Stopping thread %d\n", schedp.sched_priority);
break;
}
}
@@ -157,7 +137,7 @@ void* func_lowrt(void* arg)
void* func_rt(void* arg)
{
- Thread* pthr = (Thread*)arg;
+ struct thread* pthr = (struct thread* )arg ;
int rc, i, j, policy, tid = gettid();
struct sched_param schedp;
cpu_set_t mask;
@@ -177,7 +157,7 @@ void* func_rt(void* arg)
/* Let the lower prio RT task grab the lock */
pthread_barrier_wait(&barrier);
- printf("Thread running %d\n", pthr->priority);
+ printf("Thread running %d\n", schedp.sched_priority);
pthread_mutex_lock(&glob_mutex);
printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",
pthr->priority,
policy, schedp.sched_priority);
@@ -201,7 +181,7 @@ void* func_rt(void* arg)
pthread_mutex_unlock(&(pthr->mutex));
}
if ((pthr->flags & THREAD_STOP) != 0 ) {
- printf("Stopping thread %d\n", pthr->priority);
+ printf("Stopping thread %d\n", schedp.sched_priority);
break;
}
}
@@ -211,7 +191,7 @@ void* func_rt(void* arg)
void* func_noise(void* arg)
{
- Thread* pthr = (Thread*)arg;
+ struct thread* pthr = (struct thread* )arg ;
int rc, i, j, policy, tid = gettid();
struct sched_param schedp;
cpu_set_t mask;
@@ -230,13 +210,13 @@ void* func_noise(void* arg)
pthread_barrier_wait(&barrier);
- printf("Noise Thread running %d\n", pthr->priority);
+ printf("Noise Thread running %d\n", schedp.sched_priority);
for (i=0;i<10000;i++) {
if (i%100 == 0) {
sched_getparam(tid, &schedp);
policy = sched_getscheduler(tid);
- printf("Noise Thread %d(%d) loop %d pthread pol %d pri %d\n", tid,
pthr->priority, i,
+ printf("Noise Thread %d(%d) loop %d pthread pol %d pri %d\n", tid,
pthr->priority ,i,
policy, schedp.sched_priority);
fflush(NULL);
}
@@ -245,83 +225,10 @@ void* func_noise(void* arg)
pthread_mutex_lock(&(pthr->mutex));
pthread_mutex_unlock(&(pthr->mutex));
}
- if ((pthr->flags & THREAD_STOP) != 0 ) {
- printf("Stopping Noise thread %d\n", pthr->priority);
- break;
- }
}
return NULL;
}
-int startThread(Thread* thrd)
-{
- struct sched_param schedp;
- pthread_condattr_t condattr;
- int retc, policy, inherit;
-
- printf("Start thread priority %d\n", thrd->priority);
- if (pthread_attr_init(&(thrd->attr)) != 0) {
- printf("Attr init failed");
- exit(2);
- }
- thrd->flags = 0;
- memset(&schedp, 0, sizeof(schedp));
- schedp.sched_priority = thrd->priority;
- policy = thrd->policy;
-
- if (pthread_attr_setschedpolicy(&(thrd->attr), policy) != 0) {
- printf("Can't set policy %d\n", policy);
- }
- if (pthread_attr_getschedpolicy(&(thrd->attr), &policy) != 0) {
- printf("Can't get policy\n");
- } else {
- printf("Policy in attribs is %d\n", policy);
- }
- if (pthread_attr_setschedparam(&(thrd->attr), &schedp) != 0) {
- printf("Can't set params");
- }
- if (pthread_attr_getschedparam(&(thrd->attr), &schedp) != 0) {
- printf("Can't get params");
- } else {
- printf("Priority in attribs is %d\n", schedp.sched_priority);
- }
- if (pthread_attr_setinheritsched(&(thrd->attr), PTHREAD_EXPLICIT_SCHED) !=
0) {
- printf("Can't set inheritsched\n");
- }
- if (pthread_attr_getinheritsched(&(thrd->attr), &inherit) != 0) {
- printf("Can't get inheritsched\n");
- } else {
- printf("inherit sched in attribs is %d\n", inherit);
- }
- if ((retc = pthread_mutex_init(&(thrd->mutex), NULL)) != 0) {
- printf("Failed to init mutex: %d\n", retc);
- }
- if (pthread_condattr_init(&condattr) != 0) {
- printf("Failed to init condattr\n");
- }
- if (pthread_cond_init(&(thrd->cond), &condattr) != 0) {
- printf("Failed to init cond\n");
- }
- retc = pthread_create(&(thrd->pthread),&(thrd->attr), thrd->func, thrd);
- printf("Create returns %d\n\n", retc);
- return retc;
-}
-
-void stopThread(Thread* thr)
-{
- thr->flags += THREAD_STOP;
- joinThread(thr);
-}
-
-void joinThread(Thread* thr)
-{
- void* ret = NULL;
- if (pthread_join(thr->pthread, &ret) != 0) {
- printf("Join failed\n");
- }
- printf("Join gave %p\n", ret);
-}
-
/*
* Test pthread creation at different thread priorities.
*/
@@ -350,16 +257,8 @@ int main(int argc, char* argv[]) {
}
retc = sched_getaffinity(0, sizeof(mask), &mask);
- arg1.policy = SCHED_RR; arg1.priority = 10; arg1.func = func_lowrt;
- arg2.policy = SCHED_RR; arg2.priority = 20; arg2.func = func_rt;
- arg3.policy = SCHED_FIFO; arg3.priority = 30; arg3.func = func_rt;
- arg4.policy = SCHED_FIFO; arg4.priority = 40; arg4.func = func_rt;
- arg5.policy = SCHED_RR; arg5.priority = 40; arg5.func = func_noise;
-
for (i=0;i<argc;i++) {
if (strcmp(argv[i],"nopi") == 0) nopi = 1;
- if (strcmp(argv[i],"SCHED_RR") == 0) arg5.policy = SCHED_RR;
- if (strcmp(argv[i],"SCHED_FIFO") == 0) arg5.policy = SCHED_FIFO;
}
if (!nopi) {
@@ -383,24 +282,16 @@ int main(int argc, char* argv[]) {
printf("pthread_barrier_init failed: %s\n", strerror(retc));
exit(retc);
}
+ create_rr_thread(func_lowrt, NULL, 10);
+ create_rr_thread(func_rt, NULL, 20);
+ create_fifo_thread(func_rt, NULL, 30);
+ create_fifo_thread(func_rt, NULL, 40);
+ create_rr_thread(func_noise, NULL, 40);
- startThread(&arg1);
- startThread(&arg2);
- startThread(&arg3);
- startThread(&arg4);
- startThread(&arg5);
-
- sleep(10);
+ sleep(10);
printf("Stopping threads\n");
- stopThread(&arg1);
- stopThread(&arg2);
- stopThread(&arg3);
- stopThread(&arg4);
- stopThread(&arg5);
-
- printf("Thread counts %d %d %d %d %d\n",arg1.id, arg2.id,
- arg3.id, arg4.id, arg5.id);
+ join_threads();
printf("Done\n");
printf("Criteria: Low Priority Thread and High Priority Thread should prempt
each other multiple times\n");
return 0;
diff --git a/testcases/realtime/func/pi-tests/testpi-4.c
b/testcases/realtime/func/pi-tests/testpi-4.c
index f805e61..2852e2c 100644
--- a/testcases/realtime/func/pi-tests/testpi-4.c
+++ b/testcases/realtime/func/pi-tests/testpi-4.c
@@ -88,35 +88,17 @@ typedef void* (*entrypoint_t)(void*);
pthread_mutex_t *glob_mutex;
-/*typedef struct thread {
- int priority;
- int policy;
- entrypoint_t func;
- pthread_attr_t attr;
- pthread_t handle;
- pthread_mutex_t mutex;
- pthread_cond_t cond;
- int flags;
- int count;
-} Thread;*/
-
-typedef struct thread Thread;
-
-Thread arg1, arg2, arg3, arg4, arg5;
-
-int strartThread(Thread* thr);
-void stopThread(Thread* thr);
-void joinThread(Thread* thr);
-
void* func_nonrt(void* arg)
{
- Thread* pthr = (Thread*)arg;
+
+ struct thread* pthr = (struct thread* )arg;
int rc, i, j, policy, tid = gettid();
struct sched_param schedp;
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(0, &mask);
-
+
+ pthr->pthread = pthread_self();
rc = sched_setaffinity(0, sizeof(mask), &mask);
if (rc < 0) {
printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
@@ -130,7 +112,7 @@ void* func_nonrt(void* arg)
pthread_mutex_lock(glob_mutex);
printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",
pthr->priority,
- policy, schedp.sched_priority);
+ policy, pthr->priority);
pthread_barrier_wait(&barrier);
for (i=0;i<10000;i++) {
@@ -138,7 +120,7 @@ void* func_nonrt(void* arg)
sched_getparam(tid, &schedp);
policy = sched_getscheduler(tid);
printf("Thread %d(%d) loop %d pthread pol %d pri %d\n", tid,
pthr->priority, i,
- policy, schedp.sched_priority);
+ policy, pthr->priority);
fflush(NULL);
}
pthr->id++;
@@ -146,10 +128,6 @@ void* func_nonrt(void* arg)
pthread_mutex_lock(&(pthr->mutex));
pthread_mutex_unlock(&(pthr->mutex));
}
- if ((pthr->flags & THREAD_STOP) != 0 ) {
- printf("Stopping thread %d\n", pthr->priority);
- break;
- }
}
pthread_mutex_unlock(glob_mutex);
return NULL;
@@ -157,13 +135,14 @@ void* func_nonrt(void* arg)
void* func_rt(void* arg)
{
- Thread* pthr = (Thread*)arg;
+ struct thread* pthr = (struct thread* )arg;
int rc, i, j, policy, tid = gettid();
struct sched_param schedp;
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(0, &mask);
-
+
+ pthr->pthread = pthread_self();
rc = sched_setaffinity(0, sizeof(mask), &mask);
if (rc < 0) {
printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
@@ -178,7 +157,7 @@ void* func_rt(void* arg)
printf("Thread running %d\n", pthr->priority);
pthread_mutex_lock(glob_mutex);
printf("Thread %d at start pthread pol %d pri %d - Got global lock\n",
pthr->priority,
- policy, schedp.sched_priority);
+ policy, pthr->priority);
/* we just use the mutex as something to slow things down */
/* say who we are and then do nothing for a while. The aim
@@ -190,7 +169,7 @@ void* func_rt(void* arg)
sched_getparam(tid, &schedp);
policy = sched_getscheduler(tid);
printf("Thread %d(%d) loop %d pthread pol %d pri %d\n", tid,
pthr->priority, i,
- policy, schedp.sched_priority);
+ policy, pthr->priority);
fflush(NULL);
}
pthr->id++;
@@ -209,13 +188,14 @@ void* func_rt(void* arg)
void* func_noise(void* arg)
{
- Thread* pthr = (Thread*)arg;
+ struct thread* pthr = (struct thread* )arg;
int rc, i, j, policy, tid = gettid();
struct sched_param schedp;
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(0, &mask);
+ pthr->pthread = pthread_self();
rc = sched_setaffinity(0, sizeof(mask), &mask);
if (rc < 0) {
printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
@@ -235,7 +215,7 @@ void* func_noise(void* arg)
sched_getparam(tid, &schedp);
policy = sched_getscheduler(tid);
printf("Noise Thread %d(%d) loop %d pthread pol %d pri %d\n", tid,
pthr->priority, i,
- policy, schedp.sched_priority);
+ policy, pthr->priority);
fflush(NULL);
}
pthr->id++;
@@ -251,75 +231,6 @@ void* func_noise(void* arg)
return NULL;
}
-int startThread(Thread* thrd)
-{
- struct sched_param schedp;
- pthread_condattr_t condattr;
- int retc, policy, inherit;
-
- printf("Start thread priority %d\n", thrd->priority);
- if (pthread_attr_init(&(thrd->attr)) != 0) {
- printf("Attr init failed");
- exit(2);
- }
- thrd->flags = 0;
- memset(&schedp, 0, sizeof(schedp));
- schedp.sched_priority = thrd->priority;
- policy = thrd->policy;
-
- if (pthread_attr_setschedpolicy(&(thrd->attr), policy) != 0) {
- printf("Can't set policy %d\n", policy);
- }
- if (pthread_attr_getschedpolicy(&(thrd->attr), &policy) != 0) {
- printf("Can't get policy\n");
- } else {
- printf("Policy in attribs is %d\n", policy);
- }
- if (pthread_attr_setschedparam(&(thrd->attr), &schedp) != 0) {
- printf("Can't set params");
- }
- if (pthread_attr_getschedparam(&(thrd->attr), &schedp) != 0) {
- printf("Can't get params");
- } else {
- printf("Priority in attribs is %d\n", schedp.sched_priority);
- }
- if (pthread_attr_setinheritsched(&(thrd->attr), PTHREAD_EXPLICIT_SCHED) !=
0) {
- printf("Can't set inheritsched\n");
- }
- if (pthread_attr_getinheritsched(&(thrd->attr), &inherit) != 0) {
- printf("Can't get inheritsched\n");
- } else {
- printf("inherit sched in attribs is %d\n", inherit);
- }
- if ((retc = pthread_mutex_init(&(thrd->mutex), NULL)) != 0) {
- printf("Failed to init mutex: %d\n", retc);
- }
- if (pthread_condattr_init(&condattr) != 0) {
- printf("Failed to init condattr\n");
- }
- if (pthread_cond_init(&(thrd->cond), &condattr) != 0) {
- printf("Failed to init cond\n");
- }
- retc = pthread_create(&(thrd->pthread),&(thrd->attr), thrd->func, thrd);
- printf("Create returns %d\n\n", retc);
- return retc;
-}
-
-void stopThread(Thread* thr)
-{
- thr->flags += THREAD_STOP;
- joinThread(thr);
-}
-
-void joinThread(Thread* thr)
-{
- void* ret = NULL;
- if (pthread_join(thr->pthread, &ret) != 0) {
- printf("Join failed\n");
- }
- printf("Join gave %p\n", ret);
-}
-
/*
* Test pthread creation at different thread priorities.
*/
@@ -347,12 +258,6 @@ int main(int argc, char* argv[]) {
}
retc = sched_getaffinity(0, sizeof(mask), &mask);
- arg1.policy = SCHED_OTHER; arg1.priority = 0; arg1.func = func_nonrt;
- arg2.policy = SCHED_RR; arg2.priority = 20; arg2.func = func_rt;
- arg3.policy = SCHED_RR; arg3.priority = 30; arg3.func = func_rt;
- arg4.policy = SCHED_RR; arg4.priority = 40; arg4.func = func_rt;
- arg5.policy = SCHED_RR; arg5.priority = 40; arg5.func = func_noise;
-
for (i=0;i<argc;i++) {
if (strcmp(argv[i],"nopi") == 0) nopi = 1;
}
@@ -387,23 +292,15 @@ int main(int argc, char* argv[]) {
exit(retc);
}
- startThread(&arg1);
- startThread(&arg2);
- startThread(&arg3);
- startThread(&arg4);
- startThread(&arg5);
-
sleep(10);
-
- printf("Stopping threads\n");
- stopThread(&arg1);
- stopThread(&arg2);
- stopThread(&arg3);
- stopThread(&arg4);
- stopThread(&arg5);
-
- printf("Thread counts %d %d %d %d %d\n",arg1.id, arg2.id,
- arg3.id, arg4.id, arg5.id);
+ create_other_thread(func_nonrt, NULL);
+ create_rr_thread(func_rt, NULL, 20);
+ create_rr_thread(func_rt, NULL, 30);
+ create_rr_thread(func_rt, NULL, 40);
+ create_rr_thread(func_noise, NULL, 40);
+
+ printf("Joining threads\n");
+ join_threads();
printf("Done\n");
return 0;
diff --git a/testcases/realtime/func/pi-tests/testpi-5.c
b/testcases/realtime/func/pi-tests/testpi-5.c
index 4b62a96..d257ff1 100644
--- a/testcases/realtime/func/pi-tests/testpi-5.c
+++ b/testcases/realtime/func/pi-tests/testpi-5.c
@@ -41,7 +41,7 @@
#include <pthread.h>
#include <string.h>
#include <unistd.h>
-
+#include <librttest.h>
pthread_mutex_t child_mutex;
void* child_thread (void* arg)
@@ -68,7 +68,6 @@ void* child_thread (void* arg)
int do_test(int argc, char ** argv)
{
- pthread_t thread;
pthread_mutexattr_t mutexattr;
int retc, protocol;
@@ -87,10 +86,9 @@ int do_test(int argc, char ** argv)
printf("Failed to init mutex: %d\n", retc);
}
- pthread_create (&thread, NULL, child_thread, NULL);
-
- pthread_join(thread, NULL);
+ create_other_thread(child_thread, NULL);
+ join_threads();
return 0;
}
diff --git a/testcases/realtime/func/pi-tests/testpi-6.c
b/testcases/realtime/func/pi-tests/testpi-6.c
index c835932..0e84183 100644
--- a/testcases/realtime/func/pi-tests/testpi-6.c
+++ b/testcases/realtime/func/pi-tests/testpi-6.c
@@ -41,7 +41,7 @@
#include <pthread.h>
#include <string.h>
#include <unistd.h>
-
+#include <librttest.h>
pthread_mutex_t child_mutex;
void* child_thread (void* arg)
@@ -68,7 +68,6 @@ void* child_thread (void* arg)
int do_test(int argc, char **argv)
{
- pthread_t thread;
pthread_mutexattr_t mutexattr;
int retc, robust;
@@ -87,9 +86,9 @@ int do_test(int argc, char **argv)
printf("Failed to init mutex: %d\n", retc);
}
- pthread_create (&thread, NULL, child_thread, NULL);
+ create_other_thread (child_thread, NULL);
- pthread_join(thread, NULL);
+ join_threads();
return 0;
}
--
Cheers,
Chirag Jog
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list