Line data Source code
1 : /* 2 : Unix SMB/CIFS implementation. 3 : 4 : anonymous_shared testing 5 : 6 : Copyright (C) Stefan Metzmacher 2011 7 : 8 : This program is free software; you can redistribute it and/or modify 9 : it under the terms of the GNU General Public License as published by 10 : the Free Software Foundation; either version 3 of the License, or 11 : (at your option) any later version. 12 : 13 : This program is distributed in the hope that it will be useful, 14 : but WITHOUT ANY WARRANTY; without even the implied warranty of 15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 : GNU General Public License for more details. 17 : 18 : You should have received a copy of the GNU General Public License 19 : along with this program. If not, see <http://www.gnu.org/licenses/>. 20 : */ 21 : 22 : #include "includes.h" 23 : #include "torture/torture.h" 24 : #include "torture/local/proto.h" 25 : 26 1 : static bool test_anonymous_shared_simple(struct torture_context *tctx) 27 : { 28 1 : void *ptr; 29 1 : size_t len; 30 : 31 1 : torture_comment(tctx, "anonymous_shared_free(NULL)\n"); 32 1 : anonymous_shared_free(NULL); 33 : 34 1 : len = 500; 35 1 : torture_comment(tctx, "anonymous_shared_allocate(%llu)\n", 36 : (unsigned long long)len); 37 1 : ptr = anonymous_shared_allocate(len); 38 1 : torture_assert(tctx, ptr, "valid pointer"); 39 1 : memset(ptr, 0xfe, len); 40 1 : torture_comment(tctx, "anonymous_shared_free(ptr)\n"); 41 1 : anonymous_shared_free(ptr); 42 : 43 1 : len = 50000; 44 1 : torture_comment(tctx, "anonymous_shared_allocate(%llu)\n", 45 : (unsigned long long)len); 46 1 : ptr = anonymous_shared_allocate(len); 47 1 : torture_assert(tctx, ptr, "valid pointer"); 48 1 : memset(ptr, 0xfe, len); 49 1 : torture_comment(tctx, "anonymous_shared_free(ptr)\n"); 50 1 : anonymous_shared_free(ptr); 51 : 52 1 : memset(&len, 0xFF, sizeof(len)); 53 1 : torture_comment(tctx, "anonymous_shared_allocate(%llu)\n", 54 : (unsigned long long)len); 55 1 : ptr = anonymous_shared_allocate(len); 56 1 : torture_assert(tctx, ptr == NULL, "null pointer"); 57 : 58 0 : return true; 59 : } 60 : 61 : /* local.anonymous_shared test suite creation */ 62 2354 : struct torture_suite *torture_local_util_anonymous_shared(TALLOC_CTX *mem_ctx) 63 : { 64 2354 : struct torture_suite *suite = torture_suite_create(mem_ctx, "anonymous_shared"); 65 : 66 2354 : torture_suite_add_simple_test(suite, "simple", 67 : test_anonymous_shared_simple); 68 : 69 2354 : return suite; 70 : }