tests: update template and add pids

Generalised the library API tests and created a common
test-runner. Instead of copy and pasting the same code in
each time.

First cut of pids API test, for _new so far.
This commit is contained in:
Craig Small
2016-04-19 21:33:02 +10:00
parent 714ea69c6d
commit aa16ab0dc1
8 changed files with 130 additions and 92 deletions

View File

@@ -20,15 +20,12 @@
#include <stdio.h>
#include <proc/sysinfo.h>
struct test_func {
int (*func)(void *data);
char *name;
};
#include "tests.h"
int check_hertz(void *data)
{
long hz;
testname = "procps_hertz_get()";
hz = procps_hertz_get();
return (hz > 0);
@@ -37,6 +34,7 @@ int check_hertz(void *data)
int check_loadavg(void *data)
{
double a,b,c;
testname = "procps_loadavg()";
if (procps_loadavg(&a, &b, &c) == 0)
return 1;
@@ -45,33 +43,22 @@ int check_loadavg(void *data)
int check_loadavg_null(void *data)
{
testname = "procps_loadavg() with NULLs";
if (procps_loadavg(NULL, NULL, NULL) == 0)
return 1;
return 0;
}
struct test_func tests[] = {
{ check_hertz, "procps_hertz_get()"},
{ check_loadavg, "procps_loadavg()"},
{ check_loadavg, "procps_loadavg() with NULLs"},
{ NULL, NULL}
TestFunction test_funcs[] = {
check_hertz,
check_loadavg,
check_loadavg_null,
NULL,
};
int main(int argc, char *argv[])
{
int i;
struct test_func *current;
for(i=0; tests[i].func != NULL; i++) {
current = &tests[i];
if (!current->func(NULL)) {
fprintf(stderr, "FAIL: %s\n", current->name);
return EXIT_FAILURE;
} else {
fprintf(stderr, "PASS: %s\n", current->name);
}
}
return EXIT_SUCCESS;
return run_tests(test_funcs, NULL);
}