rusage: Refactor test programs

Change-Id: I846a6416acf903f7fa19db98d4d937c51c10b4af
This commit is contained in:
Masamichi Takagi
2018-09-18 16:13:56 +09:00
parent 60011718d2
commit 159092c58e
56 changed files with 1608 additions and 1846 deletions

38
test/rusage/200_lin.c Normal file
View File

@@ -0,0 +1,38 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include "ihklib.h"
#include "mckernel/ihklib_rusage.h"
#include "util.h"
#define DELAY0 (100UL * 1000 * 1000)
#define DELAY1 (200UL * 1000 * 1000)
#define SCALE 1.5
#define WITHIN_RANGE(x, y, s) (x >= y && x <= y * s)
int main(int argc, char **argv)
{
int ret = 0;
struct mckernel_rusage rusage;
if ((ret = ihk_os_getrusage(0, &rusage, sizeof(rusage)))) {
fprintf(stderr, "%s: ihk_os_getrusage failed\n", __func__);
ret = -EINVAL;
goto fn_fail;
}
OKNG(WITHIN_RANGE(rusage.cpuacct_usage_percpu[1], DELAY0, SCALE),
"cpu 0: user time: expected: %ld nsec, reported: %ld nsec\n",
DELAY0, rusage.cpuacct_usage_percpu[1]);
OKNG(WITHIN_RANGE(rusage.cpuacct_usage_percpu[2], DELAY1, SCALE),
"cpu 1: user time: expected: %ld nsec, reported: %ld nsec\n",
DELAY1, rusage.cpuacct_usage_percpu[2]);
printf("All tests finished\n");
fn_fail:
return ret;
}