00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "config.h"
00019
00020 #ifndef DEBUG
00021 #define DEBUG
00022 #endif
00023
00024 #include <stdlib.h>
00025 #include <sys/types.h>
00026 #include <unistd.h>
00027
00028 #include <assert_pp.h>
00029 #include <instrumentation.h>
00030
00031 #include <rk/rk.h>
00032 #include "rk_util.h"
00033
00034 int main(int argc, char *argv[])
00035 {
00036 int retval = EXIT_FAILURE;
00037 rk_resource_set_t rs;
00038
00039 instrumentation_data.iid_OutputFileName = "-";
00040 atexit(iPrintPointsAtExit);
00041
00042 if( (rs = rk_resource_set_create("rk_util_test")) != NULL_RESOURCE_SET )
00043 {
00044 struct rk_resource_set_usage rsu;
00045
00046 require(rk_resource_set_get_by_name("rk_util_test") !=
00047 NULL_RESOURCE_SET);
00048 require(rk_resource_set_get_by_name("non-existent") ==
00049 NULL_RESOURCE_SET);
00050
00051 rsu.proc_count = 1;
00052 rsu.cpu_usage = 1;
00053 if( rk_resource_set_get_usage(rs, &rsu) == 0 )
00054 {
00055 ensure(rsu.proc_count == 0);
00056 ensure(rsu.cpu_usage == 0);
00057 }
00058 if( rk_resource_set_attach_process(rs, getpid()) == 0 )
00059 {
00060 unsigned long long last_usage = 0;
00061 int lpc;
00062
00063 retval = EXIT_SUCCESS;
00064 for( lpc = 0; lpc < 1000; lpc++ )
00065 {
00066 require(rk_resource_set_get_usage(rs, &rsu) == 0);
00067 require(rsu.proc_count == 1);
00068
00069 if( rsu.cpu_usage < last_usage )
00070 {
00071 retval = EXIT_FAILURE;
00072 }
00073 last_usage = rsu.cpu_usage;
00074 }
00075 }
00076 else
00077 {
00078 perror("rk_resource_set_attach_process");
00079 }
00080 rk_resource_set_destroy(rs);
00081 }
00082 else
00083 {
00084 perror("rk_resource_set_create");
00085 }
00086 return( retval );
00087 }