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:
@@ -26,6 +26,7 @@
|
||||
|
||||
int check_uptime(void *data)
|
||||
{
|
||||
testname = "procps_uptime()";
|
||||
double up=0, idle=0;
|
||||
int rc;
|
||||
rc = procps_uptime(&up, &idle);
|
||||
@@ -36,6 +37,7 @@ int check_uptime_nullup(void *data)
|
||||
{
|
||||
double idle=0;
|
||||
int rc;
|
||||
testname = "procps_uptime() (up=NULL)";
|
||||
rc = procps_uptime(NULL, &idle);
|
||||
return (rc > 0 && idle > 0);
|
||||
}
|
||||
@@ -44,6 +46,7 @@ int check_uptime_nullidle(void *data)
|
||||
{
|
||||
double up=0;
|
||||
int rc;
|
||||
testname = "procps_uptime() (idle=NULL)";
|
||||
rc = procps_uptime(&up, NULL);
|
||||
return (rc > 0 && up > 0);
|
||||
}
|
||||
@@ -51,6 +54,7 @@ int check_uptime_nullidle(void *data)
|
||||
int check_uptime_nullall(void *data)
|
||||
{
|
||||
int rc;
|
||||
testname = "procps_uptime() (up,idle=NULL)";
|
||||
rc = procps_uptime(NULL, NULL);
|
||||
return (rc > 0);
|
||||
}
|
||||
@@ -58,6 +62,7 @@ int check_uptime_nullall(void *data)
|
||||
int check_uptime_sprint(void *data)
|
||||
{
|
||||
char *str;
|
||||
testname = "procps_uptime_sprint()";
|
||||
|
||||
str = procps_uptime_sprint();
|
||||
|
||||
@@ -67,37 +72,26 @@ int check_uptime_sprint(void *data)
|
||||
int check_uptime_sprint_short(void *data)
|
||||
{
|
||||
char *str;
|
||||
testname = "procps_uptime_sprint_short()";
|
||||
|
||||
str = procps_uptime_sprint_short();
|
||||
|
||||
return (str != NULL && str[0] != '\0');
|
||||
}
|
||||
|
||||
struct test_func tests[] = {
|
||||
{ check_uptime, "procps_uptime()"},
|
||||
{ check_uptime_nullup, "procps_uptime() (up=NULL)"},
|
||||
{ check_uptime_nullidle, "procps_uptime() (idle=NULL)"},
|
||||
{ check_uptime_nullall, "procps_uptime() (up,idle=NULL)"},
|
||||
{ check_uptime_sprint, "procps_uptime_sprint()"},
|
||||
{ check_uptime_sprint_short, "procps_uptime_sprint_short()"},
|
||||
{ NULL, NULL}
|
||||
TestFunction test_funcs[] = {
|
||||
check_uptime,
|
||||
check_uptime_nullup,
|
||||
check_uptime_nullidle,
|
||||
check_uptime_nullall,
|
||||
check_uptime_sprint,
|
||||
check_uptime_sprint_short,
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user