Changeset 740 for vendor/current/lib/talloc/testsuite.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/lib/talloc/testsuite.c
r414 r740 26 26 #include "replace.h" 27 27 #include "system/time.h" 28 #include "talloc.h" 28 #include <talloc.h> 29 30 #include "talloc_testsuite.h" 29 31 30 32 static struct timeval timeval_current(void) … … 102 104 static unsigned int test_abort_count; 103 105 106 #if 0 104 107 static void test_abort_fn(const char *reason) 105 108 { … … 113 116 talloc_set_abort_fn(test_abort_fn); 114 117 } 118 #endif 115 119 116 120 static void test_abort_stop(void) … … 1120 1124 void *pool; 1121 1125 void *p1, *p2, *p3, *p4; 1126 void *p2_2; 1122 1127 1123 1128 pool = talloc_pool(NULL, 1024); 1124 1129 1125 1130 p1 = talloc_size(pool, 80); 1131 memset(p1, 0x11, talloc_get_size(p1)); 1126 1132 p2 = talloc_size(pool, 20); 1133 memset(p2, 0x11, talloc_get_size(p2)); 1127 1134 p3 = talloc_size(p1, 50); 1135 memset(p3, 0x11, talloc_get_size(p3)); 1128 1136 p4 = talloc_size(p3, 1000); 1137 memset(p4, 0x11, talloc_get_size(p4)); 1138 1139 #if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */ 1140 p2_2 = talloc_realloc_size(pool, p2, 20+1); 1141 torture_assert("pool realloc 20+1", p2_2 == p2, "failed: pointer changed"); 1142 memset(p2, 0x11, talloc_get_size(p2)); 1143 p2_2 = talloc_realloc_size(pool, p2, 20-1); 1144 torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed"); 1145 memset(p2, 0x11, talloc_get_size(p2)); 1146 p2_2 = talloc_realloc_size(pool, p2, 20-1); 1147 torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed"); 1148 memset(p2, 0x11, talloc_get_size(p2)); 1149 1150 talloc_free(p3); 1151 1152 /* this should reclaim the memory of p4 and p3 */ 1153 p2_2 = talloc_realloc_size(pool, p2, 400); 1154 torture_assert("pool realloc 400", p2_2 == p2, "failed: pointer changed"); 1155 memset(p2, 0x11, talloc_get_size(p2)); 1156 1157 talloc_free(p1); 1158 1159 /* this should reclaim the memory of p1 */ 1160 p2_2 = talloc_realloc_size(pool, p2, 800); 1161 torture_assert("pool realloc 800", p2_2 == p1, "failed: pointer not changed"); 1162 p2 = p2_2; 1163 memset(p2, 0x11, talloc_get_size(p2)); 1164 1165 /* this should do a malloc */ 1166 p2_2 = talloc_realloc_size(pool, p2, 1800); 1167 torture_assert("pool realloc 1800", p2_2 != p2, "failed: pointer not changed"); 1168 p2 = p2_2; 1169 memset(p2, 0x11, talloc_get_size(p2)); 1170 1171 /* this should reclaim the memory from the pool */ 1172 p3 = talloc_size(pool, 80); 1173 torture_assert("pool alloc 80", p3 == p1, "failed: pointer changed"); 1174 memset(p3, 0x11, talloc_get_size(p3)); 1175 1176 talloc_free(p2); 1177 talloc_free(p3); 1178 1179 p1 = talloc_size(pool, 80); 1180 memset(p1, 0x11, talloc_get_size(p1)); 1181 p2 = talloc_size(pool, 20); 1182 memset(p2, 0x11, talloc_get_size(p2)); 1183 1184 talloc_free(p1); 1185 1186 p2_2 = talloc_realloc_size(pool, p2, 20-1); 1187 torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed"); 1188 memset(p2, 0x11, talloc_get_size(p2)); 1189 p2_2 = talloc_realloc_size(pool, p2, 20-1); 1190 torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed"); 1191 memset(p2, 0x11, talloc_get_size(p2)); 1192 1193 /* this should do a malloc */ 1194 p2_2 = talloc_realloc_size(pool, p2, 1800); 1195 torture_assert("pool realloc 1800", p2_2 != p2, "failed: pointer not changed"); 1196 p2 = p2_2; 1197 memset(p2, 0x11, talloc_get_size(p2)); 1198 1199 /* this should reclaim the memory from the pool */ 1200 p3 = talloc_size(pool, 800); 1201 torture_assert("pool alloc 800", p3 == p1, "failed: pointer changed"); 1202 memset(p3, 0x11, talloc_get_size(p3)); 1203 1204 #endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */ 1129 1205 1130 1206 talloc_free(pool); … … 1132 1208 return true; 1133 1209 } 1210 1211 static bool test_pool_steal(void) 1212 { 1213 void *root; 1214 void *pool; 1215 void *p1, *p2; 1216 void *p1_2, *p2_2; 1217 size_t hdr; 1218 size_t ofs1, ofs2; 1219 1220 root = talloc_new(NULL); 1221 pool = talloc_pool(root, 1024); 1222 1223 p1 = talloc_size(pool, 4 * 16); 1224 torture_assert("pool allocate 4 * 16", p1 != NULL, "failed "); 1225 memset(p1, 0x11, talloc_get_size(p1)); 1226 p2 = talloc_size(pool, 4 * 16); 1227 torture_assert("pool allocate 4 * 16", p2 > p1, "failed: !(p2 > p1) "); 1228 memset(p2, 0x11, talloc_get_size(p2)); 1229 1230 ofs1 = PTR_DIFF(p2, p1); 1231 hdr = ofs1 - talloc_get_size(p1); 1232 1233 talloc_steal(root, p1); 1234 talloc_steal(root, p2); 1235 1236 talloc_free(pool); 1237 1238 p1_2 = p1; 1239 1240 #if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */ 1241 p1_2 = talloc_realloc_size(root, p1, 5 * 16); 1242 torture_assert("pool realloc 5 * 16", p1_2 > p2, "failed: pointer not changed"); 1243 memset(p1_2, 0x11, talloc_get_size(p1_2)); 1244 ofs1 = PTR_DIFF(p1_2, p2); 1245 ofs2 = talloc_get_size(p2) + hdr; 1246 1247 torture_assert("pool realloc ", ofs1 == ofs2, "failed: pointer offset unexpected"); 1248 1249 p2_2 = talloc_realloc_size(root, p2, 3 * 16); 1250 torture_assert("pool realloc 5 * 16", p2_2 == p2, "failed: pointer changed"); 1251 memset(p2_2, 0x11, talloc_get_size(p2_2)); 1252 #endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */ 1253 1254 talloc_free(p1_2); 1255 1256 p2_2 = p2; 1257 1258 #if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */ 1259 /* now we should reclaim the full pool */ 1260 p2_2 = talloc_realloc_size(root, p2, 8 * 16); 1261 torture_assert("pool realloc 8 * 16", p2_2 == p1, "failed: pointer not expected"); 1262 p2 = p2_2; 1263 memset(p2_2, 0x11, talloc_get_size(p2_2)); 1264 1265 /* now we malloc and free the full pool space */ 1266 p2_2 = talloc_realloc_size(root, p2, 2 * 1024); 1267 torture_assert("pool realloc 2 * 1024", p2_2 != p1, "failed: pointer not expected"); 1268 memset(p2_2, 0x11, talloc_get_size(p2_2)); 1269 1270 #endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */ 1271 1272 talloc_free(p2_2); 1273 1274 talloc_free(root); 1275 1276 return true; 1277 } 1278 1279 static bool test_free_ref_null_context(void) 1280 { 1281 void *p1, *p2, *p3; 1282 int ret; 1283 1284 talloc_disable_null_tracking(); 1285 p1 = talloc_new(NULL); 1286 p2 = talloc_new(NULL); 1287 1288 p3 = talloc_reference(p2, p1); 1289 torture_assert("reference", p3 == p1, "failed: reference on null"); 1290 1291 ret = talloc_free(p1); 1292 torture_assert("ref free with null parent", ret == 0, "failed: free with null parent"); 1293 talloc_free(p2); 1294 1295 talloc_enable_null_tracking_no_autofree(); 1296 p1 = talloc_new(NULL); 1297 p2 = talloc_new(NULL); 1298 1299 p3 = talloc_reference(p2, p1); 1300 torture_assert("reference", p3 == p1, "failed: reference on null"); 1301 1302 ret = talloc_free(p1); 1303 torture_assert("ref free with null tracked parent", ret == 0, "failed: free with null parent"); 1304 talloc_free(p2); 1305 1306 return true; 1307 } 1308 1309 static bool test_rusty(void) 1310 { 1311 void *root; 1312 const char *p1; 1313 1314 talloc_enable_null_tracking(); 1315 root = talloc_new(NULL); 1316 p1 = talloc_strdup(root, "foo"); 1317 talloc_increase_ref_count(p1); 1318 talloc_report_full(root, stdout); 1319 talloc_free(root); 1320 return true; 1321 } 1322 1134 1323 1135 1324 static void test_reset(void) … … 1141 1330 } 1142 1331 1143 struct torture_context;1144 1332 bool torture_local_talloc(struct torture_context *tctx) 1145 1333 { … … 1186 1374 test_reset(); 1187 1375 ret &= test_pool(); 1376 test_reset(); 1377 ret &= test_pool_steal(); 1378 test_reset(); 1379 ret &= test_free_ref_null_context(); 1380 test_reset(); 1381 ret &= test_rusty(); 1188 1382 1189 1383 if (ret) { … … 1195 1389 1196 1390 test_reset(); 1197 1391 talloc_disable_null_tracking(); 1198 1392 return ret; 1199 1393 }
Note:
See TracChangeset
for help on using the changeset viewer.