From b628064a06cfaed42e795e846d1ea2038aa9d995 Mon Sep 17 00:00:00 2001
From: ohnx <me@masonx.ca>
Date: Tue, 12 Dec 2017 05:22:52 +0000
Subject: [PATCH] Add tests for calloc()
---
src/tests/system/libroot/posix/Jamfile | 1 +
src/tests/system/libroot/posix/calloc_test.c | 37 ++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
create mode 100644 src/tests/system/libroot/posix/calloc_test.c
diff --git a/src/tests/system/libroot/posix/Jamfile b/src/tests/system/libroot/posix/Jamfile
index 3736add4df..ee5e4f60f9 100644
a
|
b
|
TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCH)
|
10 | 10 | SimpleTest abort_test : abort_test.cpp ; |
11 | 11 | SimpleTest SyslogTest : SyslogTest.cpp ; |
12 | 12 | SimpleTest brk_test : brk_test.c ; |
| 13 | SimpleTest calloc_test : calloc_test.c ; |
13 | 14 | SimpleTest clearenv : clearenv.cpp ; |
14 | 15 | SimpleTest dirent_test : dirent_test.cpp ; |
15 | 16 | SimpleTest flock_test : flock_test.cpp ; |
diff --git a/src/tests/system/libroot/posix/calloc_test.c b/src/tests/system/libroot/posix/calloc_test.c
new file mode 100644
index 0000000000..9a0e2e2d9c
-
|
+
|
|
| 1 | /* |
| 2 | * Copyright 2017, ohnx, me@masonx.ca. |
| 3 | * Distributed under the terms of the CC0 License. |
| 4 | */ |
| 5 | |
| 6 | #include <stdint.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <stdio.h> |
| 9 | |
| 10 | int |
| 11 | main() |
| 12 | { |
| 13 | void *ptr; |
| 14 | |
| 15 | printf("Testing calloc(SIZE_MAX, SIZE_MAX)... "); |
| 16 | if (calloc(SIZE_MAX, SIZE_MAX) != NULL) { |
| 17 | printf("fail!\n"); |
| 18 | return -1; |
| 19 | } |
| 20 | printf("pass!\n"); |
| 21 | |
| 22 | printf("Testing calloc(0, 0)... "); |
| 23 | ptr = calloc(0, 0); |
| 24 | /* free the value, since calloc() should return a free() able pointer */ |
| 25 | free(ptr); |
| 26 | /* if the test reaches this point, then calloc() works exactly as expected */ |
| 27 | printf("pass!\n"); |
| 28 | |
| 29 | printf("Testing calloc(-1, -1)... "); |
| 30 | if (calloc(-1, -1) != NULL) { |
| 31 | printf("fail!\n"); |
| 32 | return -1; |
| 33 | } |
| 34 | printf("pass!\n"); |
| 35 | |
| 36 | return 0; |
| 37 | } |