File: | pr/Linux4.19_x86_64_gcc_glibc_PTH_64_DBG.OBJ/pr/tests/../../../pr/tests/randseed.c |
Warning: | line 75, column 21 Value stored to 'i' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | |
6 | /* |
7 | ** File: rngseed.c |
8 | ** Description: |
9 | ** Test NSPR's Random Number Seed generator |
10 | ** |
11 | ** Initial test: Just make sure it outputs some data. |
12 | ** |
13 | ** ... more? ... check some iterations to ensure it is random (no dupes) |
14 | ** ... more? ... histogram distribution of random numbers |
15 | */ |
16 | |
17 | #include "plgetopt.h" |
18 | #include "nspr.h" |
19 | #include "prrng.h" |
20 | #include <stdio.h> |
21 | #include <stdlib.h> |
22 | #include <string.h> |
23 | |
24 | /* |
25 | ** Test harness infrastructure |
26 | */ |
27 | PRLogModuleInfo *lm; |
28 | PRLogModuleLevel msgLevel = PR_LOG_NONE; |
29 | PRIntn debug = 0; |
30 | PRUint32 failed_already = 0; |
31 | /* end Test harness infrastructure */ |
32 | |
33 | PRIntn optRandCount = 30; |
34 | char buf[40]; |
35 | PRSize bufSize = sizeof(buf); |
36 | PRSize rSize; |
37 | PRIntn i; |
38 | |
39 | /* |
40 | ** Emit help text for this test |
41 | */ |
42 | static void Help( void ) |
43 | { |
44 | printf("Template: Help(): display your help message(s) here"); |
45 | exit(1); |
46 | } /* end Help() */ |
47 | |
48 | static void PrintRand( void *buf, PRIntn size ) |
49 | { |
50 | PRUint32 *rp = buf; |
51 | PRIntn i; |
52 | |
53 | printf("%4.4d--\n", size ); |
54 | while (size > 0 ) { |
55 | switch( size ) { |
56 | case 1 : |
57 | printf("%2.2X\n", *(rp++) ); |
58 | size -= 4; |
59 | break; |
60 | case 2 : |
61 | printf("%4.4X\n", *(rp++) ); |
62 | size -= 4; |
63 | break; |
64 | case 3 : |
65 | printf("%6.6X\n", *(rp++) ); |
66 | size -= 4; |
67 | break; |
68 | default: |
69 | while ( size >= 4) { |
70 | PRIntn i = 3; |
71 | do { |
72 | printf("%8.8X ", *(rp++) ); |
73 | size -= 4; |
74 | } while( i-- ); |
75 | i = 3; |
Value stored to 'i' is never read | |
76 | printf("\n"); |
77 | } |
78 | break; |
79 | } /* end switch() */ |
80 | } /* end while() */ |
81 | } /* end PrintRand() */ |
82 | |
83 | |
84 | int main(int argc, char **argv) |
85 | { |
86 | { |
87 | /* |
88 | ** Get command line options |
89 | */ |
90 | PLOptStatus os; |
91 | PLOptState *opt = PL_CreateOptState(argc, argv, "hdv"); |
92 | |
93 | while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) |
94 | { |
95 | if (PL_OPT_BAD == os) { |
96 | continue; |
97 | } |
98 | switch (opt->option) |
99 | { |
100 | case 'd': /* debug */ |
101 | debug = 1; |
102 | msgLevel = PR_LOG_ERROR; |
103 | break; |
104 | case 'v': /* verbose mode */ |
105 | msgLevel = PR_LOG_DEBUG; |
106 | break; |
107 | case 'h': /* help message */ |
108 | Help(); |
109 | break; |
110 | default: |
111 | break; |
112 | } |
113 | } |
114 | PL_DestroyOptState(opt); |
115 | } |
116 | |
117 | lm = PR_NewLogModule("Test"); /* Initialize logging */ |
118 | for ( i = 0; i < optRandCount ; i++ ) { |
119 | memset( buf, 0, bufSize ); |
120 | rSize = PR_GetRandomNoise( buf, bufSize ); |
121 | if (!rSize) { |
122 | fprintf(stderrstderr, "Not implemented\n" ); |
123 | failed_already = PR_TRUE1; |
124 | break; |
125 | } |
126 | if (debug) { |
127 | PrintRand( buf, rSize ); |
128 | } |
129 | } |
130 | |
131 | if (debug) { |
132 | printf("%s\n", (failed_already)? "FAIL" : "PASS"); |
133 | } |
134 | return( (failed_already == PR_TRUE1 )? 1 : 0 ); |
135 | } /* main() */ |
136 | /* end template.c */ |
137 |