1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) Linux Test Project, 2003-2021 4f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2002 5f08c3bdfSopenharmony_ci * 01/02/2003 Port to LTP <avenkat@us.ibm.com> 6f08c3bdfSopenharmony_ci * 06/30/2001 Port to Linux <nsharoff@us.ibm.com> 7f08c3bdfSopenharmony_ci */ 8f08c3bdfSopenharmony_ci 9f08c3bdfSopenharmony_ci/*\ 10f08c3bdfSopenharmony_ci * [Description] 11f08c3bdfSopenharmony_ci * 12f08c3bdfSopenharmony_ci * Basic mallinfo() and mallopt() testing. 13f08c3bdfSopenharmony_ci */ 14f08c3bdfSopenharmony_ci 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_ci#include "../mallinfo/mallinfo_common.h" 17f08c3bdfSopenharmony_ci#include "tst_safe_macros.h" 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_ci#ifdef HAVE_MALLOPT 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ci#define MAX_FAST_SIZE (80 * sizeof(size_t) / 4) 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_cistruct mallinfo info; 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_civoid test_mallopt(void) 26f08c3bdfSopenharmony_ci{ 27f08c3bdfSopenharmony_ci char *buf; 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_ci buf = SAFE_MALLOC(20480); 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_ci info = mallinfo(); 32f08c3bdfSopenharmony_ci if (info.uordblks < 20480) { 33f08c3bdfSopenharmony_ci print_mallinfo("Test uordblks", &info); 34f08c3bdfSopenharmony_ci tst_res(TFAIL, "mallinfo() failed: uordblks < 20K"); 35f08c3bdfSopenharmony_ci } 36f08c3bdfSopenharmony_ci if (info.smblks != 0) { 37f08c3bdfSopenharmony_ci print_mallinfo("Test smblks", &info); 38f08c3bdfSopenharmony_ci tst_res(TFAIL, "mallinfo() failed: smblks != 0"); 39f08c3bdfSopenharmony_ci } 40f08c3bdfSopenharmony_ci if (info.uordblks >= 20480 && info.smblks == 0) 41f08c3bdfSopenharmony_ci tst_res(TPASS, "mallinfo() succeeded"); 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_ci free(buf); 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_ci if (mallopt(M_MXFAST, MAX_FAST_SIZE) == 0) 46f08c3bdfSopenharmony_ci tst_res(TFAIL, "mallopt(M_MXFAST, %d) failed", (int)MAX_FAST_SIZE); 47f08c3bdfSopenharmony_ci else 48f08c3bdfSopenharmony_ci tst_res(TPASS, "mallopt(M_MXFAST, %d) succeeded", (int)MAX_FAST_SIZE); 49f08c3bdfSopenharmony_ci 50f08c3bdfSopenharmony_ci if ((buf = malloc(1024)) == NULL) { 51f08c3bdfSopenharmony_ci tst_res(TFAIL, "malloc(1024) failed"); 52f08c3bdfSopenharmony_ci } else { 53f08c3bdfSopenharmony_ci tst_res(TPASS, "malloc(1024) succeeded"); 54f08c3bdfSopenharmony_ci free(buf); 55f08c3bdfSopenharmony_ci } 56f08c3bdfSopenharmony_ci 57f08c3bdfSopenharmony_ci if (mallopt(M_MXFAST, 0) == 0) 58f08c3bdfSopenharmony_ci tst_res(TFAIL, "mallopt(M_MXFAST, 0) failed"); 59f08c3bdfSopenharmony_ci else 60f08c3bdfSopenharmony_ci tst_res(TPASS, "mallopt(M_MXFAST, 0) succeeded"); 61f08c3bdfSopenharmony_ci 62f08c3bdfSopenharmony_ci if ((buf = malloc(1024)) == NULL) { 63f08c3bdfSopenharmony_ci tst_res(TFAIL, "malloc(1024) failed"); 64f08c3bdfSopenharmony_ci } else { 65f08c3bdfSopenharmony_ci tst_res(TPASS, "malloc(1024) succeeded"); 66f08c3bdfSopenharmony_ci free(buf); 67f08c3bdfSopenharmony_ci } 68f08c3bdfSopenharmony_ci} 69f08c3bdfSopenharmony_ci 70f08c3bdfSopenharmony_cistatic struct tst_test test = { 71f08c3bdfSopenharmony_ci .test_all = test_mallopt, 72f08c3bdfSopenharmony_ci}; 73f08c3bdfSopenharmony_ci 74f08c3bdfSopenharmony_ci#else 75f08c3bdfSopenharmony_ciTST_TEST_TCONF("system doesn't implement non-POSIX mallopt()"); 76f08c3bdfSopenharmony_ci#endif 77