Changeset 12781 for trunk/psLib/test/sys/tap_psTrace.c
- Timestamp:
- Apr 10, 2007, 11:09:31 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/sys/tap_psTrace.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/sys/tap_psTrace.c
r12513 r12781 8 8 #include <fcntl.h> 9 9 #include <unistd.h> 10 11 10 #include "pslib.h" 12 11 #include "tap.h" … … 14 13 15 14 16 static psS32 testTrace00(void);17 static psS32 testTrace01(void);18 static psS32 testTrace02(void);19 static psS32 testTrace03(void);20 static psS32 testTrace04(void);21 static psS32 testTrace05(void);22 static psS32 testTrace05a(void);23 static psS32 testTrace06(void);24 static psS32 testTrace08(void);25 26 27 15 psS32 main( psS32 argc, char* argv[] ) 28 16 { 29 plan_tests(45); 30 31 testTrace00(); 32 testTrace01(); 33 testTrace02(); 34 testTrace03(); 35 testTrace04(); 36 testTrace05(); 37 testTrace05a(); 38 testTrace06(); 39 testTrace08(); 40 } 41 42 43 static psS32 testTrace00(void) 44 { 45 // diag("testTrace00"); 46 47 psS32 i; 48 psS32 lev = 0; 49 50 // psTraceSetDestination(stderr); 51 (void)psTraceSetDestination(2); 52 53 for (i=0;i<10;i++) { 54 (void)psTraceSetLevel(".", i); 55 lev = psTraceGetLevel("."); 56 ok(lev == i, "trace level was %d, actual was %d\n", i, lev); 57 } 58 59 (void)psTraceSetLevel(".", 3); 60 61 for (i=5;i<10;i++) { 62 (void)psTraceSetLevel(".NODE00", i); 63 lev = psTraceGetLevel(".NODE00"); 64 ok (lev == i,"(.NODE00) expected trace level was %d, actual was %d\n", 65 i, lev); 66 67 lev = psTraceGetLevel("."); 68 ok (lev == 3, 69 "expected trace level was %d, actual was %d\n", i, 3); 70 } 71 72 73 (void)psTraceSetLevel(".NODE00.NODE01", 4); 74 for (i=0;i<10;i++) { 75 (void)psTraceSetLevel(".NODE00.NODE01", i); 76 lev = psTraceGetLevel(".NODE00.NODE01"); 77 ok (lev == i, 78 "(.NODE00.NODE01) expected trace level was %d, actual was %d\n", 79 i, lev); 80 } 81 82 return 0; 83 } 84 85 86 static psS32 testTrace01(void) 87 { 88 // diag("testTrace01"); 89 90 // psTraceSetDestination(stderr); 91 (void)psTraceSetDestination(2); 92 (void)psTraceSetLevel(".A.B.C.D.E", 5); 93 94 psTrace(".A.C.D.C",1,"You should not see this.\n"); 95 psTrace(".A.B.C.D.E",2,"You should see this.\n"); 96 psTrace(".A.B.C.D.E.F",3,"You should see this too.\n"); 97 98 psTracePrintLevels(); 99 100 return 0; 101 } 102 103 static psS32 testTrace02(void) 104 { 105 // diag("testTrace02"); 106 107 psTraceReset(); 108 // psTraceSetDestination(stderr); 109 (void)psTraceSetDestination(2); 110 (void)psTraceSetLevel(".A.B", 2); 111 (void)psTraceSetLevel(".A.B.C.D.E", 5); 112 psTracePrintLevels(); 113 (void)psTraceSetLevel(".A.B", 10); 114 psTracePrintLevels(); 115 116 ok (10 == psTraceGetLevel(".A.B.C"), 117 ".A.B.C did not dynamically inherit a trace level (%d)\n", 118 psTraceGetLevel(".A.B.C")); 119 120 ok (10 == psTraceGetLevel(".A.B.C.D"), 121 ".A.B.C.D did not dynamically inherit a trace level (%d)\n", 122 psTraceGetLevel(".A.B.C.D")); 123 124 ok (5 == psTraceGetLevel(".A.B.C.D.E"), 125 ".A.B.C.D.E did dynamically inherit a trace level (%d)\n", 126 psTraceGetLevel(".A.B.C.D.E")); 127 128 return 0; 129 } 130 131 static psS32 testTrace03(void) 132 { 133 // diag("testTrace03"); 134 135 psS32 i = 0; 136 psS32 lev = 0; 137 138 // psTraceSetDestination(stderr); 139 (void)psTraceSetDestination(2); 140 141 for (i=0;i<10;i++) { 142 (void)psTraceSetLevel(".", i); 143 psTraceReset(); 144 145 lev = psTraceGetLevel("."); 146 ok (lev == PS_UNKNOWN_TRACE_LEVEL, 147 "expected trace level was %d, actual was %d\n", 148 PS_UNKNOWN_TRACE_LEVEL, lev); 149 } 150 151 (void)psTraceSetLevel(".", 5); 152 (void)psTraceSetLevel(".a", 4); 153 (void)psTraceSetLevel(".a.b", 3); 154 (void)psTraceSetLevel(".a.b.c", 2); 155 ok (!((5 != psTraceGetLevel(".")) || 156 (4 != psTraceGetLevel(".a")) || 157 (3 != psTraceGetLevel(".a.b")) || 158 (2 != psTraceGetLevel(".a.b.c"))), 159 "trace successFlag = false;levels were not settable?\n"); 160 161 psTraceReset(); 162 ok (!((PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".")) || 163 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a")) || 164 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a.b")) || 165 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a.b.c"))), 166 "trace levels were not reset properly\n"); 167 168 return 0; 169 } 170 171 172 static psS32 testTrace04(void) 173 { 174 // diag("testTrace04"); 175 176 int FD; 177 psS32 nb = 0; 178 FD = creat("tst_psTrace02_OUT", 0666); 179 // printf("\nFD = %d\n", FD); 180 // fp = fopen("tst_psTrace02_OUT", "w"); 181 for (nb = 0 ; nb<4;nb++) { 182 if (nb == 0) 183 // psTraceSetDestination(stdout); 184 (void)psTraceSetDestination(1); 185 if (nb == 1) 186 // psTraceSetDestination(stderr); 187 (void)psTraceSetDestination(2); 188 if (nb == 2) 189 (void)psTraceSetDestination(0); //NULL 190 if (nb == 3) 191 (void)psTraceSetDestination(FD); 192 193 (void)psTraceSetLevel(".", 4); 194 psTrace(".", 5, "(0) This message should not be displayed (%x)\n", 195 0xbeefface); 196 (void)psTraceSetLevel(".", 7); 197 psTrace(".", 5, "(0) This message should be displayed (%x)\n", 198 0xbeefface); 199 17 psLogSetFormat("HLNM"); 18 psLogSetLevel(PS_LOG_INFO); 19 plan_tests(54); 20 21 // testTrace00() 22 { 23 psMemId id = psMemGetId(); 24 psS32 lev = 0; 25 (void)psTraceSetDestination(2); 26 for (int i=0;i<10;i++) { 27 (void)psTraceSetLevel(".", i); 28 lev = psTraceGetLevel("."); 29 ok(lev == i, "trace level was %d, actual was %d", i, lev); 30 } 31 32 (void)psTraceSetLevel(".", 3); 33 for (int i=5;i<10;i++) { 34 (void)psTraceSetLevel(".NODE00", i); 35 lev = psTraceGetLevel(".NODE00"); 36 ok (lev == i,"(.NODE00) expected trace level was %d, actual was %d", 37 i, lev); 38 39 lev = psTraceGetLevel("."); 40 ok (lev == 3, 41 "expected trace level was %d, actual was %d", i, 3); 42 } 43 44 (void)psTraceSetLevel(".NODE00.NODE01", 4); 45 for (int i=0;i<10;i++) { 46 (void)psTraceSetLevel(".NODE00.NODE01", i); 47 lev = psTraceGetLevel(".NODE00.NODE01"); 48 ok (lev == i, 49 "(.NODE00.NODE01) expected trace level was %d, actual was %d", 50 i, lev); 51 } 52 53 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 54 } 55 56 57 // testTrace01() 58 { 59 psMemId id = psMemGetId(); 60 (void)psTraceSetDestination(2); 61 (void)psTraceSetLevel(".A.B.C.D.E", 5); 62 psTrace(".A.C.D.C",1,"You should not see this"); 63 psTrace(".A.B.C.D.E",2,"You should see this"); 64 psTrace(".A.B.C.D.E.F",3,"You should see this too"); 65 psTracePrintLevels(); 66 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 67 } 68 69 70 // testTrace02() 71 { 72 psMemId id = psMemGetId(); 73 psTraceReset(); 74 (void)psTraceSetDestination(2); 75 (void)psTraceSetLevel(".A.B", 2); 76 (void)psTraceSetLevel(".A.B.C.D.E", 5); 77 psTracePrintLevels(); 78 (void)psTraceSetLevel(".A.B", 10); 79 psTracePrintLevels(); 80 81 ok (10 == psTraceGetLevel(".A.B.C"), 82 ".A.B.C did not dynamically inherit a trace level (%d)", 83 psTraceGetLevel(".A.B.C")); 84 85 ok (10 == psTraceGetLevel(".A.B.C.D"), 86 ".A.B.C.D did not dynamically inherit a trace level (%d)", 87 psTraceGetLevel(".A.B.C.D")); 88 89 ok (5 == psTraceGetLevel(".A.B.C.D.E"), 90 ".A.B.C.D.E did dynamically inherit a trace level (%d)", 91 psTraceGetLevel(".A.B.C.D.E")); 92 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 93 } 94 95 96 // testTrace03() 97 { 98 psMemId id = psMemGetId(); 99 (void)psTraceSetDestination(2); 100 101 for (int i=0;i<10;i++) { 102 (void)psTraceSetLevel(".", i); 103 psTraceReset(); 104 int lev = psTraceGetLevel("."); 105 ok (lev == PS_UNKNOWN_TRACE_LEVEL, 106 "expected trace level was %d, actual was %d", 107 PS_UNKNOWN_TRACE_LEVEL, lev); 108 } 109 110 (void)psTraceSetLevel(".", 5); 200 111 (void)psTraceSetLevel(".a", 4); 201 psTrace(".a", 5, "(1) This message should not be displayed (%x)\n", 202 0xbeefface); 203 (void)psTraceSetLevel(".a", 7); 204 psTrace(".a", 5, "(1) This message should be displayed (%x)\n", 205 0xbeefface); 206 207 208 (void)psTraceSetLevel(".a.b", 4); 209 psTrace(".a.b", 5, "(2) This message should not be displayed (%x)\n", 210 0xbeefface); 211 (void)psTraceSetLevel(".a.b", 7); 212 psTrace(".a.b", 5, "(2) This message should be displayed (%x)\n", 213 0xbeefface); 214 (void)psTraceSetLevel(".a.b.c", 12); 215 psTrace(".a.b.c", 11, "(3) This message should be displayed (%x)\n", 216 0xbeefface); 217 218 } 219 220 close(FD); 221 222 return(0); 223 } 224 225 static psS32 testTrace05(void) 226 { 227 // psTraceSetDestination(stderr); 228 (void)psTraceSetDestination(2); 229 230 (void)psTraceSetLevel(".", 9); 231 232 (void)psTraceSetLevel(".a", 8); 233 (void)psTraceSetLevel(".b", 7); 234 (void)psTraceSetLevel(".c", 5); 235 236 (void)psTraceSetLevel(".a.a", 4); 237 (void)psTraceSetLevel(".a.b", 3); 238 239 (void)psTraceSetLevel(".b.a", 2); 240 (void)psTraceSetLevel(".b.b", 1); 241 242 (void)psTraceSetLevel(".c.a", 0); 243 (void)psTraceSetLevel(".c.b", 3); 244 (void)psTraceSetLevel(".c.c", 5); 245 246 psTracePrintLevels(); 247 248 return 0; 249 250 } 251 252 static psS32 testTrace05a(void) 253 { 254 (void)psTraceSetLevel(".", 9); 255 256 (void)psTraceSetLevel("a", 8); 257 (void)psTraceSetLevel("b", 7); 258 (void)psTraceSetLevel("c", 5); 259 260 (void)psTraceSetLevel("a.a", 4); 261 (void)psTraceSetLevel("a.b", 3); 262 263 (void)psTraceSetLevel("b.a", 2); 264 (void)psTraceSetLevel("b.b", 1); 265 266 (void)psTraceSetLevel("c.a", 0); 267 (void)psTraceSetLevel("c.b", 3); 268 (void)psTraceSetLevel("c.c", 5); 269 270 psTracePrintLevels(); 271 272 return 0; 273 274 } 275 276 static psS32 testTrace06(void) 277 { 278 // psTraceSetDestination(stderr); 279 (void)psTraceSetDestination(2); 280 281 (void)psTraceSetLevel(".", 9); 282 283 (void)psTraceSetLevel(".a", 8); 284 (void)psTraceSetLevel(".b", 7); 285 (void)psTraceSetLevel(".c", 5); 286 287 (void)psTraceSetLevel(".a.a", 4); 288 (void)psTraceSetLevel(".a.b", 3); 289 290 (void)psTraceSetLevel(".b.a", 2); 291 (void)psTraceSetLevel(".b.b", 1); 292 293 (void)psTraceSetLevel(".c.a", 0); 294 (void)psTraceSetLevel(".c.b", 3); 295 (void)psTraceSetLevel(".c.c", 5); 296 297 psTraceReset(); 298 299 if ((psTraceGetLevel(".")!=PS_UNKNOWN_TRACE_LEVEL) || 112 (void)psTraceSetLevel(".a.b", 3); 113 (void)psTraceSetLevel(".a.b.c", 2); 114 ok (!((5 != psTraceGetLevel(".")) || 115 (4 != psTraceGetLevel(".a")) || 116 (3 != psTraceGetLevel(".a.b")) || 117 (2 != psTraceGetLevel(".a.b.c"))), 118 "trace successFlag = false;levels were not settable?"); 119 120 psTraceReset(); 121 ok (!((PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".")) || 122 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a")) || 123 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a.b")) || 124 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a.b.c"))), 125 "trace levels were not reset properly"); 126 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 127 } 128 129 130 // testTrace04() 131 { 132 psMemId id = psMemGetId(); 133 int FD = creat("tst_psTrace02_OUT", 0666); 134 for (int nb = 0 ; nb<4;nb++) { 135 if (nb == 0) 136 (void)psTraceSetDestination(1); 137 if (nb == 1) 138 (void)psTraceSetDestination(2); 139 if (nb == 2) 140 (void)psTraceSetDestination(0); 141 if (nb == 3) 142 (void)psTraceSetDestination(FD); 143 144 (void)psTraceSetLevel(".", 4); 145 psTrace(".", 5, "(0) This message should not be displayed (%x)", 146 0xbeefface); 147 (void)psTraceSetLevel(".", 7); 148 psTrace(".", 5, "(0) This message should be displayed (%x)", 149 0xbeefface); 150 151 (void)psTraceSetLevel(".a", 4); 152 psTrace(".a", 5, "(1) This message should not be displayed (%x)", 153 0xbeefface); 154 (void)psTraceSetLevel(".a", 7); 155 psTrace(".a", 5, "(1) This message should be displayed (%x)", 156 0xbeefface); 157 158 (void)psTraceSetLevel(".a.b", 4); 159 psTrace(".a.b", 5, "(2) This message should not be displayed (%x)", 160 0xbeefface); 161 (void)psTraceSetLevel(".a.b", 7); 162 psTrace(".a.b", 5, "(2) This message should be displayed (%x)", 163 0xbeefface); 164 (void)psTraceSetLevel(".a.b.c", 12); 165 psTrace(".a.b.c", 11, "(3) This message should be displayed (%x)", 166 0xbeefface); 167 } 168 close(FD); 169 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 170 } 171 172 173 // testTrace05() 174 { 175 psMemId id = psMemGetId(); 176 (void)psTraceSetDestination(2); 177 (void)psTraceSetLevel(".", 9); 178 (void)psTraceSetLevel(".a", 8); 179 (void)psTraceSetLevel(".b", 7); 180 (void)psTraceSetLevel(".c", 5); 181 (void)psTraceSetLevel(".a.a", 4); 182 (void)psTraceSetLevel(".a.b", 3); 183 (void)psTraceSetLevel(".b.a", 2); 184 (void)psTraceSetLevel(".b.b", 1); 185 (void)psTraceSetLevel(".c.a", 0); 186 (void)psTraceSetLevel(".c.b", 3); 187 (void)psTraceSetLevel(".c.c", 5); 188 psTracePrintLevels(); 189 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 190 } 191 192 193 // testTrace05a() 194 { 195 psMemId id = psMemGetId(); 196 (void)psTraceSetLevel(".", 9); 197 (void)psTraceSetLevel("a", 8); 198 (void)psTraceSetLevel("b", 7); 199 (void)psTraceSetLevel("c", 5); 200 (void)psTraceSetLevel("a.a", 4); 201 (void)psTraceSetLevel("a.b", 3); 202 (void)psTraceSetLevel("b.a", 2); 203 (void)psTraceSetLevel("b.b", 1); 204 (void)psTraceSetLevel("c.a", 0); 205 (void)psTraceSetLevel("c.b", 3); 206 (void)psTraceSetLevel("c.c", 5); 207 psTracePrintLevels(); 208 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 209 } 210 211 212 // testTrace06() 213 { 214 psMemId id = psMemGetId(); 215 (void)psTraceSetDestination(2); 216 (void)psTraceSetLevel(".", 9); 217 (void)psTraceSetLevel(".a", 8); 218 (void)psTraceSetLevel(".b", 7); 219 (void)psTraceSetLevel(".c", 5); 220 (void)psTraceSetLevel(".a.a", 4); 221 (void)psTraceSetLevel(".a.b", 3); 222 (void)psTraceSetLevel(".b.a", 2); 223 (void)psTraceSetLevel(".b.b", 1); 224 (void)psTraceSetLevel(".c.a", 0); 225 (void)psTraceSetLevel(".c.b", 3); 226 (void)psTraceSetLevel(".c.c", 5); 227 psTraceReset(); 228 229 if ((psTraceGetLevel(".")!=PS_UNKNOWN_TRACE_LEVEL) || 300 230 (psTraceGetLevel(".a")!=PS_UNKNOWN_TRACE_LEVEL) || 301 231 (psTraceGetLevel(".b")!=PS_UNKNOWN_TRACE_LEVEL) || … … 308 238 (psTraceGetLevel(".c.b")!=PS_UNKNOWN_TRACE_LEVEL) || 309 239 (psTraceGetLevel(".c.c")!=PS_UNKNOWN_TRACE_LEVEL)) { 310 return 1; 311 } 312 313 return 0; 314 } 315 316 // Ensure that the leading dot in the component names are optional. 317 static psS32 testTrace08(void) 318 { 319 psTraceReset(); 320 (void)psTraceSetLevel(".", 9); 321 322 (void)psTraceSetLevel(".a", 8); 323 (void)psTraceSetLevel(".b", 7); 324 (void)psTraceSetLevel(".c", 5); 325 326 (void)psTraceSetLevel(".a.a", 4); 327 (void)psTraceSetLevel(".a.b", 3); 328 329 (void)psTraceSetLevel(".b.a", 2); 330 (void)psTraceSetLevel(".b.b", 1); 331 332 (void)psTraceSetLevel(".c.a", 0); 333 (void)psTraceSetLevel(".c.b", 3); 334 (void)psTraceSetLevel(".c.c", 5); 335 336 psTracePrintLevels(); 337 338 if ((psTraceGetLevel(".")!=9) || 240 return 1; 241 } 242 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 243 } 244 245 246 // Ensure that the leading dot in the component names are optional. 247 // testTrace08() 248 { 249 psMemId id = psMemGetId(); 250 psTraceReset(); 251 (void)psTraceSetLevel(".", 9); 252 (void)psTraceSetLevel(".a", 8); 253 (void)psTraceSetLevel(".b", 7); 254 (void)psTraceSetLevel(".c", 5); 255 (void)psTraceSetLevel(".a.a", 4); 256 (void)psTraceSetLevel(".a.b", 3); 257 (void)psTraceSetLevel(".b.a", 2); 258 (void)psTraceSetLevel(".b.b", 1); 259 (void)psTraceSetLevel(".c.a", 0); 260 (void)psTraceSetLevel(".c.b", 3); 261 (void)psTraceSetLevel(".c.c", 5); 262 psTracePrintLevels(); 263 if ((psTraceGetLevel(".")!=9) || 339 264 (psTraceGetLevel("a")!=8) || 340 265 (psTraceGetLevel("b")!=7) || … … 347 272 (psTraceGetLevel("c.b")!=3) || 348 273 (psTraceGetLevel("c.c")!=5)) { 349 printf("psTraceGetLevel(.) is %d\n", psTraceGetLevel(".")); 350 printf("psTraceGetLevel(a) is %d\n", psTraceGetLevel("a")); 351 printf("psTraceGetLevel(b) is %d\n", psTraceGetLevel("b")); 352 printf("psTraceGetLevel(c) is %d\n", psTraceGetLevel("c")); 353 printf("psTraceGetLevel(a.a) is %d\n", psTraceGetLevel("a.a")); 354 printf("psTraceGetLevel(a.b) is %d\n", psTraceGetLevel("a.b")); 355 printf("psTraceGetLevel(b.a) is %d\n", psTraceGetLevel("b.a")); 356 printf("psTraceGetLevel(b.b) is %d\n", psTraceGetLevel("b.b")); 357 printf("psTraceGetLevel(c.a) is %d\n", psTraceGetLevel("c.a")); 358 printf("psTraceGetLevel(c.b) is %d\n", psTraceGetLevel("c.b")); 359 printf("psTraceGetLevel(c.c) is %d\n", psTraceGetLevel("c.c")); 360 361 return 1; 362 } 363 364 return 0; 274 printf("psTraceGetLevel(.) is %d", psTraceGetLevel(".")); 275 printf("psTraceGetLevel(a) is %d", psTraceGetLevel("a")); 276 printf("psTraceGetLevel(b) is %d", psTraceGetLevel("b")); 277 printf("psTraceGetLevel(c) is %d", psTraceGetLevel("c")); 278 printf("psTraceGetLevel(a.a) is %d", psTraceGetLevel("a.a")); 279 printf("psTraceGetLevel(a.b) is %d", psTraceGetLevel("a.b")); 280 printf("psTraceGetLevel(b.a) is %d", psTraceGetLevel("b.a")); 281 printf("psTraceGetLevel(b.b) is %d", psTraceGetLevel("b.b")); 282 printf("psTraceGetLevel(c.a) is %d", psTraceGetLevel("c.a")); 283 printf("psTraceGetLevel(c.b) is %d", psTraceGetLevel("c.b")); 284 printf("psTraceGetLevel(c.c) is %d", psTraceGetLevel("c.c")); 285 return 1; 286 } 287 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 288 } 365 289 }
Note:
See TracChangeset
for help on using the changeset viewer.
