|
0
|
1 //========================================================================== |
|
|
2 // |
|
|
3 // cnt_sem1.cxx |
|
|
4 // |
|
|
5 // Counting semaphore test 1 |
|
|
6 // |
|
|
7 //========================================================================== |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //========================================================================== |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): dsm |
|
|
33 // Contributors: dsm |
|
|
34 // Date: 1998-02-24 |
|
|
35 // Description: Tests basic counting semaphore functionality. |
|
|
36 //####DESCRIPTIONEND#### |
|
|
37 |
|
|
38 #include <pkgconf/kernel.h> |
|
|
39 |
|
|
40 #include <cyg/kernel/thread.hxx> // Cyg_Thread |
|
|
41 #include <cyg/kernel/thread.inl> |
|
|
42 #include <cyg/kernel/sched.hxx> // Cyg_Scheduler::start() |
|
|
43 |
|
|
44 #include <cyg/kernel/sema.hxx> |
|
|
45 |
|
|
46 #include <cyg/infra/testcase.h> |
|
|
47 |
|
|
48 #include <cyg/kernel/sched.inl> |
|
|
49 |
|
|
50 |
|
|
51 #define NTHREADS 2 |
|
|
52 #include "testaux.hxx" |
|
|
53 |
|
|
54 static Cyg_Counting_Semaphore s0(0), s1(2), s2; |
|
|
55 |
|
|
56 static volatile cyg_ucount8 q = 0; |
|
|
57 |
|
|
58 static void entry0( CYG_ADDRWORD data ) |
|
|
59 { |
|
|
60 s0.wait(); |
|
|
61 CHECK( 1 == q++ ); |
|
|
62 s1.post(); |
|
|
63 s0.wait(); |
|
|
64 CHECK( 3 == q++ ); |
|
|
65 CHECK( 0 == s0.peek() ); |
|
|
66 CHECK( ! s0.trywait() ); |
|
|
67 s0.post(); |
|
|
68 CHECK( 4 == q++ ); |
|
|
69 CHECK( 1 == s0.peek() ); |
|
|
70 s0.post(); |
|
|
71 CHECK( 2 == s0.peek() ); |
|
|
72 s1.post(); |
|
|
73 CHECK( 0 == s2.peek() ); |
|
|
74 s2.wait(); |
|
|
75 CHECK( 6 == q++ ); |
|
|
76 CYG_TEST_PASS_FINISH("Counting Semaphore 1 OK"); |
|
|
77 } |
|
|
78 |
|
|
79 static void entry1( CYG_ADDRWORD data ) |
|
|
80 { |
|
|
81 CHECK( 2 == s1.peek() ); |
|
|
82 s1.wait(); |
|
|
83 CHECK( 1 == s1.peek() ); |
|
|
84 s1.wait(); |
|
|
85 CHECK( 0 == q++ ); |
|
|
86 CHECK( 0 == s0.peek() ); |
|
|
87 s0.post(); |
|
|
88 s1.wait(); |
|
|
89 CHECK( 2 == q++ ); |
|
|
90 s0.post(); |
|
|
91 s1.wait(); |
|
|
92 CHECK( 5 == q++ ); |
|
|
93 CHECK( 2 == s0.peek() ); |
|
|
94 CHECK( s0.trywait() ); |
|
|
95 CHECK( 1 == s0.peek() ); |
|
|
96 CHECK( s0.trywait() ); |
|
|
97 CHECK( 0 == s0.peek() ); |
|
|
98 s2.post(); |
|
|
99 s0.wait(); |
|
|
100 CYG_TEST_FAIL_FINISH("Not reached"); |
|
|
101 } |
|
|
102 |
|
|
103 void cnt_sem1_main( void ) |
|
|
104 { |
|
|
105 CYG_TEST_INIT(); |
|
|
106 |
|
|
107 new_thread(entry0, 0); |
|
|
108 new_thread(entry1, 1); |
|
|
109 |
|
|
110 Cyg_Scheduler::start(); |
|
|
111 |
|
|
112 CYG_TEST_FAIL_FINISH("Not reached"); |
|
|
113 } |
|
|
114 |
|
|
115 externC void |
|
|
116 cyg_start( void ) |
|
|
117 { |
|
|
118 cnt_sem1_main(); |
|
|
119 } |
|
|
120 |
|
|
121 // EOF cnt_sem1.cxx |