int dm_leak_check_end(struct unit_test_state *uts) { struct mallinfo end; int id, diff; /* Don't delete the root class, since we started with that */ for (id = UCLASS_ROOT + 1; id < UCLASS_COUNT; id++) { struct uclass *uc; uc = uclass_find(id); if (!uc) continue; ut_assertok(uclass_destroy(uc)); } end = mallinfo(); diff = end.uordblks - uts->start.uordblks; if (diff > 0) printf("Leak: lost %#xd bytes\n", diff); else if (diff < 0) printf("Leak: gained %#xd bytes\n", -diff); ut_asserteq(uts->start.uordblks, end.uordblks); return 0; }
/* Test uclass init/destroy methods */ static int dm_test_uclass(struct unit_test_state *uts) { struct uclass *uc; ut_assertok(uclass_get(UCLASS_TEST, &uc)); ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]); ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_DESTROY]); ut_assert(uc->priv); ut_assertok(uclass_destroy(uc)); ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]); ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_DESTROY]); return 0; }
static int dm_test_destroy(struct dm_test_state *dms) { int id; for (id = 0; id < UCLASS_COUNT; id++) { struct uclass *uc; /* * If the uclass doesn't exist we don't want to create it. So * check that here before we call uclass_find_device()/ */ uc = uclass_find(id); if (!uc) continue; ut_assertok(uclass_destroy(uc)); } return 0; }
/* Remove and recreate everything, check for memory leaks */ static int dm_test_leak(struct dm_test_state *dms) { int i; for (i = 0; i < 2; i++) { struct mallinfo start, end; struct udevice *dev; int ret; int id; start = mallinfo(); if (!start.uordblks) puts("Warning: Please add '#define DEBUG' to the top of common/dlmalloc.c\n"); ut_assertok(dm_scan_platdata()); ut_assertok(dm_scan_fdt(gd->fdt_blob)); /* Scanning the uclass is enough to probe all the devices */ for (id = UCLASS_ROOT; id < UCLASS_COUNT; id++) { for (ret = uclass_first_device(UCLASS_TEST, &dev); dev; ret = uclass_next_device(&dev)) ; ut_assertok(ret); } /* Don't delete the root class, since we started with that */ for (id = UCLASS_ROOT + 1; id < UCLASS_COUNT; id++) { struct uclass *uc; uc = uclass_find(id); if (!uc) continue; ut_assertok(uclass_destroy(uc)); } end = mallinfo(); ut_asserteq(start.uordblks, end.uordblks); } return 0; }
int dm_leak_check_end(struct unit_test_state *uts) { struct mallinfo end; int id; /* Don't delete the root class, since we started with that */ for (id = UCLASS_ROOT + 1; id < UCLASS_COUNT; id++) { struct uclass *uc; uc = uclass_find(id); if (!uc) continue; ut_assertok(uclass_destroy(uc)); } end = mallinfo(); ut_asserteq(uts->start.uordblks, end.uordblks); return 0; }