~ubuntu-branches/ubuntu/saucy/ldb/saucy

« back to all changes in this revision

Viewing changes to lib/talloc/testsuite.c

  • Committer: Package Import Robot
  • Author(s): Andrew Bartlett
  • Date: 2013-02-12 19:02:05 UTC
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: package-import@ubuntu.com-20130212190205-uocod1m4hk2pggxe
Tags: upstream-1.1.15
ImportĀ upstreamĀ versionĀ 1.1.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
1355
1355
        return true;
1356
1356
}
1357
1357
 
 
1358
static bool test_memlimit(void)
 
1359
{
 
1360
        void *root;
 
1361
        char *l1, *l2, *l3, *l4, *l5, *t;
 
1362
 
 
1363
        printf("test: memlimit\n# MEMORY LIMITS\n");
 
1364
 
 
1365
        printf("==== talloc_new(NULL)\n");
 
1366
        root = talloc_new(NULL);
 
1367
 
 
1368
        talloc_report_full(root, stdout);
 
1369
 
 
1370
        printf("==== talloc_size(root, 2048)\n");
 
1371
        l1 = talloc_size(root, 2048);
 
1372
        torture_assert("memlimit", l1 != NULL,
 
1373
                "failed: alloc should not fail due to memory limit\n");
 
1374
 
 
1375
        talloc_report_full(root, stdout);
 
1376
 
 
1377
        printf("==== talloc_free(l1)\n");
 
1378
        talloc_free(l1);
 
1379
 
 
1380
        talloc_report_full(root, stdout);
 
1381
 
 
1382
        printf("==== talloc_strdup(root, level 1)\n");
 
1383
        l1 = talloc_strdup(root, "level 1");
 
1384
        torture_assert("memlimit", l1 != NULL,
 
1385
                "failed: alloc should not fail due to memory limit\n");
 
1386
 
 
1387
        talloc_report_full(root, stdout);
 
1388
 
 
1389
        printf("==== talloc_set_memlimit(l1, 2048)\n");
 
1390
        torture_assert("memlimit", talloc_set_memlimit(l1, 2048) == 0,
 
1391
                "failed: setting memlimit should never fail\n");
 
1392
 
 
1393
        talloc_report_full(root, stdout);
 
1394
 
 
1395
        printf("==== talloc_size(root, 2048)\n");
 
1396
        l2 = talloc_size(l1, 2048);
 
1397
        torture_assert("memlimit", l2 == NULL,
 
1398
                "failed: alloc should fail due to memory limit\n");
 
1399
 
 
1400
        talloc_report_full(root, stdout);
 
1401
 
 
1402
        printf("==== talloc_strdup(l1, level 2)\n");
 
1403
        l2 = talloc_strdup(l1, "level 2");
 
1404
        torture_assert("memlimit", l2 != NULL,
 
1405
                "failed: alloc should not fail due to memory limit\n");
 
1406
 
 
1407
        talloc_report_full(root, stdout);
 
1408
 
 
1409
        printf("==== talloc_free(l2)\n");
 
1410
        talloc_free(l2);
 
1411
 
 
1412
        talloc_report_full(root, stdout);
 
1413
 
 
1414
        printf("==== talloc_size(NULL, 2048)\n");
 
1415
        l2 = talloc_size(NULL, 2048);
 
1416
 
 
1417
        talloc_report_full(root, stdout);
 
1418
 
 
1419
        printf("==== talloc_steal(l1, l2)\n");
 
1420
        talloc_steal(l1, l2);
 
1421
 
 
1422
        talloc_report_full(root, stdout);
 
1423
 
 
1424
        printf("==== talloc_strdup(l2, level 3)\n");
 
1425
        l3 = talloc_strdup(l2, "level 3");
 
1426
        torture_assert("memlimit", l3 == NULL,
 
1427
                "failed: alloc should fail due to memory limit\n");
 
1428
 
 
1429
        talloc_report_full(root, stdout);
 
1430
 
 
1431
        printf("==== talloc_free(l2)\n");
 
1432
        talloc_free(l2);
 
1433
 
 
1434
        talloc_report_full(root, stdout);
 
1435
 
 
1436
        printf("==== talloc_strdup(NULL, level 2)\n");
 
1437
        l2 = talloc_strdup(NULL, "level 2");
 
1438
        talloc_steal(l1, l2);
 
1439
 
 
1440
        talloc_report_full(root, stdout);
 
1441
 
 
1442
        printf("==== talloc_strdup(l2, level 3)\n");
 
1443
        l3 = talloc_strdup(l2, "level 3");
 
1444
        torture_assert("memlimit", l3 != NULL,
 
1445
                "failed: alloc should not fail due to memory limit\n");
 
1446
 
 
1447
        talloc_report_full(root, stdout);
 
1448
 
 
1449
        printf("==== talloc_set_memlimit(l3, 1024)\n");
 
1450
        torture_assert("memlimit", talloc_set_memlimit(l3, 1024) == 0,
 
1451
                "failed: setting memlimit should never fail\n");
 
1452
 
 
1453
        talloc_report_full(root, stdout);
 
1454
 
 
1455
        printf("==== talloc_strdup(l3, level 4)\n");
 
1456
        l4 = talloc_strdup(l3, "level 4");
 
1457
        torture_assert("memlimit", l4 != NULL,
 
1458
                "failed: alloc should not fail due to memory limit\n");
 
1459
 
 
1460
        talloc_report_full(root, stdout);
 
1461
 
 
1462
        printf("==== talloc_set_memlimit(l4, 512)\n");
 
1463
        torture_assert("memlimit", talloc_set_memlimit(l4, 512) == 0,
 
1464
                "failed: setting memlimit should never fail\n");
 
1465
 
 
1466
        talloc_report_full(root, stdout);
 
1467
 
 
1468
        printf("==== talloc_strdup(l4, level 5)\n");
 
1469
        l5 = talloc_strdup(l4, "level 5");
 
1470
        torture_assert("memlimit", l5 != NULL,
 
1471
                "failed: alloc should not fail due to memory limit\n");
 
1472
 
 
1473
        talloc_report_full(root, stdout);
 
1474
 
 
1475
        printf("==== talloc_realloc(NULL, l5, char, 600)\n");
 
1476
        t = talloc_realloc(NULL, l5, char, 600);
 
1477
        torture_assert("memlimit", t == NULL,
 
1478
                "failed: alloc should fail due to memory limit\n");
 
1479
 
 
1480
        talloc_report_full(root, stdout);
 
1481
 
 
1482
        printf("==== talloc_realloc(NULL, l5, char, 5)\n");
 
1483
        l5 = talloc_realloc(NULL, l5, char, 5);
 
1484
        torture_assert("memlimit", l5 != NULL,
 
1485
                "failed: alloc should not fail due to memory limit\n");
 
1486
 
 
1487
        talloc_report_full(root, stdout);
 
1488
 
 
1489
        printf("==== talloc_strdup(l3, level 4)\n");
 
1490
        l4 = talloc_strdup(l3, "level 4");
 
1491
        torture_assert("memlimit", l4 != NULL,
 
1492
                "failed: alloc should not fail due to memory limit\n");
 
1493
 
 
1494
        talloc_report_full(root, stdout);
 
1495
 
 
1496
        printf("==== talloc_set_memlimit(l4, 512)\n");
 
1497
        torture_assert("memlimit", talloc_set_memlimit(l4, 512) == 0,
 
1498
                "failed: setting memlimit should never fail\n");
 
1499
 
 
1500
        talloc_report_full(root, stdout);
 
1501
 
 
1502
        printf("==== talloc_strdup(l4, level 5)\n");
 
1503
        l5 = talloc_strdup(l4, "level 5");
 
1504
        torture_assert("memlimit", l5 != NULL,
 
1505
                "failed: alloc should not fail due to memory limit\n");
 
1506
 
 
1507
        talloc_report_full(root, stdout);
 
1508
 
 
1509
        printf("==== Make new temp context and steal l5\n");
 
1510
        t = talloc_new(root);
 
1511
        talloc_steal(t, l5);
 
1512
 
 
1513
        talloc_report_full(root, stdout);
 
1514
 
 
1515
        printf("==== talloc_size(t, 2048)\n");
 
1516
        l1 = talloc_size(t, 2048);
 
1517
        torture_assert("memlimit", l1 != NULL,
 
1518
                "failed: alloc should not fail due to memory limit\n");
 
1519
 
 
1520
        talloc_report_full(root, stdout);
 
1521
        talloc_free(root);
 
1522
 
 
1523
        printf("success: memlimit\n");
 
1524
 
 
1525
        return true;
 
1526
}
1358
1527
 
1359
1528
static void test_reset(void)
1360
1529
{
1416
1585
        ret &= test_rusty();
1417
1586
        test_reset();
1418
1587
        ret &= test_free_children();
 
1588
        test_reset();
 
1589
        ret &= test_memlimit();
 
1590
 
1419
1591
 
1420
1592
        if (ret) {
1421
1593
                test_reset();