aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAngelo Marletta <angelo.marletta@gmail.com>2012-06-19 01:23:06 +0100
committerAngelo Marletta <angelo.marletta@gmail.com>2012-06-19 01:23:06 +0100
commit01a76753a060c27e26ac691c0d69f99b975038e5 (patch)
tree821fc1226395108504f2e850eff5d193956b7f95 /tests
parentfe3e3c7e3be29d29b3b7efc22f4933c64e883776 (diff)
downloadcpulimit-01a76753a060c27e26ac691c0d69f99b975038e5.tar.gz
process_iterator working for linux and freebsd. tests pass
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile2
-rw-r--r--tests/process_iterator_test.c38
2 files changed, 32 insertions, 8 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 11359e6..d187359 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -14,7 +14,7 @@ all:: $(TARGETS)
busy: busy.c $(LIBS)
$(CC) -o busy busy.c $(LIBS) $(CFLAGS)
-process_iterator_test: process_iterator_test.c $(LIBS)
+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)
clean:
diff --git a/tests/process_iterator_test.c b/tests/process_iterator_test.c
index 1822449..ac5d542 100644
--- a/tests/process_iterator_test.c
+++ b/tests/process_iterator_test.c
@@ -18,24 +18,23 @@ int test_single_process()
count = 0;
now = time(NULL);
init_process_iterator(&it, &filter);
- while (read_next_process(&it, &process) == 0)
+ while (get_next_process(&it, &process) == 0)
{
assert(process.pid == getpid());
assert(process.ppid == getppid());
assert(process.cputime < 100);
assert(process.starttime == now || process.starttime == now - 1);
-
count++;
}
assert(count == 1);
close_process_iterator(&it);
//iterate children
filter.pid = getpid();
- filter.include_children = 1;
+ filter.include_children = 0;
count = 0;
now = time(NULL);
init_process_iterator(&it, &filter);
- while (read_next_process(&it, &process) == 0)
+ while (get_next_process(&it, &process) == 0)
{
assert(process.pid == getpid());
assert(process.ppid == getppid());
@@ -65,7 +64,7 @@ int test_multiple_process()
init_process_iterator(&it, &filter);
int count = 0;
time_t now = time(NULL);
- while (read_next_process(&it, &process) == 0)
+ while (get_next_process(&it, &process) == 0)
{
if (process.pid == getpid()) assert(process.ppid == getppid());
else if (process.pid == child) assert(process.ppid == getpid());
@@ -79,10 +78,35 @@ int test_multiple_process()
return 0;
}
+int test_all_processes()
+{
+ struct process_iterator it;
+ struct process process;
+ struct process_filter filter;
+ filter.pid = 0;
+ init_process_iterator(&it, &filter);
+ int count = 0;
+ time_t now = time(NULL);
+ while (get_next_process(&it, &process) == 0)
+ {
+ if (process.pid == getpid())
+ {
+ assert(process.ppid == getppid());
+ assert(process.cputime < 100);
+ assert(process.starttime == now || process.starttime == now - 1);
+ }
+ count++;
+ }
+ assert(count >= 10);
+ close_process_iterator(&it);
+ return 0;
+}
+
int main()
{
- printf("Current PID %d\n", getpid());
+ printf("Pid %d\n", getpid());
test_single_process();
test_multiple_process();
+ test_all_processes();
return 0;
-} \ No newline at end of file
+}
Un proyecto texto-plano.xyz