~pbatch/patchwerk

patchwerk/examples/stress.c -rw-r--r-- 1.6 KiB
9c265356 — paul plan9 additions from Sigrid 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdlib.h>
#include <soundpipe.h>
#include "patchwerk.h"

#define NBUFS 8
#define STACKSIZE 10

void stress_out_pool(void)
{
    pw_patch *patch;
    pw_bufferpool *pool;
    pw_buffer *dummy;
    int n;
    int rc;
    int nbufs;

    patch = calloc(1, pw_patch_size());
    pw_patch_init(patch, BLKSIZE);
    pw_patch_alloc(patch, NBUFS, STACKSIZE);
    pool = pw_patch_pool(patch);

    nbufs = 0;
    for (n = 0; n < NBUFS + 2; n++) {
        rc = pw_bufferpool_nextfree(pool, &dummy);
        if (rc != PW_OK) {
            printf("(Expected) Error: %s\n", pw_error(rc));
            nbufs++;
        }
    }

    if (nbufs != 2) {
        printf("Expected 2 errors, got %d instead\n", nbufs);
    }

    pw_patch_destroy(patch);
    free(patch);
}

void stress_out_stack(void)
{
    pw_patch *patch;
    pw_stack *stack;
    int n;
    int rc;
    pw_bufferpool *pool;
    pw_buffer *buf;
    int nstacks;

    patch = calloc(1, pw_patch_size());
    pw_patch_init(patch, BLKSIZE);
    pw_patch_alloc(patch, NBUFS, STACKSIZE);
    stack = pw_patch_stack(patch);
    pool = pw_patch_pool(patch);

    pw_bufferpool_nextfree(pool, &buf);
    nstacks = 0;
    for (n = 0; n < STACKSIZE + 2; n++) {
        rc = pw_stack_push_buffer(stack, buf);
        if (rc != PW_OK) {
            printf("(Expected) Error: %s\n", pw_error(rc));
            nstacks++;
        }
    }

    if (nstacks != 2) {
        printf("Expected 2 errors, got %d instead\n", nstacks);
    }

    pw_patch_destroy(patch);
    free(patch);
}

int main(int argc, char *argv[])
{
    stress_out_pool();
    stress_out_stack();
    return 0;
}