1358
static bool test_memlimit(void)
1361
char *l1, *l2, *l3, *l4, *l5, *t;
1363
printf("test: memlimit\n# MEMORY LIMITS\n");
1365
printf("==== talloc_new(NULL)\n");
1366
root = talloc_new(NULL);
1368
talloc_report_full(root, stdout);
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");
1375
talloc_report_full(root, stdout);
1377
printf("==== talloc_free(l1)\n");
1380
talloc_report_full(root, stdout);
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");
1387
talloc_report_full(root, stdout);
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");
1393
talloc_report_full(root, stdout);
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");
1400
talloc_report_full(root, stdout);
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");
1407
talloc_report_full(root, stdout);
1409
printf("==== talloc_free(l2)\n");
1412
talloc_report_full(root, stdout);
1414
printf("==== talloc_size(NULL, 2048)\n");
1415
l2 = talloc_size(NULL, 2048);
1417
talloc_report_full(root, stdout);
1419
printf("==== talloc_steal(l1, l2)\n");
1420
talloc_steal(l1, l2);
1422
talloc_report_full(root, stdout);
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");
1429
talloc_report_full(root, stdout);
1431
printf("==== talloc_free(l2)\n");
1434
talloc_report_full(root, stdout);
1436
printf("==== talloc_strdup(NULL, level 2)\n");
1437
l2 = talloc_strdup(NULL, "level 2");
1438
talloc_steal(l1, l2);
1440
talloc_report_full(root, stdout);
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");
1447
talloc_report_full(root, stdout);
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");
1453
talloc_report_full(root, stdout);
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");
1460
talloc_report_full(root, stdout);
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");
1466
talloc_report_full(root, stdout);
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");
1473
talloc_report_full(root, stdout);
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");
1480
talloc_report_full(root, stdout);
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");
1487
talloc_report_full(root, stdout);
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");
1494
talloc_report_full(root, stdout);
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");
1500
talloc_report_full(root, stdout);
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");
1507
talloc_report_full(root, stdout);
1509
printf("==== Make new temp context and steal l5\n");
1510
t = talloc_new(root);
1511
talloc_steal(t, l5);
1513
talloc_report_full(root, stdout);
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");
1520
talloc_report_full(root, stdout);
1523
printf("success: memlimit\n");
1359
1528
static void test_reset(void)