diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-10-04 13:37:44 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-10-06 08:54:07 +0200 |
commit | bfb56528767beb950a6fa3729ed8f9d436e0abac (patch) | |
tree | bdbfdabe892a173481ab8643f05872efc2124bcc | |
parent | bfbb1afb8f73702fb6751d2c51602c10365ad649 (diff) |
validation: Test rtems_cpu_usage_reset()
-rw-r--r-- | spec/build/testsuites/validation/validation-no-clock-0.yml | 1 | ||||
-rw-r--r-- | testsuites/validation/tc-cpuuse.c | 142 |
2 files changed, 143 insertions, 0 deletions
diff --git a/spec/build/testsuites/validation/validation-no-clock-0.yml b/spec/build/testsuites/validation/validation-no-clock-0.yml index 65d771a87f..6de52fc9c7 100644 --- a/spec/build/testsuites/validation/validation-no-clock-0.yml +++ b/spec/build/testsuites/validation/validation-no-clock-0.yml @@ -16,6 +16,7 @@ source: - testsuites/validation/tc-clock-get-uptime.c - testsuites/validation/tc-clock-nanosleep.c - testsuites/validation/tc-clock-set.c +- testsuites/validation/tc-cpuuse.c - testsuites/validation/tc-message-broadcast.c - testsuites/validation/tc-message-flush-pending.c - testsuites/validation/tc-message-macros.c diff --git a/testsuites/validation/tc-cpuuse.c b/testsuites/validation/tc-cpuuse.c new file mode 100644 index 0000000000..99dc48aebf --- /dev/null +++ b/testsuites/validation/tc-cpuuse.c @@ -0,0 +1,142 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTestCaseRtemsCpuuseValCpuuse + */ + +/* + * Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * This file is part of the RTEMS quality process and was automatically + * generated. If you find something that needs to be fixed or + * worded better please post a report or patch to an RTEMS mailing list + * or raise a bug report: + * + * https://www.rtems.org/bugs.html + * + * For information on updating and regenerating please refer to the How-To + * section in the Software Requirements Engineering chapter of the + * RTEMS Software Engineering manual. The manual is provided as a part of + * a release. For development sources please refer to the online + * documentation at: + * + * https://docs.rtems.org + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/cpuuse.h> +#include <rtems/score/threadimpl.h> + +#include "tx-support.h" + +#include <rtems/test.h> + +/** + * @defgroup RTEMSTestCaseRtemsCpuuseValCpuuse spec:/rtems/cpuuse/val/cpuuse + * + * @ingroup RTEMSTestSuiteTestsuitesValidationNoClock0 + * + * @brief Tests the CPU usage reporting and reset. + * + * This test case performs the following actions: + * + * - Create a worker thread. Generate some CPU usage. + * + * - Check that we have a non-zero CPU usage. Reset the CPU usage. Check + * that it was cleared to zero. + * + * - Clean up all used resources. + * + * @{ + */ + +static void Worker( rtems_task_argument arg ) +{ + (void) arg; + + while ( true ) { + Yield(); + } +} + +/** + * @brief Create a worker thread. Generate some CPU usage. + */ +static void RtemsCpuuseValCpuuse_Action_0( void ) +{ + rtems_id id; + Thread_Control *self; + Thread_Control *other; + Timestamp_Control timestamp; + + id = CreateTask( "WORK", GetSelfPriority() ); + StartTask( id, Worker, NULL ); + + self = GetThread( RTEMS_SELF ); + other = GetThread( id ); + + Yield(); + Yield(); + + /* + * Check that we have a non-zero CPU usage. Reset the CPU usage. Check that + * it was cleared to zero. + */ + _Thread_Get_CPU_time_used( self, ×tamp ); + T_gt_i64( timestamp, 0 ); + + _Thread_Get_CPU_time_used( other, ×tamp ); + T_gt_i64( timestamp, 0 ); + + rtems_cpu_usage_reset(); + + /* Our CPU usage is now exactly one tick of the software timecounter */ + _Thread_Get_CPU_time_used( self, ×tamp ); + T_eq_i64( timestamp, 4295 ); + + _Thread_Get_CPU_time_used( other, ×tamp ); + T_eq_i64( timestamp, 0 ); + + /* + * Clean up all used resources. + */ + DeleteTask( id ); +} + +/** + * @fn void T_case_body_RtemsCpuuseValCpuuse( void ) + */ +T_TEST_CASE( RtemsCpuuseValCpuuse ) +{ + RtemsCpuuseValCpuuse_Action_0(); +} + +/** @} */ |