Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/lib/talloc/testsuite.c

    r414 r745  
    2626#include "replace.h"
    2727#include "system/time.h"
    28 #include "talloc.h"
     28#include <talloc.h>
     29
     30#include "talloc_testsuite.h"
    2931
    3032static struct timeval timeval_current(void)
     
    102104static unsigned int test_abort_count;
    103105
     106#if 0
    104107static void test_abort_fn(const char *reason)
    105108{
     
    113116        talloc_set_abort_fn(test_abort_fn);
    114117}
     118#endif
    115119
    116120static void test_abort_stop(void)
     
    11201124        void *pool;
    11211125        void *p1, *p2, *p3, *p4;
     1126        void *p2_2;
    11221127
    11231128        pool = talloc_pool(NULL, 1024);
    11241129
    11251130        p1 = talloc_size(pool, 80);
     1131        memset(p1, 0x11, talloc_get_size(p1));
    11261132        p2 = talloc_size(pool, 20);
     1133        memset(p2, 0x11, talloc_get_size(p2));
    11271134        p3 = talloc_size(p1, 50);
     1135        memset(p3, 0x11, talloc_get_size(p3));
    11281136        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 */
    11291205
    11301206        talloc_free(pool);
     
    11321208        return true;
    11331209}
     1210
     1211static 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
     1279static 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
     1309static 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
    11341323
    11351324static void test_reset(void)
     
    11411330}
    11421331
    1143 struct torture_context;
    11441332bool torture_local_talloc(struct torture_context *tctx)
    11451333{
     
    11861374        test_reset();
    11871375        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();
    11881382
    11891383        if (ret) {
     
    11951389
    11961390        test_reset();
    1197 
     1391        talloc_disable_null_tracking();
    11981392        return ret;
    11991393}
Note: See TracChangeset for help on using the changeset viewer.