summaryrefslogtreecommitdiff
path: root/FreeRTOS/Test/Target/tests/smp/multiple_tasks_running/multiple_tasks_running.c
diff options
context:
space:
mode:
authorActoryOu <ousc@amazon.com>2023-03-06 15:47:27 +0800
committerGitHub <noreply@github.com>2023-03-06 13:17:27 +0530
commit67911f83a6b4caa5ca3fa1c99ed4e8e136a1d616 (patch)
tree65f9c8a2a229a7b39f53759bdebe29d9ad326afc /FreeRTOS/Test/Target/tests/smp/multiple_tasks_running/multiple_tasks_running.c
parent93a35f87d2afa8e531b0d75e35431755cb3eb438 (diff)
downloadfreertos-git-67911f83a6b4caa5ca3fa1c99ed4e8e136a1d616.tar.gz
Create SMP on target test framework. (#911)
* Framework initialization. * Move testRunner.c to test case subfolder. * Update README doc and formatting. * Add default configurations in test_config.h. * Fix License & formatting check. * Fix typo. * Move setup/teardown functions to main.c file. * Move setup/teardown functions back. * Update README doc. * Patch for comments. * Correct test runner file name. * Move test_config.h to the end of FreeRTOSConfig.h. * Add undef in test_config.h and description in README doc. * Correct the file format. * Fix chinglee-iot comments. * Code review suggestions Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> * Fix spell check Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> --------- Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
Diffstat (limited to 'FreeRTOS/Test/Target/tests/smp/multiple_tasks_running/multiple_tasks_running.c')
-rw-r--r--FreeRTOS/Test/Target/tests/smp/multiple_tasks_running/multiple_tasks_running.c156
1 files changed, 156 insertions, 0 deletions
diff --git a/FreeRTOS/Test/Target/tests/smp/multiple_tasks_running/multiple_tasks_running.c b/FreeRTOS/Test/Target/tests/smp/multiple_tasks_running/multiple_tasks_running.c
new file mode 100644
index 000000000..035e2699d
--- /dev/null
+++ b/FreeRTOS/Test/Target/tests/smp/multiple_tasks_running/multiple_tasks_running.c
@@ -0,0 +1,156 @@
+/*
+ * FreeRTOS V202212.00
+ * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
+ *
+ */
+
+/**
+ * @file multiple_tasks_running.c
+ * @brief The user shall be able to schedule tasks across multiple identical processor cores
+ * with one instance of FreeRTOS scheduler.
+ *
+ * Procedure:
+ * - Create ( num of cores - 1 ) tasks and keep them in busy loop.
+ * Expected:
+ * - All tasks are in running state.
+ */
+
+/* Kernel includes. */
+#include "FreeRTOS.h" /* Must come first. */
+#include "task.h" /* RTOS task related API prototypes. */
+
+/* Unity includes. */
+#include "unity.h"
+/*-----------------------------------------------------------*/
+
+#ifndef TEST_CONFIG_H
+ #error test_config.h must be included at the end of FreeRTOSConfig.h.
+#endif
+
+#if ( configNUMBER_OF_CORES < 2 )
+ #error This test is for FreeRTOS SMP and therefore, requires at least 2 cores.
+#endif /* if configNUMBER_OF_CORES != 2 */
+
+#if ( configRUN_MULTIPLE_PRIORITIES != 1 )
+ #error configRUN_MULTIPLE_PRIORITIES must be set to 1 for this test.
+#endif /* if ( configRUN_MULTIPLE_PRIORITIES != 1 ) */
+
+#if ( configMAX_PRIORITIES <= 2 )
+ #error configMAX_PRIORITIES must be larger than 2 to avoid scheduling idle tasks unexpectedly.
+#endif /* if ( configMAX_PRIORITIES <= 2 ) */
+/*-----------------------------------------------------------*/
+
+/**
+ * @brief Function that implements a never blocking FreeRTOS task.
+ */
+static void prvEverRunningTask( void * pvParameters );
+
+/**
+ * @brief Test case "Multiple Tasks Running".
+ */
+static void Test_MultipleTasksRunning( void );
+/*-----------------------------------------------------------*/
+
+/**
+ * @brief Handles of the tasks created in this test.
+ */
+static TaskHandle_t xTaskHandles[ configNUMBER_OF_CORES - 1 ];
+/*-----------------------------------------------------------*/
+
+static void Test_MultipleTasksRunning( void )
+{
+ int i;
+ eTaskState xTaskState;
+
+ /* Delay for other cores to run tasks. */
+ vTaskDelay( pdMS_TO_TICKS( 10 ) );
+
+ /* Ensure that all the tasks are running. */
+ for( i = 0; i < ( configNUMBER_OF_CORES - 1 ); i++ )
+ {
+ xTaskState = eTaskGetState( xTaskHandles[ i ] );
+
+ TEST_ASSERT_EQUAL_MESSAGE( eRunning, xTaskState, "Task is not running." );
+ }
+}
+/*-----------------------------------------------------------*/
+
+static void prvEverRunningTask( void * pvParameters )
+{
+ /* Silence warnings about unused parameters. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* Always running, put asm here to avoid optimization by compiler. */
+ __asm volatile ( "nop" );
+ }
+}
+/*-----------------------------------------------------------*/
+
+/* Runs before every test, put init calls here. */
+void setUp( void )
+{
+ int i;
+ BaseType_t xTaskCreationResult;
+
+ /* Create configNUMBER_OF_CORES - 1 low priority tasks. */
+ for( i = 0; i < ( configNUMBER_OF_CORES - 1 ); i++ )
+ {
+ xTaskCreationResult = xTaskCreate( prvEverRunningTask,
+ "EverRunning",
+ configMINIMAL_STACK_SIZE,
+ NULL,
+ configMAX_PRIORITIES - 2,
+ &( xTaskHandles[ i ] ) );
+
+ TEST_ASSERT_EQUAL_MESSAGE( pdPASS, xTaskCreationResult, "Task creation failed." );
+ }
+}
+/*-----------------------------------------------------------*/
+
+/* Runs after every test, put clean-up calls here. */
+void tearDown( void )
+{
+ int i;
+
+ /* Delete all the tasks. */
+ for( i = 0; i < ( configNUMBER_OF_CORES - 1 ); i++ )
+ {
+ if( xTaskHandles[ i ] != NULL )
+ {
+ vTaskDelete( xTaskHandles[ i ] );
+ }
+ }
+}
+/*-----------------------------------------------------------*/
+
+void vRunMultipleTasksRunningTest( void )
+{
+ UNITY_BEGIN();
+
+ RUN_TEST( Test_MultipleTasksRunning );
+
+ UNITY_END();
+}
+/*-----------------------------------------------------------*/