-
Notifications
You must be signed in to change notification settings - Fork 55
/
engine_testapp.c
725 lines (643 loc) · 23.3 KB
/
engine_testapp.c
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* arcus-memcached - Arcus memory cache server
* Copyright 2010-2014 NAVER Corp.
* Copyright 2015 JaM2in Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "config.h"
#include <assert.h>
#include <dlfcn.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <engine_loader.h>
#include <memcached/engine_testapp.h>
#include <memcached/extension_loggers.h>
#include <memcached/mock_server.h>
struct mock_engine {
ENGINE_HANDLE_V1 me;
ENGINE_HANDLE_V1 *the_engine;
};
static inline struct mock_engine* get_handle(ENGINE_HANDLE* handle) {
return (struct mock_engine*)handle;
}
static const engine_info* mock_get_info(ENGINE_HANDLE* handle) {
struct mock_engine *me = get_handle(handle);
return me->the_engine->get_info((ENGINE_HANDLE*)me->the_engine);
}
static ENGINE_ERROR_CODE mock_initialize(ENGINE_HANDLE* handle,
const char* config_str) {
struct mock_engine *me = get_handle(handle);
return me->the_engine->initialize((ENGINE_HANDLE*)me->the_engine, config_str);
}
static void mock_destroy(ENGINE_HANDLE* handle) {
struct mock_engine *me = get_handle(handle);
me->the_engine->destroy((ENGINE_HANDLE*)me->the_engine);
}
static ENGINE_ERROR_CODE mock_allocate(ENGINE_HANDLE* handle,
const void* cookie,
item **item,
const void* key,
const size_t nkey,
const size_t nbytes,
const int flags,
const rel_time_t exptime,
const uint64_t cas) {
struct mock_engine *me = get_handle(handle);
struct mock_connstruct *c = (void*)cookie;
if (c == NULL) {
c = (void*)create_mock_cookie();
}
c->nblocks = 0;
ENGINE_ERROR_CODE ret = ENGINE_SUCCESS;
pthread_mutex_lock(&c->mutex);
while (ret == ENGINE_SUCCESS &&
(ret = me->the_engine->allocate((ENGINE_HANDLE*)me->the_engine, c,
item, key, nkey,
nbytes, flags,
exptime, cas)) == ENGINE_EWOULDBLOCK &&
c->handle_ewouldblock)
{
++c->nblocks;
pthread_cond_wait(&c->cond, &c->mutex);
ret = c->status;
}
pthread_mutex_unlock(&c->mutex);
if (c != cookie) {
destroy_mock_cookie(c);
}
return ret;
}
static ENGINE_ERROR_CODE mock_remove(ENGINE_HANDLE* handle,
const void* cookie,
const void* key,
const size_t nkey,
uint64_t cas,
uint16_t vbucket)
{
struct mock_engine *me = get_handle(handle);
struct mock_connstruct *c = (void*)cookie;
if (c == NULL) {
c = (void*)create_mock_cookie();
}
c->nblocks = 0;
ENGINE_ERROR_CODE ret = ENGINE_SUCCESS;
pthread_mutex_lock(&c->mutex);
while (ret == ENGINE_SUCCESS &&
(ret = me->the_engine->remove((ENGINE_HANDLE*)me->the_engine, c, key,
nkey, cas, vbucket)) == ENGINE_EWOULDBLOCK &&
c->handle_ewouldblock)
{
++c->nblocks;
pthread_cond_wait(&c->cond, &c->mutex);
ret = c->status;
}
pthread_mutex_unlock(&c->mutex);
if (c != cookie) {
destroy_mock_cookie(c);
}
return ret;
}
static void mock_release(ENGINE_HANDLE* handle,
const void *cookie,
item* item) {
struct mock_engine *me = get_handle(handle);
me->the_engine->release((ENGINE_HANDLE*)me->the_engine, cookie, item);
}
static ENGINE_ERROR_CODE mock_get(ENGINE_HANDLE* handle,
const void* cookie,
item** item,
const void* key,
const int nkey,
uint16_t vbucket) {
struct mock_engine *me = get_handle(handle);
struct mock_connstruct *c = (void*)cookie;
if (c == NULL) {
c = (void*)create_mock_cookie();
}
c->nblocks = 0;
ENGINE_ERROR_CODE ret = ENGINE_SUCCESS;
pthread_mutex_lock(&c->mutex);
while (ret == ENGINE_SUCCESS &&
(ret = me->the_engine->get((ENGINE_HANDLE*)me->the_engine, c, item,
key, nkey, vbucket)) == ENGINE_EWOULDBLOCK &&
c->handle_ewouldblock)
{
++c->nblocks;
pthread_cond_wait(&c->cond, &c->mutex);
ret = c->status;
}
pthread_mutex_unlock(&c->mutex);
if (c != cookie) {
destroy_mock_cookie(c);
}
return ret;
}
static ENGINE_ERROR_CODE mock_get_stats(ENGINE_HANDLE* handle,
const void* cookie,
const char* stat_key,
int nkey,
ADD_STAT add_stat)
{
struct mock_engine *me = get_handle(handle);
struct mock_connstruct *c = (void*)cookie;
if (c == NULL) {
c = (void*)create_mock_cookie();
}
c->nblocks = 0;
ENGINE_ERROR_CODE ret = ENGINE_SUCCESS;
pthread_mutex_lock(&c->mutex);
while (ret == ENGINE_SUCCESS &&
(ret = me->the_engine->get_stats((ENGINE_HANDLE*)me->the_engine, c, stat_key,
nkey, add_stat)) == ENGINE_EWOULDBLOCK &&
c->handle_ewouldblock)
{
++c->nblocks;
pthread_cond_wait(&c->cond, &c->mutex);
ret = c->status;
}
pthread_mutex_unlock(&c->mutex);
if (c != cookie) {
destroy_mock_cookie(c);
}
return ret;
}
static ENGINE_ERROR_CODE mock_store(ENGINE_HANDLE* handle,
const void *cookie,
item* item,
uint64_t *cas,
ENGINE_STORE_OPERATION operation,
uint16_t vbucket) {
struct mock_engine *me = get_handle(handle);
struct mock_connstruct *c = (void*)cookie;
if (c == NULL) {
c = (void*)create_mock_cookie();
}
c->nblocks = 0;
ENGINE_ERROR_CODE ret = ENGINE_SUCCESS;
pthread_mutex_lock(&c->mutex);
while (ret == ENGINE_SUCCESS &&
(ret = me->the_engine->store((ENGINE_HANDLE*)me->the_engine, c, item, cas,
operation, vbucket)) == ENGINE_EWOULDBLOCK &&
c->handle_ewouldblock)
{
++c->nblocks;
pthread_cond_wait(&c->cond, &c->mutex);
ret = c->status;
}
pthread_mutex_unlock(&c->mutex);
if (c != cookie) {
destroy_mock_cookie(c);
}
return ret;
}
static ENGINE_ERROR_CODE mock_arithmetic(ENGINE_HANDLE* handle,
const void* cookie,
const void* key,
const int nkey,
const bool increment,
const bool create,
const uint64_t delta,
const uint64_t initial,
const int flags,
const rel_time_t exptime,
uint64_t *cas,
uint64_t *result,
uint16_t vbucket) {
struct mock_engine *me = get_handle(handle);
struct mock_connstruct *c = (void*)cookie;
if (c == NULL) {
c = (void*)create_mock_cookie();
}
c->nblocks = 0;
ENGINE_ERROR_CODE ret = ENGINE_SUCCESS;
pthread_mutex_lock(&c->mutex);
while (ret == ENGINE_SUCCESS &&
(ret = me->the_engine->arithmetic((ENGINE_HANDLE*)me->the_engine, c, key,
nkey, increment, create,
delta, initial, flags, exptime,
cas, result, vbucket)) == ENGINE_EWOULDBLOCK &&
c->handle_ewouldblock)
{
++c->nblocks;
pthread_cond_wait(&c->cond, &c->mutex);
ret = c->status;
}
pthread_mutex_unlock(&c->mutex);
if (c != cookie) {
destroy_mock_cookie(c);
}
return ret;
}
static ENGINE_ERROR_CODE mock_flush(ENGINE_HANDLE* handle, const void* cookie,
const void *prefix, const int nprefix, rel_time_t when) {
struct mock_engine *me = get_handle(handle);
struct mock_connstruct *c = (void*)cookie;
if (c == NULL) {
c = (void*)create_mock_cookie();
}
c->nblocks = 0;
ENGINE_ERROR_CODE ret = ENGINE_SUCCESS;
pthread_mutex_lock(&c->mutex);
while (ret == ENGINE_SUCCESS &&
(ret = me->the_engine->flush((ENGINE_HANDLE*)me->the_engine, c, NULL, -1, when)) == ENGINE_EWOULDBLOCK &&
c->handle_ewouldblock)
{
++c->nblocks;
pthread_cond_wait(&c->cond, &c->mutex);
ret = c->status;
}
pthread_mutex_unlock(&c->mutex);
if (c != cookie) {
destroy_mock_cookie(c);
}
return ret;
}
static void mock_reset_stats(ENGINE_HANDLE* handle, const void *cookie) {
struct mock_engine *me = get_handle(handle);
me->the_engine->reset_stats((ENGINE_HANDLE*)me->the_engine, cookie);
}
static ENGINE_ERROR_CODE mock_unknown_command(ENGINE_HANDLE* handle,
const void* cookie,
protocol_binary_request_header *request,
ADD_RESPONSE response)
{
struct mock_engine *me = get_handle(handle);
struct mock_connstruct *c = (void*)cookie;
if (c == NULL) {
c = (void*)create_mock_cookie();
}
c->nblocks = 0;
ENGINE_ERROR_CODE ret = ENGINE_SUCCESS;
pthread_mutex_lock(&c->mutex);
while (ret == ENGINE_SUCCESS &&
(ret = me->the_engine->unknown_command((ENGINE_HANDLE*)me->the_engine, c,
request, response)) == ENGINE_EWOULDBLOCK &&
c->handle_ewouldblock)
{
++c->nblocks;
pthread_cond_wait(&c->cond, &c->mutex);
ret = c->status;
}
pthread_mutex_unlock(&c->mutex);
if (c != cookie) {
destroy_mock_cookie(c);
}
return ret;
}
static bool mock_get_item_info(ENGINE_HANDLE *handle, const void *cookie,
const item* item, item_info *item_info)
{
struct mock_engine *me = get_handle(handle);
return me->the_engine->get_item_info((ENGINE_HANDLE*)me->the_engine,
cookie, item, item_info);
}
static void *mock_get_stats_struct(ENGINE_HANDLE* handle, const void* cookie)
{
struct mock_engine *me = get_handle(handle);
return me->the_engine->get_stats_struct((ENGINE_HANDLE*)me->the_engine, cookie);
}
static ENGINE_ERROR_CODE mock_aggregate_stats(ENGINE_HANDLE* handle,
const void* cookie,
void (*callback)(void*, void*),
void *vptr)
{
struct mock_engine *me = get_handle(handle);
struct mock_connstruct *c = (void*)cookie;
if (c == NULL) {
c = (void*)create_mock_cookie();
}
c->nblocks = 0;
ENGINE_ERROR_CODE ret = ENGINE_SUCCESS;
pthread_mutex_lock(&c->mutex);
while (ret == ENGINE_SUCCESS &&
(ret = me->the_engine->aggregate_stats((ENGINE_HANDLE*)me->the_engine, c,
callback, vptr)) == ENGINE_EWOULDBLOCK &&
c->handle_ewouldblock)
{
++c->nblocks;
pthread_cond_wait(&c->cond, &c->mutex);
ret = c->status;
}
pthread_mutex_unlock(&c->mutex);
if (c != cookie) {
destroy_mock_cookie(c);
}
return ret;
}
static size_t mock_errinfo(ENGINE_HANDLE *handle, const void* cookie,
char *buffer, size_t buffsz) {
struct mock_engine *me = get_handle(handle);
return me->the_engine->errinfo((ENGINE_HANDLE*)me->the_engine, cookie,
buffer, buffsz);
}
struct mock_engine default_mock_engine = {
.me = {
.interface = {
.interface = 1
},
.get_info = mock_get_info,
.initialize = mock_initialize,
.destroy = mock_destroy,
.allocate = mock_allocate,
.remove = mock_remove,
.release = mock_release,
.get = mock_get,
.store = mock_store,
.arithmetic = mock_arithmetic,
.flush = mock_flush,
.get_stats = mock_get_stats,
.reset_stats = mock_reset_stats,
.get_stats_struct = mock_get_stats_struct,
.aggregate_stats = mock_aggregate_stats,
.unknown_command = mock_unknown_command,
.get_item_info = mock_get_item_info,
.errinfo = mock_errinfo
}
};
struct mock_engine mock_engine;
EXTENSION_LOGGER_DESCRIPTOR *logger_descriptor = NULL;
static ENGINE_HANDLE *handle = NULL;
static ENGINE_HANDLE_V1 *handle_v1 = NULL;
static void usage(void) {
printf("\n");
printf("engine_testapp -E <path_to_engine_lib> -T <path_to_testlib>\n");
printf(" [-e <engine_config>] [-h]\n");
printf("\n");
printf("-E <path_to_engine_lib> Path to the engine library file. The\n");
printf(" engine library file is a library file\n");
printf(" (.so or .dll) that the contains the \n");
printf(" implementation of the engine being\n");
printf(" tested.\n");
printf("\n");
printf("-T <path_to_testlib> Path to the test library file. The test\n");
printf(" library file is a library file (.so or\n");
printf(" .dll) that contains the set of tests\n");
printf(" to be executed.\n");
printf("\n");
printf("-e <engine_config> Engine configuration string passed to\n");
printf(" the engine.\n");
printf("\n");
printf("-h Prints this usage text.\n");
printf("\n");
}
static int report_test(enum test_result r) {
int rc = 0;
char *msg = NULL;
bool color_enabled = getenv("TESTAPP_ENABLE_COLOR") != NULL;
int color = 0;
char color_str[8] = { 0 };
char *reset_color = "\033[m";
switch(r) {
case SUCCESS:
msg="OK";
color = 32;
break;
case FAIL:
color = 31;
msg="FAIL";
rc = 1;
break;
case DIED:
color = 31;
msg = "DIED";
rc = 1;
break;
case CORE:
color = 31;
msg = "CORE DUMPED";
rc = 1;
break;
case PENDING:
color = 33;
msg = "PENDING";
break;
}
assert(msg);
if (color_enabled) {
snprintf(color_str, sizeof(color_str), "\033[%dm", color);
}
printf("%s%s%s\n", color_str, msg, color_enabled ? reset_color : "");
return rc;
}
static ENGINE_HANDLE_V1 *start_your_engines(const char *engine, const char* cfg, bool engine_init) {
init_mock_server(handle);
if (!load_engine(engine, &get_mock_server_api, logger_descriptor, &handle)) {
fprintf(stderr, "Failed to load engine %s.\n", engine);
return NULL;
}
if (engine_init) {
if(!init_engine(handle, cfg, logger_descriptor)) {
fprintf(stderr, "Failed to init engine %s with config %s.\n", engine, cfg);
return NULL;
}
}
mock_engine = default_mock_engine;
handle_v1 = mock_engine.the_engine = (ENGINE_HANDLE_V1*)handle;
handle = (ENGINE_HANDLE*)&mock_engine.me;
handle_v1 = &mock_engine.me;
// Reset all members that aren't set (to allow the users to write
// testcases to verify that they initialize them..
assert(mock_engine.me.interface.interface == mock_engine.the_engine->interface.interface);
if (mock_engine.the_engine->get_stats_struct == NULL) {
mock_engine.me.get_stats_struct = NULL;
}
if (mock_engine.the_engine->aggregate_stats == NULL) {
mock_engine.me.aggregate_stats = NULL;
}
if (mock_engine.the_engine->unknown_command == NULL) {
mock_engine.me.unknown_command = NULL;
}
if (mock_engine.the_engine->errinfo == NULL) {
mock_engine.me.errinfo = NULL;
}
return &mock_engine.me;
}
static void destroy_engine(void) {
if (handle_v1) {
handle_v1->destroy(handle);
handle_v1 = NULL;
handle = NULL;
}
}
static void reload_engine(ENGINE_HANDLE **h, ENGINE_HANDLE_V1 **h1, const char* engine, const char *cfg, bool init) {
destroy_engine();
handle_v1 = start_your_engines(engine, cfg, init);
handle = (ENGINE_HANDLE*)(handle_v1);
*h1 = handle_v1;
*h = handle;
}
static enum test_result run_test(engine_test_t test, const char *engine, const char *default_cfg) {
enum test_result ret = PENDING;
if (test.tfun != NULL) {
#if !defined(USE_GCOV) && !defined(WIN32)
pid_t pid = fork();
if (pid == 0) {
#endif
/* Start the engines and go */
start_your_engines(engine, test.cfg ? test.cfg : default_cfg, true);
if (test.test_setup != NULL) {
if (!test.test_setup(handle, handle_v1)) {
fprintf(stderr, "Failed to run setup for test %s\n", test.name);
return FAIL;
}
}
ret = test.tfun(handle, handle_v1);
if (test.test_teardown != NULL) {
if (!test.test_teardown(handle, handle_v1)) {
fprintf(stderr, "WARNING: Failed to run teardown for test %s\n", test.name);
}
}
destroy_engine();
#if !defined(USE_GCOV) && !defined(WIN32)
exit((int)ret);
} else if (pid == (pid_t)-1) {
ret = FAIL;
} else {
int rc;
while (waitpid(pid, &rc, 0) == (pid_t)-1) {
if (errno != EINTR) {
abort();
}
}
if (WIFEXITED(rc)) {
ret = (enum test_result)WEXITSTATUS(rc);
} else if (WIFSIGNALED(rc) && WCOREDUMP(rc)) {
ret = CORE;
} else {
ret = DIED;
}
}
#endif
}
return ret;
}
int main(int argc, char **argv) {
int c, exitcode = 0, num_cases = 0;
const char *engine = NULL;
const char *engine_args = NULL;
const char *test_suite = NULL;
engine_test_t *testcases = NULL;
logger_descriptor = get_null_logger();
/* Hack to remove the warning from C99 */
union {
GET_TESTS get_tests;
void* voidptr;
} my_get_test = {.get_tests = NULL };
/* Hack to remove the warning from C99 */
union {
SETUP_SUITE setup_suite;
void* voidptr;
} my_setup_suite = {.setup_suite = NULL };
/* Hack to remove the warning from C99 */
union {
TEARDOWN_SUITE teardown_suite;
void* voidptr;
} my_teardown_suite = {.teardown_suite = NULL };
/* Use unbuffered stdio */
setbuf(stdout, NULL);
setbuf(stderr, NULL);
/* process arguments */
while (-1 != (c = getopt(argc, argv,
"h" /* usage */
"E:" /* Engine to load */
"e:" /* Engine options */
"T:" /* Library with tests to load */
))) {
switch (c) {
case 'E':
engine = optarg;
break;
case 'e':
engine_args = optarg;
break;
case 'h':
usage();
return 0;
case 'T':
test_suite = optarg;
break;
default:
fprintf(stderr, "Illegal argument \"%c\"\n", c);
return 1;
}
}
//validate args
if (engine == NULL) {
fprintf(stderr, "You must provide a path to the storage engine library.\n");
return 1;
}
if (test_suite == NULL) {
fprintf(stderr, "You must provide a path to the testsuite library.\n");
return 1;
}
//load test_suite
void* handle = dlopen(test_suite, RTLD_NOW | RTLD_LOCAL);
if (handle == NULL) {
const char *msg = dlerror();
fprintf(stderr, "Failed to load testsuite %s: %s\n", test_suite, msg ? msg : "unknown error");
return 1;
}
//get the test cases
void *symbol = dlsym(handle, "get_tests");
if (symbol == NULL) {
const char *msg = dlerror();
fprintf(stderr, "Could not find get_tests function in testsuite %s: %s\n", test_suite, msg ? msg : "unknown error");
return 1;
}
my_get_test.voidptr = symbol;
testcases = (*my_get_test.get_tests)();
//set up the suite if needed
struct test_harness harness = { .default_engine_cfg = engine_args,
.engine_path = engine,
.reload_engine = reload_engine,
.start_engine = start_your_engines,
.create_cookie = create_mock_cookie,
.destroy_cookie = destroy_mock_cookie,
.set_ewouldblock_handling = mock_set_ewouldblock_handling,
.lock_cookie = lock_mock_cookie,
.unlock_cookie = unlock_mock_cookie,
.waitfor_cookie = waitfor_mock_cookie};
symbol = dlsym(handle, "setup_suite");
if (symbol != NULL) {
my_setup_suite.voidptr = symbol;
if (!(*my_setup_suite.setup_suite)(&harness)) {
fprintf(stderr, "Failed to set up test suite %s \n", test_suite);
return 1;
}
}
for (num_cases = 0; testcases[num_cases].name; num_cases++) {
/* Just counting */
}
printf("1..%d\n", num_cases);
int i;
for (i = 0; testcases[i].name; i++) {
printf("Running %s... ", testcases[i].name);
fflush(stdout);
exitcode += report_test(run_test(testcases[i], engine, engine_args));
}
//tear down the suite if needed
symbol = dlsym(handle, "teardown_suite");
if (symbol != NULL) {
my_teardown_suite.voidptr = symbol;
if (!(*my_teardown_suite.teardown_suite)()) {
fprintf(stderr, "Failed to teardown up test suite %s \n", test_suite);
}
}
return exitcode;
}