diff options
| author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-04-13 08:15:51 +0000 | 
|---|---|---|
| committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-04-13 08:15:51 +0000 | 
| commit | f140302b0b3e9f7c84fede1120e3bb15c2c4322a (patch) | |
| tree | 86ff3985fd57c65923a911141eea0634b6affd4d /test | |
| parent | 90c431b280ac0188980b43a42b11191ca2800fa8 (diff) | |
| download | ChibiOS-f140302b0b3e9f7c84fede1120e3bb15c2c4322a.tar.gz ChibiOS-f140302b0b3e9f7c84fede1120e3bb15c2c4322a.tar.bz2 ChibiOS-f140302b0b3e9f7c84fede1120e3bb15c2c4322a.zip  | |
97.92% code coverage for threads.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@899 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'test')
| -rw-r--r-- | test/test.c | 4 | ||||
| -rw-r--r-- | test/test.mk | 2 | ||||
| -rw-r--r-- | test/testthd.c (renamed from test/testrdy.c) | 92 | ||||
| -rw-r--r-- | test/testthd.h (renamed from test/testrdy.h) | 2 | 
4 files changed, 81 insertions, 19 deletions
diff --git a/test/test.c b/test/test.c index 5cc11f542..73fbe7381 100644 --- a/test/test.c +++ b/test/test.c @@ -20,7 +20,7 @@  #include <ch.h>
  #include "test.h"
 -#include "testrdy.h"
 +#include "testthd.h"
  #include "testsem.h"
  #include "testmtx.h"
  #include "testmsg.h"
 @@ -35,7 +35,7 @@   * Array of all the test patterns.
   */
  static const struct testcase **patterns[] = {
 -  patternrdy,
 +  patternthd,
    patternsem,
    patternmtx,
    patternmsg,
 diff --git a/test/test.mk b/test/test.mk index 9f423de64..ee5128ac2 100644 --- a/test/test.mk +++ b/test/test.mk @@ -1,5 +1,5 @@  # List of all the ChibiOS/RT test files.
 -TESTSRC = ../../test/test.c      ../../test/testrdy.c   ../../test/testsem.c \
 +TESTSRC = ../../test/test.c      ../../test/testthd.c   ../../test/testsem.c \
            ../../test/testmtx.c   ../../test/testmsg.c   ../../test/testmbox.c \
            ../../test/testevt.c   ../../test/testheap.c  ../../test/testpools.c \
            ../../test/testdyn.c   ../../test/testbmk.c
 diff --git a/test/testrdy.c b/test/testthd.c index d35b783c4..92f0bfe9f 100644 --- a/test/testrdy.c +++ b/test/testthd.c @@ -27,12 +27,12 @@ static msg_t thread(void *p) {    return 0;
  }
 -static char *rdy1_gettest(void) {
 +static char *thd1_gettest(void) {
 -  return "Ready List, priority enqueuing test #1";
 +  return "Threads, enqueuing test #1";
  }
 -static void rdy1_execute(void) {
 +static void thd1_execute(void) {
    threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-5, thread, "E");
    threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-4, thread, "D");
 @@ -43,19 +43,19 @@ static void rdy1_execute(void) {    test_assert_sequence("ABCDE");
  }
 -const struct testcase testrdy1 = {
 -  rdy1_gettest,
 +const struct testcase testthd1 = {
 +  thd1_gettest,
    NULL,
    NULL,
 -  rdy1_execute
 +  thd1_execute
  };
 -static char *rdy2_gettest(void) {
 +static char *thd2_gettest(void) {
 -  return "Ready List, priority enqueuing test #2";
 +  return "Threads, enqueuing test #2";
  }
 -static void rdy2_execute(void) {
 +static void thd2_execute(void) {
    threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-4, thread, "D");
    threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-5, thread, "E");
 @@ -66,18 +66,80 @@ static void rdy2_execute(void) {    test_assert_sequence("ABCDE");
  }
 -const struct testcase testrdy2 = {
 -  rdy2_gettest,
 +const struct testcase testthd2 = {
 +  thd2_gettest,
    NULL,
    NULL,
 -  rdy2_execute
 +  thd2_execute
 +};
 +
 +static char *thd3_gettest(void) {
 +
 +  return "Threads, priority change";
 +}
 +
 +static void thd3_execute(void) {
 +  tprio_t prio, p1;
 +
 +  prio = chThdGetPriority();
 +  p1 = chThdSetPriority(prio + 1);
 +  test_assert(p1 == prio, "#1");
 +  test_assert(chThdGetPriority() == prio + 1, "#2");
 +  p1 = chThdSetPriority(p1);
 +  test_assert(p1 == prio + 1, "#3");
 +  test_assert(chThdGetPriority() == prio, "#4");
 +}
 +
 +const struct testcase testthd3 = {
 +  thd3_gettest,
 +  NULL,
 +  NULL,
 +  thd3_execute
 +};
 +
 +static char *thd4_gettest(void) {
 +
 +  return "Threads, delays";
 +}
 +
 +static void thd4_execute(void) {
 +  systime_t time;
 +
 +  /* Timeouts in microseconds.*/
 +  time = chTimeNow();
 +  chThdSleepMicroseconds(100000);
 +  test_assert(chTimeIsWithin(time + US2ST(100000), time + US2ST(100000) + 1), "#1");
 +
 +  /* Timeouts in milliseconds.*/
 +  time = chTimeNow();
 +  chThdSleepMilliseconds(100);
 +  test_assert(chTimeIsWithin(time + MS2ST(100), time + MS2ST(100) + 1), "#2");
 +
 +  /* Timeouts in seconds.*/
 +  time = chTimeNow();
 +  chThdSleepSeconds(1);
 +  test_assert(chTimeIsWithin(time + S2ST(1), time + S2ST(1) + 1), "#3");
 +
 +  /* Absolute timelines.*/
 +  time = chTimeNow() + MS2ST(100);
 +  chThdSleepUntil(time);
 +  test_assert(chTimeIsWithin(time, time + 1), "#4");
 +}
 +
 +const struct testcase testthd4 = {
 +  thd4_gettest,
 +  NULL,
 +  NULL,
 +  thd4_execute
  };
  /*
   * Test sequence for ready list pattern.
   */
 -const struct testcase * const patternrdy[] = {
 -  &testrdy1,
 -  &testrdy2,
 +const struct testcase * const patternthd[] = {
 +  &testthd1,
 +  &testthd2,
 +  &testthd3,
 +  &testthd4,
    NULL
  };
 diff --git a/test/testrdy.h b/test/testthd.h index 3be545b1b..936795e56 100644 --- a/test/testrdy.h +++ b/test/testthd.h @@ -20,6 +20,6 @@  #ifndef _TESTRDY_H_
  #define _TESTRDY_H_
 -extern const struct testcase *patternrdy[];
 +extern const struct testcase *patternthd[];
  #endif /* _TESTRDY_H_ */
  | 
