--- /dev/null
+// -----------------------------------------------------------------------\r
+// Copyright (C) 2006 - 2007 by the FRESCOR consortium:\r
+//\r
+// Universidad de Cantabria, SPAIN\r
+// University of York, UK\r
+// Scuola Superiore Sant'Anna, ITALY\r
+// Kaiserslautern University, GERMANY\r
+// Univ. Politecnica Valencia, SPAIN\r
+// Czech Technical University in Prague, CZECH REPUBLIC\r
+// ENEA SWEDEN\r
+// Thales Communication S.A. FRANCE\r
+// Visual Tools S.A. SPAIN\r
+// Rapita Systems Ltd UK\r
+// Evidence ITALY\r
+//\r
+// See http://www.frescor.org\r
+//\r
+// The FRESCOR project (FP6/2005/IST/5-034026) is funded\r
+// in part by the European Union Sixth Framework Programme\r
+// The European Union is not liable of any use that may be\r
+// made of this code.\r
+//\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or \r
+// without modification, are permitted provided that the \r
+// following conditions are met:\r
+//\r
+// * Redistributions of source code must retain the above \r
+// copyright notice, this list of conditions and the \r
+// following disclaimer.\r
+// * Redistributions in binary form must reproduce the above \r
+// copyright notice, this list of conditions and the \r
+// following disclaimer in the documentation and/or other \r
+// materials provided with the distribution.\r
+// * Neither the name of FRESCOR nor the names of its \r
+// contributors may be used to endorse or promote products \r
+// derived from this software without specific prior \r
+// written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND \r
+// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, \r
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF \r
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE \r
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR \r
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, \r
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES \r
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE \r
+// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR \r
+// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF \r
+// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT \r
+// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \r
+// POSSIBILITY OF SUCH DAMAGE.\r
+// -----------------------------------------------------------------------\r
+#include "frsh.h"\r
+#include "frsh_fosa.c"\r
+#include "fosa.h"\r
+#include "fosa_app_def_sched.h"\r
+\r
+#include "fosa_ose_implementation_specific.h"\r
+\r
+#include "stdio.h"\r
+#include "string.h"\r
+#include "malloc.h"\r
+#include "test_configuration.h"\r
+#include "test_thread_and_signals.h"\r
+\r
+void test_fosa_thread_attr(void) {\r
+ frsh_thread_attr_t attr;\r
+ int ret_code[] = {-1,-1};\r
+ \r
+ //Test of function frsh_thread_attr_init().\r
+ ret_code[0] = frsh_thread_attr_init(&attr);\r
+ if (ret_code[0] == 0) {\r
+ _printf("Sucess by: frsh_thread_attr_init() \n");\r
+ } else {\r
+ printf("Failiure by: frsh_thread_attr_init() \n");\r
+ } \r
+ \r
+ //Test of function fosa_thread_attr_set/get_prio(). \r
+ //Should test priorities outside the limits, too give error.\r
+ int initial_prio = 8;\r
+ size_t retreived_prio;\r
+ ret_code[0] = fosa_thread_attr_set_prio(&attr, initial_prio);\r
+ ret_code[1] = fosa_thread_attr_get_prio(&attr, &retreived_prio);\r
+ if ((retreived_prio == initial_prio) && (ret_code[0] == 0) \r
+ && (ret_code[1] == 0 )) {\r
+ _printf("Sucess by: fosa_thread_attr_set/get_prio() \n"); \r
+ } else {\r
+ printf("Failiure by: fosa_thread_attr_set/get_prio() \n"); \r
+ } \r
+ \r
+ //Test of function frsh_thread_attr_set/get_stacksize().\r
+ size_t stacksize = 1002; //Number of bytes.\r
+ size_t received_size = 0;\r
+ ret_code[0] = frsh_thread_attr_set_stacksize(&attr, stacksize);\r
+ ret_code[1] = frsh_thread_attr_get_stacksize(&attr, &received_size);\r
+ if ((ret_code[0] == 0) &&\r
+ (ret_code[1] == 0) &&\r
+ (received_size == stacksize)) {\r
+ _printf("Sucess by: frsh_thread_attr_set/get_stacksize() \n");\r
+ } else {\r
+ printf("Failiure by: frsh_thread_attr_set/get_stacksize() \n");\r
+ } \r
+ \r
+ //Test of function fosa_thread_attr_set/get_appscheduled().\r
+ ret_code[0] = -1, ret_code[1] = -1;\r
+ ret_code[0] = fosa_thread_attr_set_appscheduled(&attr, true);\r
+ bool b = false;\r
+ ret_code[1] = fosa_thread_attr_get_appscheduled(&attr, &b);\r
+ \r
+ if ((ret_code[0] == 0) && (b) && (ret_code[1] == 0)) {\r
+ _printf("Sucess by: fosa_thread_attr_set/get_appscheduled() \n");\r
+ } else {\r
+ printf("Failiure by: fosa_thread_attr_set/get_appscheduled() \n");\r
+ }\r
+ \r
+ //Test of function fosa_thread_attr_set/get_appsched_params().\r
+ ret_code[0] = -1, ret_code[1] = -1;\r
+ char param[] = "Swedish: Karl är en långsam häst!\n";\r
+ ret_code[0] = fosa_thread_attr_set_appsched_params(&attr,\r
+ (void *)param, sizeof(param));\r
+ char *returned_param;\r
+ size_t returned_size;\r
+ \r
+ returned_param = (void *) malloc(sizeof(param)); \r
+ ret_code[1] = fosa_thread_attr_get_appsched_params(&attr,\r
+ returned_param, &returned_size);\r
+ if ((ret_code[0] == 0) && (ret_code[1] == 0) &&\r
+ (sizeof(param) == returned_size) &&\r
+ (memcmp( param,returned_param, sizeof(param)) == 0)) {\r
+ _printf("Sucess by: fosa_thread_attr_set/get_appsched_params()\n");\r
+ } else {\r
+ printf("Failiure by: fosa_thread_attr_set/get_appsched_params() \\r
+ \n");\r
+ }\r
+ free(returned_param);\r
+ \r
+ //Test of function frsh_thread_attr_destroy().\r
+ //Possible to check if memory are freed, not done here now.\r
+ ret_code[0] = frsh_thread_attr_init(&attr);\r
+ //char param[] = "Swedish: Karl är en långsam häst!\n";\r
+ ret_code[0] = fosa_thread_attr_set_appsched_params(&attr,\r
+ (void *)param, sizeof(param));\r
+ ret_code[1] = frsh_thread_attr_destroy(&attr);\r
+ if ((ret_code[0] == 0) &&\r
+ (ret_code[1] == 0)) {\r
+ _printf("Sucess by: frsh_thread_attr_destroy() \n");\r
+ } else {\r
+ printf("Failiure by: frsh_thread_attr_destroy() \n");\r
+ } \r
+\r
+ ret_code[0] = -1;\r
+ frsh_thread_id_t tid;\r
+ frsh_thread_code_t code = (void *) &test_function;\r
+ char arg[] = "Sucess by: part of fosa_thread_create(), ptr passing\n";\r
+ ret_code[0] = fosa_thread_create(&tid, NULL, code, &arg);\r
+ \r
+ \r
+ //Test of function fosa_ads_get_appscheduled().\r
+ bool set_bool = true;\r
+ bool got_bool = false;\r
+ ret_code[0] = fosa_ads_set_appscheduled(tid, set_bool);\r
+ ret_code[1] = fosa_ads_get_appscheduled(tid, &got_bool);\r
+ if ((ret_code[0] == 0) &&\r
+ (ret_code[1] == 0) &&\r
+ (got_bool == set_bool)) {\r
+ _printf("Sucess by: fosa_ads_set/get_appscheduled() \n");\r
+ } else {\r
+ printf("Failiure by: fosa_ads_set/get_appscheduled() \n");\r
+ } \r
+ \r
+ //Test of function fosa_ads_get_appschedparam() before set.\r
+ void *empty = NULL;\r
+ size_t param_size = 0;\r
+ ret_code[0] = fosa_ads_get_appsched_params(tid, empty, ¶m_size);\r
+ if ((ret_code[0] == 0) &&\r
+ (empty == NULL) &&\r
+ (param_size == 0)) {\r
+ _printf("Sucess by: fosa_ads_get_appschedparam() before set \n");\r
+ } else {\r
+ printf("Failiure by: fosa_ads_get_appschedparam() before set \n");\r
+ } \r
+ \r
+ //Test of function fosa_ads_get/set_appsched_params().\r
+ char str[] = "Kalle kan springa\n";\r
+ ret_code[0] = fosa_ads_set_appsched_params(tid, str, sizeof(str));\r
+ ret_code[1] = fosa_ads_get_appsched_params(tid, param, ¶m_size);\r
+ if ((ret_code[0] == 0) &&\r
+ (ret_code[1] == 0) &&\r
+ (strncmp(param, str, param_size) == 0)) {\r
+ _printf("Sucess by: fosa_ads_get/set_appsched_params() \n");\r
+ } else {\r
+ printf("Failiure by: fosa_ads_get/set_appsched_params() \n");\r
+ }\r
+ \r
+ //Test of function fosa_ose_process_list_node_remove().\r
+ ret_code[0] = fosa_ose_process_list_node_remove(tid);\r
+ fosa_ose_process_info_t* node = fosa_ose_process_get_node(tid);\r
+ if ((ret_code[0] == 0) &&\r
+ (node == NULL)) {\r
+ _printf("Sucess by: fosa_ose_process_list_node_remove() \n");\r
+ } else {\r
+ printf("Failiure by: fosa_ose_process_list_node_remove() \n");\r
+ }\r
+ \r
+}\r