1 //=================================================================
5 // test case for the cpuload code.
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 2002 Andrew Lunn
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
46 // Description: Tests the calculation code
47 //####DESCRIPTIONEND####
49 #include <cyg/hal/hal_arch.h>
50 #include <cyg/kernel/kapi.h>
51 #include <cyg/infra/testcase.h>
52 #include <cyg/infra/diag.h>
53 #include <cyg/cpuload/cpuload.h>
56 do_test(cyg_addrword_t data) {
57 cyg_uint32 calibration;
58 cyg_cpuload_t cpuload;
60 cyg_uint32 average_point1s;
61 cyg_uint32 average_1s;
62 cyg_uint32 average_10s;
65 CYG_TEST_INFO("About to calibrate cpuload");
67 cyg_cpuload_calibrate(&calibration);
69 CYG_TEST_INFO("Performing 100% load test");
71 cyg_cpuload_create(&cpuload,calibration,&handle);
73 /* Busy loop doing useless work. This will cause the cpu load to be
74 100%. After all these iterations, check the measured load really
78 for (j=calibration*10; j-- ; )
80 cyg_cpuload_get(handle,&average_point1s,&average_1s,&average_10s);
81 /* diag_printf("%d %d %d\n",average_point1s,average_1s,average_10s);*/
84 /* Rounding errors mean it will probably never reach 100% */
85 if ((average_point1s == 100) &&
86 (average_1s >= 99) && (average_1s <=100) &&
87 (average_10s >= 98) && (average_10s <= 100))
88 CYG_TEST_PASS("100% load o.k.");
90 CYG_TEST_FAIL("100% load");
93 /* Sleeping doing nothing. This will cause the cpuload to be
94 0%. After all these iterations, check the measured load really is
96 CYG_TEST_INFO("Performing 0% load test");
99 cyg_cpuload_get(handle,&average_point1s,&average_1s,&average_10s);
100 /* diag_printf("%d %d %d\n",average_point1s,average_1s,average_10s);*/
103 if ((average_point1s == 0) &&
105 (average_10s >= 0) && (average_10s <= 2))
106 CYG_TEST_PASS_FINISH("0% load o.k.");
108 CYG_TEST_FAIL_FINISH("0% load");
116 #ifdef CYGPKG_HAL_SYNTH
118 CYG_TEST_NA("Not applicable to Synth target");
120 static char stack[CYGNUM_HAL_STACK_SIZE_MINIMUM];
121 static cyg_handle_t handle;
122 static cyg_thread thread;
126 cyg_thread_create(4,do_test,0,"cpuload",
127 stack,sizeof(stack),&handle,&thread);
128 cyg_thread_resume(handle);
130 cyg_scheduler_start();