~ubuntu-branches/ubuntu/utopic/libpthread-workqueue/utopic

« back to all changes in this revision

Viewing changes to testing/api/test.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Heily
  • Date: 2011-05-07 11:57:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110507115722-n8ftqsa8w2el0xkn
Tags: 0.5.1-1
* New upstream version.
* Update control file with new Standards-Version.
* Remove -m64 from CFLAGS (Closes: #622798)
* Limit architecture to linux-any (Closes: #622799)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include <stdlib.h>
3
3
#include <stdio.h>
4
4
#include <string.h>
5
 
#include <unistd.h>
6
5
 
7
 
#include "config.h"
8
 
#include "src/private.h"
 
6
#if !defined(_WIN32)
 
7
# if !defined(NO_CONFIG_H)
 
8
#  include "config.h"
 
9
# endif
 
10
#endif
 
11
#include "../../src/private.h"
9
12
 
10
13
#if HAVE_ERR_H
11
14
# include <err.h>
14
17
# define errx(rc,msg,...) do { puts(msg); exit(rc); } while (0)
15
18
#endif
16
19
 
17
 
#include "pthread_workqueue.h"
 
20
#include <pthread_workqueue.h>
18
21
 
19
22
static int work_cnt;
20
23
 
23
26
void additem(void (*func)(void *), 
24
27
             void * arg)
25
28
{
 
29
 
26
30
    int rv;
27
31
    
28
32
    rv = pthread_workqueue_additem_np(wq, *func, arg, NULL, NULL);
35
39
compute(void *arg)
36
40
{
37
41
    int *count = (int *) arg;
38
 
    static const int nval = 5000;
 
42
#define nval 5000
39
43
    int val[nval];
40
44
    int i,j;
41
45
 
78
82
run_blocking_test(void)
79
83
{
80
84
        const int rounds = 50;
 
85
        long i = 0;
81
86
        work_cnt = rounds;
82
 
    for (unsigned long i = 0; i < rounds; i++) {
 
87
    for (i = 0; i < rounds; i++) {
83
88
        additem(lazy, (void *) i);
84
89
    }
85
90
        while (work_cnt > 0)
90
95
run_cond_wait_test(void)
91
96
{
92
97
        const int rounds = 10;
 
98
        long i = 0;
93
99
 
94
100
        sleep(3);       /* Allow time for the workers to enter pthread_cond_wait() */
95
101
        work_cnt = rounds;
96
 
    for (unsigned long i = 0; i < rounds; i++) {
 
102
    for (i = 0; i < rounds; i++) {
97
103
        additem(lazy, (void *) i);
98
104
                sleep(1);
99
105
    }
105
111
run_load_test(void)
106
112
{
107
113
    char buf[16];
108
 
    for (int i = 0; i < 1024; i++) {
 
114
        int i = 0;
 
115
    for (i = 0; i < 1024; i++) {
109
116
        sprintf(buf, "%d", i);
110
117
        additem(sleepy, strdup(buf));
111
118
        additem(compute, NULL);
117
124
void
118
125
run_stress_test(int rounds)
119
126
{
 
127
        int i = 0;
120
128
        work_cnt = rounds;
121
 
    for (int i = 0; i < rounds; i++) {
 
129
    for (i = 0; i < rounds; i++) {
122
130
        additem(compute, &work_cnt);
123
131
    }
124
132
        while (work_cnt > 0)