Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: test/roc_driver.c

Issue 2344973002: Update libsrtp to version 2.0 (Closed)
Patch Set: Add '.' back to include_dirs Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/replay_driver.c ('k') | test/rtp.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * roc_driver.c 2 * roc_driver.c
3 * 3 *
4 * test driver for rollover counter replay implementation 4 * test driver for rollover counter replay implementation
5 * 5 *
6 * David A. McGrew 6 * David A. McGrew
7 * Cisco Systems, Inc. 7 * Cisco Systems, Inc.
8 */ 8 */
9 9
10 /* 10 /*
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 46
47 #ifdef HAVE_CONFIG_H 47 #ifdef HAVE_CONFIG_H
48 #include <config.h> 48 #include <config.h>
49 #endif 49 #endif
50 50
51 #include <stdio.h> 51 #include <stdio.h>
52 52
53 /* 53 /*
54 * defining ROC_TEST causes small datatypes to be used in 54 * defining ROC_TEST causes small datatypes to be used in
55 * xtd_seq_num_t - this allows the functions to be exhaustively tested. 55 * srtp_xtd_seq_num_t - this allows the functions to be exhaustively tested.
56 */ 56 */
57 #if ROC_NEEDS_TO_BE_TESTED 57 #if ROC_NEEDS_TO_BE_TESTED
58 #define ROC_TEST 58 #define ROC_TEST
59 #endif 59 #endif
60 60
61 #include "rdbx.h" 61 #include "rdbx.h"
62 #include "ut_sim.h" 62 #include "ut_sim.h"
63 63
64 err_status_t 64 srtp_err_status_t
65 roc_test(int num_trials); 65 roc_test(int num_trials);
66 66
67 int 67 int
68 main (void) { 68 main (void) {
69 err_status_t status; 69 srtp_err_status_t status;
70 70
71 printf("rollover counter test driver\n" 71 printf("rollover counter test driver\n"
72 "David A. McGrew\n" 72 "David A. McGrew\n"
73 "Cisco Systems, Inc.\n"); 73 "Cisco Systems, Inc.\n");
74 74
75 printf("testing index functions..."); 75 printf("testing index functions...");
76 status = roc_test(1 << 18); 76 status = roc_test(1 << 18);
77 if (status) { 77 if (status) {
78 printf("failed\n"); 78 printf("failed\n");
79 exit(status); 79 exit(status);
80 } 80 }
81 printf("passed\n"); 81 printf("passed\n");
82 return 0; 82 return 0;
83 } 83 }
84 84
85 85
86 #define ROC_VERBOSE 0 86 #define ROC_VERBOSE 0
87 87
88 err_status_t 88 srtp_err_status_t
89 roc_test(int num_trials) { 89 roc_test(int num_trials) {
90 xtd_seq_num_t local, est, ref; 90 srtp_xtd_seq_num_t local, est, ref;
91 ut_connection utc; 91 ut_connection utc;
92 int i, num_bad_est = 0; 92 int i, num_bad_est = 0;
93 int delta; 93 int delta;
94 uint32_t ircvd; 94 uint32_t ircvd;
95 double failure_rate; 95 double failure_rate;
96 96
97 index_init(&local); 97 srtp_index_init(&local);
98 index_init(&ref); 98 srtp_index_init(&ref);
99 index_init(&est); 99 srtp_index_init(&est);
100 100
101 printf("\n\ttesting sequential insertion..."); 101 printf("\n\ttesting sequential insertion...");
102 for (i=0; i < 2048; i++) { 102 for (i=0; i < 2048; i++) {
103 delta = index_guess(&local, &est, (uint16_t) ref); 103 delta = srtp_index_guess(&local, &est, (uint16_t) ref);
104 #if ROC_VERBOSE 104 #if ROC_VERBOSE
105 printf("%lld, %lld, %d\n", ref, est, i); 105 printf("%lld, %lld, %d\n", ref, est, i);
106 #endif 106 #endif
107 if (ref != est) { 107 if (ref != est) {
108 #if ROC_VERBOSE 108 #if ROC_VERBOSE
109 printf(" *bad estimate*\n"); 109 printf(" *bad estimate*\n");
110 #endif 110 #endif
111 ++num_bad_est; 111 ++num_bad_est;
112 } 112 }
113 index_advance(&ref, 1); 113 srtp_index_advance(&ref, 1);
114 } 114 }
115 failure_rate = (double) num_bad_est / num_trials; 115 failure_rate = (double) num_bad_est / num_trials;
116 if (failure_rate > 0.01) { 116 if (failure_rate > 0.01) {
117 printf("error: failure rate too high (%d bad estimates in %d trials)\n", 117 printf("error: failure rate too high (%d bad estimates in %d trials)\n",
118 num_bad_est, num_trials); 118 num_bad_est, num_trials);
119 return err_status_algo_fail; 119 return srtp_err_status_algo_fail;
120 } 120 }
121 printf("done\n"); 121 printf("done\n");
122 122
123 123
124 printf("\ttesting non-sequential insertion..."); 124 printf("\ttesting non-sequential insertion...");
125 index_init(&local); 125 srtp_index_init(&local);
126 index_init(&ref); 126 srtp_index_init(&ref);
127 index_init(&est); 127 srtp_index_init(&est);
128 ut_init(&utc); 128 ut_init(&utc);
129 129
130 for (i=0; i < num_trials; i++) { 130 for (i=0; i < num_trials; i++) {
131 131
132 /* get next seq num from unreliable transport simulator */ 132 /* get next seq num from unreliable transport simulator */
133 ircvd = ut_next_index(&utc); 133 ircvd = ut_next_index(&utc);
134 134
135 /* set ref to value of ircvd */ 135 /* set ref to value of ircvd */
136 ref = ircvd; 136 ref = ircvd;
137 137
138 /* estimate index based on low bits of ircvd */ 138 /* estimate index based on low bits of ircvd */
139 delta = index_guess(&local, &est, (uint16_t) ref); 139 delta = srtp_index_guess(&local, &est, (uint16_t) ref);
140 #if ROC_VERBOSE 140 #if ROC_VERBOSE
141 printf("ref: %lld, local: %lld, est: %lld, ircvd: %d, delta: %d\n", 141 printf("ref: %lld, local: %lld, est: %lld, ircvd: %d, delta: %d\n",
142 ref, local, est, ircvd, delta); 142 ref, local, est, ircvd, delta);
143 #endif 143 #endif
144 144
145 if (local + delta != est) { 145 if (local + delta != est) {
146 printf(" *bad delta*: local %llu + delta %d != est %llu\n", 146 printf(" *bad delta*: local %llu + delta %d != est %llu\n",
147 (unsigned long long)local, delta, (unsigned long long)est); 147 (unsigned long long)local, delta, (unsigned long long)est);
148 return err_status_algo_fail; 148 return srtp_err_status_algo_fail;
149 } 149 }
150 150
151 /* now update local xtd_seq_num_t as necessary */ 151 /* now update local srtp_xtd_seq_num_t as necessary */
152 if (delta > 0) 152 if (delta > 0)
153 index_advance(&local, delta); 153 srtp_index_advance(&local, delta);
154 154
155 if (ref != est) { 155 if (ref != est) {
156 #if ROC_VERBOSE 156 #if ROC_VERBOSE
157 printf(" *bad estimate*\n"); 157 printf(" *bad estimate*\n");
158 #endif 158 #endif
159 /* record failure event */ 159 /* record failure event */
160 ++num_bad_est; 160 ++num_bad_est;
161 161
162 /* reset local value to correct value */ 162 /* reset local value to correct value */
163 local = ref; 163 local = ref;
164 } 164 }
165 } 165 }
166 failure_rate = (double) num_bad_est / num_trials; 166 failure_rate = (double) num_bad_est / num_trials;
167 if (failure_rate > 0.01) { 167 if (failure_rate > 0.01) {
168 printf("error: failure rate too high (%d bad estimates in %d trials)\n", 168 printf("error: failure rate too high (%d bad estimates in %d trials)\n",
169 num_bad_est, num_trials); 169 num_bad_est, num_trials);
170 return err_status_algo_fail; 170 return srtp_err_status_algo_fail;
171 } 171 }
172 printf("done\n"); 172 printf("done\n");
173 173
174 return err_status_ok; 174 return srtp_err_status_ok;
175 } 175 }
OLDNEW
« no previous file with comments | « test/replay_driver.c ('k') | test/rtp.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698