1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
30 #include "tst_malloc_canaries.h"
31 #include "tst_preload_FILE.h"
35 tst_msg("This test does nothing");
36 tst_msg("But successfully");
51 int stack_overflow_fn(void)
53 int ret
= stack_overflow_fn() + stack_overflow_fn();
60 tst_msg("Sleeping for ten seconds");
69 /* log current working directory */
70 res
= getcwd(buf
, sizeof(buf
));
71 tst_msg("CWD is '%s'", res
);
76 int malloc_leak_fn(void)
89 tst_msg("Leaking 1 chunks 4 bytes total");
94 int malloc_ok_fn(void)
96 unsigned int perm
[20] = {
97 1, 3, 2, 6, 4, 5, 0, 9, 8, 14,
98 7, 11, 13, 10, 12, 19, 17, 16, 15, 18,
104 for (i
= 0; i
< 20; i
++)
105 p
[i
] = malloc((7 * i
) % 127);
107 for (i
= 0; i
< 20; i
++)
113 int double_free(void)
115 void *p
= malloc(100);
123 int canary_allocation(void)
125 char *buf
= tst_malloc_canary_right(31);
129 for (i
= 0; i
< 31; i
++)
132 tst_msg("About to use address after the buffer with barrier");
136 tst_msg("This is not printed at all");
143 struct tst_fail_FILE failures
[] = {
144 {.path
= "test_fail_fopen", .call
= TST_FAIL_FOPEN
, .err
= EPERM
},
145 {.path
= "test_fail_fclose", .call
= TST_FAIL_FCLOSE
, .err
= ENOSPC
},
149 tst_fail_FILE_register(failures
);
154 f
= fopen("test_fail_fclose", "w");
157 tst_msg("Failed to open 'test_fail_fclose' for writing: %s",
162 tst_msg("Correctly opened 'test_fail_fclose'");
166 if (ret
== 0 || errno
!= ENOSPC
) {
167 tst_msg("Failed to fail to close 'test_fail_fclose'");
171 tst_msg("Correctly failed to close 'test_fail_fclose'");
173 f
= fopen("test_fail_fopen", "w");
175 if (f
!= NULL
&& errno
!= EPERM
) {
176 tst_msg("Failed to fail to open 'test_fail_fopen'");
181 tst_msg("Correctly failed to open 'test_fail_fopen'");
189 static int messages_test_fn(void)
191 /* stdout and stderr capture test */
192 printf("This is stdout\n");
193 fprintf(stderr
, "This is stderr\n");
195 tst_msg("This is message");
196 tst_warn("This is a warning");
197 tst_err("This is an error");
203 * This status is returned when the could not be started
204 * because of unsufficient configuration
206 static int skipped_fn(void)
212 * This status is returned when there was failure prior
213 * the actuall testing so we could not test the feature
216 static int untested_fn(void)
221 static int res_fn(void)
223 if (access("test.c", R_OK
) == 0)
224 tst_msg("File correctly copied");
229 static int fpe_fn(void)
231 /* its volatile so compiler doesn't detect the division by zero */
238 * Let's benchmark memset.
240 static int benchmark_fn(void)
245 for (i
= 0; i
< 4000000; i
++)
246 memset(buf
, i
%100, sizeof(buf
));
251 const struct tst_suite tst_suite
= {
252 .suite_name
= "Testing Framework Example",
254 {.name
= "Success test", .tst_fn
= success_fn
},
255 {.name
= "Skipped test", .tst_fn
= skipped_fn
},
256 {.name
= "Untested test", .tst_fn
= untested_fn
},
257 {.name
= "Sigsegv test", .tst_fn
= sigsegv_fn
},
258 {.name
= "Failed test", .tst_fn
= failed_fn
},
259 {.name
= "Stack overflow test", .tst_fn
= stack_overflow_fn
},
260 {.name
= "Timeout test", .tst_fn
= timeout_fn
, .timeout
= 1},
261 {.name
= "Tempdir test", .tst_fn
= temp_dir_fn
, .flags
= TST_TMPDIR
},
262 {.name
= "Mem Leak test", .tst_fn
= malloc_leak_fn
, .flags
= TST_CHECK_MALLOC
},
263 {.name
= "Mem Ok test", .tst_fn
= malloc_ok_fn
, .flags
= TST_CHECK_MALLOC
},
264 {.name
= "Double free()", .tst_fn
= double_free
},
265 {.name
= "Canary allocation", .tst_fn
= canary_allocation
},
266 {.name
= "Failed FILE", .tst_fn
= fail_FILE
, .flags
= TST_TMPDIR
},
267 {.name
= "Resource", .tst_fn
= res_fn
, .flags
= TST_TMPDIR
,
268 .res_path
= "test.c"},
269 {.name
= "FP exception", .tst_fn
= fpe_fn
},
270 {.name
= "Messages test", .tst_fn
= messages_test_fn
},
271 {.name
= "Benchmark test", .tst_fn
= benchmark_fn
, .bench_iter
= 10},