]> rtime.felk.cvut.cz Git - frescor/fosa.git/blobdiff - src_ose/frescor_fosa_test/src/test_clocks_and_timers.c
• Brief description:
[frescor/fosa.git] / src_ose / frescor_fosa_test / src / test_clocks_and_timers.c
diff --git a/src_ose/frescor_fosa_test/src/test_clocks_and_timers.c b/src_ose/frescor_fosa_test/src/test_clocks_and_timers.c
new file mode 100644 (file)
index 0000000..da82d14
--- /dev/null
@@ -0,0 +1,141 @@
+// -----------------------------------------------------------------------\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 "time.h"\r
+#include "stdio.h"\r
+#include "ose.h"\r
+#include "fosa.h"\r
+#include "test_configuration.h"\r
+\r
+#define FOSA_OSE_TEST_SIGNAL 300\r
+\r
+\r
+void test_fosa_clocks_and_timers(void) {\r
+    int ret_code = -1;\r
+    \r
+    //Test of function fosa_thread_get_cputime_clock().\r
+    PROCESS pid = current_process();\r
+    fosa_clock_id_t clock_id;\r
+    int ret_code2 = fosa_thread_get_cputime_clock(0, &clock_id);\r
+    ret_code = fosa_thread_get_cputime_clock(pid, &clock_id);\r
+    if ((ret_code == 0) && ( pid == clock_id) && (ret_code2 == EINVAL)){\r
+        _printf("Sucess by: fosa_thread_get_cputime_clock() \n");\r
+    } else {\r
+        printf("Failiure by: fosa_thread_get_cputime_clock() \n");\r
+    } \r
+    \r
+    //Test of function fosa_clock_get_time().\r
+    struct timespec current_time;\r
+    ret_code = fosa_clock_get_time(FOSA_CLOCK_REALTIME, &current_time);\r
+    if ((ret_code == 0) && \r
+        ((current_time.tv_sec > 0) || (current_time.tv_nsec > 0))) {\r
+        _printf("Sucess by: fosa_clock_get_time() \n");\r
+        //printf("Sucess by: fosa_clock_get_time(), time(s:ns): %010ld:%010ld \n",\r
+        //       current_time.tv_sec,current_time.tv_nsec);\r
+    } else {\r
+        printf("Failiure by: fosa_clock_get_time(), time(s:ns): %010ld:%010ld \n",\r
+               current_time.tv_sec,current_time.tv_nsec);\r
+    }\r
+    \r
+    //Test of function fosa_timer_create().\r
+    clock_id = 0;\r
+    frsh_signal_info_t  info;\r
+    fosa_timer_id_t     timerid;\r
+    frsh_signal_t signal    = FOSA_OSE_TEST_SIGNAL;\r
+    info.value              = 50;\r
+    ret_code = fosa_timer_create(clock_id, signal, info, &timerid);\r
+    if (ret_code == 0) {\r
+        _printf("Sucess by: fosa_timer_create() \n");\r
+    } else {\r
+        printf("Failiure by: fosa_timer_create() \n");\r
+    }\r
+    \r
+    //Test of function fosa_timer_arm().\r
+    bool abstime = false;\r
+    frsh_signal_t set[] = {FOSA_OSE_TEST_SIGNAL};\r
+    frsh_signal_t signal_received;\r
+    frsh_signal_info_t info_received;\r
+    struct timespec value = {0, 5000000};\r
+     \r
+    ret_code = fosa_timer_arm(timerid, abstime, &value);\r
+    fosa_signal_timedwait(set, 1, &signal_received, \r
+       &info_received, &value); \r
+    if ((ret_code == 0) &&\r
+        (signal_received == FOSA_OSE_TEST_SIGNAL) &&\r
+        (info_received.value == 50)) \r
+    {\r
+        _printf("Sucess by: fosa_timer_arm() \n");\r
+    } else {\r
+        printf("Failiure by: fosa_timer_arm() \n");\r
+    }\r
+    \r
+    //Test of function fosa_timer_disarm().\r
+    fosa_timer_arm(timerid, abstime, &value);\r
+    ret_code = fosa_timer_disarm(timerid);\r
+    if (ret_code == 0) {\r
+        _printf("Sucess by: fosa_timer_disarm() \n");\r
+    } else {\r
+        printf("Failiure by: fosa_timer_disarm() \n");\r
+    } \r
+\r
+    //Test of function fosa_timer_delete().\r
+    fosa_timer_arm(timerid, abstime, &value);\r
+    ret_code = fosa_timer_delete(timerid);\r
+    if (ret_code == 0) {\r
+        _printf("Sucess by: fosa_timer_delete() \n");\r
+    } else {\r
+        printf("Failiure by: fosa_timer_delete() \n");\r
+    }    \r
+}\r