tst-mallopt.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Copyright (C) 2014-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include <malloc.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. static int errors = 0;
  18. static void
  19. merror (const char *msg)
  20. {
  21. ++errors;
  22. printf ("Error: %s\n", msg);
  23. }
  24. static int
  25. do_test (void)
  26. {
  27. int ret;
  28. ret = mallopt(M_CHECK_ACTION, 1);
  29. if (ret != 1)
  30. merror ("mallopt (M_CHECK_ACTION, 1) failed.");
  31. ret = mallopt(M_MMAP_MAX, 64*1024);
  32. if (ret != 1)
  33. merror ("mallopt (M_MMAP_MAX, 64*1024) failed.");
  34. ret = mallopt(M_MMAP_THRESHOLD, 64*1024);
  35. if (ret != 1)
  36. merror ("mallopt (M_MMAP_THRESHOLD, 64*1024) failed.");
  37. ret = mallopt(M_MXFAST, 0);
  38. if (ret != 1)
  39. merror ("mallopt (M_MXFAST, 0) failed.");
  40. ret = mallopt(M_PERTURB, 0xa5);
  41. if (ret != 1)
  42. merror ("mallopt (M_PERTURB, 0xa5) failed.");
  43. ret = mallopt(M_TOP_PAD, 64*1024);
  44. if (ret != 1)
  45. merror ("mallopt (M_TOP_PAD, 64*1024) failed.");
  46. ret = mallopt(M_TRIM_THRESHOLD, -1);
  47. if (ret != 1)
  48. merror ("mallopt (M_TRIM_THRESHOLD, -1) failed.");
  49. return errors != 0;
  50. }
  51. #define TEST_FUNCTION do_test ()
  52. #include "../test-skeleton.c"