![]() |
|
|||
File indexing completed on 2025-05-11 08:24:35
0001 #include <rtems/test.h> 0002 0003 T_TEST_CASE(malloc_free) 0004 { 0005 void *p; 0006 0007 p = T_malloc(1); 0008 T_assert_not_null(p); 0009 T_free(p); 0010 } 0011 0012 T_TEST_CASE(malloc_auto) 0013 { 0014 void *p; 0015 0016 p = T_malloc(1); 0017 T_assert_not_null(p); 0018 } 0019 0020 static void 0021 destroy(void *p) 0022 { 0023 int *i; 0024 0025 i = p; 0026 T_step_eq_int(2, *i, 1); 0027 } 0028 0029 T_TEST_CASE(zalloc_auto) 0030 { 0031 int *i; 0032 0033 T_plan(3); 0034 i = T_zalloc(sizeof(*i), destroy); 0035 T_step_assert_not_null(0, i); 0036 T_step_eq_int(1, *i, 0); 0037 *i = 1; 0038 } 0039 0040 T_TEST_CASE(malloc_huge) 0041 { 0042 void *p; 0043 0044 p = T_malloc(SIZE_MAX); 0045 T_null(p); 0046 } 0047 0048 T_TEST_CASE(calloc_auto) 0049 { 0050 int *i; 0051 0052 i = T_calloc(1, sizeof(*i)); 0053 T_assert_not_null(i); 0054 T_eq_int(*i, 0); 0055 } 0056 0057 #include "t-self-test.h" 0058 0059 T_TEST_OUTPUT(malloc_free, 0060 "B:malloc_free\n" 0061 "P:0:0:UI1:test-malloc.c:8\n" 0062 "E:malloc_free:N:1:F:0:D:0.001000\n"); 0063 0064 T_TEST_OUTPUT(malloc_auto, 0065 "B:malloc_auto\n" 0066 "P:0:0:UI1:test-malloc.c:17\n" 0067 "E:malloc_auto:N:1:F:0:D:0.001000\n"); 0068 0069 T_TEST_OUTPUT(zalloc_auto, 0070 "B:zalloc_auto\n" 0071 "P:0:0:UI1:test-malloc.c:35\n" 0072 "P:1:0:UI1:test-malloc.c:36\n" 0073 "P:2:0:UI1:test-malloc.c:26\n" 0074 "E:zalloc_auto:N:3:F:0:D:0.001000\n"); 0075 0076 T_TEST_OUTPUT(malloc_huge, 0077 "B:malloc_huge\n" 0078 "P:0:0:UI1:test-malloc.c:45\n" 0079 "E:malloc_huge:N:1:F:0:D:0.001000\n"); 0080 0081 T_TEST_OUTPUT(calloc_auto, 0082 "B:calloc_auto\n" 0083 "P:0:0:UI1:test-malloc.c:53\n" 0084 "P:1:0:UI1:test-malloc.c:54\n" 0085 "E:calloc_auto:N:2:F:0:D:0.001000\n"); 0086 0087 /* 0088 * The license is at the end of the file to be able to use the test code and 0089 * output in examples in the documentation. This is also the reason for the 0090 * dual licensing. The license for RTEMS documentation is CC-BY-SA-4.0. 0091 */ 0092 0093 /* 0094 * SPDX-License-Identifier: BSD-2-Clause OR CC-BY-SA-4.0 0095 * 0096 * Copyright (C) 2018, 2019 embedded brains GmbH & Co. KG 0097 * 0098 * Redistribution and use in source and binary forms, with or without 0099 * modification, are permitted provided that the following conditions 0100 * are met: 0101 * 1. Redistributions of source code must retain the above copyright 0102 * notice, this list of conditions and the following disclaimer. 0103 * 2. Redistributions in binary form must reproduce the above copyright 0104 * notice, this list of conditions and the following disclaimer in the 0105 * documentation and/or other materials provided with the distribution. 0106 * 0107 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0108 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0109 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0110 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0111 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0112 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0113 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0114 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0115 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0116 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0117 * POSSIBILITY OF SUCH DAMAGE. 0118 * 0119 * ALTERNATIVELY, this software may be distributed under the terms of the 0120 * Creative Commons Attribution-ShareAlike 4.0 International Public License as 0121 * published by Creative Commons, PO Box 1866, Mountain View, CA 94042 0122 * (https://creativecommons.org/licenses/by-sa/4.0/legalcode). 0123 */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |