--- /dev/null
+// -----------------------------------------------------------------------
+// Copyright (C) 2006 - 2007 by the FRESCOR consortium:
+//
+// Universidad de Cantabria, SPAIN
+// University of York, UK
+// Scuola Superiore Sant'Anna, ITALY
+// Kaiserslautern University, GERMANY
+// Univ. Politecnica Valencia, SPAIN
+// Czech Technical University in Prague, CZECH REPUBLIC
+// ENEA SWEDEN
+// Thales Communication S.A. FRANCE
+// Visual Tools S.A. SPAIN
+// Rapita Systems Ltd UK
+// Evidence ITALY
+//
+// See http://www.frescor.org
+//
+// The FRESCOR project (FP6/2005/IST/5-034026) is funded
+// in part by the European Union Sixth Framework Programme
+// The European Union is not liable of any use that may be
+// made of this code.
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or
+// without modification, are permitted provided that the
+// following conditions are met:
+//
+// * Redistributions of source code must retain the above
+// copyright notice, this list of conditions and the
+// following disclaimer.
+// * 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.
+// * Neither the name of FRESCOR nor the names of its
+// contributors may be used to endorse or promote products
+// derived from this software without specific prior
+// written permission.
+//
+// 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.
+// -----------------------------------------------------------------------
+/**
+ * @file fosa_test.c
+ *
+ * @brief This file makes test for the adaption layer fosa.
+ *
+ */
+#include "sys/time.h"
+#include "ose.h"
+#include "efs.h"
+#include "stdio.h"
+#include "string.h"
+#include "ramlog.h"
+
+#include "test_configuration.h"
+#include "fosa.h"
+#include "frsh.h"
+#include "test_condvars.h"
+#include "test_mutexes.h"
+#include "test_thread_and_signals.h"
+#include "test_thread_attr.h"
+#include "test_clocks_and_timers.h"
+#include "test_appsched.h"
+#include "test_execution_time_measurement.h"
+
+
+const char fosa_test_synopsis[] = "frescor_fosa_test";
+const char fosa_test_descr[] = "test of frescor_fosa functions";
+
+
+typedef struct {
+ SIGSELECT signo;
+ char text[1]; /* Variable size. */
+}print_sig_t;
+
+union SIGNAL {
+ SIGSELECT signo;
+ print_sig_t print_sig;
+};
+
+static OS_PROCESS(world)
+{
+ static const SIGSELECT sel_any[] = { 0 };
+ union SIGNAL *sig;
+ int i;
+
+ for(i=0; i<2; i++) {
+ /* Receive first signal in signal queue. */
+ sig = receive(sel_any);
+
+ /* Check signal number. */
+ switch(sig->signo) {
+ /* Act on the PRINT_SIG signal. */
+ case TEST_SIG :
+ {
+ print_sig_t *prsig = (print_sig_t *)sig;
+ char text[100] = "";
+ strcat(text, prsig->text);
+ strcat(text,
+ ", recieved and printed by world process!\n");
+ fputs(text, stdout);
+ break;
+ }
+
+ case PRINT_SIG :
+ {
+ print_sig_t *prsig = (print_sig_t *)sig;
+ fputs(prsig->text, stdout);
+ break;
+ }
+
+ /* Call error() for all unexpected signals. */
+ default :
+ printf("Error i världen.\n ");
+ error2(0xFFFFFFFE, (OSERRCODE)sig);
+ break;
+ }
+ /* Free received signal. */
+ free_buf(&sig);
+ }
+ /* Send signal to world process. */
+ print_sig_t *my_sig;
+ PROCESS moon_pid;
+
+ /* Finn process id för world processen. */
+ hunt("moon", 0, &moon_pid, (union SIGNAL **) NULL);
+
+ /* Text att sända */
+ static const char ping_msg[] = "Pong! From world process";
+
+ /* Allokera minne för signalen och ge den ett signalnummer/typ. */
+ my_sig = (print_sig_t *)alloc(sizeof(print_sig_t) +
+ strlen(ping_msg), TEST_SIG);
+ strcpy(my_sig->text, ping_msg);
+
+ /* Sänd signalen till world */
+ send((union SIGNAL **)&my_sig, moon_pid);
+
+//-----------------------------Test case----------------------------------
+ //Test of function fosa_signal_queue().
+ frsh_signal_t signal_nr = 500;
+ frsh_signal_info_t signal_info;
+ signal_info.value = 8;
+ int ret_code;
+ for (i = 0; i < 3; ++i) {
+ ret_code = fosa_signal_queue(signal_nr+i, signal_info, moon_pid);
+ if (ret_code == 0) {
+ _printf("Sucess by: fosa_signal_queue() \n");
+ } else {
+ printf("Failiure by: fosa_signal_queue(), error code: %d \n",
+ ret_code);
+ }
+ signal_info.value++;
+ }
+ delay(200); //To make the recive timeout (fosa_signal_timedwait).
+ fosa_signal_queue(signal_nr+i, signal_info, moon_pid);
+//-----------------------------End test case------------------------------
+
+ /* Terminate self (open files are NOT flushed and closed). */
+ kill_proc(current_process());
+}
+
+static OS_PROCESS(moon)
+{
+ //delay(10000);
+//-----------------------------Test cases---------------------------------
+ test_fosa_threads_and_signals_from_moon(current_process());
+
+//-----------------------------End test cases-----------------------------
+
+ static const SIGSELECT sel_any[] = { 0 };
+ union SIGNAL *sig;
+ print_sig_t *my_sig;
+ PROCESS world_pid;
+
+ /* Send signal to world process. */
+ static const char ping_msg[] = "\nPing! From moon process";
+
+ /* Allokera minne för signalen och ge den ett signalnummer/typ. */
+ my_sig = (print_sig_t *)alloc(sizeof(print_sig_t) +
+ strlen(ping_msg), TEST_SIG);
+ strcpy(my_sig->text, ping_msg);
+
+ /* Finn process id för world processen. */
+ hunt("world", 0, &world_pid, (union SIGNAL **) NULL);
+
+ /* Sänd signalen till world */
+ send((union SIGNAL **)&my_sig, world_pid);
+
+ int i;
+ for(i=0; i<2; i++) {
+ /* Receive first signal in signal queue. */
+ sig = receive(sel_any);
+
+ /* Check signal number. */
+ switch(sig->signo)
+ {
+ /* Act on the PRINT_SIG signal. */
+ case TEST_SIG :
+ {
+ print_sig_t *prsig = (print_sig_t *)sig;
+ char text[100] = "";
+ strcat(text, prsig->text);
+ strcat(text,
+ ", recieved and printed by moon process!\n\n");
+ fputs(text, stdout);
+ break;
+ }
+
+ case PRINT_SIG :
+ {
+ print_sig_t *prsig = (print_sig_t *)sig;
+ fputs(prsig->text, stdout);
+
+ test_fosa_mutexes();
+ break;
+ }
+
+ /* Call error() for all unexpected signals. */
+ default :
+ printf("Error på månen.\n ");
+ error2(0xFFFFFFFE, (OSERRCODE)sig);
+ break;
+ }
+ free_buf(&sig);
+
+ }
+
+//-----------------------------Test case----------------------------------
+ //Test of function fosa_signal_wait().
+ frsh_signal_t set_of_accepted_signals[] ={499, 500, 502, 503};
+ frsh_signal_t signal_received;
+ frsh_signal_info_t signal_info;
+ int size = 4, ret_code = -1;
+ ret_code = fosa_signal_wait(set_of_accepted_signals, size,
+ &signal_received, &signal_info);
+ if ((signal_info.value == 8) &&
+ (signal_received == 500) &&
+ (ret_code == 0)) {
+ _printf("Sucess by: fosa_signal_wait() \n");
+ } else {
+ printf("Failiure by: fosa_signal_wait() \n");
+ }
+
+ //Test of function fosa_signal_timedwait().
+ //First test to receive directly and then if timeout.
+ //Better timedout test is needed................................
+ struct timespec *time_to_wait;
+ time_to_wait->tv_nsec = 40000; time_to_wait->tv_sec = 0;
+ ret_code = fosa_signal_timedwait(set_of_accepted_signals, size,
+ &signal_received, &signal_info, time_to_wait);
+ if ((signal_info.value == 10) &&
+ (signal_received == 502) &&
+ (ret_code == 0)) {
+ _printf("Sucess by: fosa_signal_timedwait() \n");
+ } else {
+ printf("Failiure by: fosa_signal_timedwait() \n");
+ }
+ time_to_wait->tv_nsec = 1000;
+ time_to_wait->tv_sec = 0;
+ ret_code = fosa_signal_timedwait(set_of_accepted_signals, size,
+ &signal_received, &signal_info, time_to_wait);
+ if (ret_code == FOSA_EAGAIN) {
+ _printf("Sucess by: fosa_signal_timedwait() \n");
+ // (int)ret_code);
+ } else {
+ printf("Failiure by: fosa_signal_timedwait(), ret_code: %d\n",
+ (int)ret_code);
+ }
+//-----------------------------End test case------------------------------
+
+ /* Terminate self (open files are NOT flushed and closed). */
+ kill_proc(current_process());
+}
+
+static OS_PROCESS(mars) {
+ test_fosa_condvars_from_process_one();
+ kill_proc(current_process());
+}
+
+static OS_PROCESS(mars2) {
+ test_fosa_condvars_from_process_two();
+ kill_proc(current_process());
+}
+
+const char hello_synopsis[] = "hello";
+const char hello_descr[] = "print hello world!";
+
+int fosa_test_main(int argc, char *argv[])
+{
+ printf("\n");
+
+//-----------------------------Test cases---------------------------------
+ _printf(
+ " Tis program tests the individual FOSA-functions. \n\n\
+ Testcases begin and the following tests are made. When you\n\
+ see this text the macro for viewing each successed test are turned \n\
+ on, standard are to have this off. If it is off, you will only see \n\
+ the tests that fail. Configure this in the file \n\
+ test_configuration.h and rebuild. \n\n");
+
+ ramlog_printf("FOSA_TEST: started.\n");
+
+ test_fosa_appsched();
+
+ test_fosa_thread_attr();
+
+ test_fosa_clocks_and_timers();
+
+ test_fosa_appsched_system_test();
+
+ test_fosa_execution_time_measurement();
+
+ //Test of function fosa_signal_queue().
+ //First test of limits then functionality.
+ frsh_signal_t frsh_signal[] = {250,30000,260}; //Not valid x2, valid.
+ frsh_signal_info_t info_union;
+ info_union.value=5;
+ int i;
+ for (i = 0; i < 3; ++i) {
+ //Not shore about the accepted process numbers here (error if to
+ //small number in the reciever in send. Might need to be at least
+ //documented.
+ int ret = fosa_signal_queue( frsh_signal[i],
+ info_union, (frsh_thread_id_t) current_process() );
+ if ((ret != FOSA_EINVAL && i==1) ||
+ (ret != FOSA_EINVAL && i==0) ||
+ (ret == FOSA_EINVAL && i>=2)) {
+ printf("Failiure by: fosa_signal_queue() \n");
+
+ } else {
+ _printf("Sucess by: fosa_signal_queue() \n");
+ }
+ }
+
+//-----------------------------End test cases-----------------------------
+
+ PROCESS world_pid;
+ static const SIGSELECT sel_attach[] = { 1, OS_ATTACH_SIG };
+ union SIGNAL *sig;
+ print_sig_t *prsig;
+ static const char msg[] = "world!!\n";
+
+ /* Create world process with same type and priority. */
+ world_pid = create_process(OS_PRI_PROC, /* Process type. */
+ "world", /* Name. */
+ world, /* Entrypoint. */
+ 1000, /* Stacksize. */
+ 3, /* Priority. */
+ 0, 0, NULL, 0, 0); /* Uninteresting. */
+ /* Supervise world process (attach default signal to it). */
+ attach(NULL, world_pid);
+
+ /* Make world process inherit my stdio etc. */
+ efs_clone(world_pid);
+
+
+ /* Allocate, initialize and send signal with text to print. */
+ prsig = (print_sig_t *)alloc(sizeof(print_sig_t) + strlen(msg),
+ PRINT_SIG);
+ strcpy(prsig->text, msg);
+ send((union SIGNAL **)&prsig, world_pid);
+
+ /* Print first part of message. */
+ printf("\nYellow ");
+
+//-----------------------------Test cases---------------------------------
+ //Test of function fosa_ose_execute_action_activate().
+ extern void fosa_ose_execute_action_activate();
+ fosa_ose_execute_action_activate(world_pid);
+
+ //Test of function fosa_ose_execute_action_suspend().
+ extern void fosa_ose_execute_action_suspend();
+ fosa_ose_execute_action_suspend(world_pid);
+
+ //Test of function fosa_thread_set/get_prio().
+ int new_prio = 20000, got_prio=-1;
+ int ret_code = -1;
+ ret_code = fosa_thread_set_prio(world_pid, new_prio);
+ if (ret_code == FOSA_EINVAL) {
+ _printf("Sucess by: fosa_thread_set/get_prio(), ret code. \n");
+ } else {
+ printf("Failiure by: fosa_thread_set/get_prio(), ret code. \n");
+ }
+ new_prio = 5;
+ ret_code = fosa_thread_set_prio(world_pid, new_prio);
+ if (ret_code == 0) {
+ _printf("Sucess by: fosa_thread_set/get_prio(), set \n");
+ } else {
+ printf("Failiure by: fosa_thread_set/get_prio(), set. \n");
+ }
+ ret_code = fosa_thread_get_prio(world_pid, &got_prio);
+ if ((ret_code == 0) && (got_prio == new_prio)) {
+ _printf("Sucess by: fosa_thread_set/get_prio() \n");
+ } else {
+ printf("Failiure by: fosa_thread_set/get_prio(). \n \
+ Prio set to %d, got %d. \n", new_prio, got_prio);
+ }
+
+//-----------------------------End test cases-----------------------------
+ /* Start world process. */
+ start(world_pid);
+
+ /*My own code*/
+ PROCESS moon_pid;
+ static const char moon_msg[] = "moon!\n";
+ moon_pid = create_process(OS_PRI_PROC, /* Process type. */
+ "moon", /* Name. */
+ moon, /* Entrypoint. */
+ 2000, /* Stacksize. */
+ 23, /* Priority. */
+ 0, 0, NULL, 0, 0); /* Uninteresting. */
+
+ attach(NULL, moon_pid);
+ efs_clone(moon_pid);
+ prsig = (print_sig_t *)alloc(sizeof(print_sig_t) + strlen(moon_msg),
+ PRINT_SIG);
+ strcpy(prsig->text, moon_msg);
+ send((union SIGNAL **)&prsig, moon_pid);
+
+//-----------------------------Test cases---------------------------------
+ test_fosa_threads_and_signals(world_pid, moon_pid);
+
+//-----------------------------End test cases-----------------------------
+ printf("Yelloww "); fflush(stdout);
+ start(moon_pid);
+
+ /* Wait for world and moon processes to terminate. */
+ sig = receive(sel_attach);
+ free_buf(&sig);
+ sig = receive(sel_attach);
+ free_buf(&sig);
+
+ //Mars process to test parts of condvars.
+ PROCESS mars_pid;
+ mars_pid = create_process(OS_PRI_PROC, /* Process type. */
+ "mars", /* Name. */
+ mars, /* Entrypoint. */
+ 2000, /* Stacksize. */
+ 23, /* Priority. */
+ 0, 0, NULL, 0, 0); /* Unintresting. */
+
+ attach(NULL, mars_pid);
+ efs_clone(mars_pid);
+
+ //Mars2 process to test parts of condvars.
+ PROCESS mars2_pid;
+ mars2_pid = create_process(OS_PRI_PROC, /* Process type. */
+ "mars2", /* Name. */
+ mars2, /* Entrypoint. */
+ 2000, /* Stacksize. */
+ 23, /* Priority. */
+ 0, 0, NULL, 0, 0); /* Unintresting. */
+
+ attach(NULL, mars2_pid);
+ efs_clone(mars2_pid);
+
+ start(mars_pid);
+ start(mars2_pid);
+
+ // Wait for two times Mars processes to terminate.
+ sig = receive(sel_attach);
+ free_buf(&sig);
+ sig = receive(sel_attach);
+ free_buf(&sig);
+
+ /* Expand LIBWHAT macro in order to reference library what-string. */
+#ifdef LIBWHAT
+ LIBWHAT
+#endif
+ _printf("\nFOSA_TEST: ended.\n");
+ _printf("\n");
+
+ /* Return success from my command. */
+ return 0;
+
+}