Changeset 41171 for trunk/psLib/test/sys/tap_psTrace.c
- Timestamp:
- Nov 27, 2019, 11:57:38 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/sys/tap_psTrace.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/sys/tap_psTrace.c
r17515 r41171 2 2 This code will test whether trace levels can be set successfully. 3 3 4 XXX: For the last two testpoints, must verify that the results are 5 correct, and put that verification in the test as well. 6 *****************************************************************************/ 4 XXX : various tests result in text sent to stdout -- these should go to a file 5 or buffer and be validated against a truth set. 6 7 XXX : some of the error messages have the wrong sense (they report a negative result even if the test is successful) 8 *****************************************************************************/ 7 9 #include <stdio.h> 8 10 #include <fcntl.h> … … 20 22 21 23 # define DEBUG 1 22 # if ( DEBUG)24 # if (!DEBUG) 23 25 FILE *output = fopen ("/dev/null", "w"); 24 26 int outFD = fileno (output); … … 30 32 { 31 33 psMemId id = psMemGetId(); 32 psS32 lev = 0; 33 (void)psTraceSetDestination(outFD); 34 for (int i=0;i<10;i++) { 35 (void)psTraceSetLevel(".", i); 36 lev = psTraceGetLevel("."); 37 ok(lev == i, "trace level was %d, actual was %d", i, lev); 38 } 39 40 (void)psTraceSetLevel(".", 3); 41 for (int i=5;i<10;i++) { 42 (void)psTraceSetLevel(".NODE00", i); 43 lev = psTraceGetLevel(".NODE00"); 44 ok (lev == i,"(.NODE00) expected trace level was %d, actual was %d", 45 i, lev); 34 psTraceSetDestination(outFD); 35 for (int i = 0; i < 10; i++) { 36 psTraceSetLevel(".", i); 37 int lev = psTraceGetLevel("."); 38 ok (lev == i, "trace level was %d, actual was %d", i, lev); 39 } 40 41 psTraceSetLevel(".", 3); 42 for (int i = 5; i < 10;i++) { 43 psTraceSetLevel(".NODE00", i); 44 int lev1 = psTraceGetLevel(".NODE00"); 45 ok (lev1 == i,"(.NODE00) expected trace level was %d, actual was %d", i, lev1); 46 46 47 lev = psTraceGetLevel("."); 48 ok (lev == 3, 49 "expected trace level was %d, actual was %d", i, 3); 47 int lev2 = psTraceGetLevel("."); 48 ok (lev2 == 3, "expected trace level was %d, actual was %d", 3, lev2); 50 49 } 51 50 52 (void)psTraceSetLevel(".NODE00.NODE01", 4); 53 for (int i=0;i<10;i++) { 54 (void)psTraceSetLevel(".NODE00.NODE01", i); 55 lev = psTraceGetLevel(".NODE00.NODE01"); 56 ok (lev == i, 57 "(.NODE00.NODE01) expected trace level was %d, actual was %d", 58 i, lev); 59 } 60 51 psTraceSetLevel(".NODE00.NODE01", 4); 52 for (int i = 0; i < 10; i++) { 53 psTraceSetLevel(".NODE00.NODE01", i); 54 int lev = psTraceGetLevel(".NODE00.NODE01"); 55 ok (lev == i, "(.NODE00.NODE01) expected trace level was %d, actual was %d", i, lev); 56 } 61 57 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 62 58 } … … 64 60 65 61 // testTrace01() 66 {67 psMemId id = psMemGetId();68 (void)psTraceSetDestination(outFD);69 (void)psTraceSetLevel(".A.B.C.D.E", 5);70 psTrace (".A.C.D.C",1,"You should not see this");71 psTrace(".A. B.C.D.E",2,"You shouldsee this");72 psTrace(".A.B.C.D.E .F",3,"You should see this too");73 psTrace PrintLevels();74 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");75 }76 62 // XXX need to check the output on these as part of the test 63 { 64 psMemId id = psMemGetId(); 65 psTraceSetDestination(outFD); 66 psTraceSetLevel(".A.B.C.D.E", 5); 67 psTrace(".A.C.D.C", 1, "You should not see this"); 68 psTrace(".A.B.C.D.E", 2, "You should see this"); 69 psTrace(".A.B.C.D.E.F", 3, "You should see this too"); 70 psTracePrintLevels(); 71 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 72 } 77 73 78 74 // testTrace02() … … 80 76 psMemId id = psMemGetId(); 81 77 psTraceReset(); 82 (void)psTraceSetDestination(outFD); 83 (void)psTraceSetLevel(".A.B", 2); 84 (void)psTraceSetLevel(".A.B.C.D.E", 5); 85 psTracePrintLevels(); 86 (void)psTraceSetLevel(".A.B", 10); 87 psTracePrintLevels(); 88 89 ok (10 == psTraceGetLevel(".A.B.C"), 90 ".A.B.C did not dynamically inherit a trace level (%d)", 91 psTraceGetLevel(".A.B.C")); 92 93 ok (10 == psTraceGetLevel(".A.B.C.D"), 94 ".A.B.C.D did not dynamically inherit a trace level (%d)", 95 psTraceGetLevel(".A.B.C.D")); 96 97 ok (5 == psTraceGetLevel(".A.B.C.D.E"), 98 ".A.B.C.D.E did dynamically inherit a trace level (%d)", 99 psTraceGetLevel(".A.B.C.D.E")); 100 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 101 } 102 78 psTraceSetDestination(outFD); 79 psTraceSetLevel(".A.B", 2); 80 psTraceSetLevel(".A.B.C.D.E", 5); 81 psTracePrintLevels(); 82 psTraceSetLevel(".A.B", 10); 83 psTracePrintLevels(); 84 85 ok (10 == psTraceGetLevel(".A.B.C"), ".A.B.C did not dynamically inherit a trace level (%d)", psTraceGetLevel(".A.B.C")); 86 ok (10 == psTraceGetLevel(".A.B.C.D"), ".A.B.C.D did not dynamically inherit a trace level (%d)", psTraceGetLevel(".A.B.C.D")); 87 ok ( 5 == psTraceGetLevel(".A.B.C.D.E"), ".A.B.C.D.E did dynamically inherit a trace level (%d)", psTraceGetLevel(".A.B.C.D.E")); 88 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 89 } 103 90 104 91 // testTrace03() 105 92 { 106 93 psMemId id = psMemGetId(); 107 (void)psTraceSetDestination(outFD);108 109 for (int i =0;i<10;i++) {110 (void)psTraceSetLevel(".", i);94 psTraceSetDestination(outFD); 95 96 for (int i = 0; i < 10; i++) { 97 psTraceSetLevel(".", i); 111 98 psTraceReset(); 112 99 int lev = psTraceGetLevel("."); 113 ok (lev == PS_UNKNOWN_TRACE_LEVEL, 114 "expected trace level was %d, actual was %d", 115 PS_UNKNOWN_TRACE_LEVEL, lev); 116 } 117 118 (void)psTraceSetLevel(".", 5); 119 (void)psTraceSetLevel(".a", 4); 120 (void)psTraceSetLevel(".a.b", 3); 121 (void)psTraceSetLevel(".a.b.c", 2); 122 ok (!((5 != psTraceGetLevel(".")) || 123 (4 != psTraceGetLevel(".a")) || 124 (3 != psTraceGetLevel(".a.b")) || 125 (2 != psTraceGetLevel(".a.b.c"))), 126 "trace successFlag = false;levels were not settable?"); 127 128 psTraceReset(); 129 ok (!((PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".")) || 130 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a")) || 131 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a.b")) || 132 (PS_UNKNOWN_TRACE_LEVEL != psTraceGetLevel(".a.b.c"))), 133 "trace levels were not reset properly"); 134 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 135 } 136 100 ok (lev == PS_UNKNOWN_TRACE_LEVEL, "expected trace level was %d, actual was %d", PS_UNKNOWN_TRACE_LEVEL, lev); 101 } 102 103 psTraceSetLevel(".", 5); 104 psTraceSetLevel(".a", 4); 105 psTraceSetLevel(".a.b", 3); 106 psTraceSetLevel(".a.b.c", 2); 107 ok (5 == psTraceGetLevel("."), "level 0"); 108 ok (4 == psTraceGetLevel(".a"), "level 1"); 109 ok (3 == psTraceGetLevel(".a.b"), "level 2"); 110 ok (2 == psTraceGetLevel(".a.b.c"), "level 3"); 111 112 psTraceReset(); 113 ok (PS_UNKNOWN_TRACE_LEVEL == psTraceGetLevel("."), "trace levels were not reset properly"); 114 ok (PS_UNKNOWN_TRACE_LEVEL == psTraceGetLevel(".a"), "trace levels were not reset properly"); 115 ok (PS_UNKNOWN_TRACE_LEVEL == psTraceGetLevel(".a.b"), "trace levels were not reset properly"); 116 ok (PS_UNKNOWN_TRACE_LEVEL == psTraceGetLevel(".a.b.c"), "trace levels were not reset properly"); 117 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 118 } 137 119 138 120 // testTrace04() … … 140 122 psMemId id = psMemGetId(); 141 123 int FD = creat("tst_psTrace02_OUT", 0666); 142 for (int nb = 0 ; nb<4;nb++) { 143 if (nb == 0) 144 (void)psTraceSetDestination(((outFD == 2) ? 1 : outFD)); 145 if (nb == 1) 146 (void)psTraceSetDestination(((outFD == 2) ? 2 : outFD)); 147 if (nb == 2) 148 (void)psTraceSetDestination(((outFD == 2) ? 0 : outFD)); 149 if (nb == 3) 150 (void)psTraceSetDestination(FD); 151 152 (void)psTraceSetLevel(".", 4); 153 psTrace(".", 5, "(0) This message should not be displayed (%x)", 154 0xbeefface); 155 (void)psTraceSetLevel(".", 7); 156 psTrace(".", 5, "(0) This message should be displayed (%x)", 157 0xbeefface); 158 159 (void)psTraceSetLevel(".a", 4); 160 psTrace(".a", 5, "(1) This message should not be displayed (%x)", 161 0xbeefface); 162 (void)psTraceSetLevel(".a", 7); 163 psTrace(".a", 5, "(1) This message should be displayed (%x)", 164 0xbeefface); 165 166 (void)psTraceSetLevel(".a.b", 4); 167 psTrace(".a.b", 5, "(2) This message should not be displayed (%x)", 168 0xbeefface); 169 (void)psTraceSetLevel(".a.b", 7); 170 psTrace(".a.b", 5, "(2) This message should be displayed (%x)", 171 0xbeefface); 172 (void)psTraceSetLevel(".a.b.c", 12); 173 psTrace(".a.b.c", 11, "(3) This message should be displayed (%x)", 174 0xbeefface); 124 for (int nb = 0; nb < 4; nb++) { 125 if (nb == 0) psTraceSetDestination(((outFD == 2) ? 1 : outFD)); 126 if (nb == 1) psTraceSetDestination(((outFD == 2) ? 2 : outFD)); 127 if (nb == 2) psTraceSetDestination(((outFD == 2) ? 0 : outFD)); 128 if (nb == 3) psTraceSetDestination(FD); 129 130 psTraceSetLevel(".", 4); 131 psTrace(".", 5, "(0) This message should not be displayed (%x)", 0xbeefface); 132 psTraceSetLevel(".", 7); 133 psTrace(".", 5, "(0) This message should be displayed (%x)", 0xbeefface); 134 135 psTraceSetLevel(".a", 4); 136 psTrace(".a", 5, "(1) This message should not be displayed (%x)", 0xbeefface); 137 psTraceSetLevel(".a", 7); 138 psTrace(".a", 5, "(1) This message should be displayed (%x)", 0xbeefface); 139 140 psTraceSetLevel(".a.b", 4); 141 psTrace(".a.b", 5, "(2) This message should not be displayed (%x)", 0xbeefface); 142 psTraceSetLevel(".a.b", 7); 143 psTrace(".a.b", 5, "(2) This message should be displayed (%x)", 0xbeefface); 144 145 psTraceSetLevel(".a.b.c", 12); 146 psTrace(".a.b.c", 11, "(3) This message should be displayed (%x)", 0xbeefface); 175 147 } 176 148 close(FD); … … 182 154 { 183 155 psMemId id = psMemGetId(); 184 (void)psTraceSetDestination(outFD);185 (void)psTraceSetLevel(".", 9);186 (void)psTraceSetLevel(".a", 8);187 (void)psTraceSetLevel(".b", 7);188 (void)psTraceSetLevel(".c", 5);189 (void)psTraceSetLevel(".a.a", 4);190 (void)psTraceSetLevel(".a.b", 3);191 (void)psTraceSetLevel(".b.a", 2);192 (void)psTraceSetLevel(".b.b", 1);193 (void)psTraceSetLevel(".c.a", 0);194 (void)psTraceSetLevel(".c.b", 3);195 (void)psTraceSetLevel(".c.c", 5);156 psTraceSetDestination(outFD); 157 psTraceSetLevel(".", 9); 158 psTraceSetLevel(".a", 8); 159 psTraceSetLevel(".b", 7); 160 psTraceSetLevel(".c", 5); 161 psTraceSetLevel(".a.a", 4); 162 psTraceSetLevel(".a.b", 3); 163 psTraceSetLevel(".b.a", 2); 164 psTraceSetLevel(".b.b", 1); 165 psTraceSetLevel(".c.a", 0); 166 psTraceSetLevel(".c.b", 3); 167 psTraceSetLevel(".c.c", 5); 196 168 psTracePrintLevels(); 197 169 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); … … 202 174 { 203 175 psMemId id = psMemGetId(); 204 (void)psTraceSetLevel(".", 9);205 (void)psTraceSetLevel("a", 8);206 (void)psTraceSetLevel("b", 7);207 (void)psTraceSetLevel("c", 5);208 (void)psTraceSetLevel("a.a", 4);209 (void)psTraceSetLevel("a.b", 3);210 (void)psTraceSetLevel("b.a", 2);211 (void)psTraceSetLevel("b.b", 1);212 (void)psTraceSetLevel("c.a", 0);213 (void)psTraceSetLevel("c.b", 3);214 (void)psTraceSetLevel("c.c", 5);176 psTraceSetLevel(".", 9); 177 psTraceSetLevel("a", 8); 178 psTraceSetLevel("b", 7); 179 psTraceSetLevel("c", 5); 180 psTraceSetLevel("a.a", 4); 181 psTraceSetLevel("a.b", 3); 182 psTraceSetLevel("b.a", 2); 183 psTraceSetLevel("b.b", 1); 184 psTraceSetLevel("c.a", 0); 185 psTraceSetLevel("c.b", 3); 186 psTraceSetLevel("c.c", 5); 215 187 psTracePrintLevels(); 216 188 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); … … 221 193 { 222 194 psMemId id = psMemGetId(); 223 (void)psTraceSetDestination(outFD); 224 (void)psTraceSetLevel(".", 9); 225 (void)psTraceSetLevel(".a", 8); 226 (void)psTraceSetLevel(".b", 7); 227 (void)psTraceSetLevel(".c", 5); 228 (void)psTraceSetLevel(".a.a", 4); 229 (void)psTraceSetLevel(".a.b", 3); 230 (void)psTraceSetLevel(".b.a", 2); 231 (void)psTraceSetLevel(".b.b", 1); 232 (void)psTraceSetLevel(".c.a", 0); 233 (void)psTraceSetLevel(".c.b", 3); 234 (void)psTraceSetLevel(".c.c", 5); 235 psTraceReset(); 236 237 if ((psTraceGetLevel(".")!=PS_UNKNOWN_TRACE_LEVEL) || 238 (psTraceGetLevel(".a")!=PS_UNKNOWN_TRACE_LEVEL) || 239 (psTraceGetLevel(".b")!=PS_UNKNOWN_TRACE_LEVEL) || 240 (psTraceGetLevel(".c")!=PS_UNKNOWN_TRACE_LEVEL) || 241 (psTraceGetLevel(".a.a")!=PS_UNKNOWN_TRACE_LEVEL) || 242 (psTraceGetLevel(".a.b")!=PS_UNKNOWN_TRACE_LEVEL) || 243 (psTraceGetLevel(".b.a")!=PS_UNKNOWN_TRACE_LEVEL) || 244 (psTraceGetLevel(".b.b")!=PS_UNKNOWN_TRACE_LEVEL) || 245 (psTraceGetLevel(".c.a")!=PS_UNKNOWN_TRACE_LEVEL) || 246 (psTraceGetLevel(".c.b")!=PS_UNKNOWN_TRACE_LEVEL) || 247 (psTraceGetLevel(".c.c")!=PS_UNKNOWN_TRACE_LEVEL)) { 248 return 1; 249 } 250 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 251 } 252 195 psTraceSetDestination(outFD); 196 psTraceSetLevel(".", 9); 197 psTraceSetLevel(".a", 8); 198 psTraceSetLevel(".b", 7); 199 psTraceSetLevel(".c", 5); 200 psTraceSetLevel(".a.a", 4); 201 psTraceSetLevel(".a.b", 3); 202 psTraceSetLevel(".b.a", 2); 203 psTraceSetLevel(".b.b", 1); 204 psTraceSetLevel(".c.a", 0); 205 psTraceSetLevel(".c.b", 3); 206 psTraceSetLevel(".c.c", 5); 207 psTraceReset(); 208 209 // the reset should clear all of the levels above 210 ok (psTraceGetLevel(".") == PS_UNKNOWN_TRACE_LEVEL, "valid trace level"); 211 ok (psTraceGetLevel(".a") == PS_UNKNOWN_TRACE_LEVEL, "valid trace level"); 212 ok (psTraceGetLevel(".b") == PS_UNKNOWN_TRACE_LEVEL, "valid trace level"); 213 ok (psTraceGetLevel(".c") == PS_UNKNOWN_TRACE_LEVEL, "valid trace level"); 214 ok (psTraceGetLevel(".a.a") == PS_UNKNOWN_TRACE_LEVEL, "valid trace level"); 215 ok (psTraceGetLevel(".a.b") == PS_UNKNOWN_TRACE_LEVEL, "valid trace level"); 216 ok (psTraceGetLevel(".b.a") == PS_UNKNOWN_TRACE_LEVEL, "valid trace level"); 217 ok (psTraceGetLevel(".b.b") == PS_UNKNOWN_TRACE_LEVEL, "valid trace level"); 218 ok (psTraceGetLevel(".c.a") == PS_UNKNOWN_TRACE_LEVEL, "valid trace level"); 219 ok (psTraceGetLevel(".c.b") == PS_UNKNOWN_TRACE_LEVEL, "valid trace level"); 220 ok (psTraceGetLevel(".c.c") == PS_UNKNOWN_TRACE_LEVEL, "valid trace level"); 221 222 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 223 } 253 224 254 225 // Ensure that the leading dot in the component names are optional. … … 257 228 psMemId id = psMemGetId(); 258 229 psTraceReset(); 259 (void)psTraceSetLevel(".", 9); 260 (void)psTraceSetLevel(".a", 8); 261 (void)psTraceSetLevel(".b", 7); 262 (void)psTraceSetLevel(".c", 5); 263 (void)psTraceSetLevel(".a.a", 4); 264 (void)psTraceSetLevel(".a.b", 3); 265 (void)psTraceSetLevel(".b.a", 2); 266 (void)psTraceSetLevel(".b.b", 1); 267 (void)psTraceSetLevel(".c.a", 0); 268 (void)psTraceSetLevel(".c.b", 3); 269 (void)psTraceSetLevel(".c.c", 5); 270 psTracePrintLevels(); 271 if ((psTraceGetLevel(".")!=9) || 272 (psTraceGetLevel("a")!=8) || 273 (psTraceGetLevel("b")!=7) || 274 (psTraceGetLevel("c")!=5) || 275 (psTraceGetLevel("a.a")!=4) || 276 (psTraceGetLevel("a.b")!=3) || 277 (psTraceGetLevel("b.a")!=2) || 278 (psTraceGetLevel("b.b")!=1) || 279 (psTraceGetLevel("c.a")!=0) || 280 (psTraceGetLevel("c.b")!=3) || 281 (psTraceGetLevel("c.c")!=5)) { 282 printf("psTraceGetLevel(.) is %d", psTraceGetLevel(".")); 283 printf("psTraceGetLevel(a) is %d", psTraceGetLevel("a")); 284 printf("psTraceGetLevel(b) is %d", psTraceGetLevel("b")); 285 printf("psTraceGetLevel(c) is %d", psTraceGetLevel("c")); 286 printf("psTraceGetLevel(a.a) is %d", psTraceGetLevel("a.a")); 287 printf("psTraceGetLevel(a.b) is %d", psTraceGetLevel("a.b")); 288 printf("psTraceGetLevel(b.a) is %d", psTraceGetLevel("b.a")); 289 printf("psTraceGetLevel(b.b) is %d", psTraceGetLevel("b.b")); 290 printf("psTraceGetLevel(c.a) is %d", psTraceGetLevel("c.a")); 291 printf("psTraceGetLevel(c.b) is %d", psTraceGetLevel("c.b")); 292 printf("psTraceGetLevel(c.c) is %d", psTraceGetLevel("c.c")); 293 return 1; 294 } 230 psTraceSetLevel(".", 9); 231 psTraceSetLevel(".a", 8); 232 psTraceSetLevel(".b", 7); 233 psTraceSetLevel(".c", 5); 234 psTraceSetLevel(".a.a", 4); 235 psTraceSetLevel(".a.b", 3); 236 psTraceSetLevel(".b.a", 2); 237 psTraceSetLevel(".b.b", 1); 238 psTraceSetLevel(".c.a", 0); 239 psTraceSetLevel(".c.b", 3); 240 psTraceSetLevel(".c.c", 5); 241 psTracePrintLevels(); 242 243 ok(psTraceGetLevel(".") == 9, "level is valid without first dot"); 244 ok(psTraceGetLevel("a") == 8, "level is valid without first dot"); 245 ok(psTraceGetLevel("b") == 7, "level is valid without first dot"); 246 ok(psTraceGetLevel("c") == 5, "level is valid without first dot"); 247 ok(psTraceGetLevel("a.a") == 4, "level is valid without first dot"); 248 ok(psTraceGetLevel("a.b") == 3, "level is valid without first dot"); 249 ok(psTraceGetLevel("b.a") == 2, "level is valid without first dot"); 250 ok(psTraceGetLevel("b.b") == 1, "level is valid without first dot"); 251 ok(psTraceGetLevel("c.a") == 0, "level is valid without first dot"); 252 ok(psTraceGetLevel("c.b") == 3, "level is valid without first dot"); 253 ok(psTraceGetLevel("c.c") == 5, "level is valid without first dot"); 254 295 255 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 296 256 }
Note:
See TracChangeset
for help on using the changeset viewer.
