Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

rk_util_test.c

Go to the documentation of this file.
00001 /*
00002  * rk_util_test.h
00003  *
00004  * Copyright (c) 2003 The University of Utah and the Flux Group.
00005  * All rights reserved.
00006  *
00007  * This file is licensed under the terms of the GNU Public License.  
00008  * See the file "license.terms" for restrictions on redistribution 
00009  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00010  */
00011 
00012 /**
00013  * @file rk_util_test.c
00014  *
00015  * Test cases for the functions in rk_util.h.
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 }

Generated on Mon Dec 1 16:29:07 2003 for CPU Broker by doxygen 1.3.4