2 ZynAddSubFX - a software synthesizer
4 PluginTest.h - CxxTest for embedding zyn
5 Copyright (C) 2013-2013 Mark McCurry
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 #include "test-suite.h"
20 #include <rtosc/thread-link.h>
22 #include "../Containers/MultiPseudoStack.h"
26 char *instance_name
=(char*)"";
42 auto *mem
= s
->alloc();
44 TS_NON_NULL(mem
->memory
);
45 TS_ASSERT(!s
->read());
47 auto *mem2
= s
->read();
48 assert_ptr_eq(mem
, mem2
,
49 "both locations are the same", __LINE__
);
54 for(int i
=0; i
<100; ++i
) {
55 auto *mem
= s
->alloc();
57 TS_NON_NULL(mem
->memory
);
58 TS_ASSERT(!s
->read());
60 auto *mem2
= s
->read();
61 assert_ptr_eq(mem
, mem2
,
62 "both locations are the same", __LINE__
);
69 void testThreads(void)
71 uint8_t messages
[OPS
*THREADS
];
72 memset(messages
, 0, sizeof(messages
));
73 std::thread
*t
[THREADS
];
74 for(int i
=0; i
<THREADS
; ++i
) {
75 t
[i
] = new std::thread([this,i
,&messages
](){
80 auto *mem
= s
->read();
83 //printf("got: <%s>\n", mem->memory);
84 messages
[atoi(mem
->memory
)]++;
88 auto *mem
= s
->alloc();
90 sprintf(mem
->memory
,"%d written by %d@op%d", i
*OPS
+op
,i
,op
);
100 printf("thread started...\n");
101 for(int i
=0; i
<THREADS
; ++i
) {
105 printf("thread stopped...\n");
108 auto *mem
= s
->read();
110 printf("got: <%s>\n", mem
->memory
);
111 messages
[atoi(mem
->memory
)]++;
118 for(int i
=0; i
<OPS
*THREADS
; ++i
) {
119 if(messages
[i
] != 1) {
133 RUN_TEST(testThreads
);
134 return test_summary();