Add basic worker and its tests
This commit is contained in:
parent
e877dc7f0d
commit
5d4b0dc3c9
5 changed files with 116 additions and 0 deletions
|
@ -28,6 +28,9 @@
|
|||
/* Define to 1 if you have the `memset' function. */
|
||||
#undef HAVE_MEMSET
|
||||
|
||||
/* Define to 1 if you have the <pthread.h> header file. */
|
||||
#undef HAVE_PTHREAD_H
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `realloc' function,
|
||||
and to 0 otherwise. */
|
||||
#undef HAVE_REALLOC
|
||||
|
|
12
include/r3_workers.h
Normal file
12
include/r3_workers.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* r3_workers.h
|
||||
* Copyright (C) 2014 c9s <c9s@c9smba.local>
|
||||
*
|
||||
* Distributed under terms of the MIT license.
|
||||
*/
|
||||
|
||||
#ifndef R3_WORKERS_H
|
||||
#define R3_WORKERS_H
|
||||
|
||||
|
||||
#endif /* !R3_WORKERS_H */
|
47
src/workers.c
Normal file
47
src/workers.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* workers.c
|
||||
* Copyright (C) 2014 c9s <c9s@c9smba.local>
|
||||
*
|
||||
* Distributed under terms of the MIT license.
|
||||
*/
|
||||
#include "r3.h"
|
||||
#include "r3_workers.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
void *PrintHello(void *threadid)
|
||||
{
|
||||
long tid;
|
||||
tid = (long)threadid;
|
||||
printf("Hello World! It's me, thread #%ld!\n", tid);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int thread_id;
|
||||
node * matched_node;
|
||||
} feedback_payload;
|
||||
|
||||
void *r3_feedback_worker(void * data) {
|
||||
feedback_payload * payload = (feedback_payload*) data; // pointer cast
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void r3_launch_feedback_worker(feedback_payload * data) {
|
||||
int rc;
|
||||
pthread_t worker_thread;
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
rc = pthread_create(&worker_thread, &attr, r3_feedback_worker, (void*) data);
|
||||
}
|
||||
|
||||
|
||||
void r3_worker_stop() {
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
|
@ -43,6 +43,9 @@ check_tree_SOURCES = check_tree.c
|
|||
TESTS += check_slug
|
||||
check_slug_SOURCES = check_slug.c
|
||||
|
||||
TESTS += check_worker
|
||||
check_worker_SOURCES = check_worker.c
|
||||
|
||||
|
||||
check_PROGRAMS = $(TESTS)
|
||||
|
||||
|
|
51
tests/check_worker.c
Normal file
51
tests/check_worker.c
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* check_worker.c
|
||||
* Copyright (C) 2014 c9s <c9s@c9smba.local>
|
||||
*
|
||||
* Distributed under terms of the MIT license.
|
||||
*/
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <check.h>
|
||||
#include <stdlib.h>
|
||||
#include "r3.h"
|
||||
#include "r3_str.h"
|
||||
#include "r3_workers.h"
|
||||
#include "str_array.h"
|
||||
#include "bench.h"
|
||||
|
||||
START_TEST (test_feedback_worker)
|
||||
{
|
||||
node * n = r3_tree_create(1);
|
||||
|
||||
r3_tree_insert_path(n, "/foo/bar/baz", NULL);
|
||||
r3_tree_insert_path(n, "/foo/bar/qux", NULL);
|
||||
r3_tree_insert_path(n, "/foo/bar/quux", NULL);
|
||||
r3_tree_insert_path(n, "/foo/bar/corge", NULL);
|
||||
r3_tree_insert_path(n, "/foo/bar/grault", NULL);
|
||||
r3_tree_insert_path(n, "/garply/grault/foo", NULL);
|
||||
r3_tree_insert_path(n, "/garply/grault/bar", NULL);
|
||||
r3_tree_compile(n);
|
||||
|
||||
r3_tree_free(n);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
Suite* r3_suite (void) {
|
||||
Suite *suite = suite_create("Worker Test");
|
||||
TCase *tcase = tcase_create("worker test");
|
||||
tcase_add_test(tcase, test_feedback_worker);
|
||||
suite_add_tcase(suite, tcase);
|
||||
return suite;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
int number_failed;
|
||||
Suite *suite = r3_suite();
|
||||
SRunner *runner = srunner_create(suite);
|
||||
srunner_run_all(runner, CK_NORMAL);
|
||||
number_failed = srunner_ntests_failed(runner);
|
||||
srunner_free(runner);
|
||||
return number_failed;
|
||||
}
|
Loading…
Reference in a new issue