diff options
author | Angelo Marletta <angelo.marletta@gmail.com> | 2012-06-20 02:48:05 +0100 |
---|---|---|
committer | Angelo Marletta <angelo.marletta@gmail.com> | 2012-06-20 02:48:05 +0100 |
commit | c08039365f62abe5f180c9c3c6c3f8fac6feb378 (patch) | |
tree | 8e5e20b979437b78ec0fc5b6e8e6baf79d1aa6a1 /tests | |
parent | 01a76753a060c27e26ac691c0d69f99b975038e5 (diff) | |
download | cpulimit-c08039365f62abe5f180c9c3c6c3f8fac6feb378.tar.gz |
added process_group and test. all tests pass
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile | 13 | ||||
-rw-r--r-- | tests/process_iterator_test.c | 26 |
2 files changed, 25 insertions, 14 deletions
diff --git a/tests/Makefile b/tests/Makefile index d187359..ffc80fa 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,8 +1,9 @@ CC?=gcc CFLAGS?=-Wall -g TARGETS=busy process_iterator_test -LIBS?=-lpthread - +SRC=../src +SYSLIBS?=-lpthread +LIBS=$(SRC)/list.o $(SRC)/process_iterator.o $(SRC)/process_group.o UNAME := $(shell uname) ifeq ($(UNAME), FreeBSD) @@ -11,11 +12,11 @@ endif all:: $(TARGETS) -busy: busy.c $(LIBS) - $(CC) -o busy busy.c $(LIBS) $(CFLAGS) +busy: busy.c $(SYSLIBS) + $(CC) -o busy busy.c $(SYSLIBS) $(CFLAGS) -process_iterator_test: process_iterator_test.c $(LIBS) ../src/process_iterator.o - $(CC) -I../src -o process_iterator_test process_iterator_test.c ../src/process_iterator.o $(LIBS) $(CFLAGS) +process_iterator_test: process_iterator_test.c $(LIBS) + $(CC) -I$(SRC) -o process_iterator_test process_iterator_test.c $(LIBS) $(SYSLIBS) $(CFLAGS) clean: rm -f *~ *.o $(TARGETS) diff --git a/tests/process_iterator_test.c b/tests/process_iterator_test.c index ac5d542..dcd4ebe 100644 --- a/tests/process_iterator_test.c +++ b/tests/process_iterator_test.c @@ -1,11 +1,14 @@ #include <stdio.h> -#include <process_iterator.h> +#include <stdlib.h> #include <sys/types.h> #include <unistd.h> #include <assert.h> #include <time.h> -int test_single_process() +#include <process_iterator.h> +#include <process_group.h> + +void test_single_process() { struct process_iterator it; struct process process; @@ -44,10 +47,9 @@ int test_single_process() } assert(count == 1); close_process_iterator(&it); - return 0; } -int test_multiple_process() +void test_multiple_process() { struct process_iterator it; struct process process; @@ -57,7 +59,7 @@ int test_multiple_process() { //child code sleep(1); - return 0; + exit(0); } filter.pid = getpid(); filter.include_children = 1; @@ -75,10 +77,9 @@ int test_multiple_process() } assert(count == 2); close_process_iterator(&it); - return 0; } -int test_all_processes() +void test_all_processes() { struct process_iterator it; struct process process; @@ -99,7 +100,15 @@ int test_all_processes() } assert(count >= 10); close_process_iterator(&it); - return 0; +} + +void test_process_list() +{ + struct process_group pgroup; + pid_t current_pid = getpid(); + assert(init_process_group(&pgroup, current_pid, 0) == 0); + update_process_group(&pgroup); + assert(close_process_group(&pgroup) == 0); } int main() @@ -108,5 +117,6 @@ int main() test_single_process(); test_multiple_process(); test_all_processes(); + test_process_list(); return 0; } |